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 20, 2023
1 parent 671aaab commit 044bec1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/c/testsuite/sock_shutdown-invalid_fd.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <assert.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/socket.h>

#include <stdio.h>

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

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

int main() {
int fd = fileno(stdout);

assert(shutdown(fd, SHUT_RD) != 0);
assert(errno == ENOTSOCK);

return EXIT_SUCCESS;
}

0 comments on commit 044bec1

Please sign in to comment.