Skip to content

Commit

Permalink
wasm2c: add wasm2c-rlbox windows build configuration for tests in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
shravanrn committed Dec 14, 2023
1 parent 8bf826c commit 423915a
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 18 deletions.
27 changes: 26 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,29 @@ jobs:
submodules: true
- run: sudo apt-get install ninja-build
- run: make clang-debug
- run: ./test/run-tests.py --exclude-dir memory64
- name: tests (excluding memory64)
run: ./test/run-tests.py --exclude memory64
build-rlbox-win:
name: rlbox-win
runs-on: windows-latest
env:
USE_NINJA: "1"
WASM2C_CFLAGS: "-DWASM_RT_USE_MMAP=1 -DWASM_RT_SKIP_SIGNAL_RECOVERY=1 -DWASM_RT_STACK_HOST_HANDLER=1 -DWASM2C_TEST_EMBEDDER_SIGNAL_HANDLING"
steps:
- uses: actions/setup-python@v1
with:
python-version: '3.x'
- uses: actions/checkout@v1
with:
submodules: true

- name: mkdir
run: mkdir -p out
- run: choco install ninja
- name: cmake (windows)
run: cmake .. -DWERROR=ON -Werror=dev
working-directory: out
- name: build
run: cmake --build out
- name: tests (excluding memory64 and stack exhaustion)
run: ./test/run-tests.py --exclude memory64 --exclude call.txt --exclude call_indirect.txt --exclude fac.txt --exclude skip-stack-guard-page.txt
21 changes: 11 additions & 10 deletions test/run-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -684,17 +684,18 @@ def _Clear(self):
sys.stderr.write('\r%s\r' % (' ' * self.last_length))


def FindTestFiles(ext, filter_pattern_re, exclude_dirs):
def FindTestFiles(ext, filter_pattern_re, excludes):
tests = []
for root, dirs, files in os.walk(TEST_DIR):
for ex in exclude_dirs:
for ex in excludes:
if ex in dirs:
# Filtering out dirs here causes os.walk not to descend into them
dirs.remove(ex)
for f in files:
path = os.path.join(root, f)
if os.path.splitext(f)[1] == ext:
tests.append(os.path.relpath(path, REPO_ROOT_DIR))
if f not in excludes:
path = os.path.join(root, f)
if os.path.splitext(f)[1] == ext:
tests.append(os.path.relpath(path, REPO_ROOT_DIR))
tests.sort()
return [test for test in tests if re.match(filter_pattern_re, test)]

Expand Down Expand Up @@ -928,10 +929,10 @@ def main(args):
action='store_true')
parser.add_argument('patterns', metavar='pattern', nargs='*',
help='test patterns.')
parser.add_argument('--exclude-dir', action='append', default=[],
help='directory to exclude.')
parser.add_argument('--exclude', action='append', default=[],
help='directory or filenames to exclude.')
options = parser.parse_args(args)
exclude_dirs = options.exclude_dir
excludes = options.exclude

if options.jobs != 1:
if options.fail_fast:
Expand All @@ -947,9 +948,9 @@ def main(args):
# By default, exclude wasi tests because WASI support is not include
# by int the build by default.
# TODO(sbc): Find some way to detect the WASI support.
exclude_dirs += ['wasi']
excludes += ['wasi']

test_names = FindTestFiles('.txt', pattern_re, exclude_dirs)
test_names = FindTestFiles('.txt', pattern_re, excludes)

if options.list:
for test_name in test_names:
Expand Down
43 changes: 36 additions & 7 deletions test/spec-wasm2c-prefix.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,16 +363,43 @@ static void init_spectest_module(w2c_spectest* instance) {
wasm_rt_allocate_funcref_table(&instance->spectest_table, 10, 20);
}

// POSIX-only test config where embedder handles signals instead of w2c runtime
// Test config where embedder handles signals instead of w2c runtime
#ifdef WASM2C_TEST_EMBEDDER_SIGNAL_HANDLING

#ifdef _WIN32

#include <windows.h>

static void* g_sig_handler_handle = 0;

static LONG signal_handler(PEXCEPTION_POINTERS info) {
if (info->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) {
wasm_rt_trap(WASM_RT_TRAP_OOB);
} else if (info->ExceptionRecord->ExceptionCode == EXCEPTION_STACK_OVERFLOW) {
wasm_rt_trap(WASM_RT_TRAP_EXHAUSTION);
}
return EXCEPTION_CONTINUE_SEARCH;
}

static void install_signal_handler(void) {
g_sig_handler_handle =
AddVectoredExceptionHandler(1 /* CALL_FIRST */, signal_handler);
}

static void cleanup_signal_handler(void) {
RemoveVectoredExceptionHandler(g_sig_handler_handle);
}

#else

#include <signal.h>

static void posix_signal_handler(int sig, siginfo_t* si, void* unused) {
static void signal_handler(int sig, siginfo_t* si, void* unused) {
wasm_rt_trap((si->si_code == SEGV_ACCERR) ? WASM_RT_TRAP_OOB
: WASM_RT_TRAP_EXHAUSTION);
}

static void posix_install_signal_handler(void) {
static void install_signal_handler(void) {
/* install altstack */
stack_t ss;
ss.ss_sp = malloc(SIGSTKSZ);
Expand All @@ -388,14 +415,14 @@ static void posix_install_signal_handler(void) {
memset(&sa, '\0', sizeof(sa));
sa.sa_flags = SA_SIGINFO | SA_ONSTACK;
sigemptyset(&sa.sa_mask);
sa.sa_sigaction = posix_signal_handler;
sa.sa_sigaction = signal_handler;
if (sigaction(SIGSEGV, &sa, NULL) != 0 || sigaction(SIGBUS, &sa, NULL) != 0) {
perror("sigaction failed");
abort();
}
}

static void posix_cleanup_signal_handler(void) {
static void cleanup_signal_handler(void) {
/* remove signal handler */
struct sigaction sa;
memset(&sa, '\0', sizeof(sa));
Expand All @@ -414,19 +441,21 @@ static void posix_cleanup_signal_handler(void) {
}
free(ss.ss_sp);
}

#endif
#endif

int main(int argc, char** argv) {
#ifdef WASM2C_TEST_EMBEDDER_SIGNAL_HANDLING
posix_install_signal_handler();
install_signal_handler();
#endif
wasm_rt_init();
init_spectest_module(&spectest_instance);
run_spec_tests();
printf("%u/%u tests passed.\n", g_tests_passed, g_tests_run);
wasm_rt_free();
#ifdef WASM2C_TEST_EMBEDDER_SIGNAL_HANDLING
posix_cleanup_signal_handler();
cleanup_signal_handler();
#endif
return g_tests_passed != g_tests_run;
}

0 comments on commit 423915a

Please sign in to comment.