github.com/alexis81/domosgo@v0.0.0-20191016125037-5aee90a434af/Domos/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 "time" 14 15 "golang.org/x/sys/unix" 16 ) 17 18 const MNT_WAIT = 1 19 const MNT_NOWAIT = 2 20 21 func TestGetfsstat(t *testing.T) { 22 const flags = MNT_NOWAIT // see golang.org/issue/16937 23 n, err := unix.Getfsstat(nil, flags) 24 if err != nil { 25 t.Fatal(err) 26 } 27 28 data := make([]unix.Statfs_t, n) 29 n2, err := unix.Getfsstat(data, flags) 30 if err != nil { 31 t.Fatal(err) 32 } 33 if n != n2 { 34 t.Errorf("Getfsstat(nil) = %d, but subsequent Getfsstat(slice) = %d", n, n2) 35 } 36 for i, stat := range data { 37 if stat == (unix.Statfs_t{}) { 38 t.Errorf("index %v is an empty Statfs_t struct", i) 39 } 40 } 41 if t.Failed() { 42 for i, stat := range data[:n2] { 43 t.Logf("data[%v] = %+v", i, stat) 44 } 45 mount, err := exec.Command("mount").CombinedOutput() 46 if err != nil { 47 t.Logf("mount: %v\n%s", err, mount) 48 } else { 49 t.Logf("mount: %s", mount) 50 } 51 } 52 } 53 54 func TestSelect(t *testing.T) { 55 err := unix.Select(0, nil, nil, nil, &unix.Timeval{Sec: 0, Usec: 0}) 56 if err != nil { 57 t.Fatalf("Select: %v", err) 58 } 59 60 dur := 250 * time.Millisecond 61 tv := unix.NsecToTimeval(int64(dur)) 62 start := time.Now() 63 err = unix.Select(0, nil, nil, nil, &tv) 64 took := time.Since(start) 65 if err != nil { 66 t.Fatalf("Select: %v", err) 67 } 68 69 // On some BSDs the actual timeout might also be slightly less than the requested. 70 // Add an acceptable margin to avoid flaky tests. 71 if took < dur*2/3 { 72 t.Errorf("Select: timeout should have been at least %v, got %v", dur, took) 73 } 74 } 75 76 func TestSysctlRaw(t *testing.T) { 77 if runtime.GOOS == "openbsd" { 78 t.Skip("kern.proc.pid does not exist on OpenBSD") 79 } 80 81 _, err := unix.SysctlRaw("kern.proc.pid", unix.Getpid()) 82 if err != nil { 83 t.Fatal(err) 84 } 85 } 86 87 func TestSysctlUint32(t *testing.T) { 88 maxproc, err := unix.SysctlUint32("kern.maxproc") 89 if err != nil { 90 t.Fatal(err) 91 } 92 t.Logf("kern.maxproc: %v", maxproc) 93 }