Changeset 4b54bd9 in mainline for uspace/lib/pcut/src
- Timestamp:
- 2018-09-12T13:23:03Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 3da0ee4
- Parents:
- 275530a4
- Location:
- uspace/lib/pcut/src
- Files:
-
- 1 added
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/pcut/src/assert.c
r275530a4 r4b54bd9 43 43 44 44 #include "internal.h" 45 46 #pragma warning(push, 0) 45 47 #include <setjmp.h> 46 48 #include <stdarg.h> 47 49 #include <stdio.h> 50 #pragma warning(pop) 51 48 52 49 53 /** Maximum length of failed-assert message. */ … … 59 63 static int message_buffer_index = 0; 60 64 61 void pcut_failed_assertion_fmt(const char *filename, int line, const char *fmt, ...) 62 { 65 void pcut_failed_assertion_fmt(const char *filename, int line, const char *fmt, ...) { 63 66 va_list args; 64 67 char *current_buffer = message_buffer[message_buffer_index]; … … 66 69 message_buffer_index = (message_buffer_index + 1) % MESSAGE_BUFFER_COUNT; 67 70 68 snprintf(current_buffer, MAX_MESSAGE_LENGTH, "%s:%d: ", filename, line);71 pcut_snprintf(current_buffer, MAX_MESSAGE_LENGTH, "%s:%d: ", filename, line); 69 72 offset = pcut_str_size(current_buffer); 70 73 -
uspace/lib/pcut/src/internal.h
r275530a4 r4b54bd9 35 35 36 36 #include <pcut/pcut.h> 37 38 #pragma warning(push, 0) 37 39 #include <stdlib.h> 40 #pragma warning(pop) 38 41 39 42 … … 48 51 */ 49 52 #ifdef PCUT_DEBUG_BUILD 53 #pragma warning(push, 0) 50 54 #include <stdio.h> 55 #pragma warning(pop) 51 56 #define PCUT_DEBUG_INTERNAL(msg, ...) \ 52 57 fprintf(stderr, "[PCUT %s:%d]: " msg "%s", __FILE__, __LINE__, __VA_ARGS__) … … 78 83 */ 79 84 #define PCUT_RUN_MODE_SINGLE 2 80 81 /*82 * Use sprintf_s in Windows but only with Microsoft compiler.83 * Namely, let MinGW use snprintf.84 */85 #if (defined(__WIN64) || defined(__WIN32) || defined(_WIN32)) && defined(_MSC_VER)86 #define snprintf sprintf_s87 #endif88 85 89 86 extern int pcut_run_mode; … … 125 122 /** Test completed. */ 126 123 void (*test_done)(pcut_item_t *, int, const char *, const char *, 127 124 const char *); 128 125 }; 129 126 … … 135 132 void pcut_report_test_start(pcut_item_t *test); 136 133 void pcut_report_test_done(pcut_item_t *test, int outcome, 137 138 134 const char *error_message, const char *teardown_error_message, 135 const char *extra_output); 139 136 void pcut_report_test_done_unparsed(pcut_item_t *test, int outcome, 140 137 const char *unparsed_output, size_t unparsed_output_size); 141 138 void pcut_report_done(void); 142 139 … … 187 184 char *pcut_str_find_char(const char *haystack, const char needle); 188 185 186 /** Format string to a buffer. 187 * 188 */ 189 int pcut_snprintf(char *dest, size_t size, const char *format, ...); 189 190 190 191 #endif -
uspace/lib/pcut/src/list.c
r275530a4 r4b54bd9 32 32 */ 33 33 34 #pragma warning(push, 0) 34 35 #include <assert.h> 35 36 #include <stdlib.h> 37 #pragma warning(pop) 38 36 39 #include "internal.h" 37 40 #include <pcut/pcut.h> … … 43 46 * @return First item with actual content or NULL on end of list. 44 47 */ 45 pcut_item_t *pcut_get_real_next(pcut_item_t *item) 46 { 48 pcut_item_t *pcut_get_real_next(pcut_item_t *item) { 47 49 if (item == NULL) { 48 50 return NULL; … … 65 67 * @return First item with actual content or NULL on end of list. 66 68 */ 67 pcut_item_t *pcut_get_real(pcut_item_t *item) 68 { 69 pcut_item_t *pcut_get_real(pcut_item_t *item) { 69 70 if (item == NULL) { 70 71 return NULL; … … 83 84 * @param nested Head of the nested list. 84 85 */ 85 static void inline_nested_lists(pcut_item_t *nested) 86 { 86 static void inline_nested_lists(pcut_item_t *nested) { 87 87 pcut_item_t *first; 88 88 … … 111 111 * @param first List head. 112 112 */ 113 static void set_ids(pcut_item_t *first) 114 { 113 static void set_ids(pcut_item_t *first) { 115 114 int id = 1; 116 115 pcut_item_t *it; … … 135 134 * @param first Head of the list. 136 135 */ 137 static void detect_skipped_tests(pcut_item_t *first) 138 { 136 static void detect_skipped_tests(pcut_item_t *first) { 139 137 pcut_item_t *it; 140 138 … … 172 170 * @return Head of the fixed list. 173 171 */ 174 pcut_item_t *pcut_fix_list_get_real_head(pcut_item_t *last) 175 { 172 pcut_item_t *pcut_fix_list_get_real_head(pcut_item_t *last) { 176 173 pcut_item_t *next, *it; 177 174 … … 201 198 * @return Number of tests. 202 199 */ 203 int pcut_count_tests(pcut_item_t *it) 204 { 200 int pcut_count_tests(pcut_item_t *it) { 205 201 int count = 0; 206 202 while (it != NULL) { -
uspace/lib/pcut/src/main.c
r275530a4 r4b54bd9 34 34 #include "internal.h" 35 35 #include "report/report.h" 36 37 #pragma warning(push, 0) 36 38 #include <assert.h> 37 39 #include <stdlib.h> 38 40 #include <stdio.h> 41 #pragma warning(pop) 42 39 43 40 44 /** Current running mode. */ … … 57 61 * @return Whether @p arg is @p opt followed by a number. 58 62 */ 59 int pcut_is_arg_with_number(const char *arg, const char *opt, int *value) 60 { 63 int pcut_is_arg_with_number(const char *arg, const char *opt, int *value) { 61 64 int opt_len = pcut_str_size(opt); 62 if (! pcut_str_start_equals(arg, opt, opt_len)) {65 if (! pcut_str_start_equals(arg, opt, opt_len)) { 63 66 return 0; 64 67 } … … 75 78 * @retval NULL No item with such id exists in the list. 76 79 */ 77 static pcut_item_t *pcut_find_by_id(pcut_item_t *first, int id) 78 { 80 static pcut_item_t *pcut_find_by_id(pcut_item_t *first, int id) { 79 81 pcut_item_t *it = pcut_get_real(first); 80 82 while (it != NULL) { … … 94 96 * @return Error code. 95 97 */ 96 static int run_suite(pcut_item_t *suite, pcut_item_t **last, const char *prog_path) 97 { 98 static int run_suite(pcut_item_t *suite, pcut_item_t **last, const char *prog_path) { 98 99 int is_first_test = 1; 99 100 int total_count = 0; … … 159 160 * @param first First item of the list. 160 161 */ 161 static void set_setup_teardown_callbacks(pcut_item_t *first) 162 { 162 static void set_setup_teardown_callbacks(pcut_item_t *first) { 163 163 pcut_item_t *active_suite = NULL; 164 164 pcut_item_t *it; … … 192 192 * @return Program exit code. 193 193 */ 194 int pcut_main(pcut_item_t *last, int argc, char *argv[]) 195 { 194 int pcut_main(pcut_item_t *last, int argc, char *argv[]) { 196 195 pcut_item_t *items = pcut_fix_list_get_real_head(last); 197 196 pcut_item_t *it; -
uspace/lib/pcut/src/os/generic.c
r275530a4 r4b54bd9 31 31 * Platform-dependent test execution function when system() is available. 32 32 */ 33 33 #pragma warning(push, 0) 34 34 #include <stdlib.h> 35 35 #include <stdio.h> … … 38 38 #include <assert.h> 39 39 #include <string.h> 40 #pragma warning(pop) 41 40 42 #include "../internal.h" 41 43 … … 55 57 56 58 #define FORMAT_COMMAND(buffer, buffer_size, self_path, test_id, temp_file) \ 57 snprintf(buffer, buffer_size, "\"\"%s\" -t%d >%s\"", self_path, test_id, temp_file)59 pcut_snprintf(buffer, buffer_size, "\"\"%s\" -t%d >%s\"", self_path, test_id, temp_file) 58 60 #define FORMAT_TEMP_FILENAME(buffer, buffer_size) \ 59 snprintf(buffer, buffer_size, "pcut_%d.tmp", _getpid())61 pcut_snprintf(buffer, buffer_size, "pcut_%d.tmp", _getpid()) 60 62 61 63 #elif defined(__unix) … … 63 65 64 66 #define FORMAT_COMMAND(buffer, buffer_size, self_path, test_id, temp_file) \ 65 snprintf(buffer, buffer_size, "%s -t%d &>%s", self_path, test_id, temp_file)67 pcut_snprintf(buffer, buffer_size, "%s -t%d &>%s", self_path, test_id, temp_file) 66 68 #define FORMAT_TEMP_FILENAME(buffer, buffer_size) \ 67 snprintf(buffer, buffer_size, "pcut_%d.tmp", getpid())69 pcut_snprintf(buffer, buffer_size, "pcut_%d.tmp", getpid()) 68 70 69 71 #else … … 81 83 * @param test Test that is about to start. 82 84 */ 83 static void before_test_start(pcut_item_t *test) 84 { 85 static void before_test_start(pcut_item_t *test) { 85 86 pcut_report_test_start(test); 86 87 … … 94 95 * @return Test outcome code. 95 96 */ 96 static int convert_wait_status_to_outcome(int status) 97 { 97 static int convert_wait_status_to_outcome(int status) { 98 98 if (status < 0) { 99 99 return PCUT_OUTCOME_INTERNAL_ERROR; … … 110 110 * @param test Test to be run. 111 111 */ 112 int pcut_run_test_forking(const char *self_path, pcut_item_t *test) 113 { 112 int pcut_run_test_forking(const char *self_path, pcut_item_t *test) { 114 113 int rc, outcome; 115 114 FILE *tempfile; … … 121 120 FORMAT_TEMP_FILENAME(tempfile_name, PCUT_TEMP_FILENAME_BUFFER_SIZE - 1); 122 121 FORMAT_COMMAND(command, PCUT_COMMAND_LINE_BUFFER_SIZE - 1, 123 124 122 self_path, (test)->id, tempfile_name); 123 125 124 PCUT_DEBUG("Will execute <%s> (temp file <%s>) with system().", 126 125 command, tempfile_name); 127 126 128 127 rc = system(command); … … 147 146 } 148 147 149 void pcut_hook_before_test(pcut_item_t *test) 150 { 148 void pcut_hook_before_test(pcut_item_t *test) { 151 149 PCUT_UNUSED(test); 152 150 -
uspace/lib/pcut/src/os/helenos.c
r275530a4 r4b54bd9 46 46 /* String functions. */ 47 47 48 int pcut_str_equals(const char *a, const char *b) 49 { 48 int pcut_str_equals(const char *a, const char *b) { 50 49 return str_cmp(a, b) == 0; 51 50 } 52 51 53 52 54 int pcut_str_start_equals(const char *a, const char *b, int len) 55 { 53 int pcut_str_start_equals(const char *a, const char *b, int len) { 56 54 return str_lcmp(a, b, len) == 0; 57 55 } 58 56 59 int pcut_str_size(const char *s) 60 { 57 int pcut_str_size(const char *s) { 61 58 return str_size(s); 62 59 } 63 60 64 int pcut_str_to_int(const char *s) 65 { 61 int pcut_str_to_int(const char *s) { 66 62 int result = strtol(s, NULL, 10); 67 63 return result; 68 64 } 69 65 70 char *pcut_str_find_char(const char *haystack, const char needle) 71 { 66 char *pcut_str_find_char(const char *haystack, const char needle) { 72 67 return str_chr(haystack, needle); 73 68 } 74 69 75 void pcut_str_error(errno_t error, char *buffer, int size) 76 { 70 void pcut_str_error(int error, char *buffer, int size) { 77 71 const char *str = str_error(error); 78 72 if (str == NULL) { … … 107 101 * @param test Test that is about to be run. 108 102 */ 109 static void before_test_start(pcut_item_t *test) 110 { 103 static void before_test_start(pcut_item_t *test) { 111 104 pcut_report_test_start(test); 112 105 … … 116 109 117 110 /** Mutex guard for forced_termination_cv. */ 118 static fibril_mutex_t forced_termination_mutex =119 111 static fibril_mutex_t forced_termination_mutex 112 = FIBRIL_MUTEX_INITIALIZER(forced_termination_mutex); 120 113 121 114 /** Condition-variable for checking whether test timed-out. */ 122 static fibril_condvar_t forced_termination_cv =123 115 static fibril_condvar_t forced_termination_cv 116 = FIBRIL_CONDVAR_INITIALIZER(forced_termination_cv); 124 117 125 118 /** Spawned task id. */ … … 137 130 * @return EOK Always. 138 131 */ 139 static errno_t test_timeout_handler_fibril(void *arg) 140 { 132 static int test_timeout_handler_fibril(void *arg) { 141 133 pcut_item_t *test = arg; 142 134 int timeout_sec = pcut_get_test_timeout(test); … … 148 140 } 149 141 errno_t rc = fibril_condvar_wait_timeout(&forced_termination_cv, 150 142 &forced_termination_mutex, timeout_us); 151 143 if (rc == ETIMEOUT) { 152 144 task_kill(test_task_id); … … 162 154 * @param test Test to be run. 163 155 */ 164 int pcut_run_test_forking(const char *self_path, pcut_item_t *test) 165 { 156 int pcut_run_test_forking(const char *self_path, pcut_item_t *test) { 166 157 before_test_start(test); 167 158 … … 235 226 } 236 227 237 void pcut_hook_before_test(pcut_item_t *test) 238 { 228 void pcut_hook_before_test(pcut_item_t *test) { 239 229 PCUT_UNUSED(test); 240 230 -
uspace/lib/pcut/src/os/stdc.c
r275530a4 r4b54bd9 32 32 */ 33 33 34 #pragma warning(push, 0) 34 35 #include <string.h> 36 #pragma warning(pop) 37 35 38 #include "../internal.h" 36 39 37 int pcut_str_equals(const char *a, const char *b) 38 { 40 int pcut_str_equals(const char *a, const char *b) { 39 41 return strcmp(a, b) == 0; 40 42 } 41 43 42 int pcut_str_start_equals(const char *a, const char *b, int len) 43 { 44 int pcut_str_start_equals(const char *a, const char *b, int len) { 44 45 return strncmp(a, b, len) == 0; 45 46 } 46 47 47 int pcut_str_size(const char *s) 48 { 48 int pcut_str_size(const char *s) { 49 49 return strlen(s); 50 50 } 51 51 52 int pcut_str_to_int(const char *s) 53 { 52 int pcut_str_to_int(const char *s) { 54 53 return atoi(s); 55 54 } 56 55 57 char *pcut_str_find_char(const char *haystack, const char needle) 58 { 56 char *pcut_str_find_char(const char *haystack, const char needle) { 59 57 return strchr(haystack, needle); 60 58 } 61 59 62 void pcut_str_error(int error, char *buffer, int size) 63 { 60 void pcut_str_error(int error, char *buffer, int size) { 64 61 const char *str = strerror(error); 65 62 if (str == NULL) { -
uspace/lib/pcut/src/os/unix.c
r275530a4 r4b54bd9 64 64 * @param test Test that is about to be run. 65 65 */ 66 static void before_test_start(pcut_item_t *test) 67 { 66 static void before_test_start(pcut_item_t *test) { 68 67 pcut_report_test_start(test); 69 68 … … 79 78 * @param sig Signal number. 80 79 */ 81 static void kill_child_on_alarm(int sig) 82 { 80 static void kill_child_on_alarm(int sig) { 83 81 PCUT_UNUSED(sig); 84 82 kill(child_pid, SIGKILL); … … 96 94 * @return Number of actually read bytes. 97 95 */ 98 static size_t read_all(int fd, char *buffer, size_t buffer_size) 99 { 96 static size_t read_all(int fd, char *buffer, size_t buffer_size) { 100 97 ssize_t actually_read; 101 98 char *buffer_start = buffer; … … 124 121 * @return Test outcome code. 125 122 */ 126 static int convert_wait_status_to_outcome(int status) 127 { 123 static int convert_wait_status_to_outcome(int status) { 128 124 if (WIFEXITED(status)) { 129 125 if (WEXITSTATUS(status) != 0) { … … 146 142 * @param test Test to be run. 147 143 */ 148 int pcut_run_test_forking(const char *self_path, pcut_item_t *test) 149 { 144 int pcut_run_test_forking(const char *self_path, pcut_item_t *test) { 150 145 int link_stdout[2], link_stderr[2]; 151 146 int rc, status, outcome; … … 159 154 rc = pipe(link_stdout); 160 155 if (rc == -1) { 161 snprintf(error_message_buffer, OUTPUT_BUFFER_SIZE - 1,162 156 pcut_snprintf(error_message_buffer, OUTPUT_BUFFER_SIZE - 1, 157 "pipe() failed: %s.", strerror(rc)); 163 158 pcut_report_test_done(test, PCUT_OUTCOME_INTERNAL_ERROR, error_message_buffer, NULL, NULL); 164 159 return PCUT_OUTCOME_INTERNAL_ERROR; … … 166 161 rc = pipe(link_stderr); 167 162 if (rc == -1) { 168 snprintf(error_message_buffer, OUTPUT_BUFFER_SIZE - 1,169 163 pcut_snprintf(error_message_buffer, OUTPUT_BUFFER_SIZE - 1, 164 "pipe() failed: %s.", strerror(rc)); 170 165 pcut_report_test_done(test, PCUT_OUTCOME_INTERNAL_ERROR, error_message_buffer, NULL, NULL); 171 166 return PCUT_OUTCOME_INTERNAL_ERROR; … … 174 169 child_pid = fork(); 175 170 if (child_pid == (pid_t)-1) { 176 snprintf(error_message_buffer, OUTPUT_BUFFER_SIZE - 1,177 171 pcut_snprintf(error_message_buffer, OUTPUT_BUFFER_SIZE - 1, 172 "fork() failed: %s.", strerror(rc)); 178 173 outcome = PCUT_OUTCOME_INTERNAL_ERROR; 179 174 goto leave_close_pipes; … … 220 215 } 221 216 222 void pcut_hook_before_test(pcut_item_t *test) 223 { 217 void pcut_hook_before_test(pcut_item_t *test) { 224 218 PCUT_UNUSED(test); 225 219 -
uspace/lib/pcut/src/os/windows.c
r275530a4 r4b54bd9 39 39 #include "../internal.h" 40 40 41 #pragma warning(push, 0) 41 42 #include <windows.h> 42 43 #include <tchar.h> 43 44 #include <stdio.h> 44 45 #include <strsafe.h> 46 #pragma warning(pop) 47 45 48 46 49 … … 61 64 * @param test Test that is about to be run. 62 65 */ 63 static void before_test_start(pcut_item_t *test) 64 { 66 static void before_test_start(pcut_item_t *test) { 65 67 pcut_report_test_start(test); 66 68 … … 74 76 * @param failed_function_name Name of the failed function. 75 77 */ 76 static void report_func_fail(pcut_item_t *test, const char *failed_function_name) 77 { 78 static void report_func_fail(pcut_item_t *test, const char *failed_function_name) { 78 79 /* TODO: get error description. */ 79 sprintf_s(error_message_buffer, OUTPUT_BUFFER_SIZE - 1,80 81 pcut_report_test_done(test, TEST_OUTCOME_ERROR, error_message_buffer, NULL, NULL);80 pcut_snprintf(error_message_buffer, OUTPUT_BUFFER_SIZE - 1, 81 "%s failed: %s.", failed_function_name, "unknown reason"); 82 pcut_report_test_done(test, PCUT_OUTCOME_INTERNAL_ERROR, error_message_buffer, NULL, NULL); 82 83 } 83 84 … … 93 94 * @return Number of actually read bytes. 94 95 */ 95 static size_t read_all(HANDLE fd, char *buffer, size_t buffer_size) 96 { 96 static size_t read_all(HANDLE fd, char *buffer, size_t buffer_size) { 97 97 DWORD actually_read; 98 98 char *buffer_start = buffer; … … 128 128 }; 129 129 130 static DWORD WINAPI read_test_output_on_background(LPVOID test_output_data_ptr) 131 { 130 static DWORD WINAPI read_test_output_on_background(LPVOID test_output_data_ptr) { 132 131 size_t stderr_size = 0; 133 132 struct test_output_data *test_output_data = (struct test_output_data *) test_output_data_ptr; 134 133 135 134 stderr_size = read_all(test_output_data->pipe_stderr, 136 137 135 test_output_data->output_buffer, 136 test_output_data->output_buffer_size - 1); 138 137 read_all(test_output_data->pipe_stdout, 139 140 138 test_output_data->output_buffer, 139 test_output_data->output_buffer_size - 1 - stderr_size); 141 140 142 141 return 0; … … 148 147 * @param test Test to be run. 149 148 */ 150 int pcut_run_test_forking(const char *self_path, pcut_item_t *test) 151 { 149 int pcut_run_test_forking(const char *self_path, pcut_item_t *test) { 152 150 /* TODO: clean-up if something goes wrong "in the middle" */ 153 151 BOOL okay = FALSE; … … 220 218 221 219 /* Format the command line. */ 222 sprintf_s(command, PCUT_COMMAND_LINE_BUFFER_SIZE - 1,223 220 pcut_snprintf(command, PCUT_COMMAND_LINE_BUFFER_SIZE - 1, 221 "\"%s\" -t%d", self_path, test->id); 224 222 225 223 /* Run the process. */ 226 224 okay = CreateProcess(NULL, command, NULL, NULL, TRUE, 0, NULL, NULL, 227 225 &start_info, &process_info); 228 226 229 227 if (!okay) { … … 267 265 268 266 test_output_thread_reader = CreateThread(NULL, 0, 269 270 267 read_test_output_on_background, &test_output_data, 268 0, NULL); 271 269 272 270 if (test_output_thread_reader == NULL) { … … 286 284 if (!okay) { 287 285 report_func_fail(test, "TerminateProcess(/* PROCESS_INFORMATION.hProcess */)"); 288 return PCUT_ ERROR_INTERNAL_FAILURE;286 return PCUT_OUTCOME_INTERNAL_ERROR; 289 287 } 290 288 rc = WaitForSingleObject(process_info.hProcess, INFINITE); … … 314 312 if (rc != WAIT_OBJECT_0) { 315 313 report_func_fail(test, "WaitForSingleObject(/* stdout reader thread */)"); 316 return PCUT_ ERROR_INTERNAL_FAILURE;314 return PCUT_OUTCOME_INTERNAL_ERROR; 317 315 } 318 316 … … 322 320 } 323 321 324 void pcut_hook_before_test(pcut_item_t *test) 325 { 322 void pcut_hook_before_test(pcut_item_t *test) { 326 323 PCUT_UNUSED(test); 327 324 -
uspace/lib/pcut/src/preproc.c
r275530a4 r4b54bd9 27 27 */ 28 28 29 # include <stdbool.h>29 #pragma warning(push, 0) 30 30 #include <stdio.h> 31 31 #include <stdlib.h> 32 32 #include <ctype.h> 33 33 #include <string.h> 34 #pragma warning(pop) 35 34 36 35 37 #define MAX_IDENTIFIER_LENGTH 256 … … 37 39 static int counter = 0; 38 40 39 static void print_numbered_identifier(int value, FILE *output) 40 { 41 static void print_numbered_identifier(int value, FILE *output) { 41 42 fprintf(output, "pcut_item_%d", value); 42 43 } 43 44 44 static void print_numbered_identifier2(int value, FILE *output) 45 { 45 static void print_numbered_identifier2(int value, FILE *output) { 46 46 fprintf(output, "pcut_item2_%d", value); 47 47 } 48 48 49 static void print_numbered_identifier3(int value, FILE *output) 50 { 49 static void print_numbered_identifier3(int value, FILE *output) { 51 50 fprintf(output, "pcut_item3_%d", value); 52 51 } … … 57 56 } identifier_t; 58 57 59 static void identifier_init(identifier_t *identifier) 60 { 58 static void identifier_init(identifier_t *identifier) { 61 59 identifier->name[0] = 0; 62 60 identifier->length = 0; 63 61 } 64 62 65 static void identifier_add_char(identifier_t *identifier, char c) 66 { 63 static void identifier_add_char(identifier_t *identifier, char c) { 67 64 if (identifier->length + 1 >= MAX_IDENTIFIER_LENGTH) { 68 65 fprintf(stderr, "Identifier %s is too long, aborting!\n", identifier->name); … … 75 72 } 76 73 77 static void identifier_print_or_expand(identifier_t *identifier, FILE *output) 78 { 74 static void identifier_print_or_expand(identifier_t *identifier, FILE *output) { 79 75 const char *name = identifier->name; 80 76 if (strcmp(name, "PCUT_ITEM_NAME") == 0) { … … 93 89 } 94 90 95 static int is_identifier_char(int c, int inside_identifier) 96 { 97 return isalpha(c) || (c == '_')|| (inside_identifier && isdigit(c));91 static int is_identifier_char(int c, int inside_identifier) { 92 return isalpha(c) || (c == '_') 93 || (inside_identifier && isdigit(c)); 98 94 } 99 95 100 int main(int argc, char *argv[]) 101 { 96 int main(int argc, char *argv[]) { 102 97 FILE *input = stdin; 103 98 FILE *output = stdout; … … 110 105 (void) argv; 111 106 112 while ( true) {107 while (1) { 113 108 int current_char_denotes_identifier; 114 109 -
uspace/lib/pcut/src/print.c
r275530a4 r4b54bd9 33 33 34 34 #include <pcut/pcut.h> 35 36 #pragma warning(push, 0) 35 37 #include <stdio.h> 36 38 #include <stdlib.h> 37 39 #include <assert.h> 40 #pragma warning(pop) 41 38 42 #include "internal.h" 39 43 … … 42 46 * @param first First item to be printed. 43 47 */ 44 void pcut_print_items(pcut_item_t *first) 45 { 48 void pcut_print_items(pcut_item_t *first) { 46 49 pcut_item_t *it = first; 47 50 printf("====>\n"); … … 72 75 * @param first First item to be printed. 73 76 */ 74 void pcut_print_tests(pcut_item_t *first) 75 { 77 void pcut_print_tests(pcut_item_t *first) { 76 78 pcut_item_t *it; 77 79 for (it = pcut_get_real(first); it != NULL; it = pcut_get_real_next(it)) { -
uspace/lib/pcut/src/report/report.c
r275530a4 r4b54bd9 33 33 34 34 #include "../internal.h" 35 35 36 #ifdef __helenos__ 36 #include < str.h>37 #include <mem.h> 37 38 #else 39 #pragma warning(push, 0) 38 40 #include <string.h> 41 #pragma warning(pop) 39 42 #endif 40 #include <stdbool.h> 43 44 #pragma warning(push, 0) 41 45 #include <stdio.h> 46 #pragma warning(pop) 47 42 48 43 49 /** Currently used report ops. */ … … 68 74 * @param msg The message to be printed. 69 75 */ 70 void pcut_print_fail_message(const char *msg) 71 { 76 void pcut_print_fail_message(const char *msg) { 72 77 if (msg == NULL) { 73 78 return; … … 99 104 */ 100 105 static void parse_command_output(const char *full_output, size_t full_output_size, 101 char *stdio_buffer, size_t stdio_buffer_size, 102 char *error_buffer, size_t error_buffer_size) 103 { 106 char *stdio_buffer, size_t stdio_buffer_size, 107 char *error_buffer, size_t error_buffer_size) { 104 108 memset(stdio_buffer, 0, stdio_buffer_size); 105 109 memset(error_buffer, 0, error_buffer_size); … … 111 115 } 112 116 113 while ( true) {117 while (1) { 114 118 size_t message_length; 115 119 … … 157 161 * @param ops Functions to use. 158 162 */ 159 void pcut_report_register_handler(pcut_report_ops_t *ops) 160 { 163 void pcut_report_register_handler(pcut_report_ops_t *ops) { 161 164 report_ops = ops; 162 165 } … … 166 169 * @param all_items List of all tests that could be run. 167 170 */ 168 void pcut_report_init(pcut_item_t *all_items) 169 { 171 void pcut_report_init(pcut_item_t *all_items) { 170 172 REPORT_CALL(init, all_items); 171 173 } … … 175 177 * @param suite Suite that was just started. 176 178 */ 177 void pcut_report_suite_start(pcut_item_t *suite) 178 { 179 void pcut_report_suite_start(pcut_item_t *suite) { 179 180 REPORT_CALL(suite_start, suite); 180 181 } … … 184 185 * @param suite Suite that just completed. 185 186 */ 186 void pcut_report_suite_done(pcut_item_t *suite) 187 { 187 void pcut_report_suite_done(pcut_item_t *suite) { 188 188 REPORT_CALL(suite_done, suite); 189 189 } … … 193 193 * @param test Test to be run just about now. 194 194 */ 195 void pcut_report_test_start(pcut_item_t *test) 196 { 195 void pcut_report_test_start(pcut_item_t *test) { 197 196 REPORT_CALL(test_start, test); 198 197 } … … 207 206 */ 208 207 void pcut_report_test_done(pcut_item_t *test, int outcome, 209 const char *error_message, const char *teardown_error_message, 210 const char *extra_output) 211 { 208 const char *error_message, const char *teardown_error_message, 209 const char *extra_output) { 212 210 REPORT_CALL(test_done, test, outcome, error_message, teardown_error_message, 213 211 extra_output); 214 212 } 215 213 … … 222 220 */ 223 221 void pcut_report_test_done_unparsed(pcut_item_t *test, int outcome, 224 const char *unparsed_output, size_t unparsed_output_size) 225 { 222 const char *unparsed_output, size_t unparsed_output_size) { 226 223 227 224 parse_command_output(unparsed_output, unparsed_output_size, 228 229 225 buffer_for_extra_output, BUFFER_SIZE, 226 buffer_for_error_messages, BUFFER_SIZE); 230 227 231 228 pcut_report_test_done(test, outcome, buffer_for_error_messages, NULL, buffer_for_extra_output); … … 235 232 * 236 233 */ 237 void pcut_report_done(void) 238 { 234 void pcut_report_done(void) { 239 235 REPORT_CALL_NO_ARGS(done); 240 236 } -
uspace/lib/pcut/src/report/tap.c
r275530a4 r4b54bd9 34 34 #include "../internal.h" 35 35 #include "report.h" 36 36 37 #ifndef __helenos__ 38 #pragma warning(push, 0) 37 39 #include <string.h> 40 #pragma warning(pop) 38 41 #endif 42 43 #pragma warning(push, 0) 39 44 #include <stdio.h> 45 #pragma warning(pop) 46 40 47 41 48 /** Counter of all run tests. */ … … 55 62 * @param all_items Start of the list with all items. 56 63 */ 57 static void tap_init(pcut_item_t *all_items) 58 { 64 static void tap_init(pcut_item_t *all_items) { 59 65 int tests_total = pcut_count_tests(all_items); 60 66 test_counter = 0; … … 68 74 * @param suite Suite that just started. 69 75 */ 70 static void tap_suite_start(pcut_item_t *suite) 71 { 76 static void tap_suite_start(pcut_item_t *suite) { 72 77 tests_in_suite = 0; 73 78 failed_tests_in_suite = 0; … … 80 85 * @param suite Suite that just ended. 81 86 */ 82 static void tap_suite_done(pcut_item_t *suite) 83 { 87 static void tap_suite_done(pcut_item_t *suite) { 84 88 if (failed_tests_in_suite == 0) { 85 89 printf("#> Finished suite %s (passed).\n", 86 90 suite->name); 87 91 } else { 88 92 printf("#> Finished suite %s (failed %d of %d).\n", 89 93 suite->name, failed_tests_in_suite, tests_in_suite); 90 94 } 91 95 } … … 97 101 * @param test Test that is started. 98 102 */ 99 static void tap_test_start(pcut_item_t *test) 100 { 103 static void tap_test_start(pcut_item_t *test) { 101 104 PCUT_UNUSED(test); 102 105 … … 110 113 * @param prefix Prefix for each new line, such as comment character. 111 114 */ 112 static void print_by_lines(const char *message, const char *prefix) 113 { 115 static void print_by_lines(const char *message, const char *prefix) { 114 116 char *next_line_start; 115 117 if ((message == NULL) || (message[0] == 0)) { … … 137 139 */ 138 140 static void tap_test_done(pcut_item_t *test, int outcome, 139 const char *error_message, const char *teardown_error_message, 140 const char *extra_output) 141 { 141 const char *error_message, const char *teardown_error_message, 142 const char *extra_output) { 142 143 const char *test_name = test->name; 143 144 const char *status_str = NULL; … … 172 173 173 174 /** Report testing done. */ 174 static void tap_done(void) 175 { 175 static void tap_done(void) { 176 176 if (failed_test_counter == 0) { 177 177 printf("#> Done: all tests passed.\n"); -
uspace/lib/pcut/src/report/xml.c
r275530a4 r4b54bd9 34 34 #include "../internal.h" 35 35 #include "report.h" 36 36 37 #ifndef __helenos__ 38 #pragma warning(push, 0) 37 39 #include <string.h> 40 #pragma warning(pop) 38 41 #endif 42 43 #pragma warning(push, 0) 39 44 #include <stdio.h> 45 #pragma warning(pop) 46 40 47 41 48 /** Counter of all run tests. */ … … 52 59 * @param all_items Start of the list with all items. 53 60 */ 54 static void xml_init(pcut_item_t *all_items) 55 { 61 static void xml_init(pcut_item_t *all_items) { 56 62 int tests_total = pcut_count_tests(all_items); 57 63 test_counter = 0; … … 65 71 * @param suite Suite that just started. 66 72 */ 67 static void xml_suite_start(pcut_item_t *suite) 68 { 73 static void xml_suite_start(pcut_item_t *suite) { 69 74 tests_in_suite = 0; 70 75 failed_tests_in_suite = 0; … … 77 82 * @param suite Suite that just ended. 78 83 */ 79 static void xml_suite_done(pcut_item_t *suite) 80 { 84 static void xml_suite_done(pcut_item_t *suite) { 81 85 printf("\t</suite><!-- %s: %d / %d -->\n", suite->name, 82 86 failed_tests_in_suite, tests_in_suite); 83 87 } 84 88 … … 89 93 * @param test Test that is started. 90 94 */ 91 static void xml_test_start(pcut_item_t *test) 92 { 95 static void xml_test_start(pcut_item_t *test) { 93 96 PCUT_UNUSED(test); 94 97 … … 102 105 * @param element_name Wrapping XML element name. 103 106 */ 104 static void print_by_lines(const char *message, const char *element_name) 105 { 107 static void print_by_lines(const char *message, const char *element_name) { 106 108 char *next_line_start; 107 109 … … 135 137 */ 136 138 static void xml_test_done(pcut_item_t *test, int outcome, 137 const char *error_message, const char *teardown_error_message, 138 const char *extra_output) 139 { 139 const char *error_message, const char *teardown_error_message, 140 const char *extra_output) { 140 141 const char *test_name = test->name; 141 142 const char *status_str = NULL; … … 158 159 159 160 printf("\t\t<testcase name=\"%s\" status=\"%s\">\n", test_name, 160 161 status_str); 161 162 162 163 print_by_lines(error_message, "error-message"); … … 169 170 170 171 /** Report testing done. */ 171 static void xml_done(void) 172 { 172 static void xml_done(void) { 173 173 printf("</report>\n"); 174 174 } -
uspace/lib/pcut/src/run.c
r275530a4 r4b54bd9 33 33 34 34 #include "internal.h" 35 35 36 #ifndef PCUT_NO_LONG_JUMP 37 #pragma warning(push, 0) 36 38 #include <setjmp.h> 39 #pragma warning(pop) 37 40 #endif 38 41 … … 73 76 static int default_suite_initialized = 0; 74 77 75 static void init_default_suite_when_needed() 76 { 78 static void init_default_suite_when_needed() { 77 79 if (default_suite_initialized) { 78 80 return; … … 92 94 * @return Always a valid test suite item. 93 95 */ 94 static pcut_item_t *pcut_find_parent_suite(pcut_item_t *it) 95 { 96 static pcut_item_t *pcut_find_parent_suite(pcut_item_t *it) { 96 97 while (it != NULL) { 97 98 if (it->kind == PCUT_KIND_TESTSUITE) { … … 108 109 * @param func Function to run (can be NULL). 109 110 */ 110 static void run_setup_teardown(pcut_setup_func_t func) 111 { 111 static void run_setup_teardown(pcut_setup_func_t func) { 112 112 if (func != NULL) { 113 113 func(); … … 122 122 * @param outcome Outcome of the current test. 123 123 */ 124 static void leave_test(int outcome) 125 { 124 static void leave_test(int outcome) { 126 125 PCUT_DEBUG("leave_test(outcome=%d), will_exit=%s", outcome, 127 126 leave_means_exit ? "yes" : "no"); 128 127 if (leave_means_exit) { 129 128 exit(outcome); … … 142 141 * @param message Message describing the failure. 143 142 */ 144 void pcut_failed_assertion(const char *message) 145 { 143 void pcut_failed_assertion(const char *message) { 146 144 static const char *prev_message = NULL; 147 145 /* … … 162 160 if (report_test_result) { 163 161 pcut_report_test_done(current_test, PCUT_OUTCOME_FAIL, 164 162 message, NULL, NULL); 165 163 } 166 164 } else { 167 165 if (report_test_result) { 168 166 pcut_report_test_done(current_test, PCUT_OUTCOME_FAIL, 169 167 prev_message, message, NULL); 170 168 } 171 169 } … … 181 179 * @return Error status (zero means success). 182 180 */ 183 static int run_test(pcut_item_t *test) 184 { 181 static int run_test(pcut_item_t *test) { 185 182 /* 186 183 * Set here as the returning point in case of test failure. … … 234 231 if (report_test_result) { 235 232 pcut_report_test_done(current_test, PCUT_OUTCOME_PASS, 236 233 NULL, NULL, NULL); 237 234 } 238 235 … … 248 245 * @return Error status (zero means success). 249 246 */ 250 int pcut_run_test_forked(pcut_item_t *test) 251 { 247 int pcut_run_test_forked(pcut_item_t *test) { 252 248 int rc; 253 249 … … 272 268 * @return Error status (zero means success). 273 269 */ 274 int pcut_run_test_single(pcut_item_t *test) 275 { 270 int pcut_run_test_single(pcut_item_t *test) { 276 271 int rc; 277 272 … … 293 288 * @return Timeout in seconds. 294 289 */ 295 int pcut_get_test_timeout(pcut_item_t *test) 296 { 290 int pcut_get_test_timeout(pcut_item_t *test) { 297 291 int timeout = PCUT_DEFAULT_TEST_TIMEOUT; 298 292 pcut_extra_t *extras = test->extras;
Note:
See TracChangeset
for help on using the changeset viewer.