package discovery import ( "os" "path/filepath" "testing" ) func TestMemoryBandwidthIsMeasured(t *testing.T) { if testing.Short() { t.Skip("reads half a gigabyte") } bw := MeasureMemoryBandwidth() // Any machine running this reads more than a gigabyte a second and less // than a few terabytes, and one core no more than all of them. if bw.All < 1 || bw.All > 5000 || bw.Core < 0.5 || bw.Core > bw.All { t.Errorf("measured %.1f GB/s, %.1f on one core", bw.All, bw.Core) } t.Logf("%.1f GB/s, %.1f on one core", bw.All, bw.Core) } func TestTheLastCacheIsReadFromSys(t *testing.T) { root := t.TempDir() for path, size := range map[string]string{"cpu0/cache/index0/size": "48K", "cpu0/cache/index3/size": "96M"} { p := filepath.Join(root, path) _ = os.MkdirAll(filepath.Dir(p), 0o755) _ = os.WriteFile(p, []byte(size+"\n"), 0o644) } if got := lastCacheBytes(root); got != 96<<20 { t.Errorf("%d", got) } }