Changes in uspace/lib/pcut/src/run.c [193d280c:9b20126] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/pcut/src/run.c
r193d280c r9b20126 73 73 static int default_suite_initialized = 0; 74 74 75 static void init_default_suite_when_needed(void) 76 { 77 if (default_suite_initialized) 75 static void init_default_suite_when_needed() { 76 if (default_suite_initialized) { 78 77 return; 79 78 } 80 79 default_suite.id = -1; 81 80 default_suite.kind = PCUT_KIND_TESTSUITE; … … 92 91 * @return Always a valid test suite item. 93 92 */ 94 static pcut_item_t *pcut_find_parent_suite(pcut_item_t *it) 95 { 93 static pcut_item_t *pcut_find_parent_suite(pcut_item_t *it) { 96 94 while (it != NULL) { 97 if (it->kind == PCUT_KIND_TESTSUITE) 95 if (it->kind == PCUT_KIND_TESTSUITE) { 98 96 return it; 99 97 } 100 98 it = it->previous; 101 99 } 102 103 100 init_default_suite_when_needed(); 104 101 return &default_suite; … … 109 106 * @param func Function to run (can be NULL). 110 107 */ 111 static void run_setup_teardown(pcut_setup_func_t func) 112 { 113 if (func != NULL) 108 static void run_setup_teardown(pcut_setup_func_t func) { 109 if (func != NULL) { 114 110 func(); 111 } 115 112 } 116 113 … … 122 119 * @param outcome Outcome of the current test. 123 120 */ 124 static void leave_test(int outcome) 125 { 121 static void leave_test(int outcome) { 126 122 PCUT_DEBUG("leave_test(outcome=%d), will_exit=%s", outcome, 127 128 if (leave_means_exit) 123 leave_means_exit ? "yes" : "no"); 124 if (leave_means_exit) { 129 125 exit(outcome); 130 126 } 127 131 128 #ifndef PCUT_NO_LONG_JUMP 132 129 longjmp(start_test_jump, 1); … … 141 138 * @param message Message describing the failure. 142 139 */ 143 void pcut_failed_assertion(const char *message) 144 { 140 void pcut_failed_assertion(const char *message) { 145 141 static const char *prev_message = NULL; 146 147 142 /* 148 143 * The assertion failed. We need to abort the current test, … … 150 145 * include running the tear-down routine. 151 146 */ 152 if (print_test_error) 147 if (print_test_error) { 153 148 pcut_print_fail_message(message); 154 149 } 150 155 151 if (execute_teardown_on_failure) { 156 152 execute_teardown_on_failure = 0; 157 153 prev_message = message; 158 154 run_setup_teardown(current_suite->teardown_func); 159 155 160 156 /* Tear-down was okay. */ 161 157 if (report_test_result) { … … 169 165 } 170 166 } 171 167 172 168 prev_message = NULL; 173 169 174 170 leave_test(TEST_OUTCOME_FAIL); /* No return. */ 175 171 } … … 180 176 * @return Error status (zero means success). 181 177 */ 182 static int run_test(pcut_item_t *test) 183 { 178 static int run_test(pcut_item_t *test) { 184 179 /* 185 180 * Set here as the returning point in case of test failure. … … 187 182 * test execution. 188 183 */ 189 190 184 #ifndef PCUT_NO_LONG_JUMP 191 185 int test_finished = setjmp(start_test_jump); 192 if (test_finished) 186 if (test_finished) { 193 187 return 1; 188 } 194 189 #endif 195 196 if (report_test_result) 190 191 if (report_test_result) { 197 192 pcut_report_test_start(test); 198 193 } 194 199 195 current_suite = pcut_find_parent_suite(test); 200 196 current_test = test; 201 197 202 198 pcut_hook_before_test(test); 203 199 204 200 /* 205 201 * If anything goes wrong, execute the tear-down function … … 207 203 */ 208 204 execute_teardown_on_failure = 1; 209 205 210 206 /* 211 207 * Run the set-up function. 212 208 */ 213 209 run_setup_teardown(current_suite->setup_func); 214 210 215 211 /* 216 212 * The setup function was performed, it is time to run … … 218 214 */ 219 215 test->test_func(); 220 216 221 217 /* 222 218 * Finally, run the tear-down function. We need to clear … … 225 221 execute_teardown_on_failure = 0; 226 222 run_setup_teardown(current_suite->teardown_func); 227 223 228 224 /* 229 225 * If we got here, it means everything went well with 230 226 * this test. 231 227 */ 232 if (report_test_result) 228 if (report_test_result) { 233 229 pcut_report_test_done(current_test, TEST_OUTCOME_PASS, 234 NULL, NULL, NULL); 235 230 NULL, NULL, NULL); 231 } 232 236 233 return 0; 237 234 } … … 245 242 * @return Error status (zero means success). 246 243 */ 247 int pcut_run_test_forked(pcut_item_t *test) 248 { 244 int pcut_run_test_forked(pcut_item_t *test) { 245 int rc; 246 249 247 report_test_result = 0; 250 248 print_test_error = 1; 251 249 leave_means_exit = 1; 252 253 intrc = run_test(test);254 250 251 rc = run_test(test); 252 255 253 current_test = NULL; 256 254 current_suite = NULL; 257 255 258 256 return rc; 259 257 } … … 267 265 * @return Error status (zero means success). 268 266 */ 269 int pcut_run_test_single(pcut_item_t *test) 270 { 267 int pcut_run_test_single(pcut_item_t *test) { 268 int rc; 269 271 270 report_test_result = 1; 272 271 print_test_error = 0; 273 272 leave_means_exit = 0; 274 275 intrc = run_test(test);276 273 274 rc = run_test(test); 275 277 276 current_test = NULL; 278 277 current_suite = NULL; 279 278 280 279 return rc; 281 280 } … … 286 285 * @return Timeout in seconds. 287 286 */ 288 int pcut_get_test_timeout(pcut_item_t *test) 289 { 287 int pcut_get_test_timeout(pcut_item_t *test) { 290 288 int timeout = PCUT_DEFAULT_TEST_TIMEOUT; 291 289 pcut_extra_t *extras = test->extras; 292 290 291 293 292 while (extras->type != PCUT_EXTRA_LAST) { 294 if (extras->type == PCUT_EXTRA_TIMEOUT) 293 if (extras->type == PCUT_EXTRA_TIMEOUT) { 295 294 timeout = extras->timeout; 296 295 } 297 296 extras++; 298 297 } 299 298 300 299 return timeout; 301 300 }
Note:
See TracChangeset
for help on using the changeset viewer.