From defe14d671072c1341aefae2f3a2c313343fd9fc Mon Sep 17 00:00:00 2001 From: Laura Peskin Date: Fri, 18 Nov 2022 12:19:27 -0800 Subject: sys/fuchsia: add test for socket syscall descriptions Also updated the constant files and added 0x0 as a valid option for `zx_socket_read` (to consume buffered data, as opposed to 0x8 = ZX_SOCKET_PEEK) --- pkg/runtest/run.go | 1 + sys/fuchsia/sockets.txt | 2 +- sys/fuchsia/sockets_amd64.const | 6 +++--- sys/fuchsia/sockets_arm64.const | 6 +++--- sys/fuchsia/test/socket | 37 +++++++++++++++++++++++++++++++++++++ 5 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 sys/fuchsia/test/socket diff --git a/pkg/runtest/run.go b/pkg/runtest/run.go index a0daf2b86..f8ef5cb86 100644 --- a/pkg/runtest/run.go +++ b/pkg/runtest/run.go @@ -310,6 +310,7 @@ func parseProg(target *prog.Target, dir, filename string) (*prog.Prog, map[strin "ZX_ERR_BAD_HANDLE": 11, "ZX_ERR_BAD_STATE": 20, "ZX_ERR_TIMED_OUT": 21, + "ZX_ERR_SHOULD_WAIT": 22, "ZX_ERR_PEER_CLOSED": 24, "ZX_ERR_ALREADY_EXISTS": 26, "ZX_ERR_ACCESS_DENIED": 30, diff --git a/sys/fuchsia/sockets.txt b/sys/fuchsia/sockets.txt index 3bb030681..0ecb8b66c 100644 --- a/sys/fuchsia/sockets.txt +++ b/sys/fuchsia/sockets.txt @@ -11,6 +11,6 @@ zx_socket_write(handle zx_socket, options flags[socket_write_options], buffer pt zx_socket_set_disposition(handle zx_socket, disposition flags[socket_disposition_options], disposition_peer flags[socket_disposition_options]) socket_create_options = ZX_SOCKET_STREAM, ZX_SOCKET_DATAGRAM -socket_read_options = ZX_SOCKET_PEEK +socket_read_options = 0, ZX_SOCKET_PEEK socket_write_options = 0 socket_disposition_options = ZX_SOCKET_DISPOSITION_WRITE_DISABLED, ZX_SOCKET_DISPOSITION_WRITE_ENABLED diff --git a/sys/fuchsia/sockets_amd64.const b/sys/fuchsia/sockets_amd64.const index 275788ba5..e1ab6b0a1 100644 --- a/sys/fuchsia/sockets_amd64.const +++ b/sys/fuchsia/sockets_amd64.const @@ -1,6 +1,6 @@ -# AUTOGENERATED FILE ZX_SOCKET_CREATE_MASK = 1 ZX_SOCKET_DATAGRAM = 1 -ZX_SOCKET_SHUTDOWN_READ = 2 -ZX_SOCKET_SHUTDOWN_WRITE = 1 ZX_SOCKET_STREAM = 0 +ZX_SOCKET_PEEK = 8 +ZX_SOCKET_DISPOSITION_WRITE_DISABLED = 1 +ZX_SOCKET_DISPOSITION_WRITE_ENABLED = 2 \ No newline at end of file diff --git a/sys/fuchsia/sockets_arm64.const b/sys/fuchsia/sockets_arm64.const index 275788ba5..e1ab6b0a1 100644 --- a/sys/fuchsia/sockets_arm64.const +++ b/sys/fuchsia/sockets_arm64.const @@ -1,6 +1,6 @@ -# AUTOGENERATED FILE ZX_SOCKET_CREATE_MASK = 1 ZX_SOCKET_DATAGRAM = 1 -ZX_SOCKET_SHUTDOWN_READ = 2 -ZX_SOCKET_SHUTDOWN_WRITE = 1 ZX_SOCKET_STREAM = 0 +ZX_SOCKET_PEEK = 8 +ZX_SOCKET_DISPOSITION_WRITE_DISABLED = 1 +ZX_SOCKET_DISPOSITION_WRITE_ENABLED = 2 \ No newline at end of file diff --git a/sys/fuchsia/test/socket b/sys/fuchsia/test/socket new file mode 100644 index 000000000..daad972a6 --- /dev/null +++ b/sys/fuchsia/test/socket @@ -0,0 +1,37 @@ +# Create a socket with the ZX_SOCKET_STREAM option. + +zx_socket_create(0x0, &AUTO=0x0, &AUTO=0x0) + +# Create a socket with the ZX_SOCKET_DATAGRAM option. + +zx_socket_create(0x1, &AUTO, &AUTO) + +# Write some data to a ZX_SOCKET_STREAM socket. + +zx_socket_write(r0, 0x0, &AUTO="0a1b2c3d", 0x4, &AUTO) +zx_socket_write(r0, 0x0, &AUTO="", 0x0, &AUTO) + +# Read some data from a ZX_SOCKET_STREAM socket, using the ZX_SOCKET_PEEK option to leave the data in the socket for a subsequent read. + +zx_socket_read(r1, 0x8, &AUTO, 0x10, &AUTO) +zx_socket_read(r1, 0x8, &AUTO, 0x10, &AUTO) + +# Read all of the buffered data from a ZX_SOCKET_STREAM socket, clearing the data from the socket. + +zx_socket_read(r1, 0x0, &AUTO, 0x10, &AUTO) +zx_socket_read(r1, 0x0, &AUTO, 0x10, &AUTO) # ZX_ERR_SHOULD_WAIT + +# Disable writes on a socket endpoint while enabling writes on its peer, then re-enable writes for both. + +zx_socket_set_disposition(r0, 0x1, 0x2) +zx_socket_write(r0, 0, &AUTO="0d", 0x1, &AUTO) # ZX_ERR_BAD_STATE +zx_socket_write(r1, 0, &AUTO="0e", 0x1, &AUTO) +zx_socket_set_disposition(r0, 0x2, 0x2) + +# Write some data to a socket, then disable writes on an endpoint. It should not be possible to re-enable writes on the write-disabled peer its peer has read the buffered data. + +zx_socket_write(r0, 0, &AUTO="0f", 0x1, &AUTO) +zx_socket_set_disposition(r0, 0x1, 0x2) +zx_socket_set_disposition(r0, 0x2, 0x2) # ZX_ERR_BAD_STATE +zx_socket_read(r1, 0x0, &AUTO, 0x10, &AUTO) +zx_socket_set_disposition(r0, 0x2, 0x2) -- cgit mrf-deployment