-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement test for Darwin icache/dcache Check that the struct members for the L1 cache match the values provided by the OS sysctl utility * Use dcache instead of icache for L1D
- Loading branch information
1 parent
e32428e
commit 1061e99
Showing
2 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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) | ||
} | ||
} |