From c6eae929fd74f11ab13d469a38bffd4e8ba50fb5 Mon Sep 17 00:00:00 2001 From: Nicolas Benech Date: Tue, 25 Sep 2018 14:37:16 -0400 Subject: gpu: nvgpu: posix: Multithreading for unit tests Add a -j argument to enable running unit tests on several threads. Also adds signal handling to prevent a fatal error in one thread from killing the whole unit test framework. JIRA NVGPU-1043 Change-Id: I891a547640cd005a50ffa5c06367ed46c54de012 Signed-off-by: Nicolas Benech Reviewed-on: https://git-master.nvidia.com/r/1847740 Reviewed-by: svc-misra-checker GVS: Gerrit_Virtual_Submit Reviewed-by: Alex Waterman Reviewed-by: mobile promotions Tested-by: mobile promotions --- userspace/src/results.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'userspace/src/results.c') diff --git a/userspace/src/results.c b/userspace/src/results.c index ae077b82..4c30c4db 100644 --- a/userspace/src/results.c +++ b/userspace/src/results.c @@ -22,12 +22,18 @@ #include #include +#include #include #include #include #include +/* + * Mutex to ensure core_add_test_record() is thread safe. + */ +pthread_mutex_t mutex_results = PTHREAD_MUTEX_INITIALIZER; + static int __init_results(struct unit_fw *fw) { struct unit_results *results; @@ -72,16 +78,22 @@ int core_add_test_record(struct unit_fw *fw, bool success) { struct unit_test_record *tr; + int err = 0; + pthread_mutex_lock(&mutex_results); /* - * Dones nothing if results are already inited. + * Does nothing if results are already inited. */ - if (__init_results(fw) != 0) - return -1; + if (__init_results(fw) != 0) { + err = -1; + goto done; + } tr = malloc(sizeof(*tr)); - if (tr == NULL) - return -1; + if (tr == NULL) { + err = -1; + goto done; + } tr->mod = mod; tr->test = test; @@ -97,7 +109,9 @@ int core_add_test_record(struct unit_fw *fw, if (success) fw->results->nr_passing += 1; - return 0; +done: + pthread_mutex_unlock(&mutex_results); + return err; } void core_print_test_status(struct unit_fw *fw) -- cgit v1.2.2