Changeset 9b20126 in mainline


Ignore:
Timestamp:
2014-09-19T08:23:01Z (10 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
Files:
11 added
21 edited
6 moved

Legend:

Unmodified
Added
Removed
  • uspace/lib/pcut/Makefile

    r15d0046 r9b20126  
    44
    55USPACE_PREFIX = ../..
     6PCUT_TEST_PREFIX = test-libpcut-
     7
     8EXTRA_OUTPUT = \
     9        $(PCUT_TEST_PREFIX)abort$(PCUT_TEST_SUFFIX) \
     10        $(PCUT_TEST_PREFIX)asserts$(PCUT_TEST_SUFFIX) \
     11        $(PCUT_TEST_PREFIX)beforeafter$(PCUT_TEST_SUFFIX) \
     12        $(PCUT_TEST_PREFIX)errno$(PCUT_TEST_SUFFIX) \
     13        $(PCUT_TEST_PREFIX)inithook$(PCUT_TEST_SUFFIX) \
     14        $(PCUT_TEST_PREFIX)manytests$(PCUT_TEST_SUFFIX) \
     15        $(PCUT_TEST_PREFIX)multisuite$(PCUT_TEST_SUFFIX) \
     16        $(PCUT_TEST_PREFIX)preinithook$(PCUT_TEST_SUFFIX) \
     17        $(PCUT_TEST_PREFIX)printing$(PCUT_TEST_SUFFIX) \
     18        $(PCUT_TEST_PREFIX)simple$(PCUT_TEST_SUFFIX) \
     19        $(PCUT_TEST_PREFIX)skip$(PCUT_TEST_SUFFIX) \
     20        $(PCUT_TEST_PREFIX)suites$(PCUT_TEST_SUFFIX) \
     21        $(PCUT_TEST_PREFIX)teardownaborts$(PCUT_TEST_SUFFIX) \
     22        $(PCUT_TEST_PREFIX)teardown$(PCUT_TEST_SUFFIX) \
     23        $(PCUT_TEST_PREFIX)testlist$(PCUT_TEST_SUFFIX) \
     24        $(PCUT_TEST_PREFIX)timeout$(PCUT_TEST_SUFFIX) \
     25        $(PCUT_TEST_PREFIX)xmlreport$(PCUT_TEST_SUFFIX)
    626
    727include helenos.mak
     
    929include $(USPACE_PREFIX)/Makefile.common
    1030
     31include helenos.test.mak
     32
     33test-libpcut-%: $(OUTPUT)
     34        $(LD) -n $(LFLAGS) -T $(LINKER_SCRIPT) -o $@ $^ $(OUTPUT) $(BASE_LIBS)
     35
  • uspace/lib/pcut/include/pcut/asserts.h

    r15d0046 r9b20126  
    3939#include <errno.h>
    4040
     41/** @def PCUT_CURRENT_FILENAME
     42 * Overwrite contents of __FILE__ when printing assertion errors.
     43 */
     44#ifndef PCUT_CURRENT_FILENAME
     45#define PCUT_CURRENT_FILENAME __FILE__
     46#endif
     47
    4148/** @cond devel */
    4249
     
    4653 * (if registered).
    4754 *
     55 * @param filename File where the assertion occurred.
     56 * @param line Line where the assertion occurred.
    4857 * @param fmt Printf-like format string.
    4958 * @param ... Extra arguments.
    5059 */
    51 void pcut_failed_assertion_fmt(const char *fmt, ...);
     60void pcut_failed_assertion_fmt(const char *filename, int line, const char *fmt, ...);
    5261
    5362/** OS-agnostic string comparison.
     
    7079void pcut_str_error(int error, char *buffer, int size);
    7180
     81/** Raise assertion error (internal version).
     82 *
     83 * We expect to be always called from PCUT_ASSERTION_FAILED() where
     84 * the last argument is empty string to conform to strict ISO C99
     85 * ("ISO C99 requires rest arguments to be used").
     86 *
     87 * @param fmt Printf-like format string.
     88 * @param ... Extra arguments.
     89 */
     90#define PCUT_ASSERTION_FAILED_INTERNAL(fmt, ...) \
     91        pcut_failed_assertion_fmt(PCUT_CURRENT_FILENAME, __LINE__, fmt, __VA_ARGS__)
     92
     93
    7294/** @endcond */
    7395
     
    7799 * abort (tear-down function of the test suite is run when available).
    78100 *
    79  * @param fmt Printf-like format string.
    80  * @param ... Extra arguments.
    81  */
    82 #define PCUT_ASSERTION_FAILED(fmt, ...) \
    83         pcut_failed_assertion_fmt(__FILE__ ":%d: " fmt, __LINE__, ##__VA_ARGS__)
     101 * @param ... Printf-like arguments.
     102 */
     103#define PCUT_ASSERTION_FAILED(...) \
     104        PCUT_ASSERTION_FAILED_INTERNAL(__VA_ARGS__, "")
    84105
    85106
     
    115136 */
    116137#define PCUT_ASSERT_EQUALS(expected, actual) \
    117                 do {\
    118                         if (!((expected) == (actual))) { \
    119                                 PCUT_ASSERTION_FAILED("Expected <"#expected "> but got <" #actual ">"); \
    120                         } \
    121                 } while (0)
     138        do {\
     139                if (!((expected) == (actual))) { \
     140                        PCUT_ASSERTION_FAILED("Expected <"#expected "> but got <" #actual ">"); \
     141                } \
     142        } while (0)
    122143
    123144/** Asserts that given pointer is NULL.
  • uspace/lib/pcut/include/pcut/datadef.h

    r15d0046 r9b20126  
    3939/** @cond devel */
    4040
     41#if defined(__GNUC__) || defined(__clang__)
     42#define PCUT_CC_UNUSED_VARIABLE(name, initializer) \
     43        name __attribute__((unused)) = initializer
     44#else
     45#define PCUT_CC_UNUSED_VARIABLE(name, initializer) \
     46        name = initializer
     47#endif
     48
     49
    4150enum {
    4251        PCUT_KIND_SKIP,
     
    5463};
    5564
     65enum {
     66        PCUT_MAIN_EXTRA_PREINIT_HOOK,
     67        PCUT_MAIN_EXTRA_INIT_HOOK,
     68        PCUT_MAIN_EXTRA_REPORT_XML,
     69        PCUT_MAIN_EXTRA_LAST
     70};
     71
    5672/** Generic wrapper for test cases, test suites etc. */
    5773typedef struct pcut_item pcut_item_t;
     
    5975/** Extra information about a test. */
    6076typedef struct pcut_extra pcut_extra_t;
     77
     78/** Extra information for the main() function. */
     79typedef struct pcut_main_extra pcut_main_extra_t;
    6180
    6281/** Test method type. */
     
    7392         */
    7493        int type;
    75         union {
    76                 /** Test-specific time-out in seconds. */
    77                 int timeout;
    78         };
     94        /** Test-specific time-out in seconds. */
     95        int timeout;
     96};
     97
     98/** @copydoc pcut_main_extra_t */
     99struct pcut_main_extra {
     100        /** Discriminator for the union.
     101         *
     102         * Use PCUT_MAIN_EXTRA_* to determine which field of the union is used.
     103         */
     104        int type;
     105        /** Callback once PCUT initializes itself. */
     106        void (*init_hook)(void);
     107        /** Callback even before command-line arguments are processed. */
     108        void (*preinit_hook)(int *, char ***);
    79109};
    80110
     
    89119        int id;
    90120
    91         /** Discriminator for the union.
    92          *
    93          * Use PCUT_KIND_* to determine which field of the union is used.
    94          */
     121        /** Discriminator for this item. */
    95122        int kind;
    96         union {
    97                 struct {
    98                         const char *name;
    99                         pcut_setup_func_t setup;
    100                         pcut_setup_func_t teardown;
    101                 } suite;
    102                 struct {
    103                         const char *name;
    104                         pcut_test_func_t func;
    105                         pcut_extra_t *extras;
    106                 } test;
    107                 /* setup is used for both set-up and tear-down */
    108                 struct {
    109                         pcut_setup_func_t func;
    110                 } setup;
    111                 struct {
    112                         pcut_item_t *last;
    113                 } nested;
    114                 struct {
    115                         int dummy;
    116                 } meta;
    117         };
     123
     124        /** Name of this item. */
     125        const char *name;
     126
     127        /** Test-case function. */
     128        pcut_test_func_t test_func;
     129
     130        /** Set-up function of a suite. */
     131        pcut_setup_func_t setup_func;
     132        /** Tear-down function of a suite. */
     133        pcut_setup_func_t teardown_func;
     134
     135        /** Extra attributes. */
     136        pcut_extra_t *extras;
     137
     138        /** Extra attributes for main() function. */
     139        pcut_main_extra_t *main_extras;
     140
     141        /** Nested lists. */
     142        pcut_item_t *nested;
    118143};
    119 
    120 #ifdef PCUT_DEBUG_BUILD
    121 #define PCUT_DEBUG(msg, ...) \
    122         printf("[PCUT]: Debug: " msg "\n", ##__VA_ARGS__)
    123 #else
    124 
    125 /** Debug printing.
    126  *
    127  * By default, this macro does nothing. Define PCUT_DEBUG_BUILD to
    128  * actually print the messages to the console.
    129  *
    130  * @param msg Printf-like formatting message.
    131  * @param ... Extra arguments for printf.
    132  */
    133 #define PCUT_DEBUG(msg, ...) (void)0
    134 #endif
    135144
    136145/** @endcond */
  • uspace/lib/pcut/include/pcut/tests.h

    r15d0046 r9b20126  
    3737#define PCUT_TESTS_H_GUARD
    3838
     39#include <pcut/helper.h>
    3940#include <pcut/datadef.h>
    4041
     
    8182/** @cond devel */
    8283
    83 /** Join the two arguments on preprocessor level (inner call). */
    84 #define PCUT_JOIN_IMPL(a, b) a##b
    85 
    86 /** Join the two arguments on preprocessor level. */
    87 #define PCUT_JOIN(a, b) PCUT_JOIN_IMPL(a, b)
    88 
    8984/** Produce identifier name for an item with given number.
    9085 *
     
    132127 */
    133128#define PCUT_ADD_ITEM(number, itemkind, ...) \
    134                 static pcut_item_t PCUT_ITEM_NAME(number) = { \
    135                                 .previous = &PCUT_ITEM_NAME_PREV(number), \
    136                                 .next = NULL, \
    137                                 .id = -1, \
    138                                 .kind = itemkind, \
    139                                 __VA_ARGS__ \
    140                 };
     129        static pcut_item_t PCUT_ITEM_NAME(number) = { \
     130                &PCUT_ITEM_NAME_PREV(number), \
     131                NULL, \
     132                -1, \
     133                itemkind, \
     134                __VA_ARGS__ \
     135        }
    141136
    142137/** @endcond */
     
    156151 */
    157152#define PCUT_TEST_SET_TIMEOUT(time_out) \
    158         { .type = PCUT_EXTRA_TIMEOUT, .timeout = (time_out) }
     153        { PCUT_EXTRA_TIMEOUT, (time_out) }
    159154
    160155/** Skip current test.
     
    163158 */
    164159#define PCUT_TEST_SKIP \
    165         { .type = PCUT_EXTRA_SKIP }
     160        { PCUT_EXTRA_SKIP, 0 }
    166161
    167162
     
    169164
    170165/** Terminate list of extra test options. */
    171 #define PCUT_TEST_EXTRA_LAST { .type = PCUT_EXTRA_LAST }
     166#define PCUT_TEST_EXTRA_LAST { PCUT_EXTRA_LAST, 0 }
    172167
    173168/** Define a new test with given name and given item number.
     
    177172 * @param ... Extra test properties.
    178173 */
    179 #define PCUT_TEST_WITH_NUMBER(testname, number, ...) \
    180                 PCUT_ITEM_COUNTER_INCREMENT \
    181                 static pcut_extra_t PCUT_ITEM_EXTRAS_NAME(number)[] = { \
    182                                 __VA_ARGS__ \
    183                 }; \
    184                 static void PCUT_JOIN(test_, testname)(void); \
    185                 PCUT_ADD_ITEM(number, PCUT_KIND_TEST, \
    186                                 .test = { \
    187                                         .name = #testname, \
    188                                         .func = PCUT_JOIN(test_, testname), \
    189                                         .extras = PCUT_ITEM_EXTRAS_NAME(number), \
    190                                 } \
    191                 ) \
    192                 void PCUT_JOIN(test_, testname)(void)
     174#define PCUT_TEST_WITH_NUMBER(number, testname, ...) \
     175        PCUT_ITEM_COUNTER_INCREMENT \
     176        static pcut_extra_t PCUT_ITEM_EXTRAS_NAME(number)[] = { \
     177                __VA_ARGS__ \
     178        }; \
     179        static int PCUT_CC_UNUSED_VARIABLE(PCUT_JOIN(testname, 0_test_name_missing_or_duplicated), 0); \
     180        static void PCUT_JOIN(test_, testname)(void); \
     181        PCUT_ADD_ITEM(number, PCUT_KIND_TEST, \
     182                PCUT_QUOTE(testname), \
     183                PCUT_JOIN(test_, testname), \
     184                NULL, NULL, \
     185                PCUT_ITEM_EXTRAS_NAME(number), \
     186                NULL, NULL \
     187        ); \
     188        void PCUT_JOIN(test_, testname)(void)
    193189
    194190/** @endcond */
     
    196192/** Define a new test with given name.
    197193 *
    198  * @param name A valid C identifier name (not quoted).
    199  * @param ... Extra test properties.
    200  */
    201 #define PCUT_TEST(name, ...) \
    202         PCUT_TEST_WITH_NUMBER(name, PCUT_ITEM_COUNTER, ##__VA_ARGS__, PCUT_TEST_EXTRA_LAST)
     194 * @param ... Test name (C identifier) followed by extra test properties.
     195 */
     196#define PCUT_TEST(...) \
     197        PCUT_TEST_WITH_NUMBER(PCUT_ITEM_COUNTER, \
     198                PCUT_VARG_GET_FIRST(__VA_ARGS__, this_arg_is_ignored), \
     199                PCUT_VARG_SKIP_FIRST(__VA_ARGS__, PCUT_TEST_EXTRA_LAST) \
     200        )
    203201
    204202
     
    221219 */
    222220#define PCUT_TEST_SUITE_WITH_NUMBER(suitename, number) \
    223                 PCUT_ITEM_COUNTER_INCREMENT \
    224                 PCUT_ADD_ITEM(number, PCUT_KIND_TESTSUITE, \
    225                                 .suite = { \
    226                                         .name = #suitename, \
    227                                         .setup = NULL, \
    228                                         .teardown = NULL \
    229                                 } \
    230                 )
     221        PCUT_ITEM_COUNTER_INCREMENT \
     222        PCUT_ADD_ITEM(number, PCUT_KIND_TESTSUITE, \
     223                #suitename, \
     224                NULL, \
     225                NULL, NULL, \
     226                NULL, NULL, \
     227                NULL \
     228        )
    231229
    232230/** Define a set-up function for a test suite.
     
    237235 */
    238236#define PCUT_TEST_BEFORE_WITH_NUMBER(number) \
    239                 PCUT_ITEM_COUNTER_INCREMENT \
    240                 static void PCUT_ITEM_SETUP_NAME(number)(void); \
    241                 PCUT_ADD_ITEM(number, PCUT_KIND_SETUP, \
    242                                 .setup.func = PCUT_ITEM_SETUP_NAME(number) \
    243                 ) \
    244                 void PCUT_ITEM_SETUP_NAME(number)(void)
     237        PCUT_ITEM_COUNTER_INCREMENT \
     238        static void PCUT_ITEM_SETUP_NAME(number)(void); \
     239        PCUT_ADD_ITEM(number, PCUT_KIND_SETUP, \
     240                "setup", NULL, \
     241                PCUT_ITEM_SETUP_NAME(number), \
     242                NULL, NULL, NULL, NULL \
     243        ); \
     244        void PCUT_ITEM_SETUP_NAME(number)(void)
    245245
    246246/** Define a tear-down function for a test suite.
     
    251251 */
    252252#define PCUT_TEST_AFTER_WITH_NUMBER(number) \
    253                 PCUT_ITEM_COUNTER_INCREMENT \
    254                 static void PCUT_ITEM_SETUP_NAME(number)(void); \
    255                 PCUT_ADD_ITEM(number, PCUT_KIND_TEARDOWN, \
    256                                 .setup.func = PCUT_ITEM_SETUP_NAME(number) \
    257                 ) \
    258                 void PCUT_ITEM_SETUP_NAME(number)(void)
     253        PCUT_ITEM_COUNTER_INCREMENT \
     254        static void PCUT_ITEM_SETUP_NAME(number)(void); \
     255        PCUT_ADD_ITEM(number, PCUT_KIND_TEARDOWN, \
     256                "teardown", NULL, NULL, \
     257                PCUT_ITEM_SETUP_NAME(number), \
     258                NULL, NULL, NULL \
     259        ); \
     260        void PCUT_ITEM_SETUP_NAME(number)(void)
    259261
    260262/** @endcond */
     
    328330        PCUT_ITEM_COUNTER_INCREMENT \
    329331        pcut_item_t pcut_exported_##identifier = { \
    330                 .previous = &PCUT_ITEM_NAME_PREV(number), \
    331                 .next = NULL, \
    332                 .kind = PCUT_KIND_SKIP \
     332                &PCUT_ITEM_NAME_PREV(number), \
     333                NULL, \
     334                -1, \
     335                PCUT_KIND_SKIP, \
     336                "exported_" #identifier, NULL, NULL, NULL, NULL, NULL, NULL \
    333337        }
    334338
     
    344348        extern pcut_item_t pcut_exported_##identifier; \
    345349        PCUT_ADD_ITEM(number, PCUT_KIND_NESTED, \
    346                 .nested.last = &pcut_exported_##identifier \
     350                "import_" #identifier, NULL, NULL, NULL, NULL, NULL, \
     351                &pcut_exported_##identifier \
    347352        )
    348353
     
    382387        PCUT_ITEM_COUNTER_INCREMENT \
    383388        static pcut_item_t PCUT_ITEM_NAME(first_number) = { \
    384                 .previous = NULL, \
    385                 .next = NULL, \
    386                 .id = -1, \
    387                 .kind = PCUT_KIND_SKIP \
     389                NULL, \
     390                NULL, \
     391                -1, \
     392                PCUT_KIND_SKIP, \
     393                "init", NULL, NULL, NULL, NULL, NULL, NULL \
    388394        }; \
    389395        PCUT_TEST_SUITE(Default);
     
    395401 * @param number Item number.
    396402 */
    397 #define PCUT_MAIN_WITH_NUMBER(number) \
    398         PCUT_ITEM_COUNTER_INCREMENT \
     403#define PCUT_MAIN_WITH_NUMBER(number, ...) \
     404        PCUT_ITEM_COUNTER_INCREMENT \
     405        static pcut_main_extra_t pcut_main_extras[] = { \
     406                __VA_ARGS__ \
     407        }; \
    399408        static pcut_item_t pcut_item_last = { \
    400                 .previous = &PCUT_ITEM_NAME_PREV(number), \
    401                 .kind = PCUT_KIND_SKIP \
     409                &PCUT_ITEM_NAME_PREV(number), \
     410                NULL, \
     411                -1, \
     412                PCUT_KIND_SKIP, \
     413                "main", NULL, NULL, NULL, \
     414                NULL, \
     415                pcut_main_extras, \
     416                NULL \
    402417        }; \
    403418        int main(int argc, char *argv[]) { \
     
    405420        }
    406421
     422/** Terminate list of extra options for main. */
     423#define PCUT_MAIN_EXTRA_SET_LAST \
     424        { PCUT_MAIN_EXTRA_LAST, NULL, NULL }
     425
    407426/** @endcond */
    408427
     
    413432/** Insert code to run all the tests. */
    414433#define PCUT_MAIN() \
    415         PCUT_MAIN_WITH_NUMBER(PCUT_ITEM_COUNTER)
    416 
     434        PCUT_MAIN_WITH_NUMBER(PCUT_ITEM_COUNTER, PCUT_MAIN_EXTRA_SET_LAST)
     435
     436
     437/** Set callback for PCUT initialization.
     438 *
     439 * Use from within PCUT_CUSTOM_MAIN().
     440 *
     441 * @warning The callback is called for each test and also for the wrapping
     442 * invocation.
     443 */
     444#define PCUT_MAIN_SET_INIT_HOOK(callback) \
     445        { PCUT_MAIN_EXTRA_INIT_HOOK, callback, NULL }
     446
     447/** Set callback for PCUT pre-initialization.
     448 *
     449 * Use from within PCUT_CUSTOM_MAIN().
     450 * This callback is useful only if you want to manipulate command-line
     451 * arguments.
     452 * You probably will not need this.
     453 *
     454 * @warning The callback is called for each test and also for the wrapping
     455 * invocation.
     456 */
     457#define PCUT_MAIN_SET_PREINIT_HOOK(callback) \
     458        { PCUT_MAIN_EXTRA_PREINIT_HOOK, NULL, callback }
     459
     460
     461/** Set XML report as default.
     462 *
     463 * Use from within PCUT_CUSTOM_MAIN().
     464 *
     465 */
     466#define PCUT_MAIN_SET_XML_REPORT \
     467        { PCUT_MAIN_EXTRA_REPORT_XML, NULL, NULL }
     468
     469
     470/** Insert code to run all tests. */
     471#define PCUT_CUSTOM_MAIN(...) \
     472        PCUT_MAIN_WITH_NUMBER(PCUT_ITEM_COUNTER, \
     473                PCUT_VARG_GET_FIRST(__VA_ARGS__, PCUT_MAIN_EXTRA_SET_LAST), \
     474                PCUT_VARG_SKIP_FIRST(__VA_ARGS__, PCUT_MAIN_EXTRA_SET_LAST) \
     475        )
    417476
    418477/**
  • 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) {
  • uspace/lib/pcut/tests/abort.c

    r15d0046 r9b20126  
    2828
    2929#include <pcut/pcut.h>
    30 #include "tested.h"
     30#include <stdlib.h>
    3131
    3232PCUT_INIT
    3333
    3434PCUT_TEST(access_null_pointer) {
    35         int a = 5;
    36         int *p = &a;
    37         PCUT_ASSERT_INT_EQUALS(5, *p);
    38         p = NULL;
    39         PCUT_ASSERT_INT_EQUALS(5, *p);
     35        abort();
    4036}
    4137
  • uspace/lib/pcut/tests/beforeafter.c

    r15d0046 r9b20126  
    2727 */
    2828
     29#define _BSD_SOURCE
     30
    2931#include <pcut/pcut.h>
    3032#include <stdlib.h>
    3133#include <stdio.h>
     34
     35/*
     36 * Use sprintf_s in Windows but only with Microsoft compiler.
     37 * Namely, let MinGW use snprintf.
     38 */
     39#if (defined(__WIN64) || defined(__WIN32) || defined(_WIN32)) && defined(_MSC_VER)
     40#define snprintf sprintf_s
     41#endif
    3242
    3343PCUT_INIT
     
    3646#define BUFFER_SIZE 512
    3747
    38 PCUT_TEST_SUITE(suite_with_setup_and_teardown)
     48PCUT_TEST_SUITE(suite_with_setup_and_teardown);
    3949
    4050PCUT_TEST_BEFORE {
     
    4858}
    4959
    50 PCUT_TEST(snprintf) {
     60PCUT_TEST(test_with_setup_and_teardown) {
    5161        snprintf(buffer, BUFFER_SIZE - 1, "%d-%s", 56, "abcd");
    5262        PCUT_ASSERT_STR_EQUALS("56-abcd", buffer);
    5363}
    5464
    55 PCUT_TEST_SUITE(another_without_setup)
     65PCUT_TEST_SUITE(another_without_setup);
    5666
    57 PCUT_TEST(whatever) {
     67PCUT_TEST(test_without_any_setup_or_teardown) {
    5868        PCUT_ASSERT_NULL(buffer);
    5969}
  • uspace/lib/pcut/tests/beforeafter.expected

    r15d0046 r9b20126  
    111..2
    22#> Starting suite suite_with_setup_and_teardown.
    3 ok 1 snprintf
     3ok 1 test_with_setup_and_teardown
    44#> Finished suite suite_with_setup_and_teardown (failed 0 of 1).
    55#> Starting suite another_without_setup.
    6 ok 2 whatever
     6ok 2 test_without_any_setup_or_teardown
    77#> Finished suite another_without_setup (failed 0 of 1).
  • uspace/lib/pcut/tests/errno.expected

    r15d0046 r9b20126  
    22#> Starting suite Default.
    33not ok 1 errno_value failed
    4 # error: errno.c:46: Expected error 0 (EOK, Success) but got error 2 (No such file or directory)
     4# error: errno.c:46: Expected error 0 (EOK, *****) but got error ***** (*****)
    55not ok 2 errno_variable failed
    6 # error: errno.c:54: Expected error 0 (EOK, Success) but got error 2 (No such file or directory)
     6# error: errno.c:54: Expected error 0 (EOK, *****) but got error ***** (*****)
    77#> Finished suite Default (failed 2 of 2).
  • uspace/lib/pcut/tests/teardown.c

    r15d0046 r9b20126  
    5050
    5151
    52 PCUT_TEST_SUITE(with_failing_teardown)
     52PCUT_TEST_SUITE(with_failing_teardown);
    5353
    5454PCUT_TEST_AFTER {
  • uspace/lib/pcut/tests/teardownaborts.c

    r15d0046 r9b20126  
    2929#include <stdio.h>
    3030#include <pcut/pcut.h>
    31 #include "tested.h"
     31#include <stdlib.h>
    3232
    3333PCUT_INIT
    3434
    3535PCUT_TEST_AFTER {
    36         int a = 5;
    37         int *p = &a;
    38         PCUT_ASSERT_INT_EQUALS(5, *p);
    39         p = NULL;
    40         PCUT_ASSERT_INT_EQUALS(5, *p);
     36        abort();
    4137}
    4238
  • uspace/lib/pcut/tests/teardownaborts.expected

    r15d0046 r9b20126  
    22#> Starting suite Default.
    33not ok 1 print_and_fail aborted
    4 # error: nullteardown.c:45: Pointer <NULL> ought not to be NULL
     4# error: teardownaborts.c:41: Pointer <NULL> ought not to be NULL
    55# stdio: Tear-down will cause null pointer access...
    66#> Finished suite Default (failed 1 of 1).
  • uspace/lib/pcut/tests/timeout.c

    r15d0046 r9b20126  
    2828
    2929#include <pcut/pcut.h>
     30
     31#ifdef __unix
    3032#include <unistd.h>
     33#endif
     34#if defined(__WIN64) || defined(__WIN32) || defined(_WIN32)
     35#include <windows.h>
     36#endif
     37
    3138#include <stdio.h>
    3239#include "tested.h"
     40
     41static void my_sleep(int sec) {
     42#ifdef __unix
     43        sleep(sec);
     44#endif
     45#if defined(__WIN64) || defined(__WIN32) || defined(_WIN32)
     46        Sleep(1000 * sec);
     47#endif
     48}
    3349
    3450PCUT_INIT
     
    3652PCUT_TEST(shall_time_out) {
    3753        printf("Text before sleeping.\n");
    38         sleep(PCUT_DEFAULT_TEST_TIMEOUT * 5);
     54        my_sleep(PCUT_DEFAULT_TEST_TIMEOUT * 5);
    3955        printf("Text after the sleep.\n");
    4056}
     
    4359                PCUT_TEST_SET_TIMEOUT(PCUT_DEFAULT_TEST_TIMEOUT * 3)) {
    4460        printf("Text before sleeping.\n");
    45         sleep(PCUT_DEFAULT_TEST_TIMEOUT * 2);
     61        my_sleep(PCUT_DEFAULT_TEST_TIMEOUT * 2);
    4662        printf("Text after the sleep.\n");
    4763}
  • uspace/lib/pcut/update-from-master.sh

    r15d0046 r9b20126  
    5151$RUN rm -f CMakeLists.txt *.cmake run_test.sh
    5252
    53 cat >Makefile <<'EOF_MAKEFILE'
     53cat >Makefile <<'EOF_MAKEFILE_HEAD'
    5454#
    5555# This file was generated by call to update-from-master.sh
     
    5757
    5858USPACE_PREFIX = ../..
     59PCUT_TEST_PREFIX = test-libpcut-
     60
     61EXTRA_OUTPUT = \
     62EOF_MAKEFILE_HEAD
     63
     64for testfile in tests/*.expected; do
     65        testname=`basename "$testfile" .expected`
     66        echo "  \$(PCUT_TEST_PREFIX)${testname}\$(PCUT_TEST_SUFFIX) \\"
     67done | sed '$s/\\$//' >>Makefile
     68
     69cat >>Makefile <<'EOF_MAKEFILE_TAIL'
    5970
    6071include helenos.mak
     
    6273include $(USPACE_PREFIX)/Makefile.common
    6374
    64 EOF_MAKEFILE
     75include helenos.test.mak
     76
     77test-libpcut-%: $(OUTPUT)
     78        $(LD) -n $(LFLAGS) -T $(LINKER_SCRIPT) -o $@ $^ $(OUTPUT) $(BASE_LIBS)
     79
     80EOF_MAKEFILE_TAIL
Note: See TracChangeset for help on using the changeset viewer.