github.com/fletavendor/sys@v0.0.0-20181107165924-66b7b1311ac8/unix/syscall_netbsd_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  	"bytes"
     9  	"testing"
    10  
    11  	"golang.org/x/sys/unix"
    12  )
    13  
    14  // stringsFromByteSlice converts a sequence of attributes to a []string.
    15  // On NetBSD, each entry consists of a single byte containing the length
    16  // of the attribute name, followed by the attribute name.
    17  // The name is _not_ NULL-terminated.
    18  func stringsFromByteSlice(buf []byte) []string {
    19  	var result []string
    20  	i := 0
    21  	for i < len(buf) {
    22  		next := i + 1 + int(buf[i])
    23  		result = append(result, string(buf[i+1:next]))
    24  		i = next
    25  	}
    26  	return result
    27  }
    28  
    29  func TestSysctlClockinfo(t *testing.T) {
    30  	ci, err := unix.SysctlClockinfo("kern.clockrate")
    31  	if err != nil {
    32  		t.Fatal(err)
    33  	}
    34  	t.Logf("tick = %v, tickadj = %v, hz = %v, profhz = %v, stathz = %v",
    35  		ci.Tick, ci.Tickadj, ci.Hz, ci.Profhz, ci.Stathz)
    36  }
    37  
    38  func TestIoctlPtmget(t *testing.T) {
    39  	fd, err := unix.Open("/dev/ptmx", unix.O_NOCTTY|unix.O_RDWR, 0666)
    40  	if err != nil {
    41  		t.Skip("failed to open /dev/ptmx, skipping test")
    42  	}
    43  	defer unix.Close(fd)
    44  
    45  	ptm, err := unix.IoctlGetPtmget(fd, unix.TIOCPTSNAME)
    46  	if err != nil {
    47  		t.Fatalf("IoctlGetPtmget: %v\n", err)
    48  	}
    49  
    50  	t.Logf("sfd = %v, ptsname = %v", ptm.Sfd, string(ptm.Sn[:bytes.IndexByte(ptm.Sn[:], 0)]))
    51  }