Skip to content

Commit

Permalink
Add s390/s390x CPU topology test
Browse files Browse the repository at this point in the history
  • Loading branch information
madeelibm committed Jun 13, 2024
1 parent 7ce7be1 commit 3eb1be1
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 7 deletions.
113 changes: 108 additions & 5 deletions machine/topology_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"os"
"path/filepath"
"reflect"
"runtime"
"sort"
"testing"

Expand Down Expand Up @@ -426,11 +427,113 @@ func TestTopologyWithNodesWithoutCPU(t *testing.T) {
}

func TestTopologyOnSystemZ(t *testing.T) {
machineArch = "s390" // overwrite package variable
nodes, cores, err := GetTopology(&fakesysfs.FakeSysFs{})
assert.Nil(t, err)
assert.Nil(t, nodes)
assert.NotNil(t, cores)
if runtime.GOARCH != "s390x" {
t.Skip("skipping TestTopologyOnSystemZ due to wrong architecture")
} else {
machineArch = "s390" // overwrite package variable
sysFs := &fakesysfs.FakeSysFs{}

c := sysfs.CacheInfo{
Id: 0,
Size: 128 * 1024,
Type: "Data",
Level: 0,
Cpus: 2,
}
sysFs.SetCacheInfo(c)

nodesPaths := []string{}
sysFs.SetNodesPaths(nodesPaths, nil)

cpusPaths := map[string][]string{
"/sys/devices/system/cpu": {
"/sys/devices/system/cpu/cpu0",
"/sys/devices/system/cpu/cpu1",
"/sys/devices/system/cpu/cpu2",
"/sys/devices/system/cpu/cpu3",
},
}
sysFs.SetCPUsPaths(cpusPaths, nil)

coreThread := map[string]string{
"/sys/devices/system/cpu/cpu0": "0",
"/sys/devices/system/cpu/cpu1": "1",
"/sys/devices/system/cpu/cpu2": "0",
"/sys/devices/system/cpu/cpu3": "1",
}
sysFs.SetCoreThreads(coreThread, nil)

physicalPackageIDs := map[string]string{
"/sys/devices/system/cpu/cpu0": "0",
"/sys/devices/system/cpu/cpu1": "1",
"/sys/devices/system/cpu/cpu2": "0",
"/sys/devices/system/cpu/cpu3": "1",
}
sysFs.SetPhysicalPackageIDs(physicalPackageIDs, nil)

bookIDs := map[string]string{
"/sys/devices/system/cpu/cpu0": "1",
"/sys/devices/system/cpu/cpu1": "1",
"/sys/devices/system/cpu/cpu2": "1",
"/sys/devices/system/cpu/cpu3": "1",
}
sysFs.SetBookIDs(bookIDs, nil)

drawerIDs := map[string]string{
"/sys/devices/system/cpu/cpu0": "0",
"/sys/devices/system/cpu/cpu1": "0",
"/sys/devices/system/cpu/cpu2": "0",
"/sys/devices/system/cpu/cpu3": "0",
}
sysFs.SetDrawerIDs(drawerIDs, nil)

topology, numCores, err := GetTopology(sysFs)
assert.Nil(t, err)
assert.Equal(t, 2, len(topology))
assert.Equal(t, 4, numCores)

topologyJSON1, err := json.Marshal(topology[0])
assert.Nil(t, err)
topologyJSON2, err := json.Marshal(topology[1])
assert.Nil(t, err)

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}`
expectedTopology2 := `
{
"node_id":1,
"memory":0,
"hugepages":null,
"distances": null,
"cores":[
{
"core_id":1,
"thread_ids":[
1,
3
],
"caches":[
{
"id": 0,
"size":131072,
"type":"Data",
"level":0
}
],
"socket_id": 1,
"book_id": "1",
"drawer_id": "0",
"uncore_caches": null
}
],
"caches":null
}`

json1 := string(topologyJSON1)
json2 := string(topologyJSON2)

assert.JSONEq(t, expectedTopology1, json1)
assert.JSONEq(t, expectedTopology2, json2)
}
}

func TestMemoryInfo(t *testing.T) {
Expand Down
10 changes: 10 additions & 0 deletions utils/sysfs/fakesysfs/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,16 @@ func (fs *FakeSysFs) SetPhysicalPackageIDs(physicalPackageIDs map[string]string,
fs.physicalPackageIDErr = physicalPackageIDErrors
}

func (fs *FakeSysFs) SetBookIDs(bookIDs map[string]string, bookIDErrors map[string]error) {
fs.bookIDs = bookIDs
fs.bookIDErr = bookIDErrors
}

func (fs *FakeSysFs) SetDrawerIDs(drawerIDs map[string]string, drawerIDErrors map[string]error) {
fs.drawerIDs = drawerIDs
fs.drawerIDErr = drawerIDErrors
}

func (fs *FakeSysFs) SetMemory(memTotal string, err error) {
fs.memTotal = memTotal
fs.memErr = err
Expand Down
4 changes: 2 additions & 2 deletions utils/sysfs/sysfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (fs *realSysFs) GetBookID(cpuPath string) (string, error) {
if err != nil {
return "", err
}
return strings.TrimSpace(string(bookID)), err
return strings.TrimSpace(string(bookID)), nil
}

func (fs *realSysFs) GetDrawerID(cpuPath string) (string, error) {
Expand All @@ -186,7 +186,7 @@ func (fs *realSysFs) GetDrawerID(cpuPath string) (string, error) {
if err != nil {
return "", err
}
return strings.TrimSpace(string(drawerID)), err
return strings.TrimSpace(string(drawerID)), nil
}

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

0 comments on commit 3eb1be1

Please sign in to comment.