mirror of
https://github.com/rwinkhart/sys.git
synced 2026-08-28 04:46:44 -04:00
unix: use same TestSelect on all Unices
Also change t.Error messages to use "got foo, expected bar" notation. Change-Id: Ia0b452f96b08cbb69a0b64cc2a467b5cf94e72da Reviewed-on: https://go-review.googlesource.com/c/sys/+/207858 Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
committed by
Tobias Klauser
parent
e882bf8e40
commit
f068ffe820
@@ -237,55 +237,6 @@ func TestRlimitAs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSelect(t *testing.T) {
|
||||
n, err := unix.Select(0, nil, nil, nil, &unix.Timeval{Sec: 0, Usec: 0})
|
||||
if err != nil {
|
||||
t.Fatalf("Select: %v", err)
|
||||
}
|
||||
if n != 0 {
|
||||
t.Fatalf("Select: expected 0 ready file descriptors, got %v", n)
|
||||
}
|
||||
|
||||
dur := 150 * time.Millisecond
|
||||
tv := unix.NsecToTimeval(int64(dur))
|
||||
start := time.Now()
|
||||
n, err = unix.Select(0, nil, nil, nil, &tv)
|
||||
took := time.Since(start)
|
||||
if err != nil {
|
||||
t.Fatalf("Select: %v", err)
|
||||
}
|
||||
if n != 0 {
|
||||
t.Fatalf("Select: expected 0 ready file descriptors, got %v", n)
|
||||
}
|
||||
|
||||
if took < dur {
|
||||
t.Errorf("Select: timeout should have been at least %v, got %v", dur, took)
|
||||
}
|
||||
|
||||
rr, ww, err := os.Pipe()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer rr.Close()
|
||||
defer ww.Close()
|
||||
|
||||
if _, err := ww.Write([]byte("HELLO GOPHER")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
rFdSet := &unix.FdSet{}
|
||||
fd := int(rr.Fd())
|
||||
rFdSet.Set(fd)
|
||||
|
||||
n, err = unix.Select(fd+1, rFdSet, nil, nil, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("Select: %v", err)
|
||||
}
|
||||
if n != 1 {
|
||||
t.Fatalf("Select: expected 1 ready file descriptors, got %v", n)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPselect(t *testing.T) {
|
||||
for {
|
||||
_, err := unix.Pselect(0, nil, nil, nil, &unix.Timespec{Sec: 0, Nsec: 0}, nil)
|
||||
|
||||
Reference in New Issue
Block a user