...
1
2
3
4
5
6
7 package unix_test
8
9 import (
10 "runtime"
11 "testing"
12 "time"
13
14 "golang.org/x/sys/unix"
15 )
16
17 func TestSysctlRaw(t *testing.T) {
18 switch runtime.GOOS {
19 case "netbsd", "openbsd":
20 t.Skipf("kern.proc.pid does not exist on %s", runtime.GOOS)
21 }
22
23 _, err := unix.SysctlRaw("kern.proc.pid", unix.Getpid())
24 if err != nil {
25 t.Fatal(err)
26 }
27 }
28
29 func TestSysctlUint32(t *testing.T) {
30 maxproc, err := unix.SysctlUint32("kern.maxproc")
31 if err != nil {
32 t.Fatal(err)
33 }
34 t.Logf("kern.maxproc: %v", maxproc)
35 }
36
37 func TestSysctlClockinfo(t *testing.T) {
38 ci, err := unix.SysctlClockinfo("kern.clockrate")
39 if err != nil {
40 if runtime.GOOS == "openbsd" && (err == unix.ENOMEM || err == unix.EIO) {
41 if osrev, _ := unix.SysctlUint32("kern.osrevision"); osrev <= 202010 {
42
43
44
45 return
46 }
47 }
48 t.Fatal(err)
49 }
50 t.Logf("tick = %v, hz = %v, profhz = %v, stathz = %v",
51 ci.Tick, ci.Hz, ci.Profhz, ci.Stathz)
52 }
53
54 func TestSysctlTimeval(t *testing.T) {
55 tv, err := unix.SysctlTimeval("kern.boottime")
56 if err != nil {
57 t.Fatal(err)
58 }
59 t.Logf("boottime = %v", time.Unix(tv.Unix()))
60 }
61
View as plain text