Commit df29b912 authored by Tobias Klauser's avatar Tobias Klauser Committed by Tobias Klauser

unix: add TestSelect for *BSD

Change-Id: I9aa4ac170c361e56e36bded0cc13fb99346f70cf
Reviewed-on: https://go-review.googlesource.com/85275
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent 801364e0
......@@ -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")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment