Changeset 9eb1ff5 in mainline for uspace/lib/pcut/src/os


Ignore:
Timestamp:
2017-12-08T14:47:08Z (8 years ago)
Author:
Vojtech Horky <vojtech.horky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c1694b6b
Parents:
6fb8b2c
Message:

Update PCUT

Updated PCUT to commit 7ce059f.

Notable changes include:

  • overall summary is printed when tests finish
  • when tests passed, the status message does not use the word 'failure'
  • program exit code is zero only when all tests passed

These changes fixes tickets 713 and 714.

http://www.helenos.org/ticket/713
http://www.helenos.org/ticket/714

Location:
uspace/lib/pcut/src/os
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/pcut/src/os/generic.c

    r6fb8b2c r9eb1ff5  
    3434#include <stdlib.h>
    3535#include <stdio.h>
     36#include <sys/types.h>
    3637#include <errno.h>
    3738#include <assert.h>
     
    9495static int convert_wait_status_to_outcome(int status) {
    9596        if (status < 0) {
    96                 return TEST_OUTCOME_ERROR;
     97                return PCUT_OUTCOME_INTERNAL_ERROR;
    9798        } else if (status == 0) {
    98                 return TEST_OUTCOME_PASS;
     99                return PCUT_OUTCOME_PASS;
    99100        } else {
    100                 return TEST_OUTCOME_FAIL;
     101                return PCUT_OUTCOME_FAIL;
    101102        }
    102103}
     
    107108 * @param test Test to be run.
    108109 */
    109 void pcut_run_test_forking(const char *self_path, pcut_item_t *test) {
    110         int rc;
     110int pcut_run_test_forking(const char *self_path, pcut_item_t *test) {
     111        int rc, outcome;
    111112        FILE *tempfile;
    112113        char tempfile_name[PCUT_TEMP_FILENAME_BUFFER_SIZE];
     
    126127        PCUT_DEBUG("system() returned 0x%04X", rc);
    127128
    128         rc = convert_wait_status_to_outcome(rc);
     129        outcome = convert_wait_status_to_outcome(rc);
    129130
    130131        tempfile = fopen(tempfile_name, "rb");
    131132        if (tempfile == NULL) {
    132133                pcut_report_test_done(test, TEST_OUTCOME_ERROR, "Failed to open temporary file.", NULL, NULL);
    133                 return;
     134                return PCUT_OUTCOME_INTERNAL_ERROR;
    134135        }
    135136
    136137        fread(extra_output_buffer, 1, OUTPUT_BUFFER_SIZE, tempfile);
    137138        fclose(tempfile);
    138         unlink(tempfile_name);
     139        remove(tempfile_name);
    139140
    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;
    141144}
    142145
  • uspace/lib/pcut/src/os/helenos.c

    r6fb8b2c r9eb1ff5  
    154154 * @param test Test to be run.
    155155 */
    156 void pcut_run_test_forking(const char *self_path, pcut_item_t *test) {
     156int pcut_run_test_forking(const char *self_path, pcut_item_t *test) {
    157157        before_test_start(test);
    158158
     
    161161        int tempfile = vfs_lookup_open(tempfile_name, WALK_REGULAR | WALK_MAY_CREATE, MODE_READ | MODE_WRITE);
    162162        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;
    165165        }
    166166
     
    174174        };
    175175
    176         int status = TEST_OUTCOME_PASS;
     176        int status = PCUT_OUTCOME_PASS;
    177177
    178178        task_wait_t test_task_wait;
     
    180180            fileno(stdin), tempfile, tempfile);
    181181        if (rc != EOK) {
    182                 status = TEST_OUTCOME_ERROR;
     182                status = PCUT_OUTCOME_INTERNAL_ERROR;
    183183                goto leave_close_tempfile;
    184184        }
     
    198198        rc = task_wait(&test_task_wait, &task_exit, &task_retval);
    199199        if (rc != EOK) {
    200                 status = TEST_OUTCOME_ERROR;
     200                status = PCUT_OUTCOME_INTERNAL_ERROR;
    201201                goto leave_close_tempfile;
    202202        }
    203203        if (task_exit == TASK_EXIT_UNEXPECTED) {
    204                 status = TEST_OUTCOME_ERROR;
     204                status = PCUT_OUTCOME_INTERNAL_ERROR;
    205205        } else {
    206                 status = task_retval == 0 ? TEST_OUTCOME_PASS : TEST_OUTCOME_FAIL;
     206                status = task_retval == 0 ? PCUT_OUTCOME_PASS : PCUT_OUTCOME_FAIL;
    207207        }
    208208
     
    221221
    222222        pcut_report_test_done_unparsed(test, status, extra_output_buffer, OUTPUT_BUFFER_SIZE);
     223
     224        return status;
    223225}
    224226
  • uspace/lib/pcut/src/os/unix.c

    r6fb8b2c r9eb1ff5  
    3636/** We need _BSD_SOURCE because of snprintf() when compiling under C89. */
    3737#define _BSD_SOURCE
     38
     39/** Newer versions of features.h needs _DEFAULT_SOURCE. */
     40#define _DEFAULT_SOURCE
     41
    3842#include <stdlib.h>
    3943#include <unistd.h>
    40 #include <stddef.h>
     44#include <sys/types.h>
    4145#include <signal.h>
    4246#include <errno.h>
     
    120124        if (WIFEXITED(status)) {
    121125                if (WEXITSTATUS(status) != 0) {
    122                         return TEST_OUTCOME_FAIL;
     126                        return PCUT_OUTCOME_FAIL;
    123127                } else {
    124                         return TEST_OUTCOME_PASS;
     128                        return PCUT_OUTCOME_PASS;
    125129                }
    126130        }
    127131
    128132        if (WIFSIGNALED(status)) {
    129                 return TEST_OUTCOME_ERROR;
     133                return PCUT_OUTCOME_INTERNAL_ERROR;
    130134        }
    131135
     
    138142 * @param test Test to be run.
    139143 */
    140 void pcut_run_test_forking(const char *self_path, pcut_item_t *test) {
     144int pcut_run_test_forking(const char *self_path, pcut_item_t *test) {
    141145        int link_stdout[2], link_stderr[2];
    142         int rc, status;
     146        int rc, status, outcome;
    143147        size_t stderr_size;
    144148
     
    152156                snprintf(error_message_buffer, OUTPUT_BUFFER_SIZE - 1,
    153157                                "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;
    156160        }
    157161        rc = pipe(link_stderr);
     
    159163                snprintf(error_message_buffer, OUTPUT_BUFFER_SIZE - 1,
    160164                                "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;
    163167        }
    164168
     
    167171                snprintf(error_message_buffer, OUTPUT_BUFFER_SIZE - 1,
    168172                        "fork() failed: %s.", strerror(rc));
    169                 rc = TEST_OUTCOME_ERROR;
     173                outcome = PCUT_OUTCOME_INTERNAL_ERROR;
    170174                goto leave_close_pipes;
    171175        }
     
    178182                close(link_stderr[0]);
    179183
    180                 rc = pcut_run_test_forked(test);
    181 
    182                 exit(rc);
     184                outcome = pcut_run_test_forked(test);
     185
     186                exit(outcome);
    183187        }
    184188
     
    195199        alarm(0);
    196200
    197         rc = convert_wait_status_to_outcome(status);
     201        outcome = convert_wait_status_to_outcome(status);
    198202
    199203        goto leave_close_parent_pipe;
     
    206210        close(link_stderr[0]);
    207211
    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;
    209215}
    210216
  • uspace/lib/pcut/src/os/windows.c

    r6fb8b2c r9eb1ff5  
    144144 * @param test Test to be run.
    145145 */
    146 void pcut_run_test_forking(const char *self_path, pcut_item_t *test) {
     146int pcut_run_test_forking(const char *self_path, pcut_item_t *test) {
    147147        /* TODO: clean-up if something goes wrong "in the middle" */
    148148        BOOL okay = FALSE;
     
    173173        if (!okay) {
    174174                report_func_fail(test, "CreatePipe(/* stdout */)");
    175                 return;
     175                return PCUT_OUTCOME_INTERNAL_ERROR;
    176176        }
    177177        okay = SetHandleInformation(link_stdout[0], HANDLE_FLAG_INHERIT, 0);
    178178        if (!okay) {
    179179                report_func_fail(test, "SetHandleInformation(/* stdout */)");
    180                 return;
     180                return PCUT_OUTCOME_INTERNAL_ERROR;
    181181        }
    182182
     
    185185        if (!okay) {
    186186                report_func_fail(test, "CreatePipe(/* stderr */)");
    187                 return;
     187                return PCUT_OUTCOME_INTERNAL_ERROR;
    188188        }
    189189        okay = SetHandleInformation(link_stderr[0], HANDLE_FLAG_INHERIT, 0);
    190190        if (!okay) {
    191191                report_func_fail(test, "SetHandleInformation(/* stderr */)");
    192                 return;
     192                return PCUT_OUTCOME_INTERNAL_ERROR;
    193193        }
    194194
     
    197197        if (!okay) {
    198198                report_func_fail(test, "CreatePipe(/* stdin */)");
    199                 return;
     199                return PCUT_OUTCOME_INTERNAL_ERROR;
    200200        }
    201201        okay = SetHandleInformation(link_stdin[1], HANDLE_FLAG_INHERIT, 0);
    202202        if (!okay) {
    203203                report_func_fail(test, "SetHandleInformation(/* stdin */)");
    204                 return;
     204                return PCUT_OUTCOME_INTERNAL_ERROR;
    205205        }
    206206
     
    224224        if (!okay) {
    225225                report_func_fail(test, "CreateProcess()");
    226                 return;
     226                return PCUT_OUTCOME_INTERNAL_ERROR;
    227227        }
    228228
     
    236236        if (!okay) {
    237237                report_func_fail(test, "CloseHandle(/* stdout */)");
    238                 return;
     238                return PCUT_OUTCOME_INTERNAL_ERROR;
    239239        }
    240240        okay = CloseHandle(link_stderr[1]);
    241241        if (!okay) {
    242242                report_func_fail(test, "CloseHandle(/* stderr */)");
    243                 return;
     243                return PCUT_OUTCOME_INTERNAL_ERROR;
    244244        }
    245245        okay = CloseHandle(link_stdin[0]);
    246246        if (!okay) {
    247247                report_func_fail(test, "CloseHandle(/* stdin */)");
    248                 return;
     248                return PCUT_OUTCOME_INTERNAL_ERROR;
    249249        }
    250250
     
    267267        if (test_output_thread_reader == NULL) {
    268268                report_func_fail(test, "CreateThread(/* read test stdout */)");
    269                 return;
     269                return PCUT_OUTCOME_INTERNAL_ERROR;
    270270        }
    271271
     
    281281                if (!okay) {
    282282                        report_func_fail(test, "TerminateProcess(/* PROCESS_INFORMATION.hProcess */)");
    283                         return;
     283                        return PCUT_ERROR_INTERNAL_FAILURE;
    284284                }
    285285                rc = WaitForSingleObject(process_info.hProcess, INFINITE);
     
    287287        if (rc != WAIT_OBJECT_0) {
    288288                report_func_fail(test, "WaitForSingleObject(/* PROCESS_INFORMATION.hProcess */)");
    289                 return;
     289                return PCUT_OUTCOME_INTERNAL_ERROR;
    290290        }
    291291
     
    294294        if (!okay) {
    295295                report_func_fail(test, "GetExitCodeProcess()");
    296                 return;
     296                return PCUT_OUTCOME_INTERNAL_ERROR;
    297297        }
    298298
    299299        if (rc == 0) {
    300                 outcome = TEST_OUTCOME_PASS;
     300                outcome = PCUT_OUTCOME_PASS;
    301301        } else if ((rc > 0) && (rc < 10) && !timed_out) {
    302                 outcome = TEST_OUTCOME_FAIL;
     302                outcome = PCUT_OUTCOME_FAIL;
    303303        } else {
    304                 outcome = TEST_OUTCOME_ERROR;
     304                outcome = PCUT_OUTCOME_INTERNAL_ERROR;
    305305        }
    306306
     
    309309        if (rc != WAIT_OBJECT_0) {
    310310                report_func_fail(test, "WaitForSingleObject(/* stdout reader thread */)");
    311                 return;
     311                return PCUT_ERROR_INTERNAL_FAILURE;
    312312        }
    313313
    314314        pcut_report_test_done_unparsed(test, outcome, extra_output_buffer, OUTPUT_BUFFER_SIZE);
     315
     316        return outcome;
    315317}
    316318
Note: See TracChangeset for help on using the changeset viewer.