nx_websocket_upgrade_test.nx
buildroot/runtime/nx_websocket_upgrade_test.nx
about
nx_websocket_upgrade_test.nx -- KAT for the server-side upgrade driver.
Uses sys_pipe2 to simulate a TCP fd: write a hand-crafted HTTP/1.1
upgrade request into the pipe, run the upgrade handshake, then read
what got written back to verify the 101 response (RFC 6455 ยง4.2.2).
The "fd" handed to the driver is a duplex socketpair would be ideal,
but two unidirectional pipes work: one for client->server (request),
one for server->client (101 response). The driver needs to read AND
write on the same fd, so we use a Unix domain socketpair via the
already-shipped sys_pipe2 trick (or socketpair if available). For
this test we use a SINGLE pipe for each direction and tie them
together via two separate calls. Concrete shape:
Test writes request bytes into pipe1.write_end.
Driver reads from pipe1.read_end + writes 101 to pipe2.write_end.
Test reads from pipe2.read_end.
That requires the driver to take SEPARATE read_fd + write_fd... but
our API takes a single fd. So we wrap by having the test:
- Write the request bytes first (full request)
- sys_close the write end (signals EOF after request)
- Pass the read end to the driver
- For the WRITE side, give the driver a separate write-pipe
But the driver's _wsu_write_n uses sys_write(fd, ...) on the same
fd it reads from. So to test the FULL flow we need a true socket
pair. Use sys_socketpair if shipped, otherwise document.
For this initial KAT we test ONLY the validation logic: feed a full
request, verify the read+parse path returns OK and writes a 101 with
the right Sec-WebSocket-Accept. Read+write on the same fd works
when both ends of a sys_pipe2 stay open during the call -- write
happens to the SAME pipe (loopback) and the test reads it after.
expect_exit: 0
license_tier: ORIGINAL
dependencies 2 imports · 0 importers
imports: nx_syscalls.nxnx_websocket_upgrade.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| none |
functions
| 42 | func main() -> i64 |