github.com/kooksee/kchain@v0.0.0-20180613035215-4aef51c04906/src/golang.org/x/sys/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 // +build darwin dragonfly freebsd openbsd 6 7 package unix_test 8 9 import ( 10 "os/exec" 11 "runtime" 12 "testing" 13 14 "golang.org/x/sys/unix" 15 ) 16 17 const MNT_WAIT = 1 18 const MNT_NOWAIT = 2 19 20 func TestGetfsstat(t *testing.T) { 21 const flags = MNT_NOWAIT // see golang.org/issue/16937 22 n, err := unix.Getfsstat(nil, flags) 23 if err != nil { 24 t.Fatal(err) 25 } 26 27 data := make([]unix.Statfs_t, n) 28 n2, err := unix.Getfsstat(data, flags) 29 if err != nil { 30 t.Fatal(err) 31 } 32 if n != n2 { 33 t.Errorf("Getfsstat(nil) = %d, but subsequent Getfsstat(slice) = %d", n, n2) 34 } 35 for i, stat := range data { 36 if stat == (unix.Statfs_t{}) { 37 t.Errorf("index %v is an empty Statfs_t struct", i) 38 } 39 } 40 if t.Failed() { 41 for i, stat := range data[:n2] { 42 t.Logf("data[%v] = %+v", i, stat) 43 } 44 mount, err := exec.Command("mount").CombinedOutput() 45 if err != nil { 46 t.Logf("mount: %v\n%s", err, mount) 47 } else { 48 t.Logf("mount: %s", mount) 49 } 50 } 51 } 52 53 func TestSysctlRaw(t *testing.T) { 54 if runtime.GOOS == "openbsd" { 55 t.Skip("kern.proc.pid does not exist on OpenBSD") 56 } 57 58 _, err := unix.SysctlRaw("kern.proc.pid", unix.Getpid()) 59 if err != nil { 60 t.Fatal(err) 61 } 62 }