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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build darwin || dragonfly || freebsd || netbsd || openbsd
package unix_test
import (
"runtime"
"testing"
"time"
"golang.org/x/sys/unix"
)
func TestSysctlRaw(t *testing.T) {
switch runtime.GOOS {
case "netbsd", "openbsd":
t.Skipf("kern.proc.pid does not exist on %s", runtime.GOOS)
}
_, err := unix.SysctlRaw("kern.proc.pid", unix.Getpid())
if err != nil {
t.Fatal(err)
}
}
func TestSysctlUint32(t *testing.T) {
maxproc, err := unix.SysctlUint32("kern.maxproc")
if err != nil {
t.Fatal(err)
}
t.Logf("kern.maxproc: %v", maxproc)
}
func TestSysctlClockinfo(t *testing.T) {
ci, err := unix.SysctlClockinfo("kern.clockrate")
if err != nil {
if runtime.GOOS == "openbsd" && (err == unix.ENOMEM || err == unix.EIO) {
if osrev, _ := unix.SysctlUint32("kern.osrevision"); osrev <= 202010 {
// SysctlClockinfo should fail gracefully due to a struct size
// mismatch on OpenBSD 6.8 and earlier, see
// https://golang.org/issue/47629
return
}
}
t.Fatal(err)
}
t.Logf("tick = %v, hz = %v, profhz = %v, stathz = %v",
ci.Tick, ci.Hz, ci.Profhz, ci.Stathz)
}
func TestSysctlTimeval(t *testing.T) {
tv, err := unix.SysctlTimeval("kern.boottime")
if err != nil {
t.Fatal(err)
}
t.Logf("boottime = %v", time.Unix(tv.Unix()))
}
|