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