mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-02 23:27:31 -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
@@ -123,26 +123,6 @@ func TestUtimesNanoAt(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 := 150 * 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)
|
|
||||||
}
|
|
||||||
|
|
||||||
if took < dur {
|
|
||||||
t.Errorf("Select: timeout should have been at least %v, got %v", dur, took)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestPselect(t *testing.T) {
|
func TestPselect(t *testing.T) {
|
||||||
if runtime.GOARCH == "ppc64" {
|
if runtime.GOARCH == "ppc64" {
|
||||||
t.Skip("pselect issue with structure timespec on AIX 7.2 tl0, skipping test")
|
t.Skip("pselect issue with structure timespec on AIX 7.2 tl0, skipping test")
|
||||||
|
|||||||
@@ -7,11 +7,9 @@
|
|||||||
package unix_test
|
package unix_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
@@ -48,57 +46,6 @@ func TestGetfsstat(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 := 250 * 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)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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)
|
|
||||||
}
|
|
||||||
|
|
||||||
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 TestSysctlRaw(t *testing.T) {
|
func TestSysctlRaw(t *testing.T) {
|
||||||
if runtime.GOOS == "openbsd" {
|
if runtime.GOOS == "openbsd" {
|
||||||
t.Skip("kern.proc.pid does not exist on OpenBSD")
|
t.Skip("kern.proc.pid does not exist on OpenBSD")
|
||||||
|
|||||||
@@ -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) {
|
func TestPselect(t *testing.T) {
|
||||||
for {
|
for {
|
||||||
_, err := unix.Pselect(0, nil, nil, nil, &unix.Timespec{Sec: 0, Nsec: 0}, nil)
|
_, err := unix.Pselect(0, nil, nil, nil, &unix.Timespec{Sec: 0, Nsec: 0}, nil)
|
||||||
|
|||||||
@@ -7,63 +7,12 @@
|
|||||||
package unix_test
|
package unix_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
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 TestStatvfs(t *testing.T) {
|
func TestStatvfs(t *testing.T) {
|
||||||
if err := unix.Statvfs("", nil); err == nil {
|
if err := unix.Statvfs("", nil); err == nil {
|
||||||
t.Fatal(`Statvfs("") expected failure`)
|
t.Fatal(`Statvfs("") expected failure`)
|
||||||
|
|||||||
@@ -512,6 +512,57 @@ func TestPoll(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: got %v ready file descriptors, expected 0", n)
|
||||||
|
}
|
||||||
|
|
||||||
|
dur := 250 * 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: got %v ready file descriptors, expected 0", n)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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: got %v timeout, expected at least %v", took, dur)
|
||||||
|
}
|
||||||
|
|
||||||
|
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: got %v ready file descriptors, expected 1", n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestGetwd(t *testing.T) {
|
func TestGetwd(t *testing.T) {
|
||||||
fd, err := os.Open(".")
|
fd, err := os.Open(".")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user