diff options
Diffstat (limited to 'userspace/src/results.c')
-rw-r--r-- | userspace/src/results.c | 26 |
1 files changed, 20 insertions, 6 deletions
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 @@ | |||
22 | 22 | ||
23 | #include <stdlib.h> | 23 | #include <stdlib.h> |
24 | #include <string.h> | 24 | #include <string.h> |
25 | #include <pthread.h> | ||
25 | 26 | ||
26 | #include <unit/io.h> | 27 | #include <unit/io.h> |
27 | #include <unit/core.h> | 28 | #include <unit/core.h> |
28 | #include <unit/unit.h> | 29 | #include <unit/unit.h> |
29 | #include <unit/results.h> | 30 | #include <unit/results.h> |
30 | 31 | ||
32 | /* | ||
33 | * Mutex to ensure core_add_test_record() is thread safe. | ||
34 | */ | ||
35 | pthread_mutex_t mutex_results = PTHREAD_MUTEX_INITIALIZER; | ||
36 | |||
31 | static int __init_results(struct unit_fw *fw) | 37 | static int __init_results(struct unit_fw *fw) |
32 | { | 38 | { |
33 | struct unit_results *results; | 39 | struct unit_results *results; |
@@ -72,16 +78,22 @@ int core_add_test_record(struct unit_fw *fw, | |||
72 | bool success) | 78 | bool success) |
73 | { | 79 | { |
74 | struct unit_test_record *tr; | 80 | struct unit_test_record *tr; |
81 | int err = 0; | ||
75 | 82 | ||
83 | pthread_mutex_lock(&mutex_results); | ||
76 | /* | 84 | /* |
77 | * Dones nothing if results are already inited. | 85 | * Does nothing if results are already inited. |
78 | */ | 86 | */ |
79 | if (__init_results(fw) != 0) | 87 | if (__init_results(fw) != 0) { |
80 | return -1; | 88 | err = -1; |
89 | goto done; | ||
90 | } | ||
81 | 91 | ||
82 | tr = malloc(sizeof(*tr)); | 92 | tr = malloc(sizeof(*tr)); |
83 | if (tr == NULL) | 93 | if (tr == NULL) { |
84 | return -1; | 94 | err = -1; |
95 | goto done; | ||
96 | } | ||
85 | 97 | ||
86 | tr->mod = mod; | 98 | tr->mod = mod; |
87 | tr->test = test; | 99 | tr->test = test; |
@@ -97,7 +109,9 @@ int core_add_test_record(struct unit_fw *fw, | |||
97 | if (success) | 109 | if (success) |
98 | fw->results->nr_passing += 1; | 110 | fw->results->nr_passing += 1; |
99 | 111 | ||
100 | return 0; | 112 | done: |
113 | pthread_mutex_unlock(&mutex_results); | ||
114 | return err; | ||
101 | } | 115 | } |
102 | 116 | ||
103 | void core_print_test_status(struct unit_fw *fw) | 117 | void core_print_test_status(struct unit_fw *fw) |