From: Brendan Hansen Date: Fri, 3 Dec 2021 17:35:52 +0000 (-0600) Subject: returning nonzero from onyx run if program returns nonzero X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=124e17f85cd477102da0f08c76dd594f5aeb7cd1;p=onyx.git returning nonzero from onyx run if program returns nonzero --- diff --git a/include/wasm_emit.h b/include/wasm_emit.h index be0255b0..5e80b038 100644 --- a/include/wasm_emit.h +++ b/include/wasm_emit.h @@ -678,7 +678,7 @@ void onyx_wasm_module_write_to_buffer(OnyxWasmModule* module, bh_buffer* buffer) void onyx_wasm_module_write_to_file(OnyxWasmModule* module, bh_file file); #ifdef ENABLE_RUN_WITH_WASMER -void onyx_run_wasm(bh_buffer code_buffer); +b32 onyx_run_wasm(bh_buffer code_buffer); #endif #endif diff --git a/scripts/run_tests.onyx b/scripts/run_tests.onyx index 0895c4a3..cb9affab 100644 --- a/scripts/run_tests.onyx +++ b/scripts/run_tests.onyx @@ -117,6 +117,8 @@ find_onyx_files :: (root: str, cases: ^[..] Test_Case) { return; } +at_least_one_test_failed := false; + test_cases :: (cases) => { for #no_close *cases { printf("[{}] Running test {}...\n", context.thread_id, it.source_file); @@ -131,6 +133,7 @@ test_cases :: (cases) => { if exit := io.process_wait(^proc); exit != .Success { // Error running the test case print_color(.Red, "[{}] Error compiling test case {}.\n{}", context.thread_id, it.source_file, output); + at_least_one_test_failed = true; continue; } @@ -140,6 +143,7 @@ test_cases :: (cases) => { if output != expected_output { print_color(.Red, "[{}] Output did not match for {}.\n", context.thread_id, it.source_file); + at_least_one_test_failed = true; } } } @@ -194,5 +198,11 @@ main :: (args) => { case_iterator->close(); - println("Done"); + if at_least_one_test_failed { + print_color(.Red, "FAILED\n"); + (package wasi).proc_exit(1); + + } else { + print_color(.Green, "SUCCESS\n"); + } } \ No newline at end of file diff --git a/src/onyx.c b/src/onyx.c index a8941882..03e82d29 100644 --- a/src/onyx.c +++ b/src/onyx.c @@ -585,14 +585,14 @@ static CompilerProgress onyx_flush_module() { } #ifdef ENABLE_RUN_WITH_WASMER -static void onyx_run() { +static b32 onyx_run() { bh_buffer code_buffer; onyx_wasm_module_write_to_buffer(context.wasm_module, &code_buffer); if (context.options->verbose_output > 0) bh_printf("Running program:\n"); - onyx_run_wasm(code_buffer); + return onyx_run_wasm(code_buffer); } #endif @@ -625,7 +625,9 @@ int main(int argc, char *argv[]) { case ONYX_COMPILE_ACTION_RUN: compiler_progress = onyx_compile(); if (compiler_progress == ONYX_COMPILER_PROGRESS_SUCCESS) { - onyx_run(); + if (!onyx_run()) { + compiler_progress = ONYX_COMPILER_PROGRESS_ERROR; + } } break; #endif diff --git a/src/wasm_runtime.c b/src/wasm_runtime.c index 24a51965..fc9424f4 100644 --- a/src/wasm_runtime.c +++ b/src/wasm_runtime.c @@ -460,9 +460,11 @@ WASM_INTEROP(onyx_process_destroy_impl) { return NULL; } -void onyx_run_wasm(bh_buffer wasm_bytes) { +// Returns 1 if successful +b32 onyx_run_wasm(bh_buffer wasm_bytes) { wasm_instance_t* instance = NULL; wasmer_features_t* features = NULL; + wasm_trap_t* run_trap = NULL; wasm_config = wasm_config_new(); if (!wasm_config) goto error_handling; @@ -631,7 +633,7 @@ void onyx_run_wasm(bh_buffer wasm_bytes) { bad_import: bh_printf("Couldn't find import %b.%b.\n", module_name->data, module_name->size, import_name->data, import_name->size); - return; + return 0; } wasm_trap_t* traps = NULL; @@ -646,7 +648,7 @@ void onyx_run_wasm(bh_buffer wasm_bytes) { wasm_val_vec_t results; wasm_val_vec_new_uninitialized(&args, 0); - wasm_func_call(start_func, &args, &results); + run_trap = wasm_func_call(start_func, &args, &results); goto cleanup; @@ -662,5 +664,5 @@ cleanup: if (wasm_module) wasm_module_delete(wasm_module); if (wasm_store) wasm_store_delete(wasm_store); if (wasm_engine) wasm_engine_delete(wasm_engine); - return; + return run_trap == NULL; }