-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #245 from fromanirh/missing-drm-node-test
gpu: test for github.com//issues/234
- Loading branch information
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// | ||
// Use and distribution licensed under the Apache license version 2. | ||
// | ||
// See the COPYING file in the root project directory for full text. | ||
// | ||
|
||
package gpu_test | ||
|
||
import ( | ||
"errors" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/jaypipes/ghw/pkg/gpu" | ||
"github.com/jaypipes/ghw/pkg/option" | ||
"github.com/jaypipes/ghw/pkg/snapshot" | ||
|
||
"github.com/jaypipes/ghw/testdata" | ||
) | ||
|
||
// testcase for https://github.com/jaypipes/ghw/issues/234 | ||
// if nothing else: demonstrate how to consume snapshots from tests; | ||
// test a boundary condition actually happened in the wild, even though on a VM environment. | ||
func TestGPUWithoutNUMANodeInfo(t *testing.T) { | ||
if _, ok := os.LookupEnv("GHW_TESTING_SKIP_GPU"); ok { | ||
t.Skip("Skipping PCI tests.") | ||
} | ||
|
||
testdataPath, err := testdata.SnapshotsDirectory() | ||
if err != nil { | ||
t.Fatalf("Expected nil err, but got %v", err) | ||
} | ||
|
||
workstationSnapshot := filepath.Join(testdataPath, "linux-amd64-amd-ryzen-1600.tar.gz") | ||
// from now on we use constants reflecting the content of the snapshot we requested, | ||
// which we reviewed beforehand. IOW, you need to know the content of the | ||
// snapshot to fully understand this test. Inspect it using | ||
// GHW_SNAPSHOT_PATH="/path/to/linux-amd64-amd-ryzen-1600.tar.gz" ghwc gpu | ||
|
||
tmpRoot, err := ioutil.TempDir("", "ghw-gpu-testing-*") | ||
if err != nil { | ||
t.Fatalf("Unable to create temporary directory: %v", err) | ||
} | ||
|
||
_, err = snapshot.UnpackInto(workstationSnapshot, tmpRoot, 0) | ||
if err != nil { | ||
t.Fatalf("Unable to unpack %q into %q: %v", workstationSnapshot, tmpRoot, err) | ||
} | ||
defer snapshot.Cleanup(tmpRoot) | ||
|
||
err = os.Remove(filepath.Join(tmpRoot, "/sys/class/drm/card0/device/numa_node")) | ||
if err != nil && !errors.Is(err, os.ErrNotExist) { | ||
t.Fatalf("Cannot remove the NUMA node info: %v", err) | ||
} | ||
|
||
info, err := gpu.New(option.WithChroot(tmpRoot)) | ||
if err != nil { | ||
t.Fatalf("Expected nil err, but got %v", err) | ||
} | ||
if info == nil { | ||
t.Fatalf("Expected non-nil GPUInfo, but got nil") | ||
} | ||
if len(info.GraphicsCards) == 0 { | ||
t.Fatalf("Expected >0 GPU cards, but found 0.") | ||
} | ||
} |
Binary file added
BIN
+33.8 KB
testdata/snapshots/linux-amd64-61797caf7c0b6bca1725ad7975ed4773.tar.gz
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
linux-amd64-61797caf7c0b6bca1725ad7975ed4773.tar.gz |