From 03b4d4ac98d148a44b73aa88baa31aac3237cf75 Mon Sep 17 00:00:00 2001 From: Marcin Kolny Date: Mon, 20 Nov 2023 11:55:37 +0000 Subject: [PATCH] Add tests for sock_shutdown() API According to the specification [1] the API should behave similarly to the POSIX one, therefore expecting specific errno codes https://github.com/WebAssembly/WASI/blob/2980bb39e1d2a4a2adae4748908cb4325cd41a26/legacy/preview1/docs.md#sock_shutdown --- tests/c/testsuite/sock_shutdown-invalid_fd.c | 13 +++++++++++++ tests/c/testsuite/sock_shutdown-not_sock.c | 12 ++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 tests/c/testsuite/sock_shutdown-invalid_fd.c create mode 100644 tests/c/testsuite/sock_shutdown-not_sock.c diff --git a/tests/c/testsuite/sock_shutdown-invalid_fd.c b/tests/c/testsuite/sock_shutdown-invalid_fd.c new file mode 100644 index 00000000..8680f86f --- /dev/null +++ b/tests/c/testsuite/sock_shutdown-invalid_fd.c @@ -0,0 +1,13 @@ +#include +#include +#include +#include +#include + +int main() { + int fd = 3; + assert(shutdown(fd, SHUT_RD) != 0); + assert(errno == EBADF); + + return EXIT_SUCCESS; +} diff --git a/tests/c/testsuite/sock_shutdown-not_sock.c b/tests/c/testsuite/sock_shutdown-not_sock.c new file mode 100644 index 00000000..e3a3e873 --- /dev/null +++ b/tests/c/testsuite/sock_shutdown-not_sock.c @@ -0,0 +1,12 @@ +#include +#include +#include +#include +#include + +int main() { + assert(shutdown(STDOUT_FILENO, SHUT_RD) != 0); + assert(errno == ENOTSOCK); + + return EXIT_SUCCESS; +}