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