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// +build darwin dragonfly freebsd openbsd 6 7package unix_test 8 9import ( 10 "os/exec" 11 "runtime" 12 "testing" 13 14 "golang.org/x/sys/unix" 15) 16 17func TestGetfsstat(t *testing.T) { 18 n, err := unix.Getfsstat(nil, unix.MNT_NOWAIT) 19 if err != nil { 20 t.Fatal(err) 21 } 22 23 data := make([]unix.Statfs_t, n) 24 n2, err := unix.Getfsstat(data, unix.MNT_NOWAIT) 25 if err != nil { 26 t.Fatal(err) 27 } 28 if n != n2 { 29 t.Errorf("Getfsstat(nil) = %d, but subsequent Getfsstat(slice) = %d", n, n2) 30 } 31 for i, stat := range data { 32 if stat == (unix.Statfs_t{}) { 33 t.Errorf("index %v is an empty Statfs_t struct", i) 34 } 35 } 36 if t.Failed() { 37 for i, stat := range data[:n2] { 38 t.Logf("data[%v] = %+v", i, stat) 39 } 40 mount, err := exec.Command("mount").CombinedOutput() 41 if err != nil { 42 t.Logf("mount: %v\n%s", err, mount) 43 } else { 44 t.Logf("mount: %s", mount) 45 } 46 } 47} 48 49func TestSysctlRaw(t *testing.T) { 50 if runtime.GOOS == "openbsd" { 51 t.Skip("kern.proc.pid does not exist on OpenBSD") 52 } 53 54 _, err := unix.SysctlRaw("kern.proc.pid", unix.Getpid()) 55 if err != nil { 56 t.Fatal(err) 57 } 58} 59 60func TestSysctlUint32(t *testing.T) { 61 maxproc, err := unix.SysctlUint32("kern.maxproc") 62 if err != nil { 63 t.Fatal(err) 64 } 65 t.Logf("kern.maxproc: %v", maxproc) 66} 67 68func TestSysctlClockinfo(t *testing.T) { 69 ci, err := unix.SysctlClockinfo("kern.clockrate") 70 if err != nil { 71 t.Fatal(err) 72 } 73 t.Logf("tick = %v, hz = %v, profhz = %v, stathz = %v", 74 ci.Tick, ci.Hz, ci.Profhz, ci.Stathz) 75} 76