github.com/jaypipes/ghw@v0.21.1/pkg/gpu/gpu_test.go (about)

     1  //
     2  // Use and distribution licensed under the Apache license version 2.
     3  //
     4  // See the COPYING file in the root project directory for full text.
     5  //
     6  
     7  package gpu_test
     8  
     9  import (
    10  	"errors"
    11  	"os"
    12  	"testing"
    13  
    14  	"github.com/jaypipes/ghw/pkg/gpu"
    15  	"github.com/jaypipes/ghw/testdata"
    16  )
    17  
    18  func TestGPU(t *testing.T) {
    19  	if _, ok := os.LookupEnv("GHW_TESTING_SKIP_GPU"); ok {
    20  		t.Skip("Skipping GPU tests.")
    21  	}
    22  	if _, err := os.Stat("/sys/class/drm"); errors.Is(err, os.ErrNotExist) {
    23  		t.Skip("Skipping GPU tests. The environment has no /sys/class/drm directory.")
    24  	}
    25  
    26  	t.Setenv("PCIDB_PATH", testdata.PCIDBChroot())
    27  
    28  	info, err := gpu.New()
    29  	if err != nil {
    30  		t.Fatalf("Expected no error creating GPUInfo, but got %v", err)
    31  	}
    32  
    33  	if len(info.GraphicsCards) == 0 {
    34  		t.Fatalf("Expected >0 GPU cards, but found 0.")
    35  	}
    36  
    37  	for _, card := range info.GraphicsCards {
    38  		if card.Address != "" {
    39  			di := card.DeviceInfo
    40  			if di == nil {
    41  				t.Fatalf("Expected card with address %s to have non-nil DeviceInfo.", card.Address)
    42  			}
    43  		}
    44  		// TODO(jaypipes): Add Card.Node test when using injected sysfs for testing
    45  	}
    46  }