| 1 |
// Copyright 2014 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
//go:build darwin || dragonfly || freebsd || netbsd || openbsd |
| 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 |
// SysctlClockinfo should fail gracefully due to a struct size |
| 43 |
// mismatch on OpenBSD 6.8 and earlier, see |
| 44 |
// https://golang.org/issue/47629 |
| 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 |
} |