test(server): drive fd sources over raw socketpairs and report dispatch errno
1 file · +19 -8
M server/xwm_test.go +19 -8
| @@ -47,7 +47,7 @@ func registry(t testing.TB, d *Display, fd int) int { | |||
| 47 | 47 | t.Fatal(err) | |
| 48 | 48 | } | |
| 49 | 49 | if xwmDispatch(d) < 0 { | |
| 50 | - | t.Fatal("dispatch failed") | |
| 50 | + | t.Fatalf("dispatch failed: errno=%v", lastErrno()) | |
| 51 | 51 | } | |
| 52 | 52 | wlDisplayFlushClients(d.c) | |
| 53 | 53 | var buf [4096]byte | |
| @@ -116,7 +116,8 @@ func TestGlobalFilter(t *testing.T) { | |||
| 116 | 116 | ||
| 117 | 117 | func TestWritableInterest(t *testing.T) { | |
| 118 | 118 | d := xwmDisplay(t) | |
| 119 | - | client, fd := xwmClient(t, d) | |
| 119 | + | fds := xwmSocketpair(t) | |
| 120 | + | fd := fds[0] | |
| 120 | 121 | reads, writes := 0, 0 | |
| 121 | 122 | s, err := d.AddFDRW(fd, func() { reads++ }, func() { writes++ }) | |
| 122 | 123 | if err != nil { | |
| @@ -124,7 +125,7 @@ func TestWritableInterest(t *testing.T) { | |||
| 124 | 125 | } | |
| 125 | 126 | dispatch := func() { | |
| 126 | 127 | if xwmDispatch(d) < 0 { | |
| 127 | - | t.Fatal("dispatch failed") | |
| 128 | + | t.Fatalf("dispatch failed: errno=%v", lastErrno()) | |
| 128 | 129 | } | |
| 129 | 130 | } | |
| 130 | 131 | dispatch() | |
| @@ -151,10 +152,7 @@ func TestWritableInterest(t *testing.T) { | |||
| 151 | 152 | t.Fatal("writable not disabled") | |
| 152 | 153 | } | |
| 153 | 154 | // Readable callbacks also stay allocation-free through the real C loop. | |
| 154 | - | serverFD, err := client.FD() | |
| 155 | - | if err != nil { | |
| 156 | - | t.Fatal(err) | |
| 157 | - | } | |
| 155 | + | serverFD := fds[1] | |
| 158 | 156 | var payload = [1]byte{1} | |
| 159 | 157 | if _, err := unix.Write(serverFD, payload[:]); err != nil { | |
| 160 | 158 | t.Fatal(err) | |
| @@ -213,7 +211,8 @@ func BenchmarkGlobalFilter(b *testing.B) { | |||
| 213 | 211 | ||
| 214 | 212 | func BenchmarkFDCallback(b *testing.B) { | |
| 215 | 213 | d := xwmDisplay(b) | |
| 216 | - | _, fd := xwmClient(b, d) | |
| 214 | + | fds := xwmSocketpair(b) | |
| 215 | + | fd := fds[0] | |
| 217 | 216 | s, err := d.AddFDRW(fd, func() {}, func() {}) | |
| 218 | 217 | if err != nil { | |
| 219 | 218 | b.Fatal(err) | |
| @@ -370,3 +369,15 @@ func xwmDispatch(d *Display) int32 { | |||
| 370 | 369 | } | |
| 371 | 370 | return -1 | |
| 372 | 371 | } | |
| 372 | + | ||
| 373 | + | // FD sources use raw sockets, not Wayland clients: arbitrary payloads must | |
| 374 | + | // never enter libwayland's protocol transport or its flush/error handling. | |
| 375 | + | func xwmSocketpair(t testing.TB) [2]int { | |
| 376 | + | t.Helper() | |
| 377 | + | fds, err := unix.Socketpair(unix.AF_UNIX, unix.SOCK_STREAM|unix.SOCK_NONBLOCK|unix.SOCK_CLOEXEC, 0) | |
| 378 | + | if err != nil { | |
| 379 | + | t.Fatal(err) | |
| 380 | + | } | |
| 381 | + | t.Cleanup(func() { unix.Close(fds[0]); unix.Close(fds[1]) }) | |
| 382 | + | return fds | |
| 383 | + | } | |
| @@ -47,7 +47,7 @@ func registry(t testing.TB, d *Display, fd int) int { | |||||
| 47 | t.Fatal(err) | 47 | t.Fatal(err) | ||
| 48 | } | 48 | } | ||
| 49 | if xwmDispatch(d) < 0 { | 49 | if xwmDispatch(d) < 0 { | ||
| 50 | - | t.Fatal("dispatch failed") | 50 | + | t.Fatalf("dispatch failed: errno=%v", lastErrno()) |
| 51 | } | 51 | } | ||
| 52 | wlDisplayFlushClients(d.c) | 52 | wlDisplayFlushClients(d.c) | ||
| 53 | var buf [4096]byte | 53 | var buf [4096]byte | ||
| @@ -116,7 +116,8 @@ func TestGlobalFilter(t *testing.T) { | |||||
| 116 | 116 | ||||
| 117 | func TestWritableInterest(t *testing.T) { | 117 | func TestWritableInterest(t *testing.T) { | ||
| 118 | d := xwmDisplay(t) | 118 | d := xwmDisplay(t) | ||
| 119 | - | client, fd := xwmClient(t, d) | 119 | + | fds := xwmSocketpair(t) |
| 120 | + | fd := fds[0] | |||
| 120 | reads, writes := 0, 0 | 121 | reads, writes := 0, 0 | ||
| 121 | s, err := d.AddFDRW(fd, func() { reads++ }, func() { writes++ }) | 122 | s, err := d.AddFDRW(fd, func() { reads++ }, func() { writes++ }) | ||
| 122 | if err != nil { | 123 | if err != nil { | ||
| @@ -124,7 +125,7 @@ func TestWritableInterest(t *testing.T) { | |||||
| 124 | } | 125 | } | ||
| 125 | dispatch := func() { | 126 | dispatch := func() { | ||
| 126 | if xwmDispatch(d) < 0 { | 127 | if xwmDispatch(d) < 0 { | ||
| 127 | - | t.Fatal("dispatch failed") | 128 | + | t.Fatalf("dispatch failed: errno=%v", lastErrno()) |
| 128 | } | 129 | } | ||
| 129 | } | 130 | } | ||
| 130 | dispatch() | 131 | dispatch() | ||
| @@ -151,10 +152,7 @@ func TestWritableInterest(t *testing.T) { | |||||
| 151 | t.Fatal("writable not disabled") | 152 | t.Fatal("writable not disabled") | ||
| 152 | } | 153 | } | ||
| 153 | // Readable callbacks also stay allocation-free through the real C loop. | 154 | // Readable callbacks also stay allocation-free through the real C loop. | ||
| 154 | - | serverFD, err := client.FD() | 155 | + | serverFD := fds[1] |
| 155 | - | if err != nil { | |||
| 156 | - | t.Fatal(err) | |||
| 157 | - | } | |||
| 158 | var payload = [1]byte{1} | 156 | var payload = [1]byte{1} | ||
| 159 | if _, err := unix.Write(serverFD, payload[:]); err != nil { | 157 | if _, err := unix.Write(serverFD, payload[:]); err != nil { | ||
| 160 | t.Fatal(err) | 158 | t.Fatal(err) | ||
| @@ -213,7 +211,8 @@ func BenchmarkGlobalFilter(b *testing.B) { | |||||
| 213 | 211 | ||||
| 214 | func BenchmarkFDCallback(b *testing.B) { | 212 | func BenchmarkFDCallback(b *testing.B) { | ||
| 215 | d := xwmDisplay(b) | 213 | d := xwmDisplay(b) | ||
| 216 | - | _, fd := xwmClient(b, d) | 214 | + | fds := xwmSocketpair(b) |
| 215 | + | fd := fds[0] | |||
| 217 | s, err := d.AddFDRW(fd, func() {}, func() {}) | 216 | s, err := d.AddFDRW(fd, func() {}, func() {}) | ||
| 218 | if err != nil { | 217 | if err != nil { | ||
| 219 | b.Fatal(err) | 218 | b.Fatal(err) | ||
| @@ -370,3 +369,15 @@ func xwmDispatch(d *Display) int32 { | |||||
| 370 | } | 369 | } | ||
| 371 | return -1 | 370 | return -1 | ||
| 372 | } | 371 | } | ||
| 372 | + | ||||
| 373 | + | // FD sources use raw sockets, not Wayland clients: arbitrary payloads must | |||
| 374 | + | // never enter libwayland's protocol transport or its flush/error handling. | |||
| 375 | + | func xwmSocketpair(t testing.TB) [2]int { | |||
| 376 | + | t.Helper() | |||
| 377 | + | fds, err := unix.Socketpair(unix.AF_UNIX, unix.SOCK_STREAM|unix.SOCK_NONBLOCK|unix.SOCK_CLOEXEC, 0) | |||
| 378 | + | if err != nil { | |||
| 379 | + | t.Fatal(err) | |||
| 380 | + | } | |||
| 381 | + | t.Cleanup(func() { unix.Close(fds[0]); unix.Close(fds[1]) }) | |||
| 382 | + | return fds | |||
| 383 | + | } | |||