syscall_netbsd_test.go 1.3 KB

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