Changeset 4b54bd9 in mainline for uspace/lib/pcut/src/os
- 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/os
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
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 self_path, (test)->id, tempfile_name);124 122 self_path, (test)->id, tempfile_name); 123 125 124 PCUT_DEBUG("Will execute <%s> (temp file <%s>) with system().", 126 command, tempfile_name);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 FIBRIL_MUTEX_INITIALIZER(forced_termination_mutex);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 FIBRIL_CONDVAR_INITIALIZER(forced_termination_cv);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 &forced_termination_mutex, timeout_us);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 "pipe() failed: %s.", strerror(rc));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 "pipe() failed: %s.", strerror(rc));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 "fork() failed: %s.", strerror(rc));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 "%s failed: %s.", failed_function_name, "unknown reason");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 test_output_data->output_buffer,137 test_output_data->output_buffer_size - 1);135 test_output_data->output_buffer, 136 test_output_data->output_buffer_size - 1); 138 137 read_all(test_output_data->pipe_stdout, 139 test_output_data->output_buffer,140 test_output_data->output_buffer_size - 1 - stderr_size);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 "\"%s\" -t%d", self_path, test->id);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 &start_info, &process_info);225 &start_info, &process_info); 228 226 229 227 if (!okay) { … … 267 265 268 266 test_output_thread_reader = CreateThread(NULL, 0, 269 read_test_output_on_background, &test_output_data,270 0, NULL);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
Note:
See TracChangeset
for help on using the changeset viewer.
