Skip to content

Commit 85f8d74

Browse files
committed
Add s390/s390x CPU topology test
1 parent 61ca49d commit 85f8d74

File tree

3 files changed

+120
-7
lines changed

3 files changed

+120
-7
lines changed

machine/topology_test.go

Lines changed: 108 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"os"
2020
"path/filepath"
2121
"reflect"
22+
"runtime"
2223
"sort"
2324
"testing"
2425

@@ -426,11 +427,113 @@ func TestTopologyWithNodesWithoutCPU(t *testing.T) {
426427
}
427428

428429
func TestTopologyOnSystemZ(t *testing.T) {
429-
machineArch = "s390" // overwrite package variable
430-
nodes, cores, err := GetTopology(&fakesysfs.FakeSysFs{})
431-
assert.Nil(t, err)
432-
assert.Nil(t, nodes)
433-
assert.NotNil(t, cores)
430+
if runtime.GOARCH != "s390x" {
431+
t.Skip("skipping TestTopologyOnSystemZ due to wrong architecture")
432+
} else {
433+
machineArch = "s390" // overwrite package variable
434+
sysFs := &fakesysfs.FakeSysFs{}
435+
436+
c := sysfs.CacheInfo{
437+
Id: 0,
438+
Size: 128 * 1024,
439+
Type: "Data",
440+
Level: 0,
441+
Cpus: 2,
442+
}
443+
sysFs.SetCacheInfo(c)
444+
445+
nodesPaths := []string{}
446+
sysFs.SetNodesPaths(nodesPaths, nil)
447+
448+
cpusPaths := map[string][]string{
449+
"/sys/devices/system/cpu": {
450+
"/sys/devices/system/cpu/cpu0",
451+
"/sys/devices/system/cpu/cpu1",
452+
"/sys/devices/system/cpu/cpu2",
453+
"/sys/devices/system/cpu/cpu3",
454+
},
455+
}
456+
sysFs.SetCPUsPaths(cpusPaths, nil)
457+
458+
coreThread := map[string]string{
459+
"/sys/devices/system/cpu/cpu0": "0",
460+
"/sys/devices/system/cpu/cpu1": "1",
461+
"/sys/devices/system/cpu/cpu2": "0",
462+
"/sys/devices/system/cpu/cpu3": "1",
463+
}
464+
sysFs.SetCoreThreads(coreThread, nil)
465+
466+
physicalPackageIDs := map[string]string{
467+
"/sys/devices/system/cpu/cpu0": "0",
468+
"/sys/devices/system/cpu/cpu1": "1",
469+
"/sys/devices/system/cpu/cpu2": "0",
470+
"/sys/devices/system/cpu/cpu3": "1",
471+
}
472+
sysFs.SetPhysicalPackageIDs(physicalPackageIDs, nil)
473+
474+
bookIDs := map[string]string{
475+
"/sys/devices/system/cpu/cpu0": "1",
476+
"/sys/devices/system/cpu/cpu1": "1",
477+
"/sys/devices/system/cpu/cpu2": "1",
478+
"/sys/devices/system/cpu/cpu3": "1",
479+
}
480+
sysFs.SetBookIDs(bookIDs, nil)
481+
482+
drawerIDs := map[string]string{
483+
"/sys/devices/system/cpu/cpu0": "0",
484+
"/sys/devices/system/cpu/cpu1": "0",
485+
"/sys/devices/system/cpu/cpu2": "0",
486+
"/sys/devices/system/cpu/cpu3": "0",
487+
}
488+
sysFs.SetDrawerIDs(drawerIDs, nil)
489+
490+
topology, numCores, err := GetTopology(sysFs)
491+
assert.Nil(t, err)
492+
assert.Equal(t, 2, len(topology))
493+
assert.Equal(t, 4, numCores)
494+
495+
topologyJSON1, err := json.Marshal(topology[0])
496+
assert.Nil(t, err)
497+
topologyJSON2, err := json.Marshal(topology[1])
498+
assert.Nil(t, err)
499+
500+
expectedTopology1 := `{"node_id":0,"memory":0,"hugepages":null,"distances":null,"cores":[{"core_id":0,"thread_ids":[0,2],"caches":[{"id":0, "size":131072,"type":"Data","level":0}], "socket_id": 0, "book_id":"1", "drawer_id":"0", "uncore_caches":null}],"caches":null}`
501+
expectedTopology2 := `
502+
{
503+
"node_id":1,
504+
"memory":0,
505+
"hugepages":null,
506+
"distances": null,
507+
"cores":[
508+
{
509+
"core_id":1,
510+
"thread_ids":[
511+
1,
512+
3
513+
],
514+
"caches":[
515+
{
516+
"id": 0,
517+
"size":131072,
518+
"type":"Data",
519+
"level":0
520+
}
521+
],
522+
"socket_id": 1,
523+
"book_id": "1",
524+
"drawer_id": "0",
525+
"uncore_caches": null
526+
}
527+
],
528+
"caches":null
529+
}`
530+
531+
json1 := string(topologyJSON1)
532+
json2 := string(topologyJSON2)
533+
534+
assert.JSONEq(t, expectedTopology1, json1)
535+
assert.JSONEq(t, expectedTopology2, json2)
536+
}
434537
}
435538

436539
func TestMemoryInfo(t *testing.T) {

utils/sysfs/fakesysfs/fake.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,16 @@ func (fs *FakeSysFs) SetPhysicalPackageIDs(physicalPackageIDs map[string]string,
199199
fs.physicalPackageIDErr = physicalPackageIDErrors
200200
}
201201

202+
func (fs *FakeSysFs) SetBookIDs(bookIDs map[string]string, bookIDErrors map[string]error) {
203+
fs.bookIDs = bookIDs
204+
fs.bookIDErr = bookIDErrors
205+
}
206+
207+
func (fs *FakeSysFs) SetDrawerIDs(drawerIDs map[string]string, drawerIDErrors map[string]error) {
208+
fs.drawerIDs = drawerIDs
209+
fs.drawerIDErr = drawerIDErrors
210+
}
211+
202212
func (fs *FakeSysFs) SetMemory(memTotal string, err error) {
203213
fs.memTotal = memTotal
204214
fs.memErr = err

utils/sysfs/sysfs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func (fs *realSysFs) GetBookID(cpuPath string) (string, error) {
177177
if err != nil {
178178
return "", err
179179
}
180-
return strings.TrimSpace(string(bookID)), err
180+
return strings.TrimSpace(string(bookID)), nil
181181
}
182182

183183
func (fs *realSysFs) GetDrawerID(cpuPath string) (string, error) {
@@ -186,7 +186,7 @@ func (fs *realSysFs) GetDrawerID(cpuPath string) (string, error) {
186186
if err != nil {
187187
return "", err
188188
}
189-
return strings.TrimSpace(string(drawerID)), err
189+
return strings.TrimSpace(string(drawerID)), nil
190190
}
191191

192192
func (fs *realSysFs) GetMemInfo(nodePath string) (string, error) {

0 commit comments

Comments
 (0)