Changeset 1433ecda in mainline for uspace/lib/pcut/src/os
- Timestamp:
- 2018-04-04T15:42:37Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 2c4e1cc
- Parents:
- 47b2d7e3
- Location:
- uspace/lib/pcut/src/os
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/pcut/src/os/generic.c
r47b2d7e3 r1433ecda 81 81 * @param test Test that is about to start. 82 82 */ 83 static void before_test_start(pcut_item_t *test) { 83 static void before_test_start(pcut_item_t *test) 84 { 84 85 pcut_report_test_start(test); 85 86 … … 93 94 * @return Test outcome code. 94 95 */ 95 static int convert_wait_status_to_outcome(int status) { 96 static int convert_wait_status_to_outcome(int status) 97 { 96 98 if (status < 0) { 97 99 return PCUT_OUTCOME_INTERNAL_ERROR; … … 108 110 * @param test Test to be run. 109 111 */ 110 int pcut_run_test_forking(const char *self_path, pcut_item_t *test) { 112 int pcut_run_test_forking(const char *self_path, pcut_item_t *test) 113 { 111 114 int rc, outcome; 112 115 FILE *tempfile; … … 118 121 FORMAT_TEMP_FILENAME(tempfile_name, PCUT_TEMP_FILENAME_BUFFER_SIZE - 1); 119 122 FORMAT_COMMAND(command, PCUT_COMMAND_LINE_BUFFER_SIZE - 1, 120 123 self_path, (test)->id, tempfile_name); 121 124 122 125 PCUT_DEBUG("Will execute <%s> (temp file <%s>) with system().", 123 126 command, tempfile_name); 124 127 125 128 rc = system(command); … … 144 147 } 145 148 146 void pcut_hook_before_test(pcut_item_t *test) { 149 void pcut_hook_before_test(pcut_item_t *test) 150 { 147 151 PCUT_UNUSED(test); 148 152 -
uspace/lib/pcut/src/os/stdc.c
r47b2d7e3 r1433ecda 35 35 #include "../internal.h" 36 36 37 int pcut_str_equals(const char *a, const char *b) { 37 int pcut_str_equals(const char *a, const char *b) 38 { 38 39 return strcmp(a, b) == 0; 39 40 } 40 41 41 int pcut_str_start_equals(const char *a, const char *b, int len) { 42 int pcut_str_start_equals(const char *a, const char *b, int len) 43 { 42 44 return strncmp(a, b, len) == 0; 43 45 } 44 46 45 int pcut_str_size(const char *s) { 47 int pcut_str_size(const char *s) 48 { 46 49 return strlen(s); 47 50 } 48 51 49 int pcut_str_to_int(const char *s) { 52 int pcut_str_to_int(const char *s) 53 { 50 54 return atoi(s); 51 55 } 52 56 53 char *pcut_str_find_char(const char *haystack, const char needle) { 57 char *pcut_str_find_char(const char *haystack, const char needle) 58 { 54 59 return strchr(haystack, needle); 55 60 } 56 61 57 void pcut_str_error(int error, char *buffer, int size) { 62 void pcut_str_error(int error, char *buffer, int size) 63 { 58 64 const char *str = strerror(error); 59 65 if (str == NULL) { -
uspace/lib/pcut/src/os/unix.c
r47b2d7e3 r1433ecda 64 64 * @param test Test that is about to be run. 65 65 */ 66 static void before_test_start(pcut_item_t *test) { 66 static void before_test_start(pcut_item_t *test) 67 { 67 68 pcut_report_test_start(test); 68 69 … … 78 79 * @param sig Signal number. 79 80 */ 80 static void kill_child_on_alarm(int sig) { 81 static void kill_child_on_alarm(int sig) 82 { 81 83 PCUT_UNUSED(sig); 82 84 kill(child_pid, SIGKILL); … … 94 96 * @return Number of actually read bytes. 95 97 */ 96 static size_t read_all(int fd, char *buffer, size_t buffer_size) { 98 static size_t read_all(int fd, char *buffer, size_t buffer_size) 99 { 97 100 ssize_t actually_read; 98 101 char *buffer_start = buffer; … … 121 124 * @return Test outcome code. 122 125 */ 123 static int convert_wait_status_to_outcome(int status) { 126 static int convert_wait_status_to_outcome(int status) 127 { 124 128 if (WIFEXITED(status)) { 125 129 if (WEXITSTATUS(status) != 0) { … … 142 146 * @param test Test to be run. 143 147 */ 144 int pcut_run_test_forking(const char *self_path, pcut_item_t *test) { 148 int pcut_run_test_forking(const char *self_path, pcut_item_t *test) 149 { 145 150 int link_stdout[2], link_stderr[2]; 146 151 int rc, status, outcome; … … 155 160 if (rc == -1) { 156 161 snprintf(error_message_buffer, OUTPUT_BUFFER_SIZE - 1, 157 162 "pipe() failed: %s.", strerror(rc)); 158 163 pcut_report_test_done(test, PCUT_OUTCOME_INTERNAL_ERROR, error_message_buffer, NULL, NULL); 159 164 return PCUT_OUTCOME_INTERNAL_ERROR; … … 162 167 if (rc == -1) { 163 168 snprintf(error_message_buffer, OUTPUT_BUFFER_SIZE - 1, 164 169 "pipe() failed: %s.", strerror(rc)); 165 170 pcut_report_test_done(test, PCUT_OUTCOME_INTERNAL_ERROR, error_message_buffer, NULL, NULL); 166 171 return PCUT_OUTCOME_INTERNAL_ERROR; … … 170 175 if (child_pid == (pid_t)-1) { 171 176 snprintf(error_message_buffer, OUTPUT_BUFFER_SIZE - 1, 172 177 "fork() failed: %s.", strerror(rc)); 173 178 outcome = PCUT_OUTCOME_INTERNAL_ERROR; 174 179 goto leave_close_pipes; … … 215 220 } 216 221 217 void pcut_hook_before_test(pcut_item_t *test) { 222 void pcut_hook_before_test(pcut_item_t *test) 223 { 218 224 PCUT_UNUSED(test); 219 225 -
uspace/lib/pcut/src/os/windows.c
r47b2d7e3 r1433ecda 61 61 * @param test Test that is about to be run. 62 62 */ 63 static void before_test_start(pcut_item_t *test) { 63 static void before_test_start(pcut_item_t *test) 64 { 64 65 pcut_report_test_start(test); 65 66 … … 73 74 * @param failed_function_name Name of the failed function. 74 75 */ 75 static void report_func_fail(pcut_item_t *test, const char *failed_function_name) { 76 static void report_func_fail(pcut_item_t *test, const char *failed_function_name) 77 { 76 78 /* TODO: get error description. */ 77 79 sprintf_s(error_message_buffer, OUTPUT_BUFFER_SIZE - 1, 78 80 "%s failed: %s.", failed_function_name, "unknown reason"); 79 81 pcut_report_test_done(test, TEST_OUTCOME_ERROR, error_message_buffer, NULL, NULL); 80 82 } … … 91 93 * @return Number of actually read bytes. 92 94 */ 93 static size_t read_all(HANDLE fd, char *buffer, size_t buffer_size) { 95 static size_t read_all(HANDLE fd, char *buffer, size_t buffer_size) 96 { 94 97 DWORD actually_read; 95 98 char *buffer_start = buffer; … … 125 128 }; 126 129 127 static DWORD WINAPI read_test_output_on_background(LPVOID test_output_data_ptr) { 130 static DWORD WINAPI read_test_output_on_background(LPVOID test_output_data_ptr) 131 { 128 132 size_t stderr_size = 0; 129 133 struct test_output_data *test_output_data = (struct test_output_data *) test_output_data_ptr; 130 134 131 135 stderr_size = read_all(test_output_data->pipe_stderr, 132 133 136 test_output_data->output_buffer, 137 test_output_data->output_buffer_size - 1); 134 138 read_all(test_output_data->pipe_stdout, 135 136 139 test_output_data->output_buffer, 140 test_output_data->output_buffer_size - 1 - stderr_size); 137 141 138 142 return 0; … … 144 148 * @param test Test to be run. 145 149 */ 146 int pcut_run_test_forking(const char *self_path, pcut_item_t *test) { 150 int pcut_run_test_forking(const char *self_path, pcut_item_t *test) 151 { 147 152 /* TODO: clean-up if something goes wrong "in the middle" */ 148 153 BOOL okay = FALSE; … … 216 221 /* Format the command line. */ 217 222 sprintf_s(command, PCUT_COMMAND_LINE_BUFFER_SIZE - 1, 218 223 "\"%s\" -t%d", self_path, test->id); 219 224 220 225 /* Run the process. */ 221 226 okay = CreateProcess(NULL, command, NULL, NULL, TRUE, 0, NULL, NULL, 222 227 &start_info, &process_info); 223 228 224 229 if (!okay) { … … 262 267 263 268 test_output_thread_reader = CreateThread(NULL, 0, 264 265 269 read_test_output_on_background, &test_output_data, 270 0, NULL); 266 271 267 272 if (test_output_thread_reader == NULL) { … … 317 322 } 318 323 319 void pcut_hook_before_test(pcut_item_t *test) { 324 void pcut_hook_before_test(pcut_item_t *test) 325 { 320 326 PCUT_UNUSED(test); 321 327
Note:
See TracChangeset
for help on using the changeset viewer.