|
|
@@ -10,6 +10,7 @@ import (
|
|
|
"os/exec"
|
|
|
"runtime"
|
|
|
"testing"
|
|
|
+ "time"
|
|
|
|
|
|
"golang.org/x/sys/unix"
|
|
|
)
|
|
|
@@ -50,6 +51,28 @@ func TestGetfsstat(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func TestSelect(t *testing.T) {
|
|
|
+ err := unix.Select(0, nil, nil, nil, &unix.Timeval{Sec: 0, Usec: 0})
|
|
|
+ if err != nil {
|
|
|
+ t.Fatalf("Select: %v", err)
|
|
|
+ }
|
|
|
+
|
|
|
+ dur := 250 * time.Millisecond
|
|
|
+ tv := unix.NsecToTimeval(int64(dur))
|
|
|
+ start := time.Now()
|
|
|
+ err = unix.Select(0, nil, nil, nil, &tv)
|
|
|
+ took := time.Since(start)
|
|
|
+ if err != nil {
|
|
|
+ t.Fatalf("Select: %v", err)
|
|
|
+ }
|
|
|
+
|
|
|
+ // On some BSDs the actual timeout might also be slightly less than the requested.
|
|
|
+ // Add an acceptable margin to avoid flaky tests.
|
|
|
+ if took < dur*2/3 {
|
|
|
+ t.Errorf("Select: timeout should have been at least %v, got %v", dur, took)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
func TestSysctlRaw(t *testing.T) {
|
|
|
if runtime.GOOS == "openbsd" {
|
|
|
t.Skip("kern.proc.pid does not exist on OpenBSD")
|