Changeset 9eb1ff5 in mainline


Ignore:
Timestamp:
2017-12-08T14:47:08Z (6 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
Files:
31 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/pcut/helenos.mak

    r6fb8b2c r9eb1ff5  
    3939
    4040EXTRA_CFLAGS = -D__helenos__
     41
    4142LIBRARY = libpcut
  • uspace/lib/pcut/include/pcut/pcut.h

    r6fb8b2c r9eb1ff5  
    3636#include <pcut/tests.h>
    3737
     38
     39/** PCUT outcome: test passed. */
     40#define PCUT_OUTCOME_PASS 0
     41
     42/** PCUT outcome: test failed. */
     43#define PCUT_OUTCOME_FAIL 1
     44
     45/** PCUT outcome: test failed unexpectedly. */
     46#define PCUT_OUTCOME_INTERNAL_ERROR 2
     47
     48/** PCUT outcome: invalid invocation of the final program. */
     49#define PCUT_OUTCOME_BAD_INVOCATION 3
     50
     51
    3852#endif
  • uspace/lib/pcut/src/assert.c

    r6fb8b2c r9eb1ff5  
    3535 */
    3636
    37 /** We need _BSD_SOURCE because of vsnprintf() when compiling under C89. */
     37/*
     38 * We need _BSD_SOURCE because of vsnprintf() when compiling under C89.
     39 * In newer versions of features.h, _DEFAULT_SOURCE must be defined as well.
     40 */
    3841#define _BSD_SOURCE
     42#define _DEFAULT_SOURCE
    3943
    4044#include "internal.h"
  • uspace/lib/pcut/src/internal.h

    r6fb8b2c r9eb1ff5  
    7979#define PCUT_RUN_MODE_SINGLE 2
    8080
    81 /** Test outcome: test passed. */
    82 #define TEST_OUTCOME_PASS 1
    83 
    84 /** Test outcome: test failed. */
    85 #define TEST_OUTCOME_FAIL 2
    86 
    87 /** Test outcome: test failed unexpectedly. */
    88 #define TEST_OUTCOME_ERROR 3
    89 
    90 
    9181/*
    9282 * Use sprintf_s in Windows but only with Microsoft compiler.
     
    10999int pcut_is_arg_with_number(const char *arg, const char *opt, int *value);
    110100
    111 void pcut_run_test_forking(const char *self_path, pcut_item_t *test);
     101int pcut_run_test_forking(const char *self_path, pcut_item_t *test);
    112102int pcut_run_test_forked(pcut_item_t *test);
    113103int pcut_run_test_single(pcut_item_t *test);
  • uspace/lib/pcut/src/main.c

    r6fb8b2c r9eb1ff5  
    9090 * @param last Pointer to first item after this suite is stored here.
    9191 * @param prog_path Path to the current binary (used in forked mode).
    92  */
    93 static void run_suite(pcut_item_t *suite, pcut_item_t **last, const char *prog_path) {
     92 * @return Error code.
     93 */
     94static int run_suite(pcut_item_t *suite, pcut_item_t **last, const char *prog_path) {
    9495        int is_first_test = 1;
    9596        int total_count = 0;
     97        int ret_code = PCUT_OUTCOME_PASS;
     98        int ret_code_tmp;
    9699
    97100        pcut_item_t *it = pcut_get_real_next(suite);
     
    114117
    115118                if (pcut_run_mode == PCUT_RUN_MODE_FORKING) {
    116                         pcut_run_test_forking(prog_path, it);
     119                        ret_code_tmp = pcut_run_test_forking(prog_path, it);
    117120                } else {
    118                         pcut_run_test_single(it);
    119                 }
     121                        ret_code_tmp = pcut_run_test_single(it);
     122                }
     123
     124                /*
     125                 * Override final return code in case of failure.
     126                 *
     127                 * In this case we suppress any special error codes as
     128                 * to the outside, there was a failure.
     129                 */
     130                if (ret_code_tmp != PCUT_OUTCOME_PASS) {
     131                        ret_code = PCUT_OUTCOME_FAIL;
     132                }
     133
    120134                total_count++;
    121135        }
     
    130144                *last = it;
    131145        }
     146
     147        return ret_code;
    132148}
    133149
     
    181197        int run_only_test = -1;
    182198
     199        int rc, rc_tmp;
     200
    183201        if (main_extras == NULL) {
    184202                main_extras = empty_main_extra;
     
    203221                        if (pcut_str_equals(argv[i], "-l")) {
    204222                                pcut_print_tests(items);
    205                                 return 0;
     223                                return PCUT_OUTCOME_PASS;
    206224                        }
    207225                        if (pcut_str_equals(argv[i], "-x")) {
     
    229247        if ((run_only_suite >= 0) && (run_only_test >= 0)) {
    230248                printf("Specify either -s or -t!\n");
    231                 return 1;
     249                return PCUT_OUTCOME_BAD_INVOCATION;
    232250        }
    233251
     
    236254                if (suite == NULL) {
    237255                        printf("Suite not found, aborting!\n");
    238                         return 2;
     256                        return PCUT_OUTCOME_BAD_INVOCATION;
    239257                }
    240258                if (suite->kind != PCUT_KIND_TESTSUITE) {
    241259                        printf("Invalid suite id!\n");
    242                         return 3;
     260                        return PCUT_OUTCOME_BAD_INVOCATION;
    243261                }
    244262
    245263                run_suite(suite, NULL, argv[0]);
    246                 return 0;
     264                return PCUT_OUTCOME_PASS;
    247265        }
    248266
    249267        if (run_only_test > 0) {
    250                 int rc;
    251268                pcut_item_t *test = pcut_find_by_id(items, run_only_test);
    252269                if (test == NULL) {
    253270                        printf("Test not found, aborting!\n");
    254                         return 2;
     271                        return PCUT_OUTCOME_BAD_INVOCATION;
    255272                }
    256273                if (test->kind != PCUT_KIND_TEST) {
    257274                        printf("Invalid test id!\n");
    258                         return 3;
     275                        return PCUT_OUTCOME_BAD_INVOCATION;
    259276                }
    260277
     
    271288        pcut_report_init(items);
    272289
     290        rc = PCUT_OUTCOME_PASS;
     291
    273292        it = items;
    274293        while (it != NULL) {
    275294                if (it->kind == PCUT_KIND_TESTSUITE) {
    276295                        pcut_item_t *tmp;
    277                         run_suite(it, &tmp, argv[0]);
     296                        rc_tmp = run_suite(it, &tmp, argv[0]);
     297                        if (rc_tmp != PCUT_OUTCOME_PASS) {
     298                                rc = rc_tmp;
     299                        }
    278300                        it = tmp;
    279301                } else {
     
    284306        pcut_report_done();
    285307
    286         return 0;
    287 }
     308        return rc;
     309}
  • 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
  • uspace/lib/pcut/src/print.c

    r6fb8b2c r9eb1ff5  
    8181                        printf("    Test `%s' [%d]\n", it->name, it->id);
    8282                        break;
     83                case PCUT_KIND_SETUP:
     84                case PCUT_KIND_TEARDOWN:
     85                        /* Fall-through, do nothing. */
     86                        break;
    8387                default:
    8488                        assert(0 && "unreachable case in item-kind switch");
  • uspace/lib/pcut/src/report/tap.c

    r6fb8b2c r9eb1ff5  
    4242static int test_counter;
    4343
     44/** Counter of all failures. */
     45static int failed_test_counter;
     46
    4447/** Counter for tests in a current suite. */
    4548static int tests_in_suite;
     
    5558        int tests_total = pcut_count_tests(all_items);
    5659        test_counter = 0;
     60        failed_test_counter = 0;
    5761
    5862        printf("1..%d\n", tests_total);
     
    7579 */
    7680static void tap_suite_done(pcut_item_t *suite) {
    77         printf("#> Finished suite %s (failed %d of %d).\n",
    78                         suite->name, failed_tests_in_suite, tests_in_suite);
     81        if (failed_tests_in_suite == 0) {
     82                printf("#> Finished suite %s (passed).\n",
     83                                suite->name);
     84        } else {
     85                printf("#> Finished suite %s (failed %d of %d).\n",
     86                                suite->name, failed_tests_in_suite, tests_in_suite);
     87        }
    7988}
    8089
     
    129138        const char *fail_error_str = NULL;
    130139
    131         if (outcome != TEST_OUTCOME_PASS) {
     140        if (outcome != PCUT_OUTCOME_PASS) {
    132141                failed_tests_in_suite++;
     142                failed_test_counter++;
    133143        }
    134144
    135145        switch (outcome) {
    136         case TEST_OUTCOME_PASS:
     146        case PCUT_OUTCOME_PASS:
    137147                status_str = "ok";
    138148                fail_error_str = "";
    139149                break;
    140         case TEST_OUTCOME_FAIL:
     150        case PCUT_OUTCOME_FAIL:
    141151                status_str = "not ok";
    142152                fail_error_str = " failed";
    143153                break;
    144         case TEST_OUTCOME_ERROR:
     154        default:
    145155                status_str = "not ok";
    146156                fail_error_str = " aborted";
    147                 break;
    148         default:
    149                 /* Shall not get here. */
    150157                break;
    151158        }
     
    160167/** Report testing done. */
    161168static void tap_done(void) {
     169        if (failed_test_counter == 0) {
     170                printf("#> Done: all tests passed.\n");
     171        } else {
     172                printf("#> Done: %d of %d tests failed.\n", failed_test_counter, test_counter);
     173        }
    162174}
    163175
  • uspace/lib/pcut/src/report/xml.c

    r6fb8b2c r9eb1ff5  
    135135        const char *status_str = NULL;
    136136
    137         if (outcome != TEST_OUTCOME_PASS) {
     137        if (outcome != PCUT_OUTCOME_PASS) {
    138138                failed_tests_in_suite++;
    139139        }
    140140
    141141        switch (outcome) {
    142         case TEST_OUTCOME_PASS:
     142        case PCUT_OUTCOME_PASS:
    143143                status_str = "pass";
    144144                break;
    145         case TEST_OUTCOME_FAIL:
     145        case PCUT_OUTCOME_FAIL:
    146146                status_str = "fail";
    147147                break;
    148         case TEST_OUTCOME_ERROR:
     148        default:
    149149                status_str = "error";
    150                 break;
    151         default:
    152                 /* Shall not get here. */
    153150                break;
    154151        }
  • uspace/lib/pcut/src/run.c

    r6fb8b2c r9eb1ff5  
    7373static int default_suite_initialized = 0;
    7474
    75 static void init_default_suite_when_needed(void)
    76 {
    77         if (default_suite_initialized)
     75static void init_default_suite_when_needed() {
     76        if (default_suite_initialized) {
    7877                return;
    79        
     78        }
    8079        default_suite.id = -1;
    8180        default_suite.kind = PCUT_KIND_TESTSUITE;
     
    9291 * @return Always a valid test suite item.
    9392 */
    94 static pcut_item_t *pcut_find_parent_suite(pcut_item_t *it)
    95 {
     93static pcut_item_t *pcut_find_parent_suite(pcut_item_t *it) {
    9694        while (it != NULL) {
    97                 if (it->kind == PCUT_KIND_TESTSUITE)
     95                if (it->kind == PCUT_KIND_TESTSUITE) {
    9896                        return it;
    99                
     97                }
    10098                it = it->previous;
    10199        }
    102        
    103100        init_default_suite_when_needed();
    104101        return &default_suite;
     
    109106 * @param func Function to run (can be NULL).
    110107 */
    111 static void run_setup_teardown(pcut_setup_func_t func)
    112 {
    113         if (func != NULL)
     108static void run_setup_teardown(pcut_setup_func_t func) {
     109        if (func != NULL) {
    114110                func();
     111        }
    115112}
    116113
     
    122119 * @param outcome Outcome of the current test.
    123120 */
    124 static void leave_test(int outcome)
    125 {
     121static void leave_test(int outcome) {
    126122        PCUT_DEBUG("leave_test(outcome=%d), will_exit=%s", outcome,
    127             leave_means_exit ? "yes" : "no");
    128         if (leave_means_exit)
     123                leave_means_exit ? "yes" : "no");
     124        if (leave_means_exit) {
    129125                exit(outcome);
    130        
     126        }
     127
    131128#ifndef PCUT_NO_LONG_JUMP
    132129        longjmp(start_test_jump, 1);
     
    141138 * @param message Message describing the failure.
    142139 */
    143 void pcut_failed_assertion(const char *message)
    144 {
     140void pcut_failed_assertion(const char *message) {
    145141        static const char *prev_message = NULL;
    146        
    147142        /*
    148143         * The assertion failed. We need to abort the current test,
     
    150145         * include running the tear-down routine.
    151146         */
    152         if (print_test_error)
     147        if (print_test_error) {
    153148                pcut_print_fail_message(message);
    154        
     149        }
     150
    155151        if (execute_teardown_on_failure) {
    156152                execute_teardown_on_failure = 0;
    157153                prev_message = message;
    158154                run_setup_teardown(current_suite->teardown_func);
    159                
     155
    160156                /* Tear-down was okay. */
    161157                if (report_test_result) {
    162                         pcut_report_test_done(current_test, TEST_OUTCOME_FAIL,
     158                        pcut_report_test_done(current_test, PCUT_OUTCOME_FAIL,
    163159                                message, NULL, NULL);
    164160                }
    165161        } else {
    166162                if (report_test_result) {
    167                         pcut_report_test_done(current_test, TEST_OUTCOME_FAIL,
     163                        pcut_report_test_done(current_test, PCUT_OUTCOME_FAIL,
    168164                                prev_message, message, NULL);
    169165                }
    170166        }
    171        
     167
    172168        prev_message = NULL;
    173        
    174         leave_test(TEST_OUTCOME_FAIL); /* No return. */
     169
     170        leave_test(PCUT_OUTCOME_FAIL); /* No return. */
    175171}
    176172
     
    180176 * @return Error status (zero means success).
    181177 */
    182 static int run_test(pcut_item_t *test)
    183 {
     178static int run_test(pcut_item_t *test) {
    184179        /*
    185180         * Set here as the returning point in case of test failure.
     
    187182         * test execution.
    188183         */
    189        
    190184#ifndef PCUT_NO_LONG_JUMP
    191185        int test_finished = setjmp(start_test_jump);
    192         if (test_finished)
    193                 return 1;
     186        if (test_finished) {
     187                return PCUT_OUTCOME_FAIL;
     188        }
    194189#endif
    195        
    196         if (report_test_result)
     190
     191        if (report_test_result) {
    197192                pcut_report_test_start(test);
    198        
     193        }
     194
    199195        current_suite = pcut_find_parent_suite(test);
    200196        current_test = test;
    201        
     197
    202198        pcut_hook_before_test(test);
    203        
     199
    204200        /*
    205201         * If anything goes wrong, execute the tear-down function
     
    207203         */
    208204        execute_teardown_on_failure = 1;
    209        
     205
    210206        /*
    211207         * Run the set-up function.
    212208         */
    213209        run_setup_teardown(current_suite->setup_func);
    214        
     210
    215211        /*
    216212         * The setup function was performed, it is time to run
     
    218214         */
    219215        test->test_func();
    220        
     216
    221217        /*
    222218         * Finally, run the tear-down function. We need to clear
     
    225221        execute_teardown_on_failure = 0;
    226222        run_setup_teardown(current_suite->teardown_func);
    227        
     223
    228224        /*
    229225         * If we got here, it means everything went well with
    230226         * this test.
    231227         */
    232         if (report_test_result)
    233                 pcut_report_test_done(current_test, TEST_OUTCOME_PASS,
    234                     NULL, NULL, NULL);
    235        
    236         return 0;
     228        if (report_test_result) {
     229                pcut_report_test_done(current_test, PCUT_OUTCOME_PASS,
     230                        NULL, NULL, NULL);
     231        }
     232
     233        return PCUT_OUTCOME_PASS;
    237234}
    238235
     
    245242 * @return Error status (zero means success).
    246243 */
    247 int pcut_run_test_forked(pcut_item_t *test)
    248 {
     244int pcut_run_test_forked(pcut_item_t *test) {
     245        int rc;
     246
    249247        report_test_result = 0;
    250248        print_test_error = 1;
    251249        leave_means_exit = 1;
    252        
    253         int rc = run_test(test);
    254        
     250
     251        rc = run_test(test);
     252
    255253        current_test = NULL;
    256254        current_suite = NULL;
    257        
     255
    258256        return rc;
    259257}
     
    267265 * @return Error status (zero means success).
    268266 */
    269 int pcut_run_test_single(pcut_item_t *test)
    270 {
     267int pcut_run_test_single(pcut_item_t *test) {
     268        int rc;
     269
    271270        report_test_result = 1;
    272271        print_test_error = 0;
    273272        leave_means_exit = 0;
    274        
    275         int rc = run_test(test);
    276        
     273
     274        rc = run_test(test);
     275
    277276        current_test = NULL;
    278277        current_suite = NULL;
    279        
     278
    280279        return rc;
    281280}
     
    286285 * @return Timeout in seconds.
    287286 */
    288 int pcut_get_test_timeout(pcut_item_t *test)
    289 {
     287int pcut_get_test_timeout(pcut_item_t *test) {
    290288        int timeout = PCUT_DEFAULT_TEST_TIMEOUT;
    291289        pcut_extra_t *extras = test->extras;
    292        
     290
     291
    293292        while (extras->type != PCUT_EXTRA_LAST) {
    294                 if (extras->type == PCUT_EXTRA_TIMEOUT)
     293                if (extras->type == PCUT_EXTRA_TIMEOUT) {
    295294                        timeout = extras->timeout;
    296                
     295                }
    297296                extras++;
    298297        }
    299        
     298
    300299        return timeout;
    301300}
  • uspace/lib/pcut/tests/abort.expected

    r6fb8b2c r9eb1ff5  
    33not ok 1 access_null_pointer aborted
    44#> Finished suite Default (failed 1 of 1).
     5#> Done: 1 of 1 tests failed.
  • uspace/lib/pcut/tests/asserts.expected

    r6fb8b2c r9eb1ff5  
    1818# error: asserts.c:72: Expected false but got <42>
    1919#> Finished suite Default (failed 7 of 9).
     20#> Done: 7 of 9 tests failed.
  • uspace/lib/pcut/tests/beforeafter.c

    r6fb8b2c r9eb1ff5  
    2828
    2929#define _BSD_SOURCE
     30#define _DEFAULT_SOURCE
    3031
    3132#include <pcut/pcut.h>
  • uspace/lib/pcut/tests/beforeafter.expected

    r6fb8b2c r9eb1ff5  
    22#> Starting suite suite_with_setup_and_teardown.
    33ok 1 test_with_setup_and_teardown
    4 #> Finished suite suite_with_setup_and_teardown (failed 0 of 1).
     4#> Finished suite suite_with_setup_and_teardown (passed).
    55#> Starting suite another_without_setup.
    66ok 2 test_without_any_setup_or_teardown
    7 #> Finished suite another_without_setup (failed 0 of 1).
     7#> Finished suite another_without_setup (passed).
     8#> Done: all tests passed.
  • uspace/lib/pcut/tests/errno.expected

    r6fb8b2c r9eb1ff5  
    66# error: errno.c:54: Expected error 0 (EOK, *****) but got error ***** (*****)
    77#> Finished suite Default (failed 2 of 2).
     8#> Done: 2 of 2 tests failed.
  • uspace/lib/pcut/tests/inithook.expected

    r6fb8b2c r9eb1ff5  
    33ok 1 check_init_counter
    44ok 2 check_init_counter_2
    5 #> Finished suite Default (failed 0 of 2).
     5#> Finished suite Default (passed).
     6#> Done: all tests passed.
  • uspace/lib/pcut/tests/manytests.expected

    r6fb8b2c r9eb1ff5  
    8181ok 79 my_test_079
    8282ok 80 my_test_080
    83 #> Finished suite Default (failed 0 of 80).
     83#> Finished suite Default (passed).
     84#> Done: all tests passed.
  • uspace/lib/pcut/tests/multisuite.expected

    r6fb8b2c r9eb1ff5  
    1111ok 4 test_same_numbers
    1212#> Finished suite intmin (failed 1 of 2).
     13#> Done: 3 of 4 tests failed.
  • uspace/lib/pcut/tests/preinithook.expected

    r6fb8b2c r9eb1ff5  
    33ok 1 check_init_counter
    44ok 2 check_init_counter_2
    5 #> Finished suite Default (failed 0 of 2).
     5#> Finished suite Default (passed).
     6#> Done: all tests passed.
  • uspace/lib/pcut/tests/printing.expected

    r6fb8b2c r9eb1ff5  
    99# stdio: Printed from a test to stdout!
    1010#> Finished suite Default (failed 1 of 3).
     11#> Done: 1 of 3 tests failed.
  • uspace/lib/pcut/tests/simple.expected

    r6fb8b2c r9eb1ff5  
    88# error: simple.c:46: Expected <abc> but got <abd> ("abc" != "XXXabd" + 3)
    99#> Finished suite Default (failed 3 of 3).
     10#> Done: 3 of 3 tests failed.
  • uspace/lib/pcut/tests/skip.expected

    r6fb8b2c r9eb1ff5  
    33ok 1 normal_test
    44ok 2 again_normal_test
    5 #> Finished suite Default (failed 0 of 2).
     5#> Finished suite Default (passed).
     6#> Done: all tests passed.
  • uspace/lib/pcut/tests/suites.expected

    r6fb8b2c r9eb1ff5  
    1010# error: suites.c:49: Expected <5> but got <654> (5 != intmin(654, 5))
    1111#> Finished suite intmin (failed 1 of 1).
     12#> Done: 3 of 3 tests failed.
  • uspace/lib/pcut/tests/teardown.expected

    r6fb8b2c r9eb1ff5  
    2121# stdio: This is failing teardown-function.
    2222#> Finished suite with_failing_teardown (failed 3 of 3).
     23#> Done: 4 of 5 tests failed.
  • uspace/lib/pcut/tests/teardownaborts.expected

    r6fb8b2c r9eb1ff5  
    55# stdio: Tear-down will cause null pointer access...
    66#> Finished suite Default (failed 1 of 1).
     7#> Done: 1 of 1 tests failed.
  • uspace/lib/pcut/tests/timeout.c

    r6fb8b2c r9eb1ff5  
    2929#include <pcut/pcut.h>
    3030
     31#ifdef __helenos__
     32#include <thread.h>
     33#else
    3134#ifdef __unix
    32 // FIXME
    33 #include <thread.h>
     35#include <unistd.h>
    3436#endif
    3537#if defined(__WIN64) || defined(__WIN32) || defined(_WIN32)
    3638#include <windows.h>
     39#endif
    3740#endif
    3841
     
    4144
    4245static void my_sleep(int sec) {
     46#ifdef __helenos__
     47        thread_sleep(sec);
     48#else
    4349#ifdef __unix
    44 // FIXME
    45         thread_sleep(sec);
     50        sleep(sec);
    4651#endif
    4752#if defined(__WIN64) || defined(__WIN32) || defined(_WIN32)
    4853        Sleep(1000 * sec);
     54#endif
    4955#endif
    5056}
  • uspace/lib/pcut/tests/timeout.expected

    r6fb8b2c r9eb1ff5  
    77# stdio: Text after the sleep.
    88#> Finished suite Default (failed 1 of 2).
     9#> Done: 1 of 2 tests failed.
  • uspace/lib/pcut/tests/xmlreport.c

    r6fb8b2c r9eb1ff5  
    3030#include "tested.h"
    3131
     32#include <pcut/pcut.h>
     33#include "tested.h"
    3234
    3335PCUT_INIT
Note: See TracChangeset for help on using the changeset viewer.