Skip to content

Commit

Permalink
Add tests for sock_shutdown() API
Browse files Browse the repository at this point in the history
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
  • Loading branch information
loganek committed Nov 24, 2023
1 parent 671aaab commit 03b4d4a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/c/testsuite/sock_shutdown-invalid_fd.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>

int main() {
int fd = 3;
assert(shutdown(fd, SHUT_RD) != 0);
assert(errno == EBADF);

return EXIT_SUCCESS;
}
12 changes: 12 additions & 0 deletions tests/c/testsuite/sock_shutdown-not_sock.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <assert.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <unistd.h>

int main() {
assert(shutdown(STDOUT_FILENO, SHUT_RD) != 0);
assert(errno == ENOTSOCK);

return EXIT_SUCCESS;
}

0 comments on commit 03b4d4a

Please sign in to comment.