diff --git a/userspace/src/exec.c b/userspace/src/exec.c index 00fb60bb0..49f2d9308 100644 --- a/userspace/src/exec.c +++ b/userspace/src/exec.c @@ -138,6 +138,24 @@ thread_exit: return NULL; } +/* + * Go over all the modules and run them one by one. + */ +static void run_modules(struct unit_fw *fw) +{ + struct unit_module **modules; + + for (modules = fw->modules; *modules != NULL; modules++) { + if (fw->args->thread_count == 1) { + core_exec_module(*modules); + } else { + sem_wait(&unit_thread_semaphore); + pthread_create(&((*modules)->thread), NULL, + core_exec_module, (void *) *modules); + } + } +} + /* * According to POSIX, "Signals which are generated by some action attributable * to a particular thread, such as a hardware fault, shall be generated for the @@ -155,6 +173,15 @@ static void thread_error_handler(int sig, siginfo_t *siginfo, void *context) core_add_test_record(thread_local_module->fw, thread_local_module, thread_local_test, FAILED); sem_post(&unit_thread_semaphore); + + /* + * If single threaded, the signal will cause the process to end, so + * exit gracefully while printing test results. + */ + if (thread_local_module->fw->args->thread_count == 1) { + core_print_test_status(thread_local_module->fw); + exit(-1); + } pthread_exit(NULL); } @@ -228,15 +255,7 @@ int core_exec(struct unit_fw *fw) } } - for (modules = fw->modules; *modules != NULL; modules++) { - if (fw->args->thread_count == 1) { - core_exec_module(*modules); - } else { - sem_wait(&unit_thread_semaphore); - pthread_create(&((*modules)->thread), NULL, - core_exec_module, (void *) *modules); - } - } + run_modules(fw); if (fw->args->thread_count > 1) { for (modules = fw->modules; *modules != NULL; modules++) {