Changeset 9b20126 in mainline for uspace/lib/pcut/src
- Timestamp:
- 2014-09-19T08:23:01Z (11 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c85a57f
- Parents:
- 15d0046
- Location:
- uspace/lib/pcut/src
- Files:
-
- 1 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/pcut/src/assert.c
r15d0046 r9b20126 35 35 */ 36 36 37 /** We need _BSD_SOURCE because of vsnprintf() when compiling under C89. */ 38 #define _BSD_SOURCE 39 37 40 #include "internal.h" 38 41 #include <setjmp.h> … … 52 55 static int message_buffer_index = 0; 53 56 54 /** Announce that assertion failed. 55 * 56 * @warning This function may not return. 57 * 58 * @param fmt printf-style formatting string. 59 * 60 */ 61 void pcut_failed_assertion_fmt(const char *fmt, ...) { 57 void pcut_failed_assertion_fmt(const char *filename, int line, const char *fmt, ...) { 58 va_list args; 62 59 char *current_buffer = message_buffer[message_buffer_index]; 60 size_t offset = 0; 63 61 message_buffer_index = (message_buffer_index + 1) % MESSAGE_BUFFER_COUNT; 64 62 65 va_list args; 66 va_start(args, fmt); 67 vsnprintf(current_buffer, MAX_MESSAGE_LENGTH, fmt, args); 68 va_end(args); 63 snprintf(current_buffer, MAX_MESSAGE_LENGTH, "%s:%d: ", filename, line); 64 offset = pcut_str_size(current_buffer); 65 66 if (offset + 1 < MAX_MESSAGE_LENGTH) { 67 va_start(args, fmt); 68 vsnprintf(current_buffer + offset, MAX_MESSAGE_LENGTH - offset, fmt, args); 69 va_end(args); 70 } 69 71 70 72 pcut_failed_assertion(current_buffer); -
uspace/lib/pcut/src/internal.h
r15d0046 r9b20126 37 37 #include <stdlib.h> 38 38 39 40 /** @def PCUT_DEBUG(msg, ...) 41 * Debug printing. 42 * 43 * By default, this macro does nothing. Define PCUT_DEBUG_BUILD to 44 * actually print the messages to the console. 45 * 46 * @param msg Printf-like formatting message. 47 * @param ... Extra arguments for printf. 48 */ 49 #ifdef PCUT_DEBUG_BUILD 50 #include <stdio.h> 51 #define PCUT_DEBUG_INTERNAL(msg, ...) \ 52 fprintf(stderr, "[PCUT %s:%d]: " msg "%s", __FILE__, __LINE__, __VA_ARGS__) 53 #define PCUT_DEBUG(...) \ 54 PCUT_DEBUG_INTERNAL( \ 55 PCUT_VARG_GET_FIRST(__VA_ARGS__, this_arg_is_ignored), \ 56 PCUT_VARG_SKIP_FIRST(__VA_ARGS__, "\n") \ 57 ) 58 #else 59 #define PCUT_DEBUG(...) (void)0 60 #endif 61 62 39 63 /** Mark a variable as unused. */ 40 64 #define PCUT_UNUSED(x) ((void)x) … … 63 87 /** Test outcome: test failed unexpectedly. */ 64 88 #define TEST_OUTCOME_ERROR 3 89 90 91 /* 92 * Use sprintf_s in Windows but only with Microsoft compiler. 93 * Namely, let MinGW use snprintf. 94 */ 95 #if (defined(__WIN64) || defined(__WIN32) || defined(_WIN32)) && defined(_MSC_VER) 96 #define snprintf sprintf_s 97 #endif 65 98 66 99 extern int pcut_run_mode; … … 92 125 /** Initialize the reporting, given all tests. */ 93 126 void (*init)(pcut_item_t *); 127 /** Finalize the reporting. */ 128 void (*done)(void); 94 129 /** Test suite just started. */ 95 130 void (*suite_start)(pcut_item_t *); … … 101 136 void (*test_done)(pcut_item_t *, int, const char *, const char *, 102 137 const char *); 103 /** Finalize the reporting. */104 void (*done)(void);105 138 }; 106 139 … … 120 153 /* OS-dependent functions. */ 121 154 155 /** Hook to execute before test starts. 156 * 157 * Useful for OS-specific preparations prior to launching the actual 158 * test code (i. e. sandboxing the process more etc.). 159 * 160 * This function is not run by the launcher process that only 161 * starts other tests in separate processes. 162 * 163 * @param test The test that is about to be executed. 164 */ 165 void pcut_hook_before_test(pcut_item_t *test); 166 122 167 /** Tell whether two strings start with the same prefix. 123 168 * -
uspace/lib/pcut/src/list.c
r15d0046 r9b20126 82 82 */ 83 83 static void inline_nested_lists(pcut_item_t *nested) { 84 pcut_item_t *first; 85 84 86 if (nested->kind != PCUT_KIND_NESTED) { 85 87 return; 86 88 } 87 89 88 if (nested->nested .last== NULL) {90 if (nested->nested == NULL) { 89 91 nested->kind = PCUT_KIND_SKIP; 90 92 return; 91 93 } 92 94 93 pcut_item_t *first = pcut_fix_list_get_real_head(nested->nested.last);94 nested->nested .last->next = nested->next;95 first = pcut_fix_list_get_real_head(nested->nested); 96 nested->nested->next = nested->next; 95 97 if (nested->next != NULL) { 96 nested->next->previous = nested->nested .last;98 nested->next->previous = nested->nested; 97 99 } 98 100 nested->next = first; … … 107 109 */ 108 110 static void set_ids(pcut_item_t *first) { 111 int id = 1; 112 pcut_item_t *it; 113 109 114 assert(first != NULL); 110 int id = 1; 115 111 116 if (first->kind == PCUT_KIND_SKIP) { 112 117 first = pcut_get_real_next(first); 113 118 } 114 for (pcut_item_t *it = first; it != NULL; it = pcut_get_real_next(it)) { 119 120 for (it = first; it != NULL; it = pcut_get_real_next(it)) { 115 121 it->id = id; 116 122 id++; … … 126 132 */ 127 133 static void detect_skipped_tests(pcut_item_t *first) { 134 pcut_item_t *it; 135 128 136 assert(first != NULL); 129 137 if (first->kind == PCUT_KIND_SKIP) { 130 138 first = pcut_get_real_next(first); 131 139 } 132 for (pcut_item_t *it = first; it != NULL; it = pcut_get_real_next(it)) { 140 141 for (it = first; it != NULL; it = pcut_get_real_next(it)) { 142 pcut_extra_t *extras; 143 133 144 if (it->kind != PCUT_KIND_TEST) { 134 145 continue; 135 146 } 136 pcut_extra_t *extras = it->test.extras; 147 148 extras = it->extras; 137 149 while (extras->type != PCUT_EXTRA_LAST) { 138 150 if (extras->type == PCUT_EXTRA_SKIP) { … … 156 168 */ 157 169 pcut_item_t *pcut_fix_list_get_real_head(pcut_item_t *last) { 170 pcut_item_t *next, *it; 171 158 172 last->next = NULL; 159 173 160 174 inline_nested_lists(last); 161 175 162 pcut_item_t *next = last; 163 164 pcut_item_t *it = last->previous; 176 next = last; 177 it = last->previous; 165 178 while (it != NULL) { 166 179 it->next = next; -
uspace/lib/pcut/src/main.c
r15d0046 r9b20126 41 41 int pcut_run_mode = PCUT_RUN_MODE_FORKING; 42 42 43 /** Empty list to bypass special handling for NULL. */ 44 static pcut_main_extra_t empty_main_extra[] = { 45 PCUT_MAIN_EXTRA_SET_LAST 46 }; 47 48 /** Helper for iteration over main extras. */ 49 #define FOR_EACH_MAIN_EXTRA(extras, it) \ 50 for (it = extras; it->type != PCUT_MAIN_EXTRA_LAST; it++) 43 51 44 52 /** Checks whether the argument is an option followed by a number. … … 54 62 return 0; 55 63 } 56 int val = pcut_str_to_int(arg + opt_len); 57 *value = val; 64 *value = pcut_str_to_int(arg + opt_len); 58 65 return 1; 59 66 } … … 85 92 */ 86 93 static void run_suite(pcut_item_t *suite, pcut_item_t **last, const char *prog_path) { 94 int is_first_test = 1; 95 int total_count = 0; 96 87 97 pcut_item_t *it = pcut_get_real_next(suite); 88 98 if ((it == NULL) || (it->kind == PCUT_KIND_TESTSUITE)) { … … 90 100 } 91 101 92 int is_first_test = 1;93 int total_count = 0;94 95 102 for (; it != NULL; it = pcut_get_real_next(it)) { 96 103 if (it->kind == PCUT_KIND_TESTSUITE) { … … 135 142 static void set_setup_teardown_callbacks(pcut_item_t *first) { 136 143 pcut_item_t *active_suite = NULL; 137 for (pcut_item_t *it = first; it != NULL; it = pcut_get_real_next(it)) { 144 pcut_item_t *it; 145 for (it = first; it != NULL; it = pcut_get_real_next(it)) { 138 146 if (it->kind == PCUT_KIND_TESTSUITE) { 139 147 active_suite = it; 140 148 } else if (it->kind == PCUT_KIND_SETUP) { 141 149 if (active_suite != NULL) { 142 active_suite->s uite.setup = it->setup.func;150 active_suite->setup_func = it->setup_func; 143 151 } 144 152 it->kind = PCUT_KIND_SKIP; 145 153 } else if (it->kind == PCUT_KIND_TEARDOWN) { 146 154 if (active_suite != NULL) { 147 active_suite-> suite.teardown = it->setup.func;155 active_suite->teardown_func = it->teardown_func; 148 156 } 149 157 it->kind = PCUT_KIND_SKIP; … … 166 174 int pcut_main(pcut_item_t *last, int argc, char *argv[]) { 167 175 pcut_item_t *items = pcut_fix_list_get_real_head(last); 176 pcut_item_t *it; 177 pcut_main_extra_t *main_extras = last->main_extras; 178 pcut_main_extra_t *main_extras_it; 168 179 169 180 int run_only_suite = -1; 170 181 int run_only_test = -1; 171 182 183 if (main_extras == NULL) { 184 main_extras = empty_main_extra; 185 } 186 172 187 pcut_report_register_handler(&pcut_report_tap); 188 189 FOR_EACH_MAIN_EXTRA(main_extras, main_extras_it) { 190 if (main_extras_it->type == PCUT_MAIN_EXTRA_REPORT_XML) { 191 pcut_report_register_handler(&pcut_report_xml); 192 } 193 if (main_extras_it->type == PCUT_MAIN_EXTRA_PREINIT_HOOK) { 194 main_extras_it->preinit_hook(&argc, &argv); 195 } 196 } 173 197 174 198 if (argc > 1) { … … 195 219 set_setup_teardown_callbacks(items); 196 220 221 FOR_EACH_MAIN_EXTRA(main_extras, main_extras_it) { 222 if (main_extras_it->type == PCUT_MAIN_EXTRA_INIT_HOOK) { 223 main_extras_it->init_hook(); 224 } 225 } 226 197 227 PCUT_DEBUG("run_only_suite = %d run_only_test = %d", run_only_suite, run_only_test); 198 228 … … 218 248 219 249 if (run_only_test > 0) { 250 int rc; 220 251 pcut_item_t *test = pcut_find_by_id(items, run_only_test); 221 252 if (test == NULL) { … … 228 259 } 229 260 230 int rc;231 261 if (pcut_run_mode == PCUT_RUN_MODE_SINGLE) { 232 262 rc = pcut_run_test_single(test); … … 241 271 pcut_report_init(items); 242 272 243 pcut_item_t *it = items;273 it = items; 244 274 while (it != NULL) { 245 275 if (it->kind == PCUT_KIND_TESTSUITE) { -
uspace/lib/pcut/src/os/generic.c
r15d0046 r9b20126 33 33 34 34 #include <stdlib.h> 35 #include <stdio.h> 35 36 #include <sys/types.h> 36 37 #include <errno.h> … … 50 51 /* Format the command to launch a test according to OS we are running on. */ 51 52 52 #if defined(__WIN64) || defined(__WIN32) 53 #if defined(__WIN64) || defined(__WIN32) || defined(_WIN32) 53 54 #include <process.h> 54 55 … … 108 109 */ 109 110 void pcut_run_test_forking(const char *self_path, pcut_item_t *test) { 111 int rc; 112 FILE *tempfile; 113 char tempfile_name[PCUT_TEMP_FILENAME_BUFFER_SIZE]; 114 char command[PCUT_COMMAND_LINE_BUFFER_SIZE]; 115 110 116 before_test_start(test); 111 117 112 char tempfile_name[PCUT_TEMP_FILENAME_BUFFER_SIZE];113 118 FORMAT_TEMP_FILENAME(tempfile_name, PCUT_TEMP_FILENAME_BUFFER_SIZE - 1); 114 115 char command[PCUT_COMMAND_LINE_BUFFER_SIZE];116 119 FORMAT_COMMAND(command, PCUT_COMMAND_LINE_BUFFER_SIZE - 1, 117 120 self_path, (test)->id, tempfile_name); 121 122 PCUT_DEBUG("Will execute <%s> (temp file <%s>) with system().", 123 command, tempfile_name); 118 124 119 int rc = system(command); 125 rc = system(command); 126 127 PCUT_DEBUG("system() returned 0x%04X", rc); 128 120 129 rc = convert_wait_status_to_outcome(rc); 121 130 122 FILE *tempfile = fopen(tempfile_name, "rb");131 tempfile = fopen(tempfile_name, "rb"); 123 132 if (tempfile == NULL) { 124 133 pcut_report_test_done(test, TEST_OUTCOME_ERROR, "Failed to open temporary file.", NULL, NULL); … … 133 142 } 134 143 144 void pcut_hook_before_test(pcut_item_t *test) { 145 PCUT_UNUSED(test); 146 147 /* Do nothing. */ 148 } 149 -
uspace/lib/pcut/src/os/helenos.c
r15d0046 r9b20126 185 185 int status = TEST_OUTCOME_PASS; 186 186 187 int rc = task_spawnvf(&test_task_id, self_path, arguments, files); 187 task_wait_t test_task_wait; 188 int rc = task_spawnvf(&test_task_id, &test_task_wait, self_path, arguments, files); 188 189 if (rc != EOK) { 189 190 status = TEST_OUTCOME_ERROR; … … 203 204 task_exit_t task_exit; 204 205 int task_retval; 205 rc = task_wait( test_task_id, &task_exit, &task_retval);206 rc = task_wait(&test_task_wait, &task_exit, &task_retval); 206 207 if (rc != EOK) { 207 208 status = TEST_OUTCOME_ERROR; … … 227 228 pcut_report_test_done_unparsed(test, status, extra_output_buffer, OUTPUT_BUFFER_SIZE); 228 229 } 230 231 void pcut_hook_before_test(pcut_item_t *test) { 232 PCUT_UNUSED(test); 233 234 /* Do nothing. */ 235 } -
uspace/lib/pcut/src/os/unix.c
r15d0046 r9b20126 32 32 */ 33 33 34 /** We need _POS X_SOURCE because of kill(). */34 /** We need _POSIX_SOURCE because of kill(). */ 35 35 #define _POSIX_SOURCE 36 /** We need _BSD_SOURCE because of snprintf() when compiling under C89. */ 37 #define _BSD_SOURCE 36 38 #include <stdlib.h> 37 39 #include <unistd.h> … … 137 139 */ 138 140 void pcut_run_test_forking(const char *self_path, pcut_item_t *test) { 141 int link_stdout[2], link_stderr[2]; 142 int rc, status; 143 size_t stderr_size; 144 139 145 PCUT_UNUSED(self_path); 140 146 141 147 before_test_start(test); 142 148 143 int link_stdout[2], link_stderr[2]; 144 145 int rc = pipe(link_stdout); 149 150 rc = pipe(link_stdout); 146 151 if (rc == -1) { 147 152 snprintf(error_message_buffer, OUTPUT_BUFFER_SIZE - 1, … … 184 189 alarm(pcut_get_test_timeout(test)); 185 190 186 s ize_t stderr_size = read_all(link_stderr[0], extra_output_buffer, OUTPUT_BUFFER_SIZE - 1);191 stderr_size = read_all(link_stderr[0], extra_output_buffer, OUTPUT_BUFFER_SIZE - 1); 187 192 read_all(link_stdout[0], extra_output_buffer, OUTPUT_BUFFER_SIZE - 1 - stderr_size); 188 193 189 int status;190 194 wait(&status); 191 195 alarm(0); … … 204 208 pcut_report_test_done_unparsed(test, rc, extra_output_buffer, OUTPUT_BUFFER_SIZE); 205 209 } 210 211 void pcut_hook_before_test(pcut_item_t *test) { 212 PCUT_UNUSED(test); 213 214 /* Do nothing. */ 215 } 216 -
uspace/lib/pcut/src/preproc.c
r15d0046 r9b20126 91 91 } 92 92 93 int main( ) {93 int main(int argc, char *argv[]) { 94 94 FILE *input = stdin; 95 95 FILE *output = stdout; … … 98 98 identifier_t last_identifier; 99 99 100 /* Unused parameters. */ 101 (void) argc; 102 (void) argv; 103 100 104 while (1) { 105 int current_char_denotes_identifier; 106 101 107 int current_char = fgetc(input); 102 108 if (current_char == EOF) { … … 104 110 } 105 111 106 intcurrent_char_denotes_identifier = is_identifier_char(current_char, last_char_was_identifier);112 current_char_denotes_identifier = is_identifier_char(current_char, last_char_was_identifier); 107 113 if (current_char_denotes_identifier) { 108 114 if (!last_char_was_identifier) { -
uspace/lib/pcut/src/print.c
r15d0046 r9b20126 48 48 switch (it->kind) { 49 49 case PCUT_KIND_TEST: 50 printf("TEST %s (%p)\n", it->test.name, it->test.func);50 printf("TEST %s\n", it->name); 51 51 break; 52 52 case PCUT_KIND_TESTSUITE: 53 printf("SUITE %s\n", it-> suite.name);53 printf("SUITE %s\n", it->name); 54 54 break; 55 55 case PCUT_KIND_SKIP: … … 72 72 */ 73 73 void pcut_print_tests(pcut_item_t *first) { 74 for (pcut_item_t *it = pcut_get_real(first); it != NULL; it = pcut_get_real_next(it)) { 74 pcut_item_t *it; 75 for (it = pcut_get_real(first); it != NULL; it = pcut_get_real_next(it)) { 75 76 switch (it->kind) { 76 77 case PCUT_KIND_TESTSUITE: 77 printf(" Suite `%s' [%d]\n", it-> suite.name, it->id);78 printf(" Suite `%s' [%d]\n", it->name, it->id); 78 79 break; 79 80 case PCUT_KIND_TEST: 80 printf(" Test `%s' [%d]\n", it-> test.name, it->id);81 printf(" Test `%s' [%d]\n", it->name, it->id); 81 82 break; 82 83 default: -
uspace/lib/pcut/src/report/report.c
r15d0046 r9b20126 44 44 * 45 45 * @param op Operation to be called on the pcut_report_ops_t. 46 * @param ... Arguments to the operation. 46 47 */ 47 48 #define REPORT_CALL(op, ...) \ 48 49 if ((report_ops != NULL) && (report_ops->op != NULL)) report_ops->op(__VA_ARGS__) 50 51 /** Call a report function if it is available. 52 * 53 * @param op Operation to be called on the pcut_report_ops_t. 54 */ 55 #define REPORT_CALL_NO_ARGS(op) \ 56 if ((report_ops != NULL) && (report_ops->op != NULL)) report_ops->op() 49 57 50 58 /** Print error message. … … 94 102 /* Ensure that we do not read past the full_output. */ 95 103 if (full_output[full_output_size - 1] != 0) { 96 / / FIXME: can this happen?104 /* FIXME: can this happen? */ 97 105 return; 98 106 } 99 107 100 108 while (1) { 109 size_t message_length; 110 101 111 /* First of all, count number of zero bytes before the text. */ 102 112 size_t cont_zeros_count = 0; … … 111 121 112 122 /* Determine the length of the text after the zeros. */ 113 size_tmessage_length = pcut_str_size(full_output);123 message_length = pcut_str_size(full_output); 114 124 115 125 if (cont_zeros_count < 2) { 116 126 /* Okay, standard I/O. */ 117 127 if (message_length > stdio_buffer_size) { 118 / / TODO: handle gracefully128 /* TODO: handle gracefully */ 119 129 return; 120 130 } … … 125 135 /* Error message. */ 126 136 if (message_length > error_buffer_size) { 127 / / TODO: handle gracefully137 /* TODO: handle gracefully */ 128 138 return; 129 139 } … … 213 223 * 214 224 */ 215 void pcut_report_done( ) {216 REPORT_CALL (done);217 } 218 225 void pcut_report_done(void) { 226 REPORT_CALL_NO_ARGS(done); 227 } 228 -
uspace/lib/pcut/src/report/tap.c
r15d0046 r9b20126 67 67 failed_tests_in_suite = 0; 68 68 69 printf("#> Starting suite %s.\n", suite-> suite.name);69 printf("#> Starting suite %s.\n", suite->name); 70 70 } 71 71 … … 76 76 static void tap_suite_done(pcut_item_t *suite) { 77 77 printf("#> Finished suite %s (failed %d of %d).\n", 78 suite-> suite.name, failed_tests_in_suite, tests_in_suite);78 suite->name, failed_tests_in_suite, tests_in_suite); 79 79 } 80 80 … … 98 98 */ 99 99 static void print_by_lines(const char *message, const char *prefix) { 100 char *next_line_start; 100 101 if ((message == NULL) || (message[0] == 0)) { 101 102 return; 102 103 } 103 char *next_line_start = pcut_str_find_char(message, '\n');104 next_line_start = pcut_str_find_char(message, '\n'); 104 105 while (next_line_start != NULL) { 105 106 next_line_start[0] = 0; … … 124 125 const char *error_message, const char *teardown_error_message, 125 126 const char *extra_output) { 126 const char *test_name = test->test.name; 127 const char *test_name = test->name; 128 const char *status_str = NULL; 129 const char *fail_error_str = NULL; 127 130 128 131 if (outcome != TEST_OUTCOME_PASS) { … … 130 133 } 131 134 132 const char *status_str = NULL;133 const char *fail_error_str = NULL;134 135 switch (outcome) { 135 136 case TEST_OUTCOME_PASS: … … 158 159 159 160 /** Report testing done. */ 160 static void tap_done( ) {161 static void tap_done(void) { 161 162 } 162 163 163 164 164 165 pcut_report_ops_t pcut_report_tap = { 165 .init = tap_init, 166 .done = tap_done, 167 .suite_start = tap_suite_start, 168 .suite_done = tap_suite_done, 169 .test_start = tap_test_start, 170 .test_done = tap_test_done 166 tap_init, tap_done, 167 tap_suite_start, tap_suite_done, 168 tap_test_start, tap_test_done 171 169 }; -
uspace/lib/pcut/src/report/xml.c
r15d0046 r9b20126 53 53 */ 54 54 static void xml_init(pcut_item_t *all_items) { 55 printf("<?xml version=\"1.0\"?>\n");56 57 55 int tests_total = pcut_count_tests(all_items); 58 56 test_counter = 0; 59 57 58 printf("<?xml version=\"1.0\"?>\n"); 60 59 printf("<report tests-total=\"%d\">\n", tests_total); 61 60 } … … 69 68 failed_tests_in_suite = 0; 70 69 71 printf("\t<suite name=\"%s\">\n", suite-> suite.name);70 printf("\t<suite name=\"%s\">\n", suite->name); 72 71 } 73 72 … … 77 76 */ 78 77 static void xml_suite_done(pcut_item_t *suite) { 79 printf("\t</suite><!-- %s: %d / %d -->\n", suite-> suite.name,78 printf("\t</suite><!-- %s: %d / %d -->\n", suite->name, 80 79 failed_tests_in_suite, tests_in_suite); 81 80 } … … 100 99 */ 101 100 static void print_by_lines(const char *message, const char *element_name) { 101 char *next_line_start; 102 102 103 if ((message == NULL) || (message[0] == 0)) { 103 104 return; … … 106 107 printf("\t\t\t<%s><![CDATA[", element_name); 107 108 108 char *next_line_start = pcut_str_find_char(message, '\n');109 next_line_start = pcut_str_find_char(message, '\n'); 109 110 while (next_line_start != NULL) { 110 111 next_line_start[0] = 0; … … 131 132 const char *error_message, const char *teardown_error_message, 132 133 const char *extra_output) { 133 const char *test_name = test->test.name; 134 const char *test_name = test->name; 135 const char *status_str = NULL; 134 136 135 137 if (outcome != TEST_OUTCOME_PASS) { … … 137 139 } 138 140 139 const char *status_str = NULL;140 141 switch (outcome) { 141 142 case TEST_OUTCOME_PASS: … … 165 166 166 167 /** Report testing done. */ 167 static void xml_done( ) {168 static void xml_done(void) { 168 169 printf("</report>\n"); 169 170 } … … 171 172 172 173 pcut_report_ops_t pcut_report_xml = { 173 .init = xml_init, 174 .done = xml_done, 175 .suite_start = xml_suite_start, 176 .suite_done = xml_suite_done, 177 .test_start = xml_test_start, 178 .test_done = xml_test_done 174 xml_init, xml_done, 175 xml_suite_start, xml_suite_done, 176 xml_test_start, xml_test_done 179 177 }; -
uspace/lib/pcut/src/run.c
r15d0046 r9b20126 70 70 71 71 /** A NULL-like suite. */ 72 static pcut_item_t default_suite = { 73 .kind = PCUT_KIND_TESTSUITE, 74 .id = -1, 75 .previous = NULL, 76 .next = NULL, 77 .suite = { 78 .name = "Default", 79 .setup = NULL, 80 .teardown = NULL 81 } 82 }; 72 static pcut_item_t default_suite; 73 static int default_suite_initialized = 0; 74 75 static void init_default_suite_when_needed() { 76 if (default_suite_initialized) { 77 return; 78 } 79 default_suite.id = -1; 80 default_suite.kind = PCUT_KIND_TESTSUITE; 81 default_suite.previous = NULL; 82 default_suite.next = NULL; 83 default_suite.name = "Default"; 84 default_suite.setup_func = NULL; 85 default_suite.teardown_func = NULL; 86 } 83 87 84 88 /** Find the suite given test belongs to. … … 94 98 it = it->previous; 95 99 } 100 init_default_suite_when_needed(); 96 101 return &default_suite; 97 102 } … … 115 120 */ 116 121 static void leave_test(int outcome) { 122 PCUT_DEBUG("leave_test(outcome=%d), will_exit=%s", outcome, 123 leave_means_exit ? "yes" : "no"); 117 124 if (leave_means_exit) { 118 125 exit(outcome); … … 145 152 execute_teardown_on_failure = 0; 146 153 prev_message = message; 147 run_setup_teardown(current_suite-> suite.teardown);154 run_setup_teardown(current_suite->teardown_func); 148 155 149 156 /* Tear-down was okay. */ … … 189 196 current_test = test; 190 197 198 pcut_hook_before_test(test); 199 191 200 /* 192 201 * If anything goes wrong, execute the tear-down function … … 198 207 * Run the set-up function. 199 208 */ 200 run_setup_teardown(current_suite->s uite.setup);209 run_setup_teardown(current_suite->setup_func); 201 210 202 211 /* … … 204 213 * the actual test. 205 214 */ 206 test->test .func();215 test->test_func(); 207 216 208 217 /* … … 211 220 */ 212 221 execute_teardown_on_failure = 0; 213 run_setup_teardown(current_suite-> suite.teardown);222 run_setup_teardown(current_suite->teardown_func); 214 223 215 224 /* … … 234 243 */ 235 244 int pcut_run_test_forked(pcut_item_t *test) { 245 int rc; 246 236 247 report_test_result = 0; 237 248 print_test_error = 1; 238 249 leave_means_exit = 1; 239 250 240 intrc = run_test(test);251 rc = run_test(test); 241 252 242 253 current_test = NULL; … … 255 266 */ 256 267 int pcut_run_test_single(pcut_item_t *test) { 268 int rc; 269 257 270 report_test_result = 1; 258 271 print_test_error = 0; 259 272 leave_means_exit = 0; 260 273 261 intrc = run_test(test);274 rc = run_test(test); 262 275 263 276 current_test = NULL; … … 273 286 */ 274 287 int pcut_get_test_timeout(pcut_item_t *test) { 275 PCUT_UNUSED(test);276 277 288 int timeout = PCUT_DEFAULT_TEST_TIMEOUT; 278 279 pcut_extra_t *extras = test->test.extras; 289 pcut_extra_t *extras = test->extras; 290 291 280 292 while (extras->type != PCUT_EXTRA_LAST) { 281 293 if (extras->type == PCUT_EXTRA_TIMEOUT) {
Note:
See TracChangeset
for help on using the changeset viewer.