syscall_solaris_test.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // Copyright 2017 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. // +build solaris
  5. package unix_test
  6. import (
  7. "os"
  8. "os/exec"
  9. "testing"
  10. "time"
  11. "golang.org/x/sys/unix"
  12. )
  13. func TestSelect(t *testing.T) {
  14. n, err := unix.Select(0, nil, nil, nil, &unix.Timeval{Sec: 0, Usec: 0})
  15. if err != nil {
  16. t.Fatalf("Select: %v", err)
  17. }
  18. if n != 0 {
  19. t.Fatalf("Select: expected 0 ready file descriptors, got %v", n)
  20. }
  21. dur := 150 * time.Millisecond
  22. tv := unix.NsecToTimeval(int64(dur))
  23. start := time.Now()
  24. n, err = unix.Select(0, nil, nil, nil, &tv)
  25. took := time.Since(start)
  26. if err != nil {
  27. t.Fatalf("Select: %v", err)
  28. }
  29. if n != 0 {
  30. t.Fatalf("Select: expected 0 ready file descriptors, got %v", n)
  31. }
  32. if took < dur {
  33. t.Errorf("Select: timeout should have been at least %v, got %v", dur, took)
  34. }
  35. rr, ww, err := os.Pipe()
  36. if err != nil {
  37. t.Fatal(err)
  38. }
  39. defer rr.Close()
  40. defer ww.Close()
  41. if _, err := ww.Write([]byte("HELLO GOPHER")); err != nil {
  42. t.Fatal(err)
  43. }
  44. rFdSet := &unix.FdSet{}
  45. fd := rr.Fd()
  46. // FD_SET(fd, rFdSet)
  47. rFdSet.Bits[fd/unix.NFDBITS] |= (1 << (fd % unix.NFDBITS))
  48. n, err = unix.Select(int(fd+1), rFdSet, nil, nil, nil)
  49. if err != nil {
  50. t.Fatalf("Select: %v", err)
  51. }
  52. if n != 1 {
  53. t.Fatalf("Select: expected 1 ready file descriptors, got %v", n)
  54. }
  55. }
  56. func TestStatvfs(t *testing.T) {
  57. if err := unix.Statvfs("", nil); err == nil {
  58. t.Fatal(`Statvfs("") expected failure`)
  59. }
  60. statvfs := unix.Statvfs_t{}
  61. if err := unix.Statvfs("/", &statvfs); err != nil {
  62. t.Errorf(`Statvfs("/") failed: %v`, err)
  63. }
  64. if t.Failed() {
  65. mount, err := exec.Command("mount").CombinedOutput()
  66. if err != nil {
  67. t.Logf("mount: %v\n%s", err, mount)
  68. } else {
  69. t.Logf("mount: %s", mount)
  70. }
  71. }
  72. }