Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/wasix/tests/wasm_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod longjmp_tests;
mod path_tests;
mod poll_tests;
mod reflection_tests;
mod sched_yield;
mod semaphore_tests;
mod shared_library_tests;
mod socket_tests;
Expand Down
12 changes: 12 additions & 0 deletions lib/wasix/tests/wasm_tests/poll_tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
use super::{run_build_script, run_wasm, run_wasm_with_result};

#[test]
fn test_epoll_create() {
let wasm = run_build_script(file!(), "epoll-create").unwrap();
run_wasm(&wasm, wasm.parent().unwrap()).unwrap();
}

#[test]
fn test_poll_oneoff_zero() {
let wasm = run_build_script(file!(), "poll-oneoff-zero").unwrap();
Expand All @@ -13,3 +19,9 @@ fn test_epoll_create_ctl_wait() {
assert_eq!(String::from_utf8_lossy(&result.stdout).trim(), "0");
assert_eq!(result.exit_code, Some(0));
}

#[test]
fn test_poll_oneoff() {
let wasm = run_build_script(file!(), "poll-oneoff").unwrap();
run_wasm(&wasm, wasm.parent().unwrap()).unwrap();
}
3 changes: 3 additions & 0 deletions lib/wasix/tests/wasm_tests/poll_tests/epoll-create/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
set -euo pipefail
$CC main.c -o main
53 changes: 53 additions & 0 deletions lib/wasix/tests/wasm_tests/poll_tests/epoll-create/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <wasi/api.h>
#include <wasi/api_wasix.h>

static void test_basic_create(void) {
printf("Test 1: epoll_create basic\n");

__wasi_fd_t epfd = 0;
__wasi_errno_t err = __wasi_epoll_create(&epfd);
assert(err == __WASI_ERRNO_SUCCESS);

__wasi_fdstat_t stat;
err = __wasi_fd_fdstat_get(epfd, &stat);
assert(err == __WASI_ERRNO_SUCCESS);
assert((stat.fs_rights_base & __WASI_RIGHTS_POLL_FD_READWRITE) ==
__WASI_RIGHTS_POLL_FD_READWRITE);

err = __wasi_fd_close(epfd);
assert(err == __WASI_ERRNO_SUCCESS);
}

static void test_multiple_create_unique(void) {
printf("Test 2: epoll_create returns distinct fds\n");

__wasi_fd_t a = 0;
__wasi_fd_t b = 0;

assert(__wasi_epoll_create(&a) == __WASI_ERRNO_SUCCESS);
assert(__wasi_epoll_create(&b) == __WASI_ERRNO_SUCCESS);
assert(a != b);

assert(__wasi_fd_close(a) == __WASI_ERRNO_SUCCESS);
assert(__wasi_fd_close(b) == __WASI_ERRNO_SUCCESS);
}

static void test_invalid_pointer(void) {
printf("Test 3: epoll_create invalid pointer\n");

__wasi_fd_t* bad_ptr = (__wasi_fd_t*)(uintptr_t)0xFFFFFFFFu;
__wasi_errno_t err = __wasi_epoll_create(bad_ptr);
assert(err == __WASI_ERRNO_MEMVIOLATION);
}

int main(void) {
printf("WASIX epoll_create integration tests\n");
test_basic_create();
test_multiple_create_unique();
test_invalid_pointer();
printf("All tests passed!\n");
return 0;
}
3 changes: 3 additions & 0 deletions lib/wasix/tests/wasm_tests/poll_tests/poll-oneoff/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
set -euo pipefail
$CC main.c -o main
62 changes: 62 additions & 0 deletions lib/wasix/tests/wasm_tests/poll_tests/poll-oneoff/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include <assert.h>
#include <poll.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

static void test_pollout(void) {
printf("Test 1: POLLOUT on pipe write end\n");
int fds[2];
assert(pipe(fds) == 0);

struct pollfd pfd = {.fd = fds[1], .events = POLLOUT, .revents = 0};
int ret = poll(&pfd, 1, -1);
assert(ret == 1);
assert((pfd.revents & POLLOUT) == POLLOUT);

close(fds[0]);
close(fds[1]);
}

static void test_pollin(void) {
printf("Test 2: POLLIN after write\n");
int fds[2];
assert(pipe(fds) == 0);

const char msg[] = "Testing";
assert(write(fds[1], msg, sizeof(msg)) == (ssize_t)sizeof(msg));

struct pollfd pfd = {.fd = fds[0], .events = POLLIN, .revents = 0};
int ret = poll(&pfd, 1, -1);
assert(ret == 1);
assert((pfd.revents & POLLIN) == POLLIN);

char buf[16] = {0};
assert(read(fds[0], buf, sizeof(msg)) == (ssize_t)sizeof(msg));

close(fds[0]);
close(fds[1]);
}

static void test_timeout(void) {
printf("Test 3: poll timeout\n");
int fds[2];
assert(pipe(fds) == 0);

struct pollfd pfd = {.fd = fds[0], .events = POLLIN, .revents = 0};
int ret = poll(&pfd, 1, 50);
assert(ret == 0);
assert(pfd.revents == 0);

close(fds[0]);
close(fds[1]);
}

int main(void) {
printf("WASI poll_oneoff (poll/ppoll) integration tests\n");
test_pollout();
test_pollin();
test_timeout();
printf("All tests passed!\n");
return 0;
}
7 changes: 7 additions & 0 deletions lib/wasix/tests/wasm_tests/sched_yield.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use super::{run_build_script, run_wasm};

#[test]
fn test_sched_yield() {
let wasm = run_build_script(file!(), ".").unwrap();
run_wasm(&wasm, wasm.parent().unwrap()).unwrap();
}
4 changes: 4 additions & 0 deletions lib/wasix/tests/wasm_tests/sched_yield/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
set -euo pipefail

$CC main.c -o main
Loading
Loading