github.com/Andyfoo/golang/x/sys@v0.0.0-20190901054642-57c1bf301704/unix/syscall_openbsd_test.go (about)

     1  // Copyright 2018 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  package unix_test
     6  
     7  import (
     8  	"testing"
     9  	"time"
    10  
    11  	"github.com/Andyfoo/golang/x/sys/unix"
    12  )
    13  
    14  func TestPpoll(t *testing.T) {
    15  	f, cleanup := mktmpfifo(t)
    16  	defer cleanup()
    17  
    18  	const timeout = 100 * time.Millisecond
    19  
    20  	ok := make(chan bool, 1)
    21  	go func() {
    22  		select {
    23  		case <-time.After(10 * timeout):
    24  			t.Errorf("Ppoll: failed to timeout after %d", 10*timeout)
    25  		case <-ok:
    26  		}
    27  	}()
    28  
    29  	fds := []unix.PollFd{{Fd: int32(f.Fd()), Events: unix.POLLIN}}
    30  	timeoutTs := unix.NsecToTimespec(int64(timeout))
    31  	n, err := unix.Ppoll(fds, &timeoutTs, nil)
    32  	ok <- true
    33  	if err != nil {
    34  		t.Errorf("Ppoll: unexpected error: %v", err)
    35  		return
    36  	}
    37  	if n != 0 {
    38  		t.Errorf("Ppoll: wrong number of events: got %v, expected %v", n, 0)
    39  		return
    40  	}
    41  }
    42  
    43  func TestSysctlClockinfo(t *testing.T) {
    44  	ci, err := unix.SysctlClockinfo("kern.clockrate")
    45  	if err != nil {
    46  		t.Fatal(err)
    47  	}
    48  	t.Logf("tick = %v, tickadj = %v, hz = %v, profhz = %v, stathz = %v",
    49  		ci.Tick, ci.Tickadj, ci.Hz, ci.Profhz, ci.Stathz)
    50  }
    51  
    52  func TestSysctlUvmexp(t *testing.T) {
    53  	uvm, err := unix.SysctlUvmexp("vm.uvmexp")
    54  	if err != nil {
    55  		t.Fatal(err)
    56  	}
    57  	t.Logf("free = %v", uvm.Free)
    58  }