Changeset 9eb1ff5 in mainline
- Timestamp:
- 2017-12-08T14:47:08Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c1694b6b
- Parents:
- 6fb8b2c
- Location:
- uspace/lib/pcut
- Files:
-
- 31 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/pcut/helenos.mak
r6fb8b2c r9eb1ff5 39 39 40 40 EXTRA_CFLAGS = -D__helenos__ 41 41 42 LIBRARY = libpcut -
uspace/lib/pcut/include/pcut/pcut.h
r6fb8b2c r9eb1ff5 36 36 #include <pcut/tests.h> 37 37 38 39 /** PCUT outcome: test passed. */ 40 #define PCUT_OUTCOME_PASS 0 41 42 /** PCUT outcome: test failed. */ 43 #define PCUT_OUTCOME_FAIL 1 44 45 /** PCUT outcome: test failed unexpectedly. */ 46 #define PCUT_OUTCOME_INTERNAL_ERROR 2 47 48 /** PCUT outcome: invalid invocation of the final program. */ 49 #define PCUT_OUTCOME_BAD_INVOCATION 3 50 51 38 52 #endif -
uspace/lib/pcut/src/assert.c
r6fb8b2c r9eb1ff5 35 35 */ 36 36 37 /** We need _BSD_SOURCE because of vsnprintf() when compiling under C89. */ 37 /* 38 * We need _BSD_SOURCE because of vsnprintf() when compiling under C89. 39 * In newer versions of features.h, _DEFAULT_SOURCE must be defined as well. 40 */ 38 41 #define _BSD_SOURCE 42 #define _DEFAULT_SOURCE 39 43 40 44 #include "internal.h" -
uspace/lib/pcut/src/internal.h
r6fb8b2c r9eb1ff5 79 79 #define PCUT_RUN_MODE_SINGLE 2 80 80 81 /** Test outcome: test passed. */82 #define TEST_OUTCOME_PASS 183 84 /** Test outcome: test failed. */85 #define TEST_OUTCOME_FAIL 286 87 /** Test outcome: test failed unexpectedly. */88 #define TEST_OUTCOME_ERROR 389 90 91 81 /* 92 82 * Use sprintf_s in Windows but only with Microsoft compiler. … … 109 99 int pcut_is_arg_with_number(const char *arg, const char *opt, int *value); 110 100 111 voidpcut_run_test_forking(const char *self_path, pcut_item_t *test);101 int pcut_run_test_forking(const char *self_path, pcut_item_t *test); 112 102 int pcut_run_test_forked(pcut_item_t *test); 113 103 int pcut_run_test_single(pcut_item_t *test); -
uspace/lib/pcut/src/main.c
r6fb8b2c r9eb1ff5 90 90 * @param last Pointer to first item after this suite is stored here. 91 91 * @param prog_path Path to the current binary (used in forked mode). 92 */ 93 static void run_suite(pcut_item_t *suite, pcut_item_t **last, const char *prog_path) { 92 * @return Error code. 93 */ 94 static int run_suite(pcut_item_t *suite, pcut_item_t **last, const char *prog_path) { 94 95 int is_first_test = 1; 95 96 int total_count = 0; 97 int ret_code = PCUT_OUTCOME_PASS; 98 int ret_code_tmp; 96 99 97 100 pcut_item_t *it = pcut_get_real_next(suite); … … 114 117 115 118 if (pcut_run_mode == PCUT_RUN_MODE_FORKING) { 116 pcut_run_test_forking(prog_path, it);119 ret_code_tmp = pcut_run_test_forking(prog_path, it); 117 120 } else { 118 pcut_run_test_single(it); 119 } 121 ret_code_tmp = pcut_run_test_single(it); 122 } 123 124 /* 125 * Override final return code in case of failure. 126 * 127 * In this case we suppress any special error codes as 128 * to the outside, there was a failure. 129 */ 130 if (ret_code_tmp != PCUT_OUTCOME_PASS) { 131 ret_code = PCUT_OUTCOME_FAIL; 132 } 133 120 134 total_count++; 121 135 } … … 130 144 *last = it; 131 145 } 146 147 return ret_code; 132 148 } 133 149 … … 181 197 int run_only_test = -1; 182 198 199 int rc, rc_tmp; 200 183 201 if (main_extras == NULL) { 184 202 main_extras = empty_main_extra; … … 203 221 if (pcut_str_equals(argv[i], "-l")) { 204 222 pcut_print_tests(items); 205 return 0;223 return PCUT_OUTCOME_PASS; 206 224 } 207 225 if (pcut_str_equals(argv[i], "-x")) { … … 229 247 if ((run_only_suite >= 0) && (run_only_test >= 0)) { 230 248 printf("Specify either -s or -t!\n"); 231 return 1;249 return PCUT_OUTCOME_BAD_INVOCATION; 232 250 } 233 251 … … 236 254 if (suite == NULL) { 237 255 printf("Suite not found, aborting!\n"); 238 return 2;256 return PCUT_OUTCOME_BAD_INVOCATION; 239 257 } 240 258 if (suite->kind != PCUT_KIND_TESTSUITE) { 241 259 printf("Invalid suite id!\n"); 242 return 3;260 return PCUT_OUTCOME_BAD_INVOCATION; 243 261 } 244 262 245 263 run_suite(suite, NULL, argv[0]); 246 return 0;264 return PCUT_OUTCOME_PASS; 247 265 } 248 266 249 267 if (run_only_test > 0) { 250 int rc;251 268 pcut_item_t *test = pcut_find_by_id(items, run_only_test); 252 269 if (test == NULL) { 253 270 printf("Test not found, aborting!\n"); 254 return 2;271 return PCUT_OUTCOME_BAD_INVOCATION; 255 272 } 256 273 if (test->kind != PCUT_KIND_TEST) { 257 274 printf("Invalid test id!\n"); 258 return 3;275 return PCUT_OUTCOME_BAD_INVOCATION; 259 276 } 260 277 … … 271 288 pcut_report_init(items); 272 289 290 rc = PCUT_OUTCOME_PASS; 291 273 292 it = items; 274 293 while (it != NULL) { 275 294 if (it->kind == PCUT_KIND_TESTSUITE) { 276 295 pcut_item_t *tmp; 277 run_suite(it, &tmp, argv[0]); 296 rc_tmp = run_suite(it, &tmp, argv[0]); 297 if (rc_tmp != PCUT_OUTCOME_PASS) { 298 rc = rc_tmp; 299 } 278 300 it = tmp; 279 301 } else { … … 284 306 pcut_report_done(); 285 307 286 return 0;287 } 308 return rc; 309 } -
uspace/lib/pcut/src/os/generic.c
r6fb8b2c r9eb1ff5 34 34 #include <stdlib.h> 35 35 #include <stdio.h> 36 #include <sys/types.h> 36 37 #include <errno.h> 37 38 #include <assert.h> … … 94 95 static int convert_wait_status_to_outcome(int status) { 95 96 if (status < 0) { 96 return TEST_OUTCOME_ERROR;97 return PCUT_OUTCOME_INTERNAL_ERROR; 97 98 } else if (status == 0) { 98 return TEST_OUTCOME_PASS;99 return PCUT_OUTCOME_PASS; 99 100 } else { 100 return TEST_OUTCOME_FAIL;101 return PCUT_OUTCOME_FAIL; 101 102 } 102 103 } … … 107 108 * @param test Test to be run. 108 109 */ 109 voidpcut_run_test_forking(const char *self_path, pcut_item_t *test) {110 int rc ;110 int pcut_run_test_forking(const char *self_path, pcut_item_t *test) { 111 int rc, outcome; 111 112 FILE *tempfile; 112 113 char tempfile_name[PCUT_TEMP_FILENAME_BUFFER_SIZE]; … … 126 127 PCUT_DEBUG("system() returned 0x%04X", rc); 127 128 128 rc= convert_wait_status_to_outcome(rc);129 outcome = convert_wait_status_to_outcome(rc); 129 130 130 131 tempfile = fopen(tempfile_name, "rb"); 131 132 if (tempfile == NULL) { 132 133 pcut_report_test_done(test, TEST_OUTCOME_ERROR, "Failed to open temporary file.", NULL, NULL); 133 return ;134 return PCUT_OUTCOME_INTERNAL_ERROR; 134 135 } 135 136 136 137 fread(extra_output_buffer, 1, OUTPUT_BUFFER_SIZE, tempfile); 137 138 fclose(tempfile); 138 unlink(tempfile_name);139 remove(tempfile_name); 139 140 140 pcut_report_test_done_unparsed(test, rc, extra_output_buffer, OUTPUT_BUFFER_SIZE); 141 pcut_report_test_done_unparsed(test, outcome, extra_output_buffer, OUTPUT_BUFFER_SIZE); 142 143 return outcome; 141 144 } 142 145 -
uspace/lib/pcut/src/os/helenos.c
r6fb8b2c r9eb1ff5 154 154 * @param test Test to be run. 155 155 */ 156 voidpcut_run_test_forking(const char *self_path, pcut_item_t *test) {156 int pcut_run_test_forking(const char *self_path, pcut_item_t *test) { 157 157 before_test_start(test); 158 158 … … 161 161 int tempfile = vfs_lookup_open(tempfile_name, WALK_REGULAR | WALK_MAY_CREATE, MODE_READ | MODE_WRITE); 162 162 if (tempfile < 0) { 163 pcut_report_test_done(test, TEST_OUTCOME_ERROR, "Failed to create temporary file.", NULL, NULL);164 return ;163 pcut_report_test_done(test, PCUT_OUTCOME_INTERNAL_ERROR, "Failed to create temporary file.", NULL, NULL); 164 return PCUT_OUTCOME_INTERNAL_ERROR; 165 165 } 166 166 … … 174 174 }; 175 175 176 int status = TEST_OUTCOME_PASS;176 int status = PCUT_OUTCOME_PASS; 177 177 178 178 task_wait_t test_task_wait; … … 180 180 fileno(stdin), tempfile, tempfile); 181 181 if (rc != EOK) { 182 status = TEST_OUTCOME_ERROR;182 status = PCUT_OUTCOME_INTERNAL_ERROR; 183 183 goto leave_close_tempfile; 184 184 } … … 198 198 rc = task_wait(&test_task_wait, &task_exit, &task_retval); 199 199 if (rc != EOK) { 200 status = TEST_OUTCOME_ERROR;200 status = PCUT_OUTCOME_INTERNAL_ERROR; 201 201 goto leave_close_tempfile; 202 202 } 203 203 if (task_exit == TASK_EXIT_UNEXPECTED) { 204 status = TEST_OUTCOME_ERROR;204 status = PCUT_OUTCOME_INTERNAL_ERROR; 205 205 } else { 206 status = task_retval == 0 ? TEST_OUTCOME_PASS : TEST_OUTCOME_FAIL;206 status = task_retval == 0 ? PCUT_OUTCOME_PASS : PCUT_OUTCOME_FAIL; 207 207 } 208 208 … … 221 221 222 222 pcut_report_test_done_unparsed(test, status, extra_output_buffer, OUTPUT_BUFFER_SIZE); 223 224 return status; 223 225 } 224 226 -
uspace/lib/pcut/src/os/unix.c
r6fb8b2c r9eb1ff5 36 36 /** We need _BSD_SOURCE because of snprintf() when compiling under C89. */ 37 37 #define _BSD_SOURCE 38 39 /** Newer versions of features.h needs _DEFAULT_SOURCE. */ 40 #define _DEFAULT_SOURCE 41 38 42 #include <stdlib.h> 39 43 #include <unistd.h> 40 #include <s tddef.h>44 #include <sys/types.h> 41 45 #include <signal.h> 42 46 #include <errno.h> … … 120 124 if (WIFEXITED(status)) { 121 125 if (WEXITSTATUS(status) != 0) { 122 return TEST_OUTCOME_FAIL;126 return PCUT_OUTCOME_FAIL; 123 127 } else { 124 return TEST_OUTCOME_PASS;128 return PCUT_OUTCOME_PASS; 125 129 } 126 130 } 127 131 128 132 if (WIFSIGNALED(status)) { 129 return TEST_OUTCOME_ERROR;133 return PCUT_OUTCOME_INTERNAL_ERROR; 130 134 } 131 135 … … 138 142 * @param test Test to be run. 139 143 */ 140 voidpcut_run_test_forking(const char *self_path, pcut_item_t *test) {144 int pcut_run_test_forking(const char *self_path, pcut_item_t *test) { 141 145 int link_stdout[2], link_stderr[2]; 142 int rc, status ;146 int rc, status, outcome; 143 147 size_t stderr_size; 144 148 … … 152 156 snprintf(error_message_buffer, OUTPUT_BUFFER_SIZE - 1, 153 157 "pipe() failed: %s.", strerror(rc)); 154 pcut_report_test_done(test, TEST_OUTCOME_ERROR, error_message_buffer, NULL, NULL);155 return ;158 pcut_report_test_done(test, PCUT_OUTCOME_INTERNAL_ERROR, error_message_buffer, NULL, NULL); 159 return PCUT_OUTCOME_INTERNAL_ERROR; 156 160 } 157 161 rc = pipe(link_stderr); … … 159 163 snprintf(error_message_buffer, OUTPUT_BUFFER_SIZE - 1, 160 164 "pipe() failed: %s.", strerror(rc)); 161 pcut_report_test_done(test, TEST_OUTCOME_ERROR, error_message_buffer, NULL, NULL);162 return ;165 pcut_report_test_done(test, PCUT_OUTCOME_INTERNAL_ERROR, error_message_buffer, NULL, NULL); 166 return PCUT_OUTCOME_INTERNAL_ERROR; 163 167 } 164 168 … … 167 171 snprintf(error_message_buffer, OUTPUT_BUFFER_SIZE - 1, 168 172 "fork() failed: %s.", strerror(rc)); 169 rc = TEST_OUTCOME_ERROR;173 outcome = PCUT_OUTCOME_INTERNAL_ERROR; 170 174 goto leave_close_pipes; 171 175 } … … 178 182 close(link_stderr[0]); 179 183 180 rc= pcut_run_test_forked(test);181 182 exit( rc);184 outcome = pcut_run_test_forked(test); 185 186 exit(outcome); 183 187 } 184 188 … … 195 199 alarm(0); 196 200 197 rc= convert_wait_status_to_outcome(status);201 outcome = convert_wait_status_to_outcome(status); 198 202 199 203 goto leave_close_parent_pipe; … … 206 210 close(link_stderr[0]); 207 211 208 pcut_report_test_done_unparsed(test, rc, extra_output_buffer, OUTPUT_BUFFER_SIZE); 212 pcut_report_test_done_unparsed(test, outcome, extra_output_buffer, OUTPUT_BUFFER_SIZE); 213 214 return outcome; 209 215 } 210 216 -
uspace/lib/pcut/src/os/windows.c
r6fb8b2c r9eb1ff5 144 144 * @param test Test to be run. 145 145 */ 146 voidpcut_run_test_forking(const char *self_path, pcut_item_t *test) {146 int pcut_run_test_forking(const char *self_path, pcut_item_t *test) { 147 147 /* TODO: clean-up if something goes wrong "in the middle" */ 148 148 BOOL okay = FALSE; … … 173 173 if (!okay) { 174 174 report_func_fail(test, "CreatePipe(/* stdout */)"); 175 return ;175 return PCUT_OUTCOME_INTERNAL_ERROR; 176 176 } 177 177 okay = SetHandleInformation(link_stdout[0], HANDLE_FLAG_INHERIT, 0); 178 178 if (!okay) { 179 179 report_func_fail(test, "SetHandleInformation(/* stdout */)"); 180 return ;180 return PCUT_OUTCOME_INTERNAL_ERROR; 181 181 } 182 182 … … 185 185 if (!okay) { 186 186 report_func_fail(test, "CreatePipe(/* stderr */)"); 187 return ;187 return PCUT_OUTCOME_INTERNAL_ERROR; 188 188 } 189 189 okay = SetHandleInformation(link_stderr[0], HANDLE_FLAG_INHERIT, 0); 190 190 if (!okay) { 191 191 report_func_fail(test, "SetHandleInformation(/* stderr */)"); 192 return ;192 return PCUT_OUTCOME_INTERNAL_ERROR; 193 193 } 194 194 … … 197 197 if (!okay) { 198 198 report_func_fail(test, "CreatePipe(/* stdin */)"); 199 return ;199 return PCUT_OUTCOME_INTERNAL_ERROR; 200 200 } 201 201 okay = SetHandleInformation(link_stdin[1], HANDLE_FLAG_INHERIT, 0); 202 202 if (!okay) { 203 203 report_func_fail(test, "SetHandleInformation(/* stdin */)"); 204 return ;204 return PCUT_OUTCOME_INTERNAL_ERROR; 205 205 } 206 206 … … 224 224 if (!okay) { 225 225 report_func_fail(test, "CreateProcess()"); 226 return ;226 return PCUT_OUTCOME_INTERNAL_ERROR; 227 227 } 228 228 … … 236 236 if (!okay) { 237 237 report_func_fail(test, "CloseHandle(/* stdout */)"); 238 return ;238 return PCUT_OUTCOME_INTERNAL_ERROR; 239 239 } 240 240 okay = CloseHandle(link_stderr[1]); 241 241 if (!okay) { 242 242 report_func_fail(test, "CloseHandle(/* stderr */)"); 243 return ;243 return PCUT_OUTCOME_INTERNAL_ERROR; 244 244 } 245 245 okay = CloseHandle(link_stdin[0]); 246 246 if (!okay) { 247 247 report_func_fail(test, "CloseHandle(/* stdin */)"); 248 return ;248 return PCUT_OUTCOME_INTERNAL_ERROR; 249 249 } 250 250 … … 267 267 if (test_output_thread_reader == NULL) { 268 268 report_func_fail(test, "CreateThread(/* read test stdout */)"); 269 return ;269 return PCUT_OUTCOME_INTERNAL_ERROR; 270 270 } 271 271 … … 281 281 if (!okay) { 282 282 report_func_fail(test, "TerminateProcess(/* PROCESS_INFORMATION.hProcess */)"); 283 return ;283 return PCUT_ERROR_INTERNAL_FAILURE; 284 284 } 285 285 rc = WaitForSingleObject(process_info.hProcess, INFINITE); … … 287 287 if (rc != WAIT_OBJECT_0) { 288 288 report_func_fail(test, "WaitForSingleObject(/* PROCESS_INFORMATION.hProcess */)"); 289 return ;289 return PCUT_OUTCOME_INTERNAL_ERROR; 290 290 } 291 291 … … 294 294 if (!okay) { 295 295 report_func_fail(test, "GetExitCodeProcess()"); 296 return ;296 return PCUT_OUTCOME_INTERNAL_ERROR; 297 297 } 298 298 299 299 if (rc == 0) { 300 outcome = TEST_OUTCOME_PASS;300 outcome = PCUT_OUTCOME_PASS; 301 301 } else if ((rc > 0) && (rc < 10) && !timed_out) { 302 outcome = TEST_OUTCOME_FAIL;302 outcome = PCUT_OUTCOME_FAIL; 303 303 } else { 304 outcome = TEST_OUTCOME_ERROR;304 outcome = PCUT_OUTCOME_INTERNAL_ERROR; 305 305 } 306 306 … … 309 309 if (rc != WAIT_OBJECT_0) { 310 310 report_func_fail(test, "WaitForSingleObject(/* stdout reader thread */)"); 311 return ;311 return PCUT_ERROR_INTERNAL_FAILURE; 312 312 } 313 313 314 314 pcut_report_test_done_unparsed(test, outcome, extra_output_buffer, OUTPUT_BUFFER_SIZE); 315 316 return outcome; 315 317 } 316 318 -
uspace/lib/pcut/src/print.c
r6fb8b2c r9eb1ff5 81 81 printf(" Test `%s' [%d]\n", it->name, it->id); 82 82 break; 83 case PCUT_KIND_SETUP: 84 case PCUT_KIND_TEARDOWN: 85 /* Fall-through, do nothing. */ 86 break; 83 87 default: 84 88 assert(0 && "unreachable case in item-kind switch"); -
uspace/lib/pcut/src/report/tap.c
r6fb8b2c r9eb1ff5 42 42 static int test_counter; 43 43 44 /** Counter of all failures. */ 45 static int failed_test_counter; 46 44 47 /** Counter for tests in a current suite. */ 45 48 static int tests_in_suite; … … 55 58 int tests_total = pcut_count_tests(all_items); 56 59 test_counter = 0; 60 failed_test_counter = 0; 57 61 58 62 printf("1..%d\n", tests_total); … … 75 79 */ 76 80 static void tap_suite_done(pcut_item_t *suite) { 77 printf("#> Finished suite %s (failed %d of %d).\n", 78 suite->name, failed_tests_in_suite, tests_in_suite); 81 if (failed_tests_in_suite == 0) { 82 printf("#> Finished suite %s (passed).\n", 83 suite->name); 84 } else { 85 printf("#> Finished suite %s (failed %d of %d).\n", 86 suite->name, failed_tests_in_suite, tests_in_suite); 87 } 79 88 } 80 89 … … 129 138 const char *fail_error_str = NULL; 130 139 131 if (outcome != TEST_OUTCOME_PASS) {140 if (outcome != PCUT_OUTCOME_PASS) { 132 141 failed_tests_in_suite++; 142 failed_test_counter++; 133 143 } 134 144 135 145 switch (outcome) { 136 case TEST_OUTCOME_PASS:146 case PCUT_OUTCOME_PASS: 137 147 status_str = "ok"; 138 148 fail_error_str = ""; 139 149 break; 140 case TEST_OUTCOME_FAIL:150 case PCUT_OUTCOME_FAIL: 141 151 status_str = "not ok"; 142 152 fail_error_str = " failed"; 143 153 break; 144 case TEST_OUTCOME_ERROR:154 default: 145 155 status_str = "not ok"; 146 156 fail_error_str = " aborted"; 147 break;148 default:149 /* Shall not get here. */150 157 break; 151 158 } … … 160 167 /** Report testing done. */ 161 168 static void tap_done(void) { 169 if (failed_test_counter == 0) { 170 printf("#> Done: all tests passed.\n"); 171 } else { 172 printf("#> Done: %d of %d tests failed.\n", failed_test_counter, test_counter); 173 } 162 174 } 163 175 -
uspace/lib/pcut/src/report/xml.c
r6fb8b2c r9eb1ff5 135 135 const char *status_str = NULL; 136 136 137 if (outcome != TEST_OUTCOME_PASS) {137 if (outcome != PCUT_OUTCOME_PASS) { 138 138 failed_tests_in_suite++; 139 139 } 140 140 141 141 switch (outcome) { 142 case TEST_OUTCOME_PASS:142 case PCUT_OUTCOME_PASS: 143 143 status_str = "pass"; 144 144 break; 145 case TEST_OUTCOME_FAIL:145 case PCUT_OUTCOME_FAIL: 146 146 status_str = "fail"; 147 147 break; 148 case TEST_OUTCOME_ERROR:148 default: 149 149 status_str = "error"; 150 break;151 default:152 /* Shall not get here. */153 150 break; 154 151 } -
uspace/lib/pcut/src/run.c
r6fb8b2c r9eb1ff5 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) { 162 pcut_report_test_done(current_test, TEST_OUTCOME_FAIL,158 pcut_report_test_done(current_test, PCUT_OUTCOME_FAIL, 163 159 message, NULL, NULL); 164 160 } 165 161 } else { 166 162 if (report_test_result) { 167 pcut_report_test_done(current_test, TEST_OUTCOME_FAIL,163 pcut_report_test_done(current_test, PCUT_OUTCOME_FAIL, 168 164 prev_message, message, NULL); 169 165 } 170 166 } 171 167 172 168 prev_message = NULL; 173 174 leave_test( TEST_OUTCOME_FAIL); /* No return. */169 170 leave_test(PCUT_OUTCOME_FAIL); /* No return. */ 175 171 } 176 172 … … 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) 193 return 1; 186 if (test_finished) { 187 return PCUT_OUTCOME_FAIL; 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) 233 pcut_report_test_done(current_test, TEST_OUTCOME_PASS, 234 NULL, NULL, NULL); 235 236 return 0; 228 if (report_test_result) { 229 pcut_report_test_done(current_test, PCUT_OUTCOME_PASS, 230 NULL, NULL, NULL); 231 } 232 233 return PCUT_OUTCOME_PASS; 237 234 } 238 235 … … 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 } -
uspace/lib/pcut/tests/abort.expected
r6fb8b2c r9eb1ff5 3 3 not ok 1 access_null_pointer aborted 4 4 #> Finished suite Default (failed 1 of 1). 5 #> Done: 1 of 1 tests failed. -
uspace/lib/pcut/tests/asserts.expected
r6fb8b2c r9eb1ff5 18 18 # error: asserts.c:72: Expected false but got <42> 19 19 #> Finished suite Default (failed 7 of 9). 20 #> Done: 7 of 9 tests failed. -
uspace/lib/pcut/tests/beforeafter.c
r6fb8b2c r9eb1ff5 28 28 29 29 #define _BSD_SOURCE 30 #define _DEFAULT_SOURCE 30 31 31 32 #include <pcut/pcut.h> -
uspace/lib/pcut/tests/beforeafter.expected
r6fb8b2c r9eb1ff5 2 2 #> Starting suite suite_with_setup_and_teardown. 3 3 ok 1 test_with_setup_and_teardown 4 #> Finished suite suite_with_setup_and_teardown ( failed 0 of 1).4 #> Finished suite suite_with_setup_and_teardown (passed). 5 5 #> Starting suite another_without_setup. 6 6 ok 2 test_without_any_setup_or_teardown 7 #> Finished suite another_without_setup (failed 0 of 1). 7 #> Finished suite another_without_setup (passed). 8 #> Done: all tests passed. -
uspace/lib/pcut/tests/errno.expected
r6fb8b2c r9eb1ff5 6 6 # error: errno.c:54: Expected error 0 (EOK, *****) but got error ***** (*****) 7 7 #> Finished suite Default (failed 2 of 2). 8 #> Done: 2 of 2 tests failed. -
uspace/lib/pcut/tests/inithook.expected
r6fb8b2c r9eb1ff5 3 3 ok 1 check_init_counter 4 4 ok 2 check_init_counter_2 5 #> Finished suite Default (failed 0 of 2). 5 #> Finished suite Default (passed). 6 #> Done: all tests passed. -
uspace/lib/pcut/tests/manytests.expected
r6fb8b2c r9eb1ff5 81 81 ok 79 my_test_079 82 82 ok 80 my_test_080 83 #> Finished suite Default (failed 0 of 80). 83 #> Finished suite Default (passed). 84 #> Done: all tests passed. -
uspace/lib/pcut/tests/multisuite.expected
r6fb8b2c r9eb1ff5 11 11 ok 4 test_same_numbers 12 12 #> Finished suite intmin (failed 1 of 2). 13 #> Done: 3 of 4 tests failed. -
uspace/lib/pcut/tests/preinithook.expected
r6fb8b2c r9eb1ff5 3 3 ok 1 check_init_counter 4 4 ok 2 check_init_counter_2 5 #> Finished suite Default (failed 0 of 2). 5 #> Finished suite Default (passed). 6 #> Done: all tests passed. -
uspace/lib/pcut/tests/printing.expected
r6fb8b2c r9eb1ff5 9 9 # stdio: Printed from a test to stdout! 10 10 #> Finished suite Default (failed 1 of 3). 11 #> Done: 1 of 3 tests failed. -
uspace/lib/pcut/tests/simple.expected
r6fb8b2c r9eb1ff5 8 8 # error: simple.c:46: Expected <abc> but got <abd> ("abc" != "XXXabd" + 3) 9 9 #> Finished suite Default (failed 3 of 3). 10 #> Done: 3 of 3 tests failed. -
uspace/lib/pcut/tests/skip.expected
r6fb8b2c r9eb1ff5 3 3 ok 1 normal_test 4 4 ok 2 again_normal_test 5 #> Finished suite Default (failed 0 of 2). 5 #> Finished suite Default (passed). 6 #> Done: all tests passed. -
uspace/lib/pcut/tests/suites.expected
r6fb8b2c r9eb1ff5 10 10 # error: suites.c:49: Expected <5> but got <654> (5 != intmin(654, 5)) 11 11 #> Finished suite intmin (failed 1 of 1). 12 #> Done: 3 of 3 tests failed. -
uspace/lib/pcut/tests/teardown.expected
r6fb8b2c r9eb1ff5 21 21 # stdio: This is failing teardown-function. 22 22 #> Finished suite with_failing_teardown (failed 3 of 3). 23 #> Done: 4 of 5 tests failed. -
uspace/lib/pcut/tests/teardownaborts.expected
r6fb8b2c r9eb1ff5 5 5 # stdio: Tear-down will cause null pointer access... 6 6 #> Finished suite Default (failed 1 of 1). 7 #> Done: 1 of 1 tests failed. -
uspace/lib/pcut/tests/timeout.c
r6fb8b2c r9eb1ff5 29 29 #include <pcut/pcut.h> 30 30 31 #ifdef __helenos__ 32 #include <thread.h> 33 #else 31 34 #ifdef __unix 32 // FIXME 33 #include <thread.h> 35 #include <unistd.h> 34 36 #endif 35 37 #if defined(__WIN64) || defined(__WIN32) || defined(_WIN32) 36 38 #include <windows.h> 39 #endif 37 40 #endif 38 41 … … 41 44 42 45 static void my_sleep(int sec) { 46 #ifdef __helenos__ 47 thread_sleep(sec); 48 #else 43 49 #ifdef __unix 44 // FIXME 45 thread_sleep(sec); 50 sleep(sec); 46 51 #endif 47 52 #if defined(__WIN64) || defined(__WIN32) || defined(_WIN32) 48 53 Sleep(1000 * sec); 54 #endif 49 55 #endif 50 56 } -
uspace/lib/pcut/tests/timeout.expected
r6fb8b2c r9eb1ff5 7 7 # stdio: Text after the sleep. 8 8 #> Finished suite Default (failed 1 of 2). 9 #> Done: 1 of 2 tests failed. -
uspace/lib/pcut/tests/xmlreport.c
r6fb8b2c r9eb1ff5 30 30 #include "tested.h" 31 31 32 #include <pcut/pcut.h> 33 #include "tested.h" 32 34 33 35 PCUT_INIT
Note:
See TracChangeset
for help on using the changeset viewer.