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.
15 "golang.org/x/sys/unix"
18 func TestIoctlGetInt(t *testing.T) {
19 f, err := os.Open("/dev/random")
21 t.Fatalf("failed to open device: %v", err)
25 v, err := unix.IoctlGetInt(int(f.Fd()), unix.RNDGETENTCNT)
27 t.Fatalf("failed to perform ioctl: %v", err)
30 t.Logf("%d bits of entropy available", v)
33 func TestTime(t *testing.T) {
35 ut2, err := unix.Time(&ut)
37 t.Fatalf("Time: %v", err)
40 t.Errorf("Time: return value %v should be equal to argument %v", ut2, ut)
45 for i := 0; i < 10; i++ {
46 ut, err = unix.Time(nil)
48 t.Fatalf("Time: %v", err)
52 diff := int64(ut) - now.Unix()
53 if -1 <= diff && diff <= 1 {
58 t.Errorf("Time: return value %v should be nearly equal to time.Now().Unix() %v±1", ut, now.Unix())
61 func TestUtime(t *testing.T) {
70 err := unix.Utime("file1", buf)
72 t.Fatalf("Utime: %v", err)
75 fi, err := os.Stat("file1")
80 if fi.ModTime().Unix() != 12345 {
81 t.Errorf("Utime: failed to change modtime: expected %v, got %v", 12345, fi.ModTime().Unix())
85 func TestPselect(t *testing.T) {
86 if runtime.GOARCH == "ppc64" {
87 t.Skip("pselect issue with structure timespec on AIX 7.2 tl0, skipping test")
90 _, err := unix.Pselect(0, nil, nil, nil, &unix.Timespec{Sec: 0, Nsec: 0}, nil)
92 t.Fatalf("Pselect: %v", err)
95 dur := 2500 * time.Microsecond
96 ts := unix.NsecToTimespec(int64(dur))
98 _, err = unix.Pselect(0, nil, nil, nil, &ts, nil)
99 took := time.Since(start)
101 t.Fatalf("Pselect: %v", err)
105 t.Errorf("Pselect: timeout should have been at least %v, got %v", dur, took)