From 1b880252cdebb517672f62111eb8cf4a7d0a925d Mon Sep 17 00:00:00 2001 From: "M.Amin Rayej" Date: Sun, 2 Jun 2024 18:59:09 +0330 Subject: [PATCH 1/5] sort tests and apply wasm-opt --- tests/wasix/test.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/wasix/test.sh b/tests/wasix/test.sh index f3349e46c4a..701be933db1 100755 --- a/tests/wasix/test.sh +++ b/tests/wasix/test.sh @@ -77,6 +77,7 @@ while read dir; do cmd="cd $dir; \ $CC $CFLAGS $LDFLAGS -o main.wasm main.c; \ + wasm-opt -O4 --asyncify -g --fpcast-emu main.wasm -o main.wasm -pa max-func-params@32; \ ./run.sh" if bash -c "$cmd"; then @@ -85,6 +86,6 @@ while read dir; do printf "\rTesting $dir ❌\n" status=1 fi -done < <(find . -mindepth 1 -maxdepth 1 -type d) +done < <(find . -mindepth 1 -maxdepth 1 -type d | sort) exit $status \ No newline at end of file From 78cd491c0b13bc6e394de8e922e460dafce4d64c Mon Sep 17 00:00:00 2001 From: "M.Amin Rayej" Date: Sun, 2 Jun 2024 18:59:32 +0330 Subject: [PATCH 2/5] add test for chdir and getcwd --- tests/wasix/chdir-getcwd/main.c | 30 ++++++++++++++++++++++++++++++ tests/wasix/chdir-getcwd/run.sh | 3 +++ 2 files changed, 33 insertions(+) create mode 100644 tests/wasix/chdir-getcwd/main.c create mode 100755 tests/wasix/chdir-getcwd/run.sh diff --git a/tests/wasix/chdir-getcwd/main.c b/tests/wasix/chdir-getcwd/main.c new file mode 100644 index 00000000000..5e284634433 --- /dev/null +++ b/tests/wasix/chdir-getcwd/main.c @@ -0,0 +1,30 @@ +#include +#include +#include +#include + +int main() +{ + char cwd[1024]; + + int status = EXIT_FAILURE; + + if (chdir("/tmp") != 0) + { + goto end; + } + + if (getcwd(cwd, sizeof(cwd)) == NULL) + { + goto end; + } + + if (strcmp(cwd, "/tmp") == 0) + { + status = EXIT_SUCCESS; + } + +end: + printf("%d", status); + exit(status); +} diff --git a/tests/wasix/chdir-getcwd/run.sh b/tests/wasix/chdir-getcwd/run.sh new file mode 100755 index 00000000000..3e033fb8981 --- /dev/null +++ b/tests/wasix/chdir-getcwd/run.sh @@ -0,0 +1,3 @@ +$WASMER -q run main.wasm > output + +printf "0" | diff -u output - 1>/dev/null \ No newline at end of file From 41be35fb7017abf4e6b8c16c3ff606767776e544 Mon Sep 17 00:00:00 2001 From: "M.Amin Rayej" Date: Sun, 2 Jun 2024 18:59:54 +0330 Subject: [PATCH 3/5] add test for signal handling --- tests/wasix/signal/main.c | 35 +++++++++++++++++++++++++++++++++++ tests/wasix/signal/run.sh | 3 +++ 2 files changed, 38 insertions(+) create mode 100644 tests/wasix/signal/main.c create mode 100755 tests/wasix/signal/run.sh diff --git a/tests/wasix/signal/main.c b/tests/wasix/signal/main.c new file mode 100644 index 00000000000..956471b24d6 --- /dev/null +++ b/tests/wasix/signal/main.c @@ -0,0 +1,35 @@ +#include +#include +#include +#include +#include + +void sig_handler(int signo) +{ + exit(signo != SIGHUP); +} + +int main(int argc, char *argv[]) +{ +pid_t pid; + int status; + + pid = fork(); + + if (pid == -1) { + return EXIT_FAILURE; + } else if (pid == 0) { + signal(SIGHUP, sig_handler); + while (1) { + sleep(1); + } + } else { + sleep(1); + + kill(pid, SIGHUP); + + waitpid(pid, &status, 0); + + printf("%d", status); + } +} \ No newline at end of file diff --git a/tests/wasix/signal/run.sh b/tests/wasix/signal/run.sh new file mode 100755 index 00000000000..3e033fb8981 --- /dev/null +++ b/tests/wasix/signal/run.sh @@ -0,0 +1,3 @@ +$WASMER -q run main.wasm > output + +printf "0" | diff -u output - 1>/dev/null \ No newline at end of file From 4b43c0508abade93fec5739e32ef77c3fbd974f1 Mon Sep 17 00:00:00 2001 From: "M.Amin Rayej" Date: Sun, 2 Jun 2024 19:00:09 +0330 Subject: [PATCH 4/5] add test for epoll --- tests/wasix/epoll-create-ctl-wait/main.c | 52 ++++++++++++++++++++++++ tests/wasix/epoll-create-ctl-wait/run.sh | 3 ++ 2 files changed, 55 insertions(+) create mode 100644 tests/wasix/epoll-create-ctl-wait/main.c create mode 100755 tests/wasix/epoll-create-ctl-wait/run.sh diff --git a/tests/wasix/epoll-create-ctl-wait/main.c b/tests/wasix/epoll-create-ctl-wait/main.c new file mode 100644 index 00000000000..2c6c930fc26 --- /dev/null +++ b/tests/wasix/epoll-create-ctl-wait/main.c @@ -0,0 +1,52 @@ +#include +#include +#include +#include +#include +#include + +int main() +{ + int status = EXIT_FAILURE; + + int efd, epoll_fd; + struct epoll_event event; + struct epoll_event events[1]; + + efd = eventfd(0, 0); + if (efd == -1) + { + goto end; + } + + epoll_fd = epoll_create1(0); + if (epoll_fd == -1) + { + goto end; + } + + event.events = EPOLLIN; + event.data.fd = efd; + if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, efd, &event) == -1) + { + goto end; + } + + uint64_t val = 1; + if (write(efd, &val, sizeof(uint64_t)) != sizeof(uint64_t)) + { + goto end; + } + + int n = epoll_wait(epoll_fd, events, 1, -1); + if (n == -1) + { + goto end;; + } + + status = EXIT_SUCCESS; + +end: + printf("%d", status); + return status; +} diff --git a/tests/wasix/epoll-create-ctl-wait/run.sh b/tests/wasix/epoll-create-ctl-wait/run.sh new file mode 100755 index 00000000000..3e033fb8981 --- /dev/null +++ b/tests/wasix/epoll-create-ctl-wait/run.sh @@ -0,0 +1,3 @@ +$WASMER -q run main.wasm > output + +printf "0" | diff -u output - 1>/dev/null \ No newline at end of file From a767f40bd5de8db554bfb381f022a888df376c39 Mon Sep 17 00:00:00 2001 From: "M.Amin Rayej" Date: Sun, 2 Jun 2024 19:00:28 +0330 Subject: [PATCH 5/5] add test for fd_pipe (socketpair) --- tests/wasix/fd_pipe/main.c | 58 ++++++++++++++++++++++++++++++++++++++ tests/wasix/fd_pipe/run.sh | 3 ++ 2 files changed, 61 insertions(+) create mode 100644 tests/wasix/fd_pipe/main.c create mode 100755 tests/wasix/fd_pipe/run.sh diff --git a/tests/wasix/fd_pipe/main.c b/tests/wasix/fd_pipe/main.c new file mode 100644 index 00000000000..acf76ff902f --- /dev/null +++ b/tests/wasix/fd_pipe/main.c @@ -0,0 +1,58 @@ +#include +#include +#include +#include +#include +#include + +int main() +{ + int status = EXIT_FAILURE; + + int socks[2]; + char buf[1024]; + ssize_t numRead; + + if (socketpair(AF_UNIX, SOCK_STREAM, 0, socks) == -1) + { + goto end; + } + + if (write(socks[0], "foo", 3) == -1) + { + goto end; + } + + memset(buf, 0, sizeof(buf)); + numRead = read(socks[1], buf, sizeof(buf)); + if (numRead == -1) + { + goto end; + } + if (strncmp(buf, "foo", 3) != 0) + { + goto end; + } + + if (write(socks[1], "bar", 3) == -1) + { + goto end; + } + + memset(buf, 0, sizeof(buf)); + numRead = read(socks[0], buf, sizeof(buf)); + if (numRead == -1) + { + goto end; + } + if (strncmp(buf, "bar", 3) != 0) + { + goto end; + } + + status = EXIT_SUCCESS; + +end: + printf("%d", status); + return status; +} diff --git a/tests/wasix/fd_pipe/run.sh b/tests/wasix/fd_pipe/run.sh new file mode 100755 index 00000000000..3e033fb8981 --- /dev/null +++ b/tests/wasix/fd_pipe/run.sh @@ -0,0 +1,3 @@ +$WASMER -q run main.wasm > output + +printf "0" | diff -u output - 1>/dev/null \ No newline at end of file