golang.org/x/sys@v0.9.0/unix/syscall_bsd_test.go (about) 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 // +build darwin dragonfly freebsd netbsd openbsd 7 8 package unix_test 9 10 import ( 11 "runtime" 12 "testing" 13 "time" 14 15 "golang.org/x/sys/unix" 16 ) 17 18 func TestSysctlRaw(t *testing.T) { 19 switch runtime.GOOS { 20 case "netbsd", "openbsd": 21 t.Skipf("kern.proc.pid does not exist on %s", runtime.GOOS) 22 } 23 24 _, err := unix.SysctlRaw("kern.proc.pid", unix.Getpid()) 25 if err != nil { 26 t.Fatal(err) 27 } 28 } 29 30 func TestSysctlUint32(t *testing.T) { 31 maxproc, err := unix.SysctlUint32("kern.maxproc") 32 if err != nil { 33 t.Fatal(err) 34 } 35 t.Logf("kern.maxproc: %v", maxproc) 36 } 37 38 func TestSysctlClockinfo(t *testing.T) { 39 ci, err := unix.SysctlClockinfo("kern.clockrate") 40 if err != nil { 41 if runtime.GOOS == "openbsd" && (err == unix.ENOMEM || err == unix.EIO) { 42 if osrev, _ := unix.SysctlUint32("kern.osrevision"); osrev <= 202010 { 43 // SysctlClockinfo should fail gracefully due to a struct size 44 // mismatch on OpenBSD 6.8 and earlier, see 45 // https://golang.org/issue/47629 46 return 47 } 48 } 49 t.Fatal(err) 50 } 51 t.Logf("tick = %v, hz = %v, profhz = %v, stathz = %v", 52 ci.Tick, ci.Hz, ci.Profhz, ci.Stathz) 53 } 54 55 func TestSysctlTimeval(t *testing.T) { 56 tv, err := unix.SysctlTimeval("kern.boottime") 57 if err != nil { 58 t.Fatal(err) 59 } 60 t.Logf("boottime = %v", time.Unix(tv.Unix())) 61 }