returning nonzero from onyx run if program returns nonzero
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 3 Dec 2021 17:35:52 +0000 (11:35 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Fri, 3 Dec 2021 17:35:52 +0000 (11:35 -0600)
include/wasm_emit.h
scripts/run_tests.onyx
src/onyx.c
src/wasm_runtime.c

index be0255b07be76238b67373083d7433b7e453d94f..5e80b0384cef3b006dc21a5a3c5d8b5c7ddbcab3 100644 (file)
@@ -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
index 0895c4a385bcc439623b6a6dacd81b7d4dce751b..cb9affab379e0ed8b7ce0fd1a973936c00c8a3c4 100644 (file)
@@ -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
index a89418822356f9540d0346443f1a57b0097fb41f..03e82d29cf541d8e9c4a81c5340a174c3aff269b 100644 (file)
@@ -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
index 24a519650d87ffce1b38206e351a3108625b99cf..fc9424f48ad9bb71635fb0a8193b7cfd1dcd02f2 100644 (file)
@@ -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;
 }