Skip to content

Commit

Permalink
topologyinfo: initial cpus test
Browse files Browse the repository at this point in the history
Bootstrap the topologyinfo/cpus suite

Signed-off-by: Francesco Romani <[email protected]>
  • Loading branch information
ffromani committed Jul 24, 2020
1 parent 6074d17 commit 4bb9f06
Show file tree
Hide file tree
Showing 17 changed files with 2,460 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.13
require (
github.com/disiqueira/gotree v1.0.0
github.com/fromanirh/cpuset v0.0.0-20200530094055-76ce61745438
github.com/google/go-cmp v0.2.0
github.com/spf13/cobra v1.0.0
github.com/spf13/pflag v1.0.3
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfb
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
Expand Down
80 changes: 80 additions & 0 deletions pkg/topologyinfo/cpus/cpus_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package cpus

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"

"testing"

"github.com/fromanirh/cpuset"
"github.com/fromanirh/numalign/pkg/fakesysfs"
"github.com/google/go-cmp/cmp"
)

func TestCPUsSingleNuma(t *testing.T) {
base, err := ioutil.TempDir("/tmp", "fakesysfs")
if err != nil {
t.Errorf("error creating temp base dir: %v", err)
}
fs, err := fakesysfs.NewFakeSysfs(base)
if err != nil {
t.Errorf("error creating fakesysfs: %v", err)
}
t.Logf("sysfs at %q", fs.Base())

allCpus := []int{0, 1, 2, 3, 4, 5, 6, 7}
cpuList := cpuset.Unparse(allCpus) + "\n"

sysDevs := fs.AddTree("sys", "devices")
devSys := sysDevs.Add("system", nil)
devNode := devSys.Add("node", nil)
devNode.Add("node0", map[string]string{
"cpulist": cpuList,
})
devCpu := devSys.Add("cpu", map[string]string{
"present": cpuList,
"online": cpuList,
})
for _, cpuID := range allCpus {
devCpu.Add(fmt.Sprintf("cpu%d", cpuID), nil).Add("topology", map[string]string{
"thread_siblings_list": cpuList,
"core_siblings_list": cpuList,
"physical_package_id": "0\n",
})
}

err = fs.Setup()
if err != nil {
t.Errorf("error setting up fakesysfs: %v", err)
}

cpus, err := NewCPUs(filepath.Join(fs.Base(), "sys"))
if err != nil {
t.Errorf("error in NewCPU: %v", err)
}
if cpus.NUMANodes != 1 || len(cpus.NUMANodeCPUs) != 1 {
t.Errorf("NUMA Nodes miscount: expected %d detected %d/%d", 1, cpus.NUMANodes, len(cpus.NUMANodeCPUs))
}

testingCpus := CPUIdList(allCpus)
if !cmp.Equal(cpus.Present, testingCpus) {
t.Errorf("not all cpus present %v vs %v", cpus.Present, testingCpus)
}
if !cmp.Equal(cpus.Online, testingCpus) {
t.Errorf("not all cpus online: %v vs %v", cpus.Online, testingCpus)
}
if !cmp.Equal(cpus.NUMANodeCPUs[0], testingCpus) {
t.Errorf("not all cpus on NUMA#0: %v vs %v", cpus.NUMANodeCPUs[0], testingCpus)
}

if _, ok := os.LookupEnv("TOPOLOGYINFO_TEST_KEEP_TREE"); ok {
t.Logf("found environment variable, keeping fake tree")
} else {
err = fs.Teardown()
if err != nil {
t.Errorf("error tearing down fakesysfs: %v", err)
}
}
}
27 changes: 27 additions & 0 deletions vendor/github.com/google/go-cmp/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4bb9f06

Please sign in to comment.