Changeset 9eb1ff5 in mainline for uspace/lib/pcut/src/os
- Timestamp:
- 2017-12-08T14:47:08Z (8 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/src/os
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.
