Changeset 9b20126 in mainline for uspace/lib/pcut/src


Ignore:
Timestamp:
2014-09-19T08:23:01Z (11 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c85a57f
Parents:
15d0046
Message:

Update PCUT to newest version

Location:
uspace/lib/pcut/src
Files:
1 added
13 edited

Legend:

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

    r15d0046 r9b20126  
    3535 */
    3636
     37/** We need _BSD_SOURCE because of vsnprintf() when compiling under C89. */
     38#define _BSD_SOURCE
     39
    3740#include "internal.h"
    3841#include <setjmp.h>
     
    5255static int message_buffer_index = 0;
    5356
    54 /** Announce that assertion failed.
    55  *
    56  * @warning This function may not return.
    57  *
    58  * @param fmt printf-style formatting string.
    59  *
    60  */
    61 void pcut_failed_assertion_fmt(const char *fmt, ...) {
     57void pcut_failed_assertion_fmt(const char *filename, int line, const char *fmt, ...) {
     58        va_list args;
    6259        char *current_buffer = message_buffer[message_buffer_index];
     60        size_t offset = 0;
    6361        message_buffer_index = (message_buffer_index + 1) % MESSAGE_BUFFER_COUNT;
    6462
    65         va_list args;
    66         va_start(args, fmt);
    67         vsnprintf(current_buffer, MAX_MESSAGE_LENGTH, fmt, args);
    68         va_end(args);
     63        snprintf(current_buffer, MAX_MESSAGE_LENGTH, "%s:%d: ", filename, line);
     64        offset = pcut_str_size(current_buffer);
     65
     66        if (offset + 1 < MAX_MESSAGE_LENGTH) {
     67                va_start(args, fmt);
     68                vsnprintf(current_buffer + offset, MAX_MESSAGE_LENGTH - offset, fmt, args);
     69                va_end(args);
     70        }
    6971
    7072        pcut_failed_assertion(current_buffer);
  • uspace/lib/pcut/src/internal.h

    r15d0046 r9b20126  
    3737#include <stdlib.h>
    3838
     39
     40/** @def PCUT_DEBUG(msg, ...)
     41 * Debug printing.
     42 *
     43 * By default, this macro does nothing. Define PCUT_DEBUG_BUILD to
     44 * actually print the messages to the console.
     45 *
     46 * @param msg Printf-like formatting message.
     47 * @param ... Extra arguments for printf.
     48 */
     49#ifdef PCUT_DEBUG_BUILD
     50#include <stdio.h>
     51#define PCUT_DEBUG_INTERNAL(msg, ...) \
     52        fprintf(stderr, "[PCUT %s:%d]: " msg "%s", __FILE__, __LINE__, __VA_ARGS__)
     53#define PCUT_DEBUG(...) \
     54        PCUT_DEBUG_INTERNAL( \
     55                PCUT_VARG_GET_FIRST(__VA_ARGS__, this_arg_is_ignored), \
     56                PCUT_VARG_SKIP_FIRST(__VA_ARGS__, "\n") \
     57        )
     58#else
     59#define PCUT_DEBUG(...) (void)0
     60#endif
     61
     62
    3963/** Mark a variable as unused. */
    4064#define PCUT_UNUSED(x) ((void)x)
     
    6387/** Test outcome: test failed unexpectedly. */
    6488#define TEST_OUTCOME_ERROR 3
     89
     90
     91/*
     92 * Use sprintf_s in Windows but only with Microsoft compiler.
     93 * Namely, let MinGW use snprintf.
     94 */
     95#if (defined(__WIN64) || defined(__WIN32) || defined(_WIN32)) && defined(_MSC_VER)
     96#define snprintf sprintf_s
     97#endif
    6598
    6699extern int pcut_run_mode;
     
    92125        /** Initialize the reporting, given all tests. */
    93126        void (*init)(pcut_item_t *);
     127        /** Finalize the reporting. */
     128        void (*done)(void);
    94129        /** Test suite just started. */
    95130        void (*suite_start)(pcut_item_t *);
     
    101136        void (*test_done)(pcut_item_t *, int, const char *, const char *,
    102137                const char *);
    103         /** Finalize the reporting. */
    104         void (*done)(void);
    105138};
    106139
     
    120153/* OS-dependent functions. */
    121154
     155/** Hook to execute before test starts.
     156 *
     157 * Useful for OS-specific preparations prior to launching the actual
     158 * test code (i. e. sandboxing the process more etc.).
     159 *
     160 * This function is not run by the launcher process that only
     161 * starts other tests in separate processes.
     162 *
     163 * @param test The test that is about to be executed.
     164 */
     165void pcut_hook_before_test(pcut_item_t *test);
     166
    122167/** Tell whether two strings start with the same prefix.
    123168 *
  • uspace/lib/pcut/src/list.c

    r15d0046 r9b20126  
    8282 */
    8383static void inline_nested_lists(pcut_item_t *nested) {
     84        pcut_item_t *first;
     85
    8486        if (nested->kind != PCUT_KIND_NESTED) {
    8587                return;
    8688        }
    8789
    88         if (nested->nested.last == NULL) {
     90        if (nested->nested == NULL) {
    8991                nested->kind = PCUT_KIND_SKIP;
    9092                return;
    9193        }
    9294
    93         pcut_item_t *first = pcut_fix_list_get_real_head(nested->nested.last);
    94         nested->nested.last->next = nested->next;
     95        first = pcut_fix_list_get_real_head(nested->nested);
     96        nested->nested->next = nested->next;
    9597        if (nested->next != NULL) {
    96                 nested->next->previous = nested->nested.last;
     98                nested->next->previous = nested->nested;
    9799        }
    98100        nested->next = first;
     
    107109 */
    108110static void set_ids(pcut_item_t *first) {
     111        int id = 1;
     112        pcut_item_t *it;
     113
    109114        assert(first != NULL);
    110         int id = 1;
     115
    111116        if (first->kind == PCUT_KIND_SKIP) {
    112117                first = pcut_get_real_next(first);
    113118        }
    114         for (pcut_item_t *it = first; it != NULL; it = pcut_get_real_next(it)) {
     119
     120        for (it = first; it != NULL; it = pcut_get_real_next(it)) {
    115121                it->id = id;
    116122                id++;
     
    126132 */
    127133static void detect_skipped_tests(pcut_item_t *first) {
     134        pcut_item_t *it;
     135
    128136        assert(first != NULL);
    129137        if (first->kind == PCUT_KIND_SKIP) {
    130138                first = pcut_get_real_next(first);
    131139        }
    132         for (pcut_item_t *it = first; it != NULL; it = pcut_get_real_next(it)) {
     140
     141        for (it = first; it != NULL; it = pcut_get_real_next(it)) {
     142                pcut_extra_t *extras;
     143
    133144                if (it->kind != PCUT_KIND_TEST) {
    134145                        continue;
    135146                }
    136                 pcut_extra_t *extras = it->test.extras;
     147
     148                extras = it->extras;
    137149                while (extras->type != PCUT_EXTRA_LAST) {
    138150                        if (extras->type == PCUT_EXTRA_SKIP) {
     
    156168 */
    157169pcut_item_t *pcut_fix_list_get_real_head(pcut_item_t *last) {
     170        pcut_item_t *next, *it;
     171
    158172        last->next = NULL;
    159173
    160174        inline_nested_lists(last);
    161175
    162         pcut_item_t *next = last;
    163 
    164         pcut_item_t *it = last->previous;
     176        next = last;
     177        it = last->previous;
    165178        while (it != NULL) {
    166179                it->next = next;
  • uspace/lib/pcut/src/main.c

    r15d0046 r9b20126  
    4141int pcut_run_mode = PCUT_RUN_MODE_FORKING;
    4242
     43/** Empty list to bypass special handling for NULL. */
     44static pcut_main_extra_t empty_main_extra[] = {
     45        PCUT_MAIN_EXTRA_SET_LAST
     46};
     47
     48/** Helper for iteration over main extras. */
     49#define FOR_EACH_MAIN_EXTRA(extras, it) \
     50        for (it = extras; it->type != PCUT_MAIN_EXTRA_LAST; it++)
    4351
    4452/** Checks whether the argument is an option followed by a number.
     
    5462                return 0;
    5563        }
    56         int val = pcut_str_to_int(arg + opt_len);
    57         *value = val;
     64        *value = pcut_str_to_int(arg + opt_len);
    5865        return 1;
    5966}
     
    8592 */
    8693static void run_suite(pcut_item_t *suite, pcut_item_t **last, const char *prog_path) {
     94        int is_first_test = 1;
     95        int total_count = 0;
     96
    8797        pcut_item_t *it = pcut_get_real_next(suite);
    8898        if ((it == NULL) || (it->kind == PCUT_KIND_TESTSUITE)) {
     
    90100        }
    91101
    92         int is_first_test = 1;
    93         int total_count = 0;
    94 
    95102        for (; it != NULL; it = pcut_get_real_next(it)) {
    96103                if (it->kind == PCUT_KIND_TESTSUITE) {
     
    135142static void set_setup_teardown_callbacks(pcut_item_t *first) {
    136143        pcut_item_t *active_suite = NULL;
    137         for (pcut_item_t *it = first; it != NULL; it = pcut_get_real_next(it)) {
     144        pcut_item_t *it;
     145        for (it = first; it != NULL; it = pcut_get_real_next(it)) {
    138146                if (it->kind == PCUT_KIND_TESTSUITE) {
    139147                        active_suite = it;
    140148                } else if (it->kind == PCUT_KIND_SETUP) {
    141149                        if (active_suite != NULL) {
    142                                 active_suite->suite.setup = it->setup.func;
     150                                active_suite->setup_func = it->setup_func;
    143151                        }
    144152                        it->kind = PCUT_KIND_SKIP;
    145153                } else if (it->kind == PCUT_KIND_TEARDOWN) {
    146154                        if (active_suite != NULL) {
    147                                 active_suite->suite.teardown = it->setup.func;
     155                                active_suite->teardown_func = it->teardown_func;
    148156                        }
    149157                        it->kind = PCUT_KIND_SKIP;
     
    166174int pcut_main(pcut_item_t *last, int argc, char *argv[]) {
    167175        pcut_item_t *items = pcut_fix_list_get_real_head(last);
     176        pcut_item_t *it;
     177        pcut_main_extra_t *main_extras = last->main_extras;
     178        pcut_main_extra_t *main_extras_it;
    168179
    169180        int run_only_suite = -1;
    170181        int run_only_test = -1;
    171182
     183        if (main_extras == NULL) {
     184                main_extras = empty_main_extra;
     185        }
     186
    172187        pcut_report_register_handler(&pcut_report_tap);
     188
     189        FOR_EACH_MAIN_EXTRA(main_extras, main_extras_it) {
     190                if (main_extras_it->type == PCUT_MAIN_EXTRA_REPORT_XML) {
     191                        pcut_report_register_handler(&pcut_report_xml);
     192                }
     193                if (main_extras_it->type == PCUT_MAIN_EXTRA_PREINIT_HOOK) {
     194                        main_extras_it->preinit_hook(&argc, &argv);
     195                }
     196        }
    173197
    174198        if (argc > 1) {
     
    195219        set_setup_teardown_callbacks(items);
    196220
     221        FOR_EACH_MAIN_EXTRA(main_extras, main_extras_it) {
     222                if (main_extras_it->type == PCUT_MAIN_EXTRA_INIT_HOOK) {
     223                        main_extras_it->init_hook();
     224                }
     225        }
     226
    197227        PCUT_DEBUG("run_only_suite = %d   run_only_test = %d", run_only_suite, run_only_test);
    198228
     
    218248
    219249        if (run_only_test > 0) {
     250                int rc;
    220251                pcut_item_t *test = pcut_find_by_id(items, run_only_test);
    221252                if (test == NULL) {
     
    228259                }
    229260
    230                 int rc;
    231261                if (pcut_run_mode == PCUT_RUN_MODE_SINGLE) {
    232262                        rc = pcut_run_test_single(test);
     
    241271        pcut_report_init(items);
    242272
    243         pcut_item_t *it = items;
     273        it = items;
    244274        while (it != NULL) {
    245275                if (it->kind == PCUT_KIND_TESTSUITE) {
  • uspace/lib/pcut/src/os/generic.c

    r15d0046 r9b20126  
    3333
    3434#include <stdlib.h>
     35#include <stdio.h>
    3536#include <sys/types.h>
    3637#include <errno.h>
     
    5051/* Format the command to launch a test according to OS we are running on. */
    5152
    52 #if defined(__WIN64) || defined(__WIN32)
     53#if defined(__WIN64) || defined(__WIN32) || defined(_WIN32)
    5354#include <process.h>
    5455
     
    108109 */
    109110void pcut_run_test_forking(const char *self_path, pcut_item_t *test) {
     111        int rc;
     112        FILE *tempfile;
     113        char tempfile_name[PCUT_TEMP_FILENAME_BUFFER_SIZE];
     114        char command[PCUT_COMMAND_LINE_BUFFER_SIZE];
     115
    110116        before_test_start(test);
    111117
    112         char tempfile_name[PCUT_TEMP_FILENAME_BUFFER_SIZE];
    113118        FORMAT_TEMP_FILENAME(tempfile_name, PCUT_TEMP_FILENAME_BUFFER_SIZE - 1);
    114 
    115         char command[PCUT_COMMAND_LINE_BUFFER_SIZE];
    116119        FORMAT_COMMAND(command, PCUT_COMMAND_LINE_BUFFER_SIZE - 1,
    117120                self_path, (test)->id, tempfile_name);
     121       
     122        PCUT_DEBUG("Will execute <%s> (temp file <%s>) with system().",
     123                command, tempfile_name);
    118124
    119         int rc = system(command);
     125        rc = system(command);
     126
     127        PCUT_DEBUG("system() returned 0x%04X", rc);
     128
    120129        rc = convert_wait_status_to_outcome(rc);
    121130
    122         FILE *tempfile = fopen(tempfile_name, "rb");
     131        tempfile = fopen(tempfile_name, "rb");
    123132        if (tempfile == NULL) {
    124133                pcut_report_test_done(test, TEST_OUTCOME_ERROR, "Failed to open temporary file.", NULL, NULL);
     
    133142}
    134143
     144void pcut_hook_before_test(pcut_item_t *test) {
     145        PCUT_UNUSED(test);
     146
     147        /* Do nothing. */
     148}
     149
  • uspace/lib/pcut/src/os/helenos.c

    r15d0046 r9b20126  
    185185        int status = TEST_OUTCOME_PASS;
    186186
    187         int rc = task_spawnvf(&test_task_id, self_path, arguments, files);
     187        task_wait_t test_task_wait;
     188        int rc = task_spawnvf(&test_task_id, &test_task_wait, self_path, arguments, files);
    188189        if (rc != EOK) {
    189190                status = TEST_OUTCOME_ERROR;
     
    203204        task_exit_t task_exit;
    204205        int task_retval;
    205         rc = task_wait(test_task_id, &task_exit, &task_retval);
     206        rc = task_wait(&test_task_wait, &task_exit, &task_retval);
    206207        if (rc != EOK) {
    207208                status = TEST_OUTCOME_ERROR;
     
    227228        pcut_report_test_done_unparsed(test, status, extra_output_buffer, OUTPUT_BUFFER_SIZE);
    228229}
     230
     231void pcut_hook_before_test(pcut_item_t *test) {
     232        PCUT_UNUSED(test);
     233
     234        /* Do nothing. */
     235}
  • uspace/lib/pcut/src/os/unix.c

    r15d0046 r9b20126  
    3232 */
    3333
    34 /** We need _POSX_SOURCE because of kill(). */
     34/** We need _POSIX_SOURCE because of kill(). */
    3535#define _POSIX_SOURCE
     36/** We need _BSD_SOURCE because of snprintf() when compiling under C89. */
     37#define _BSD_SOURCE
    3638#include <stdlib.h>
    3739#include <unistd.h>
     
    137139 */
    138140void pcut_run_test_forking(const char *self_path, pcut_item_t *test) {
     141        int link_stdout[2], link_stderr[2];
     142        int rc, status;
     143        size_t stderr_size;
     144
    139145        PCUT_UNUSED(self_path);
    140146
    141147        before_test_start(test);
    142148
    143         int link_stdout[2], link_stderr[2];
    144 
    145         int rc = pipe(link_stdout);
     149
     150        rc = pipe(link_stdout);
    146151        if (rc == -1) {
    147152                snprintf(error_message_buffer, OUTPUT_BUFFER_SIZE - 1,
     
    184189        alarm(pcut_get_test_timeout(test));
    185190
    186         size_t stderr_size = read_all(link_stderr[0], extra_output_buffer, OUTPUT_BUFFER_SIZE - 1);
     191        stderr_size = read_all(link_stderr[0], extra_output_buffer, OUTPUT_BUFFER_SIZE - 1);
    187192        read_all(link_stdout[0], extra_output_buffer, OUTPUT_BUFFER_SIZE - 1 - stderr_size);
    188193
    189         int status;
    190194        wait(&status);
    191195        alarm(0);
     
    204208        pcut_report_test_done_unparsed(test, rc, extra_output_buffer, OUTPUT_BUFFER_SIZE);
    205209}
     210
     211void pcut_hook_before_test(pcut_item_t *test) {
     212        PCUT_UNUSED(test);
     213
     214        /* Do nothing. */
     215}
     216
  • uspace/lib/pcut/src/preproc.c

    r15d0046 r9b20126  
    9191}
    9292
    93 int main() {
     93int main(int argc, char *argv[]) {
    9494        FILE *input = stdin;
    9595        FILE *output = stdout;
     
    9898        identifier_t last_identifier;
    9999
     100        /* Unused parameters. */
     101        (void) argc;
     102        (void) argv;
     103
    100104        while (1) {
     105                int current_char_denotes_identifier;
     106
    101107                int current_char = fgetc(input);
    102108                if (current_char == EOF) {
     
    104110                }
    105111
    106                 int current_char_denotes_identifier = is_identifier_char(current_char, last_char_was_identifier);
     112                current_char_denotes_identifier = is_identifier_char(current_char, last_char_was_identifier);
    107113                if (current_char_denotes_identifier) {
    108114                        if (!last_char_was_identifier) {
  • uspace/lib/pcut/src/print.c

    r15d0046 r9b20126  
    4848                switch (it->kind) {
    4949                case PCUT_KIND_TEST:
    50                         printf("TEST %s (%p)\n", it->test.name, it->test.func);
     50                        printf("TEST %s\n", it->name);
    5151                        break;
    5252                case PCUT_KIND_TESTSUITE:
    53                         printf("SUITE %s\n", it->suite.name);
     53                        printf("SUITE %s\n", it->name);
    5454                        break;
    5555                case PCUT_KIND_SKIP:
     
    7272 */
    7373void pcut_print_tests(pcut_item_t *first) {
    74         for (pcut_item_t *it = pcut_get_real(first); it != NULL; it = pcut_get_real_next(it)) {
     74        pcut_item_t *it;
     75        for (it = pcut_get_real(first); it != NULL; it = pcut_get_real_next(it)) {
    7576                switch (it->kind) {
    7677                case PCUT_KIND_TESTSUITE:
    77                         printf("  Suite `%s' [%d]\n", it->suite.name, it->id);
     78                        printf("  Suite `%s' [%d]\n", it->name, it->id);
    7879                        break;
    7980                case PCUT_KIND_TEST:
    80                         printf("    Test `%s' [%d]\n", it->test.name, it->id);
     81                        printf("    Test `%s' [%d]\n", it->name, it->id);
    8182                        break;
    8283                default:
  • uspace/lib/pcut/src/report/report.c

    r15d0046 r9b20126  
    4444 *
    4545 * @param op Operation to be called on the pcut_report_ops_t.
     46 * @param ... Arguments to the operation.
    4647 */
    4748#define REPORT_CALL(op, ...) \
    4849        if ((report_ops != NULL) && (report_ops->op != NULL)) report_ops->op(__VA_ARGS__)
     50
     51/** Call a report function if it is available.
     52 *
     53 * @param op Operation to be called on the pcut_report_ops_t.
     54 */
     55#define REPORT_CALL_NO_ARGS(op) \
     56                if ((report_ops != NULL) && (report_ops->op != NULL)) report_ops->op()
    4957
    5058/** Print error message.
     
    94102        /* Ensure that we do not read past the full_output. */
    95103        if (full_output[full_output_size - 1] != 0) {
    96                 // FIXME: can this happen?
     104                /* FIXME: can this happen? */
    97105                return;
    98106        }
    99107
    100108        while (1) {
     109                size_t message_length;
     110
    101111                /* First of all, count number of zero bytes before the text. */
    102112                size_t cont_zeros_count = 0;
     
    111121
    112122                /* Determine the length of the text after the zeros. */
    113                 size_t message_length = pcut_str_size(full_output);
     123                message_length = pcut_str_size(full_output);
    114124
    115125                if (cont_zeros_count < 2) {
    116126                        /* Okay, standard I/O. */
    117127                        if (message_length > stdio_buffer_size) {
    118                                 // TODO: handle gracefully
     128                                /* TODO: handle gracefully */
    119129                                return;
    120130                        }
     
    125135                        /* Error message. */
    126136                        if (message_length > error_buffer_size) {
    127                                 // TODO: handle gracefully
     137                                /* TODO: handle gracefully */
    128138                                return;
    129139                        }
     
    213223 *
    214224 */
    215 void pcut_report_done() {
    216         REPORT_CALL(done);
    217 }
    218 
     225void pcut_report_done(void) {
     226        REPORT_CALL_NO_ARGS(done);
     227}
     228
  • uspace/lib/pcut/src/report/tap.c

    r15d0046 r9b20126  
    6767        failed_tests_in_suite = 0;
    6868
    69         printf("#> Starting suite %s.\n", suite->suite.name);
     69        printf("#> Starting suite %s.\n", suite->name);
    7070}
    7171
     
    7676static void tap_suite_done(pcut_item_t *suite) {
    7777        printf("#> Finished suite %s (failed %d of %d).\n",
    78                         suite->suite.name, failed_tests_in_suite, tests_in_suite);
     78                        suite->name, failed_tests_in_suite, tests_in_suite);
    7979}
    8080
     
    9898 */
    9999static void print_by_lines(const char *message, const char *prefix) {
     100        char *next_line_start;
    100101        if ((message == NULL) || (message[0] == 0)) {
    101102                return;
    102103        }
    103         char *next_line_start = pcut_str_find_char(message, '\n');
     104        next_line_start = pcut_str_find_char(message, '\n');
    104105        while (next_line_start != NULL) {
    105106                next_line_start[0] = 0;
     
    124125                const char *error_message, const char *teardown_error_message,
    125126                const char *extra_output) {
    126         const char *test_name = test->test.name;
     127        const char *test_name = test->name;
     128        const char *status_str = NULL;
     129        const char *fail_error_str = NULL;
    127130
    128131        if (outcome != TEST_OUTCOME_PASS) {
     
    130133        }
    131134
    132         const char *status_str = NULL;
    133         const char *fail_error_str = NULL;
    134135        switch (outcome) {
    135136        case TEST_OUTCOME_PASS:
     
    158159
    159160/** Report testing done. */
    160 static void tap_done() {
     161static void tap_done(void) {
    161162}
    162163
    163164
    164165pcut_report_ops_t pcut_report_tap = {
    165         .init = tap_init,
    166         .done = tap_done,
    167         .suite_start = tap_suite_start,
    168         .suite_done = tap_suite_done,
    169         .test_start = tap_test_start,
    170         .test_done = tap_test_done
     166        tap_init, tap_done,
     167        tap_suite_start, tap_suite_done,
     168        tap_test_start, tap_test_done
    171169};
  • uspace/lib/pcut/src/report/xml.c

    r15d0046 r9b20126  
    5353 */
    5454static void xml_init(pcut_item_t *all_items) {
    55         printf("<?xml version=\"1.0\"?>\n");
    56 
    5755        int tests_total = pcut_count_tests(all_items);
    5856        test_counter = 0;
    5957
     58        printf("<?xml version=\"1.0\"?>\n");
    6059        printf("<report tests-total=\"%d\">\n", tests_total);
    6160}
     
    6968        failed_tests_in_suite = 0;
    7069
    71         printf("\t<suite name=\"%s\">\n", suite->suite.name);
     70        printf("\t<suite name=\"%s\">\n", suite->name);
    7271}
    7372
     
    7776 */
    7877static void xml_suite_done(pcut_item_t *suite) {
    79         printf("\t</suite><!-- %s: %d / %d -->\n", suite->suite.name,
     78        printf("\t</suite><!-- %s: %d / %d -->\n", suite->name,
    8079                failed_tests_in_suite, tests_in_suite);
    8180}
     
    10099 */
    101100static void print_by_lines(const char *message, const char *element_name) {
     101        char *next_line_start;
     102
    102103        if ((message == NULL) || (message[0] == 0)) {
    103104                return;
     
    106107        printf("\t\t\t<%s><![CDATA[", element_name);
    107108
    108         char *next_line_start = pcut_str_find_char(message, '\n');
     109        next_line_start = pcut_str_find_char(message, '\n');
    109110        while (next_line_start != NULL) {
    110111                next_line_start[0] = 0;
     
    131132                const char *error_message, const char *teardown_error_message,
    132133                const char *extra_output) {
    133         const char *test_name = test->test.name;
     134        const char *test_name = test->name;
     135        const char *status_str = NULL;
    134136
    135137        if (outcome != TEST_OUTCOME_PASS) {
     
    137139        }
    138140
    139         const char *status_str = NULL;
    140141        switch (outcome) {
    141142        case TEST_OUTCOME_PASS:
     
    165166
    166167/** Report testing done. */
    167 static void xml_done() {
     168static void xml_done(void) {
    168169        printf("</report>\n");
    169170}
     
    171172
    172173pcut_report_ops_t pcut_report_xml = {
    173         .init = xml_init,
    174         .done = xml_done,
    175         .suite_start = xml_suite_start,
    176         .suite_done = xml_suite_done,
    177         .test_start = xml_test_start,
    178         .test_done = xml_test_done
     174        xml_init, xml_done,
     175        xml_suite_start, xml_suite_done,
     176        xml_test_start, xml_test_done
    179177};
  • uspace/lib/pcut/src/run.c

    r15d0046 r9b20126  
    7070
    7171/** A NULL-like suite. */
    72 static pcut_item_t default_suite = {
    73         .kind = PCUT_KIND_TESTSUITE,
    74         .id = -1,
    75         .previous = NULL,
    76         .next = NULL,
    77         .suite = {
    78                 .name = "Default",
    79                 .setup = NULL,
    80                 .teardown = NULL
    81         }
    82 };
     72static pcut_item_t default_suite;
     73static int default_suite_initialized = 0;
     74
     75static void init_default_suite_when_needed() {
     76        if (default_suite_initialized) {
     77                return;
     78        }
     79        default_suite.id = -1;
     80        default_suite.kind = PCUT_KIND_TESTSUITE;
     81        default_suite.previous = NULL;
     82        default_suite.next = NULL;
     83        default_suite.name = "Default";
     84        default_suite.setup_func = NULL;
     85        default_suite.teardown_func = NULL;
     86}
    8387
    8488/** Find the suite given test belongs to.
     
    9498                it = it->previous;
    9599        }
     100        init_default_suite_when_needed();
    96101        return &default_suite;
    97102}
     
    115120 */
    116121static void leave_test(int outcome) {
     122        PCUT_DEBUG("leave_test(outcome=%d), will_exit=%s", outcome,
     123                leave_means_exit ? "yes" : "no");
    117124        if (leave_means_exit) {
    118125                exit(outcome);
     
    145152                execute_teardown_on_failure = 0;
    146153                prev_message = message;
    147                 run_setup_teardown(current_suite->suite.teardown);
     154                run_setup_teardown(current_suite->teardown_func);
    148155
    149156                /* Tear-down was okay. */
     
    189196        current_test = test;
    190197
     198        pcut_hook_before_test(test);
     199
    191200        /*
    192201         * If anything goes wrong, execute the tear-down function
     
    198207         * Run the set-up function.
    199208         */
    200         run_setup_teardown(current_suite->suite.setup);
     209        run_setup_teardown(current_suite->setup_func);
    201210
    202211        /*
     
    204213         * the actual test.
    205214         */
    206         test->test.func();
     215        test->test_func();
    207216
    208217        /*
     
    211220         */
    212221        execute_teardown_on_failure = 0;
    213         run_setup_teardown(current_suite->suite.teardown);
     222        run_setup_teardown(current_suite->teardown_func);
    214223
    215224        /*
     
    234243 */
    235244int pcut_run_test_forked(pcut_item_t *test) {
     245        int rc;
     246
    236247        report_test_result = 0;
    237248        print_test_error = 1;
    238249        leave_means_exit = 1;
    239250
    240         int rc = run_test(test);
     251        rc = run_test(test);
    241252
    242253        current_test = NULL;
     
    255266 */
    256267int pcut_run_test_single(pcut_item_t *test) {
     268        int rc;
     269
    257270        report_test_result = 1;
    258271        print_test_error = 0;
    259272        leave_means_exit = 0;
    260273
    261         int rc = run_test(test);
     274        rc = run_test(test);
    262275
    263276        current_test = NULL;
     
    273286 */
    274287int pcut_get_test_timeout(pcut_item_t *test) {
    275         PCUT_UNUSED(test);
    276 
    277288        int timeout = PCUT_DEFAULT_TEST_TIMEOUT;
    278 
    279         pcut_extra_t *extras = test->test.extras;
     289        pcut_extra_t *extras = test->extras;
     290
     291
    280292        while (extras->type != PCUT_EXTRA_LAST) {
    281293                if (extras->type == PCUT_EXTRA_TIMEOUT) {
Note: See TracChangeset for help on using the changeset viewer.