Changeset 193d280c in mainline for uspace/lib/pcut/src/run.c


Ignore:
Timestamp:
2015-06-01T00:04:05Z (9 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
53031c2
Parents:
91deaff
Message:

cstyle improvements
replace traditional K&R-style function declarations and definitions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/pcut/src/run.c

    r91deaff r193d280c  
    7373static int default_suite_initialized = 0;
    7474
    75 static void init_default_suite_when_needed() {
    76         if (default_suite_initialized) {
     75static void init_default_suite_when_needed(void)
     76{
     77        if (default_suite_initialized)
    7778                return;
    78         }
     79       
    7980        default_suite.id = -1;
    8081        default_suite.kind = PCUT_KIND_TESTSUITE;
     
    9192 * @return Always a valid test suite item.
    9293 */
    93 static pcut_item_t *pcut_find_parent_suite(pcut_item_t *it) {
     94static pcut_item_t *pcut_find_parent_suite(pcut_item_t *it)
     95{
    9496        while (it != NULL) {
    95                 if (it->kind == PCUT_KIND_TESTSUITE) {
     97                if (it->kind == PCUT_KIND_TESTSUITE)
    9698                        return it;
    97                 }
     99               
    98100                it = it->previous;
    99101        }
     102       
    100103        init_default_suite_when_needed();
    101104        return &default_suite;
     
    106109 * @param func Function to run (can be NULL).
    107110 */
    108 static void run_setup_teardown(pcut_setup_func_t func) {
    109         if (func != NULL) {
     111static void run_setup_teardown(pcut_setup_func_t func)
     112{
     113        if (func != NULL)
    110114                func();
    111         }
    112115}
    113116
     
    119122 * @param outcome Outcome of the current test.
    120123 */
    121 static void leave_test(int outcome) {
     124static void leave_test(int outcome)
     125{
    122126        PCUT_DEBUG("leave_test(outcome=%d), will_exit=%s", outcome,
    123                 leave_means_exit ? "yes" : "no");
    124         if (leave_means_exit) {
     127            leave_means_exit ? "yes" : "no");
     128        if (leave_means_exit)
    125129                exit(outcome);
    126         }
    127 
     130       
    128131#ifndef PCUT_NO_LONG_JUMP
    129132        longjmp(start_test_jump, 1);
     
    138141 * @param message Message describing the failure.
    139142 */
    140 void pcut_failed_assertion(const char *message) {
     143void pcut_failed_assertion(const char *message)
     144{
    141145        static const char *prev_message = NULL;
     146       
    142147        /*
    143148         * The assertion failed. We need to abort the current test,
     
    145150         * include running the tear-down routine.
    146151         */
    147         if (print_test_error) {
     152        if (print_test_error)
    148153                pcut_print_fail_message(message);
    149         }
    150 
     154       
    151155        if (execute_teardown_on_failure) {
    152156                execute_teardown_on_failure = 0;
    153157                prev_message = message;
    154158                run_setup_teardown(current_suite->teardown_func);
    155 
     159               
    156160                /* Tear-down was okay. */
    157161                if (report_test_result) {
     
    165169                }
    166170        }
    167 
     171       
    168172        prev_message = NULL;
    169 
     173       
    170174        leave_test(TEST_OUTCOME_FAIL); /* No return. */
    171175}
     
    176180 * @return Error status (zero means success).
    177181 */
    178 static int run_test(pcut_item_t *test) {
     182static int run_test(pcut_item_t *test)
     183{
    179184        /*
    180185         * Set here as the returning point in case of test failure.
     
    182187         * test execution.
    183188         */
     189       
    184190#ifndef PCUT_NO_LONG_JUMP
    185191        int test_finished = setjmp(start_test_jump);
    186         if (test_finished) {
     192        if (test_finished)
    187193                return 1;
    188         }
    189194#endif
    190 
    191         if (report_test_result) {
     195       
     196        if (report_test_result)
    192197                pcut_report_test_start(test);
    193         }
    194 
     198       
    195199        current_suite = pcut_find_parent_suite(test);
    196200        current_test = test;
    197 
     201       
    198202        pcut_hook_before_test(test);
    199 
     203       
    200204        /*
    201205         * If anything goes wrong, execute the tear-down function
     
    203207         */
    204208        execute_teardown_on_failure = 1;
    205 
     209       
    206210        /*
    207211         * Run the set-up function.
    208212         */
    209213        run_setup_teardown(current_suite->setup_func);
    210 
     214       
    211215        /*
    212216         * The setup function was performed, it is time to run
     
    214218         */
    215219        test->test_func();
    216 
     220       
    217221        /*
    218222         * Finally, run the tear-down function. We need to clear
     
    221225        execute_teardown_on_failure = 0;
    222226        run_setup_teardown(current_suite->teardown_func);
    223 
     227       
    224228        /*
    225229         * If we got here, it means everything went well with
    226230         * this test.
    227231         */
    228         if (report_test_result) {
     232        if (report_test_result)
    229233                pcut_report_test_done(current_test, TEST_OUTCOME_PASS,
    230                         NULL, NULL, NULL);
    231         }
    232 
     234                    NULL, NULL, NULL);
     235       
    233236        return 0;
    234237}
     
    242245 * @return Error status (zero means success).
    243246 */
    244 int pcut_run_test_forked(pcut_item_t *test) {
    245         int rc;
    246 
     247int pcut_run_test_forked(pcut_item_t *test)
     248{
    247249        report_test_result = 0;
    248250        print_test_error = 1;
    249251        leave_means_exit = 1;
    250 
    251         rc = run_test(test);
    252 
     252       
     253        int rc = run_test(test);
     254       
    253255        current_test = NULL;
    254256        current_suite = NULL;
    255 
     257       
    256258        return rc;
    257259}
     
    265267 * @return Error status (zero means success).
    266268 */
    267 int pcut_run_test_single(pcut_item_t *test) {
    268         int rc;
    269 
     269int pcut_run_test_single(pcut_item_t *test)
     270{
    270271        report_test_result = 1;
    271272        print_test_error = 0;
    272273        leave_means_exit = 0;
    273 
    274         rc = run_test(test);
    275 
     274       
     275        int rc = run_test(test);
     276       
    276277        current_test = NULL;
    277278        current_suite = NULL;
    278 
     279       
    279280        return rc;
    280281}
     
    285286 * @return Timeout in seconds.
    286287 */
    287 int pcut_get_test_timeout(pcut_item_t *test) {
     288int pcut_get_test_timeout(pcut_item_t *test)
     289{
    288290        int timeout = PCUT_DEFAULT_TEST_TIMEOUT;
    289291        pcut_extra_t *extras = test->extras;
    290 
    291 
     292       
    292293        while (extras->type != PCUT_EXTRA_LAST) {
    293                 if (extras->type == PCUT_EXTRA_TIMEOUT) {
     294                if (extras->type == PCUT_EXTRA_TIMEOUT)
    294295                        timeout = extras->timeout;
    295                 }
     296               
    296297                extras++;
    297298        }
    298 
     299       
    299300        return timeout;
    300301}
Note: See TracChangeset for help on using the changeset viewer.