MCPcopy
hub / github.com/jaypipes/ghw / TestCheckCPUTopologyFilesForOfflineCPU

Function TestCheckCPUTopologyFilesForOfflineCPU

pkg/cpu/cpu_linux_test.go:87–132  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

85}
86
87func TestCheckCPUTopologyFilesForOfflineCPU(t *testing.T) {
88 if _, ok := os.LookupEnv("GHW_TESTING_SKIP_CPU"); ok {
89 t.Skip("Skipping CPU tests.")
90 }
91
92 testdataPath, err := testdata.SnapshotsDirectory()
93 if err != nil {
94 t.Fatalf("Expected nil err, but got %v", err)
95 }
96
97 offlineCPUSnapshot := filepath.Join(testdataPath, "linux-amd64-offlineCPUs.tar.gz")
98
99 // Capture stderr
100 rErr, wErr, err := os.Pipe()
101 if err != nil {
102 t.Fatalf("Cannot pipe StdErr. %v", err)
103 }
104 os.Stderr = wErr
105
106 unpackDir := t.TempDir()
107 err = snapshot.UnpackInto(offlineCPUSnapshot, unpackDir)
108 if err != nil {
109 t.Fatal(err)
110 }
111
112 info, err := cpu.New(ghw.WithChroot(unpackDir))
113 if err != nil {
114 t.Fatalf("Expected nil err, but got %v", err)
115 }
116 if info == nil {
117 t.Fatalf("Expected non-nil CPUInfo, but got nil")
118 }
119
120 if len(info.Processors) == 0 {
121 t.Fatalf("Expected >0 processors but got 0.")
122 }
123 wErr.Close()
124 var bufErr bytes.Buffer
125 if _, err := io.Copy(&bufErr, rErr); err != nil {
126 t.Fatalf("Failed to copy data to buffer: %v", err)
127 }
128 errorOutput := bufErr.String()
129 if strings.Contains(errorOutput, "WARNING: failed to read int from file:") {
130 t.Fatalf("Unexpected warning related to missing files under topology directory was reported")
131 }
132}
133
134func TestNumCoresAmongOfflineCPUs(t *testing.T) {
135 if _, ok := os.LookupEnv("GHW_TESTING_SKIP_CPU"); ok {

Callers

nothing calls this directly

Calls 5

SnapshotsDirectoryFunction · 0.92
UnpackIntoFunction · 0.92
NewFunction · 0.92
CloseMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…