mirror of
https://github.com/rwinkhart/sys.git
synced 2026-08-30 22:06:37 -04:00
unix: enable TestPoll for all unix systems
Poll is now supported for all unix systems. Also enable TestPoll for all of them. Change-Id: Id6250702bf0d29c49fbeeed4cca21d232b72666a Reviewed-on: https://go-review.googlesource.com/74310 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
committed by
Tobias Klauser
parent
af4555b109
commit
95c6576299
@@ -56,34 +56,6 @@ func TestIoctlGetInt(t *testing.T) {
|
|||||||
t.Logf("%d bits of entropy available", v)
|
t.Logf("%d bits of entropy available", v)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPoll(t *testing.T) {
|
|
||||||
f, cleanup := mktmpfifo(t)
|
|
||||||
defer cleanup()
|
|
||||||
|
|
||||||
const timeout = 100
|
|
||||||
|
|
||||||
ok := make(chan bool, 1)
|
|
||||||
go func() {
|
|
||||||
select {
|
|
||||||
case <-time.After(10 * timeout * time.Millisecond):
|
|
||||||
t.Errorf("Poll: failed to timeout after %d milliseconds", 10*timeout)
|
|
||||||
case <-ok:
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
fds := []unix.PollFd{{Fd: int32(f.Fd()), Events: unix.POLLIN}}
|
|
||||||
n, err := unix.Poll(fds, timeout)
|
|
||||||
ok <- true
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("Poll: unexpected error: %v", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if n != 0 {
|
|
||||||
t.Errorf("Poll: wrong number of events: got %v, expected %v", n, 0)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestPpoll(t *testing.T) {
|
func TestPpoll(t *testing.T) {
|
||||||
f, cleanup := mktmpfifo(t)
|
f, cleanup := mktmpfifo(t)
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
@@ -113,25 +85,6 @@ func TestPpoll(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// mktmpfifo creates a temporary FIFO and provides a cleanup function.
|
|
||||||
func mktmpfifo(t *testing.T) (*os.File, func()) {
|
|
||||||
err := unix.Mkfifo("fifo", 0666)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("mktmpfifo: failed to create FIFO: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
f, err := os.OpenFile("fifo", os.O_RDWR, 0666)
|
|
||||||
if err != nil {
|
|
||||||
os.Remove("fifo")
|
|
||||||
t.Fatalf("mktmpfifo: failed to open FIFO: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return f, func() {
|
|
||||||
f.Close()
|
|
||||||
os.Remove("fifo")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTime(t *testing.T) {
|
func TestTime(t *testing.T) {
|
||||||
var ut unix.Time_t
|
var ut unix.Time_t
|
||||||
ut2, err := unix.Time(&ut)
|
ut2, err := unix.Time(&ut)
|
||||||
|
|||||||
@@ -343,3 +343,50 @@ func TestDup(t *testing.T) {
|
|||||||
t.Errorf("Dup: stdout write not in file, expected %v, got %v", string(b1), string(b2))
|
t.Errorf("Dup: stdout write not in file, expected %v, got %v", string(b1), string(b2))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPoll(t *testing.T) {
|
||||||
|
f, cleanup := mktmpfifo(t)
|
||||||
|
defer cleanup()
|
||||||
|
|
||||||
|
const timeout = 100
|
||||||
|
|
||||||
|
ok := make(chan bool, 1)
|
||||||
|
go func() {
|
||||||
|
select {
|
||||||
|
case <-time.After(10 * timeout * time.Millisecond):
|
||||||
|
t.Errorf("Poll: failed to timeout after %d milliseconds", 10*timeout)
|
||||||
|
case <-ok:
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
fds := []unix.PollFd{{Fd: int32(f.Fd()), Events: unix.POLLIN}}
|
||||||
|
n, err := unix.Poll(fds, timeout)
|
||||||
|
ok <- true
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Poll: unexpected error: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if n != 0 {
|
||||||
|
t.Errorf("Poll: wrong number of events: got %v, expected %v", n, 0)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// mktmpfifo creates a temporary FIFO and provides a cleanup function.
|
||||||
|
func mktmpfifo(t *testing.T) (*os.File, func()) {
|
||||||
|
err := unix.Mkfifo("fifo", 0666)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("mktmpfifo: failed to create FIFO: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
f, err := os.OpenFile("fifo", os.O_RDWR, 0666)
|
||||||
|
if err != nil {
|
||||||
|
os.Remove("fifo")
|
||||||
|
t.Fatalf("mktmpfifo: failed to open FIFO: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return f, func() {
|
||||||
|
f.Close()
|
||||||
|
os.Remove("fifo")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user