File: os_darwin_test.go

package info (click to toggle)
golang-github-klauspost-cpuid 2.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid
  • size: 1,280 kB
  • sloc: asm: 117; sh: 12; makefile: 3
file content (44 lines) | stat: -rw-r--r-- 1,377 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package cpuid

import (
	"os/exec"
	"strconv"
	"strings"
	"testing"
)

// Tests that the returned L1 instruction cache value matches the value returned from
// a call to the OS `sysctl` utility. Skips the test if we can't run it.
func TestDarwinL1ICache(t *testing.T) {
	out, err := exec.Command("/usr/sbin/sysctl", "-n", "hw.l1icachesize").Output()
	if err != nil {
		t.Skipf("cannot run sysctl utility: %v", err)
		return
	}
	v, err := strconv.ParseInt(strings.TrimSpace(string(out)), 10, 0)
	if err != nil {
		t.Skipf("sysctl output %q could not be parsed as int: %v", string(out), err)
		return
	}
	if CPU.Cache.L1I != int(v) {
		t.Fatalf("sysctl output %q did not match CPU.Cache.L1I %d", string(out), CPU.Cache.L1I)
	}
}

// Tests that the returned L1 data cache value matches the value returned from a call
// to the OS `sysctl` utility. Skips the test if we can't run it.
func TestDarwinL1DCache(t *testing.T) {
	out, err := exec.Command("/usr/sbin/sysctl", "-n", "hw.l1dcachesize").Output()
	if err != nil {
		t.Skipf("cannot run sysctl utility: %v", err)
		return
	}
	v, err := strconv.ParseInt(strings.TrimSpace(string(out)), 10, 0)
	if err != nil {
		t.Skipf("sysctl output %q could not be parsed as int: %v", string(out), err)
		return
	}
	if CPU.Cache.L1D != int(v) {
		t.Fatalf("sysctl output %q did not match CPU.Cache.L1D %d", string(out), CPU.Cache.L1D)
	}
}