gpu: nvgpu: unit: exit properly if signal in single thread

In the unit test framework, if a fatal error occurs in a module that
generates a POSIX signal (like segfault), the error handler will log
the error and kill the thread. However, if running in single threaded
mode (which is the default), killing the thread means killing the
process too. This means that results.json is not generated which
makes results in automation more difficult to read.

This patch updates the error handler to print the results as expected
and exit gracefully.

JIRA NVGPU-3157

Change-Id: I0204816b18312238e6502eb400e21d0e445e7e6c
Signed-off-by: Nicolas Benech <nbenech@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nvgpu/+/2278481
Reviewed-by: svc-mobile-coverity <svc-mobile-coverity@nvidia.com>
Reviewed-by: svc-mobile-cert <svc-mobile-cert@nvidia.com>
Reviewed-by: Alex Waterman <alexw@nvidia.com>
GVS: Gerrit_Virtual_Submit
Reviewed-by: Vinod Gopalakrishnakurup <vinodg@nvidia.com>
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
This commit is contained in:
Nicolas Benech
2020-01-13 11:30:49 -05:00
committed by Alex Waterman
parent ee255ef8eb
commit 048c700975

View File

@@ -138,6 +138,24 @@ thread_exit:
return NULL; 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 * 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 * 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, core_add_test_record(thread_local_module->fw, thread_local_module,
thread_local_test, FAILED); thread_local_test, FAILED);
sem_post(&unit_thread_semaphore); 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); pthread_exit(NULL);
} }
@@ -228,15 +255,7 @@ int core_exec(struct unit_fw *fw)
} }
} }
for (modules = fw->modules; *modules != NULL; modules++) { run_modules(fw);
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);
}
}
if (fw->args->thread_count > 1) { if (fw->args->thread_count > 1) {
for (modules = fw->modules; *modules != NULL; modules++) { for (modules = fw->modules; *modules != NULL; modules++) {