Changeset 9eb1ff5 in mainline for uspace/lib/pcut/src/run.c


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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.