Skip to content

Commit

Permalink
WASIX Test Suite (#4780)
Browse files Browse the repository at this point in the history
  • Loading branch information
maminrayej authored Aug 7, 2024
2 parents f571107 + 6cba5c3 commit 9a7b33a
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 1 deletion.
30 changes: 30 additions & 0 deletions tests/wasix/chdir-getcwd/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

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);
}
3 changes: 3 additions & 0 deletions tests/wasix/chdir-getcwd/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$WASMER -q run main.wasm > output

printf "0" | diff -u output - 1>/dev/null
52 changes: 52 additions & 0 deletions tests/wasix/epoll-create-ctl-wait/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/epoll.h>
#include <sys/eventfd.h>
#include <unistd.h>
#include <stdint.h>

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;
}
3 changes: 3 additions & 0 deletions tests/wasix/epoll-create-ctl-wait/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$WASMER -q run main.wasm > output

printf "0" | diff -u output - 1>/dev/null
58 changes: 58 additions & 0 deletions tests/wasix/fd_pipe/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>

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;
}
3 changes: 3 additions & 0 deletions tests/wasix/fd_pipe/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$WASMER -q run main.wasm > output

printf "0" | diff -u output - 1>/dev/null
2 changes: 1 addition & 1 deletion tests/wasix/proc-exec/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ int main(int argc, char *argv[])

execv("/code/main.wasm", newargv);

exit(EXIT_FAILURE);
goto end;
}
else
{
Expand Down
35 changes: 35 additions & 0 deletions tests/wasix/signal/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <sys/wait.h>

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);
}
}
3 changes: 3 additions & 0 deletions tests/wasix/signal/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$WASMER -q run main.wasm > output

printf "0" | diff -u output - 1>/dev/null

0 comments on commit 9a7b33a

Please sign in to comment.