Changeset 9b20126 in mainline
- Timestamp:
- 2014-09-19T08:23:01Z (10 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c85a57f
- Parents:
- 15d0046
- Location:
- uspace/lib/pcut
- Files:
-
- 11 added
- 21 edited
- 6 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/pcut/Makefile
r15d0046 r9b20126 4 4 5 5 USPACE_PREFIX = ../.. 6 PCUT_TEST_PREFIX = test-libpcut- 7 8 EXTRA_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) 6 26 7 27 include helenos.mak … … 9 29 include $(USPACE_PREFIX)/Makefile.common 10 30 31 include helenos.test.mak 32 33 test-libpcut-%: $(OUTPUT) 34 $(LD) -n $(LFLAGS) -T $(LINKER_SCRIPT) -o $@ $^ $(OUTPUT) $(BASE_LIBS) 35 -
uspace/lib/pcut/include/pcut/asserts.h
r15d0046 r9b20126 39 39 #include <errno.h> 40 40 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 41 48 /** @cond devel */ 42 49 … … 46 53 * (if registered). 47 54 * 55 * @param filename File where the assertion occurred. 56 * @param line Line where the assertion occurred. 48 57 * @param fmt Printf-like format string. 49 58 * @param ... Extra arguments. 50 59 */ 51 void pcut_failed_assertion_fmt(const char *f mt, ...);60 void pcut_failed_assertion_fmt(const char *filename, int line, const char *fmt, ...); 52 61 53 62 /** OS-agnostic string comparison. … … 70 79 void pcut_str_error(int error, char *buffer, int size); 71 80 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 72 94 /** @endcond */ 73 95 … … 77 99 * abort (tear-down function of the test suite is run when available). 78 100 * 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__, "") 84 105 85 106 … … 115 136 */ 116 137 #define PCUT_ASSERT_EQUALS(expected, actual) \ 117 118 119 120 121 138 do {\ 139 if (!((expected) == (actual))) { \ 140 PCUT_ASSERTION_FAILED("Expected <"#expected "> but got <" #actual ">"); \ 141 } \ 142 } while (0) 122 143 123 144 /** Asserts that given pointer is NULL. -
uspace/lib/pcut/include/pcut/datadef.h
r15d0046 r9b20126 39 39 /** @cond devel */ 40 40 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 41 50 enum { 42 51 PCUT_KIND_SKIP, … … 54 63 }; 55 64 65 enum { 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 56 72 /** Generic wrapper for test cases, test suites etc. */ 57 73 typedef struct pcut_item pcut_item_t; … … 59 75 /** Extra information about a test. */ 60 76 typedef struct pcut_extra pcut_extra_t; 77 78 /** Extra information for the main() function. */ 79 typedef struct pcut_main_extra pcut_main_extra_t; 61 80 62 81 /** Test method type. */ … … 73 92 */ 74 93 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 */ 99 struct 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 ***); 79 109 }; 80 110 … … 89 119 int id; 90 120 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. */ 95 122 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; 118 143 }; 119 120 #ifdef PCUT_DEBUG_BUILD121 #define PCUT_DEBUG(msg, ...) \122 printf("[PCUT]: Debug: " msg "\n", ##__VA_ARGS__)123 #else124 125 /** Debug printing.126 *127 * By default, this macro does nothing. Define PCUT_DEBUG_BUILD to128 * 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)0134 #endif135 144 136 145 /** @endcond */ -
uspace/lib/pcut/include/pcut/tests.h
r15d0046 r9b20126 37 37 #define PCUT_TESTS_H_GUARD 38 38 39 #include <pcut/helper.h> 39 40 #include <pcut/datadef.h> 40 41 … … 81 82 /** @cond devel */ 82 83 83 /** Join the two arguments on preprocessor level (inner call). */84 #define PCUT_JOIN_IMPL(a, b) a##b85 86 /** Join the two arguments on preprocessor level. */87 #define PCUT_JOIN(a, b) PCUT_JOIN_IMPL(a, b)88 89 84 /** Produce identifier name for an item with given number. 90 85 * … … 132 127 */ 133 128 #define PCUT_ADD_ITEM(number, itemkind, ...) \ 134 135 .previous =&PCUT_ITEM_NAME_PREV(number), \136 .next =NULL, \137 .id =-1, \138 .kind =itemkind, \139 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 } 141 136 142 137 /** @endcond */ … … 156 151 */ 157 152 #define PCUT_TEST_SET_TIMEOUT(time_out) \ 158 { .type = PCUT_EXTRA_TIMEOUT, .timeout =(time_out) }153 { PCUT_EXTRA_TIMEOUT, (time_out) } 159 154 160 155 /** Skip current test. … … 163 158 */ 164 159 #define PCUT_TEST_SKIP \ 165 { .type = PCUT_EXTRA_SKIP}160 { PCUT_EXTRA_SKIP, 0 } 166 161 167 162 … … 169 164 170 165 /** 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 } 172 167 173 168 /** Define a new test with given name and given item number. … … 177 172 * @param ... Extra test properties. 178 173 */ 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) 193 189 194 190 /** @endcond */ … … 196 192 /** Define a new test with given name. 197 193 * 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 ) 203 201 204 202 … … 221 219 */ 222 220 #define PCUT_TEST_SUITE_WITH_NUMBER(suitename, number) \ 223 224 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 ) 231 229 232 230 /** Define a set-up function for a test suite. … … 237 235 */ 238 236 #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) 245 245 246 246 /** Define a tear-down function for a test suite. … … 251 251 */ 252 252 #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) 259 261 260 262 /** @endcond */ … … 328 330 PCUT_ITEM_COUNTER_INCREMENT \ 329 331 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 \ 333 337 } 334 338 … … 344 348 extern pcut_item_t pcut_exported_##identifier; \ 345 349 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 \ 347 352 ) 348 353 … … 382 387 PCUT_ITEM_COUNTER_INCREMENT \ 383 388 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 \ 388 394 }; \ 389 395 PCUT_TEST_SUITE(Default); … … 395 401 * @param number Item number. 396 402 */ 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 }; \ 399 408 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 \ 402 417 }; \ 403 418 int main(int argc, char *argv[]) { \ … … 405 420 } 406 421 422 /** Terminate list of extra options for main. */ 423 #define PCUT_MAIN_EXTRA_SET_LAST \ 424 { PCUT_MAIN_EXTRA_LAST, NULL, NULL } 425 407 426 /** @endcond */ 408 427 … … 413 432 /** Insert code to run all the tests. */ 414 433 #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 ) 417 476 418 477 /** -
uspace/lib/pcut/src/assert.c
r15d0046 r9b20126 35 35 */ 36 36 37 /** We need _BSD_SOURCE because of vsnprintf() when compiling under C89. */ 38 #define _BSD_SOURCE 39 37 40 #include "internal.h" 38 41 #include <setjmp.h> … … 52 55 static int message_buffer_index = 0; 53 56 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, ...) { 57 void pcut_failed_assertion_fmt(const char *filename, int line, const char *fmt, ...) { 58 va_list args; 62 59 char *current_buffer = message_buffer[message_buffer_index]; 60 size_t offset = 0; 63 61 message_buffer_index = (message_buffer_index + 1) % MESSAGE_BUFFER_COUNT; 64 62 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 } 69 71 70 72 pcut_failed_assertion(current_buffer); -
uspace/lib/pcut/src/internal.h
r15d0046 r9b20126 37 37 #include <stdlib.h> 38 38 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 39 63 /** Mark a variable as unused. */ 40 64 #define PCUT_UNUSED(x) ((void)x) … … 63 87 /** Test outcome: test failed unexpectedly. */ 64 88 #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 65 98 66 99 extern int pcut_run_mode; … … 92 125 /** Initialize the reporting, given all tests. */ 93 126 void (*init)(pcut_item_t *); 127 /** Finalize the reporting. */ 128 void (*done)(void); 94 129 /** Test suite just started. */ 95 130 void (*suite_start)(pcut_item_t *); … … 101 136 void (*test_done)(pcut_item_t *, int, const char *, const char *, 102 137 const char *); 103 /** Finalize the reporting. */104 void (*done)(void);105 138 }; 106 139 … … 120 153 /* OS-dependent functions. */ 121 154 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 */ 165 void pcut_hook_before_test(pcut_item_t *test); 166 122 167 /** Tell whether two strings start with the same prefix. 123 168 * -
uspace/lib/pcut/src/list.c
r15d0046 r9b20126 82 82 */ 83 83 static void inline_nested_lists(pcut_item_t *nested) { 84 pcut_item_t *first; 85 84 86 if (nested->kind != PCUT_KIND_NESTED) { 85 87 return; 86 88 } 87 89 88 if (nested->nested .last== NULL) {90 if (nested->nested == NULL) { 89 91 nested->kind = PCUT_KIND_SKIP; 90 92 return; 91 93 } 92 94 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; 95 97 if (nested->next != NULL) { 96 nested->next->previous = nested->nested .last;98 nested->next->previous = nested->nested; 97 99 } 98 100 nested->next = first; … … 107 109 */ 108 110 static void set_ids(pcut_item_t *first) { 111 int id = 1; 112 pcut_item_t *it; 113 109 114 assert(first != NULL); 110 int id = 1; 115 111 116 if (first->kind == PCUT_KIND_SKIP) { 112 117 first = pcut_get_real_next(first); 113 118 } 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)) { 115 121 it->id = id; 116 122 id++; … … 126 132 */ 127 133 static void detect_skipped_tests(pcut_item_t *first) { 134 pcut_item_t *it; 135 128 136 assert(first != NULL); 129 137 if (first->kind == PCUT_KIND_SKIP) { 130 138 first = pcut_get_real_next(first); 131 139 } 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 133 144 if (it->kind != PCUT_KIND_TEST) { 134 145 continue; 135 146 } 136 pcut_extra_t *extras = it->test.extras; 147 148 extras = it->extras; 137 149 while (extras->type != PCUT_EXTRA_LAST) { 138 150 if (extras->type == PCUT_EXTRA_SKIP) { … … 156 168 */ 157 169 pcut_item_t *pcut_fix_list_get_real_head(pcut_item_t *last) { 170 pcut_item_t *next, *it; 171 158 172 last->next = NULL; 159 173 160 174 inline_nested_lists(last); 161 175 162 pcut_item_t *next = last; 163 164 pcut_item_t *it = last->previous; 176 next = last; 177 it = last->previous; 165 178 while (it != NULL) { 166 179 it->next = next; -
uspace/lib/pcut/src/main.c
r15d0046 r9b20126 41 41 int pcut_run_mode = PCUT_RUN_MODE_FORKING; 42 42 43 /** Empty list to bypass special handling for NULL. */ 44 static 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++) 43 51 44 52 /** Checks whether the argument is an option followed by a number. … … 54 62 return 0; 55 63 } 56 int val = pcut_str_to_int(arg + opt_len); 57 *value = val; 64 *value = pcut_str_to_int(arg + opt_len); 58 65 return 1; 59 66 } … … 85 92 */ 86 93 static 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 87 97 pcut_item_t *it = pcut_get_real_next(suite); 88 98 if ((it == NULL) || (it->kind == PCUT_KIND_TESTSUITE)) { … … 90 100 } 91 101 92 int is_first_test = 1;93 int total_count = 0;94 95 102 for (; it != NULL; it = pcut_get_real_next(it)) { 96 103 if (it->kind == PCUT_KIND_TESTSUITE) { … … 135 142 static void set_setup_teardown_callbacks(pcut_item_t *first) { 136 143 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)) { 138 146 if (it->kind == PCUT_KIND_TESTSUITE) { 139 147 active_suite = it; 140 148 } else if (it->kind == PCUT_KIND_SETUP) { 141 149 if (active_suite != NULL) { 142 active_suite->s uite.setup = it->setup.func;150 active_suite->setup_func = it->setup_func; 143 151 } 144 152 it->kind = PCUT_KIND_SKIP; 145 153 } else if (it->kind == PCUT_KIND_TEARDOWN) { 146 154 if (active_suite != NULL) { 147 active_suite-> suite.teardown = it->setup.func;155 active_suite->teardown_func = it->teardown_func; 148 156 } 149 157 it->kind = PCUT_KIND_SKIP; … … 166 174 int pcut_main(pcut_item_t *last, int argc, char *argv[]) { 167 175 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; 168 179 169 180 int run_only_suite = -1; 170 181 int run_only_test = -1; 171 182 183 if (main_extras == NULL) { 184 main_extras = empty_main_extra; 185 } 186 172 187 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 } 173 197 174 198 if (argc > 1) { … … 195 219 set_setup_teardown_callbacks(items); 196 220 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 197 227 PCUT_DEBUG("run_only_suite = %d run_only_test = %d", run_only_suite, run_only_test); 198 228 … … 218 248 219 249 if (run_only_test > 0) { 250 int rc; 220 251 pcut_item_t *test = pcut_find_by_id(items, run_only_test); 221 252 if (test == NULL) { … … 228 259 } 229 260 230 int rc;231 261 if (pcut_run_mode == PCUT_RUN_MODE_SINGLE) { 232 262 rc = pcut_run_test_single(test); … … 241 271 pcut_report_init(items); 242 272 243 pcut_item_t *it = items;273 it = items; 244 274 while (it != NULL) { 245 275 if (it->kind == PCUT_KIND_TESTSUITE) { -
uspace/lib/pcut/src/os/generic.c
r15d0046 r9b20126 33 33 34 34 #include <stdlib.h> 35 #include <stdio.h> 35 36 #include <sys/types.h> 36 37 #include <errno.h> … … 50 51 /* Format the command to launch a test according to OS we are running on. */ 51 52 52 #if defined(__WIN64) || defined(__WIN32) 53 #if defined(__WIN64) || defined(__WIN32) || defined(_WIN32) 53 54 #include <process.h> 54 55 … … 108 109 */ 109 110 void 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 110 116 before_test_start(test); 111 117 112 char tempfile_name[PCUT_TEMP_FILENAME_BUFFER_SIZE];113 118 FORMAT_TEMP_FILENAME(tempfile_name, PCUT_TEMP_FILENAME_BUFFER_SIZE - 1); 114 115 char command[PCUT_COMMAND_LINE_BUFFER_SIZE];116 119 FORMAT_COMMAND(command, PCUT_COMMAND_LINE_BUFFER_SIZE - 1, 117 120 self_path, (test)->id, tempfile_name); 121 122 PCUT_DEBUG("Will execute <%s> (temp file <%s>) with system().", 123 command, tempfile_name); 118 124 119 int rc = system(command); 125 rc = system(command); 126 127 PCUT_DEBUG("system() returned 0x%04X", rc); 128 120 129 rc = convert_wait_status_to_outcome(rc); 121 130 122 FILE *tempfile = fopen(tempfile_name, "rb");131 tempfile = fopen(tempfile_name, "rb"); 123 132 if (tempfile == NULL) { 124 133 pcut_report_test_done(test, TEST_OUTCOME_ERROR, "Failed to open temporary file.", NULL, NULL); … … 133 142 } 134 143 144 void 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 185 185 int status = TEST_OUTCOME_PASS; 186 186 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); 188 189 if (rc != EOK) { 189 190 status = TEST_OUTCOME_ERROR; … … 203 204 task_exit_t task_exit; 204 205 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); 206 207 if (rc != EOK) { 207 208 status = TEST_OUTCOME_ERROR; … … 227 228 pcut_report_test_done_unparsed(test, status, extra_output_buffer, OUTPUT_BUFFER_SIZE); 228 229 } 230 231 void 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 32 32 */ 33 33 34 /** We need _POS X_SOURCE because of kill(). */34 /** We need _POSIX_SOURCE because of kill(). */ 35 35 #define _POSIX_SOURCE 36 /** We need _BSD_SOURCE because of snprintf() when compiling under C89. */ 37 #define _BSD_SOURCE 36 38 #include <stdlib.h> 37 39 #include <unistd.h> … … 137 139 */ 138 140 void 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 139 145 PCUT_UNUSED(self_path); 140 146 141 147 before_test_start(test); 142 148 143 int link_stdout[2], link_stderr[2]; 144 145 int rc = pipe(link_stdout); 149 150 rc = pipe(link_stdout); 146 151 if (rc == -1) { 147 152 snprintf(error_message_buffer, OUTPUT_BUFFER_SIZE - 1, … … 184 189 alarm(pcut_get_test_timeout(test)); 185 190 186 s ize_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); 187 192 read_all(link_stdout[0], extra_output_buffer, OUTPUT_BUFFER_SIZE - 1 - stderr_size); 188 193 189 int status;190 194 wait(&status); 191 195 alarm(0); … … 204 208 pcut_report_test_done_unparsed(test, rc, extra_output_buffer, OUTPUT_BUFFER_SIZE); 205 209 } 210 211 void 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 91 91 } 92 92 93 int main( ) {93 int main(int argc, char *argv[]) { 94 94 FILE *input = stdin; 95 95 FILE *output = stdout; … … 98 98 identifier_t last_identifier; 99 99 100 /* Unused parameters. */ 101 (void) argc; 102 (void) argv; 103 100 104 while (1) { 105 int current_char_denotes_identifier; 106 101 107 int current_char = fgetc(input); 102 108 if (current_char == EOF) { … … 104 110 } 105 111 106 intcurrent_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); 107 113 if (current_char_denotes_identifier) { 108 114 if (!last_char_was_identifier) { -
uspace/lib/pcut/src/print.c
r15d0046 r9b20126 48 48 switch (it->kind) { 49 49 case PCUT_KIND_TEST: 50 printf("TEST %s (%p)\n", it->test.name, it->test.func);50 printf("TEST %s\n", it->name); 51 51 break; 52 52 case PCUT_KIND_TESTSUITE: 53 printf("SUITE %s\n", it-> suite.name);53 printf("SUITE %s\n", it->name); 54 54 break; 55 55 case PCUT_KIND_SKIP: … … 72 72 */ 73 73 void 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)) { 75 76 switch (it->kind) { 76 77 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); 78 79 break; 79 80 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); 81 82 break; 82 83 default: -
uspace/lib/pcut/src/report/report.c
r15d0046 r9b20126 44 44 * 45 45 * @param op Operation to be called on the pcut_report_ops_t. 46 * @param ... Arguments to the operation. 46 47 */ 47 48 #define REPORT_CALL(op, ...) \ 48 49 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() 49 57 50 58 /** Print error message. … … 94 102 /* Ensure that we do not read past the full_output. */ 95 103 if (full_output[full_output_size - 1] != 0) { 96 / / FIXME: can this happen?104 /* FIXME: can this happen? */ 97 105 return; 98 106 } 99 107 100 108 while (1) { 109 size_t message_length; 110 101 111 /* First of all, count number of zero bytes before the text. */ 102 112 size_t cont_zeros_count = 0; … … 111 121 112 122 /* Determine the length of the text after the zeros. */ 113 size_tmessage_length = pcut_str_size(full_output);123 message_length = pcut_str_size(full_output); 114 124 115 125 if (cont_zeros_count < 2) { 116 126 /* Okay, standard I/O. */ 117 127 if (message_length > stdio_buffer_size) { 118 / / TODO: handle gracefully128 /* TODO: handle gracefully */ 119 129 return; 120 130 } … … 125 135 /* Error message. */ 126 136 if (message_length > error_buffer_size) { 127 / / TODO: handle gracefully137 /* TODO: handle gracefully */ 128 138 return; 129 139 } … … 213 223 * 214 224 */ 215 void pcut_report_done( ) {216 REPORT_CALL (done);217 } 218 225 void pcut_report_done(void) { 226 REPORT_CALL_NO_ARGS(done); 227 } 228 -
uspace/lib/pcut/src/report/tap.c
r15d0046 r9b20126 67 67 failed_tests_in_suite = 0; 68 68 69 printf("#> Starting suite %s.\n", suite-> suite.name);69 printf("#> Starting suite %s.\n", suite->name); 70 70 } 71 71 … … 76 76 static void tap_suite_done(pcut_item_t *suite) { 77 77 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); 79 79 } 80 80 … … 98 98 */ 99 99 static void print_by_lines(const char *message, const char *prefix) { 100 char *next_line_start; 100 101 if ((message == NULL) || (message[0] == 0)) { 101 102 return; 102 103 } 103 char *next_line_start = pcut_str_find_char(message, '\n');104 next_line_start = pcut_str_find_char(message, '\n'); 104 105 while (next_line_start != NULL) { 105 106 next_line_start[0] = 0; … … 124 125 const char *error_message, const char *teardown_error_message, 125 126 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; 127 130 128 131 if (outcome != TEST_OUTCOME_PASS) { … … 130 133 } 131 134 132 const char *status_str = NULL;133 const char *fail_error_str = NULL;134 135 switch (outcome) { 135 136 case TEST_OUTCOME_PASS: … … 158 159 159 160 /** Report testing done. */ 160 static void tap_done( ) {161 static void tap_done(void) { 161 162 } 162 163 163 164 164 165 pcut_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 171 169 }; -
uspace/lib/pcut/src/report/xml.c
r15d0046 r9b20126 53 53 */ 54 54 static void xml_init(pcut_item_t *all_items) { 55 printf("<?xml version=\"1.0\"?>\n");56 57 55 int tests_total = pcut_count_tests(all_items); 58 56 test_counter = 0; 59 57 58 printf("<?xml version=\"1.0\"?>\n"); 60 59 printf("<report tests-total=\"%d\">\n", tests_total); 61 60 } … … 69 68 failed_tests_in_suite = 0; 70 69 71 printf("\t<suite name=\"%s\">\n", suite-> suite.name);70 printf("\t<suite name=\"%s\">\n", suite->name); 72 71 } 73 72 … … 77 76 */ 78 77 static 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, 80 79 failed_tests_in_suite, tests_in_suite); 81 80 } … … 100 99 */ 101 100 static void print_by_lines(const char *message, const char *element_name) { 101 char *next_line_start; 102 102 103 if ((message == NULL) || (message[0] == 0)) { 103 104 return; … … 106 107 printf("\t\t\t<%s><![CDATA[", element_name); 107 108 108 char *next_line_start = pcut_str_find_char(message, '\n');109 next_line_start = pcut_str_find_char(message, '\n'); 109 110 while (next_line_start != NULL) { 110 111 next_line_start[0] = 0; … … 131 132 const char *error_message, const char *teardown_error_message, 132 133 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; 134 136 135 137 if (outcome != TEST_OUTCOME_PASS) { … … 137 139 } 138 140 139 const char *status_str = NULL;140 141 switch (outcome) { 141 142 case TEST_OUTCOME_PASS: … … 165 166 166 167 /** Report testing done. */ 167 static void xml_done( ) {168 static void xml_done(void) { 168 169 printf("</report>\n"); 169 170 } … … 171 172 172 173 pcut_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 179 177 }; -
uspace/lib/pcut/src/run.c
r15d0046 r9b20126 70 70 71 71 /** 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 }; 72 static pcut_item_t default_suite; 73 static int default_suite_initialized = 0; 74 75 static 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 } 83 87 84 88 /** Find the suite given test belongs to. … … 94 98 it = it->previous; 95 99 } 100 init_default_suite_when_needed(); 96 101 return &default_suite; 97 102 } … … 115 120 */ 116 121 static void leave_test(int outcome) { 122 PCUT_DEBUG("leave_test(outcome=%d), will_exit=%s", outcome, 123 leave_means_exit ? "yes" : "no"); 117 124 if (leave_means_exit) { 118 125 exit(outcome); … … 145 152 execute_teardown_on_failure = 0; 146 153 prev_message = message; 147 run_setup_teardown(current_suite-> suite.teardown);154 run_setup_teardown(current_suite->teardown_func); 148 155 149 156 /* Tear-down was okay. */ … … 189 196 current_test = test; 190 197 198 pcut_hook_before_test(test); 199 191 200 /* 192 201 * If anything goes wrong, execute the tear-down function … … 198 207 * Run the set-up function. 199 208 */ 200 run_setup_teardown(current_suite->s uite.setup);209 run_setup_teardown(current_suite->setup_func); 201 210 202 211 /* … … 204 213 * the actual test. 205 214 */ 206 test->test .func();215 test->test_func(); 207 216 208 217 /* … … 211 220 */ 212 221 execute_teardown_on_failure = 0; 213 run_setup_teardown(current_suite-> suite.teardown);222 run_setup_teardown(current_suite->teardown_func); 214 223 215 224 /* … … 234 243 */ 235 244 int pcut_run_test_forked(pcut_item_t *test) { 245 int rc; 246 236 247 report_test_result = 0; 237 248 print_test_error = 1; 238 249 leave_means_exit = 1; 239 250 240 intrc = run_test(test);251 rc = run_test(test); 241 252 242 253 current_test = NULL; … … 255 266 */ 256 267 int pcut_run_test_single(pcut_item_t *test) { 268 int rc; 269 257 270 report_test_result = 1; 258 271 print_test_error = 0; 259 272 leave_means_exit = 0; 260 273 261 intrc = run_test(test);274 rc = run_test(test); 262 275 263 276 current_test = NULL; … … 273 286 */ 274 287 int pcut_get_test_timeout(pcut_item_t *test) { 275 PCUT_UNUSED(test);276 277 288 int timeout = PCUT_DEFAULT_TEST_TIMEOUT; 278 279 pcut_extra_t *extras = test->test.extras; 289 pcut_extra_t *extras = test->extras; 290 291 280 292 while (extras->type != PCUT_EXTRA_LAST) { 281 293 if (extras->type == PCUT_EXTRA_TIMEOUT) { -
uspace/lib/pcut/tests/abort.c
r15d0046 r9b20126 28 28 29 29 #include <pcut/pcut.h> 30 #include "tested.h"30 #include <stdlib.h> 31 31 32 32 PCUT_INIT 33 33 34 34 PCUT_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(); 40 36 } 41 37 -
uspace/lib/pcut/tests/beforeafter.c
r15d0046 r9b20126 27 27 */ 28 28 29 #define _BSD_SOURCE 30 29 31 #include <pcut/pcut.h> 30 32 #include <stdlib.h> 31 33 #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 32 42 33 43 PCUT_INIT … … 36 46 #define BUFFER_SIZE 512 37 47 38 PCUT_TEST_SUITE(suite_with_setup_and_teardown) 48 PCUT_TEST_SUITE(suite_with_setup_and_teardown); 39 49 40 50 PCUT_TEST_BEFORE { … … 48 58 } 49 59 50 PCUT_TEST( snprintf) {60 PCUT_TEST(test_with_setup_and_teardown) { 51 61 snprintf(buffer, BUFFER_SIZE - 1, "%d-%s", 56, "abcd"); 52 62 PCUT_ASSERT_STR_EQUALS("56-abcd", buffer); 53 63 } 54 64 55 PCUT_TEST_SUITE(another_without_setup) 65 PCUT_TEST_SUITE(another_without_setup); 56 66 57 PCUT_TEST( whatever) {67 PCUT_TEST(test_without_any_setup_or_teardown) { 58 68 PCUT_ASSERT_NULL(buffer); 59 69 } -
uspace/lib/pcut/tests/beforeafter.expected
r15d0046 r9b20126 1 1 1..2 2 2 #> Starting suite suite_with_setup_and_teardown. 3 ok 1 snprintf3 ok 1 test_with_setup_and_teardown 4 4 #> Finished suite suite_with_setup_and_teardown (failed 0 of 1). 5 5 #> Starting suite another_without_setup. 6 ok 2 whatever6 ok 2 test_without_any_setup_or_teardown 7 7 #> Finished suite another_without_setup (failed 0 of 1). -
uspace/lib/pcut/tests/errno.expected
r15d0046 r9b20126 2 2 #> Starting suite Default. 3 3 not 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 ***** (*****) 5 5 not 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 ***** (*****) 7 7 #> Finished suite Default (failed 2 of 2). -
uspace/lib/pcut/tests/teardown.c
r15d0046 r9b20126 50 50 51 51 52 PCUT_TEST_SUITE(with_failing_teardown) 52 PCUT_TEST_SUITE(with_failing_teardown); 53 53 54 54 PCUT_TEST_AFTER { -
uspace/lib/pcut/tests/teardownaborts.c
r15d0046 r9b20126 29 29 #include <stdio.h> 30 30 #include <pcut/pcut.h> 31 #include "tested.h"31 #include <stdlib.h> 32 32 33 33 PCUT_INIT 34 34 35 35 PCUT_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(); 41 37 } 42 38 -
uspace/lib/pcut/tests/teardownaborts.expected
r15d0046 r9b20126 2 2 #> Starting suite Default. 3 3 not ok 1 print_and_fail aborted 4 # error: nullteardown.c:45: Pointer <NULL> ought not to be NULL4 # error: teardownaborts.c:41: Pointer <NULL> ought not to be NULL 5 5 # stdio: Tear-down will cause null pointer access... 6 6 #> Finished suite Default (failed 1 of 1). -
uspace/lib/pcut/tests/timeout.c
r15d0046 r9b20126 28 28 29 29 #include <pcut/pcut.h> 30 31 #ifdef __unix 30 32 #include <unistd.h> 33 #endif 34 #if defined(__WIN64) || defined(__WIN32) || defined(_WIN32) 35 #include <windows.h> 36 #endif 37 31 38 #include <stdio.h> 32 39 #include "tested.h" 40 41 static 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 } 33 49 34 50 PCUT_INIT … … 36 52 PCUT_TEST(shall_time_out) { 37 53 printf("Text before sleeping.\n"); 38 sleep(PCUT_DEFAULT_TEST_TIMEOUT * 5);54 my_sleep(PCUT_DEFAULT_TEST_TIMEOUT * 5); 39 55 printf("Text after the sleep.\n"); 40 56 } … … 43 59 PCUT_TEST_SET_TIMEOUT(PCUT_DEFAULT_TEST_TIMEOUT * 3)) { 44 60 printf("Text before sleeping.\n"); 45 sleep(PCUT_DEFAULT_TEST_TIMEOUT * 2);61 my_sleep(PCUT_DEFAULT_TEST_TIMEOUT * 2); 46 62 printf("Text after the sleep.\n"); 47 63 } -
uspace/lib/pcut/update-from-master.sh
r15d0046 r9b20126 51 51 $RUN rm -f CMakeLists.txt *.cmake run_test.sh 52 52 53 cat >Makefile <<'EOF_MAKEFILE '53 cat >Makefile <<'EOF_MAKEFILE_HEAD' 54 54 # 55 55 # This file was generated by call to update-from-master.sh … … 57 57 58 58 USPACE_PREFIX = ../.. 59 PCUT_TEST_PREFIX = test-libpcut- 60 61 EXTRA_OUTPUT = \ 62 EOF_MAKEFILE_HEAD 63 64 for testfile in tests/*.expected; do 65 testname=`basename "$testfile" .expected` 66 echo " \$(PCUT_TEST_PREFIX)${testname}\$(PCUT_TEST_SUFFIX) \\" 67 done | sed '$s/\\$//' >>Makefile 68 69 cat >>Makefile <<'EOF_MAKEFILE_TAIL' 59 70 60 71 include helenos.mak … … 62 73 include $(USPACE_PREFIX)/Makefile.common 63 74 64 EOF_MAKEFILE 75 include helenos.test.mak 76 77 test-libpcut-%: $(OUTPUT) 78 $(LD) -n $(LFLAGS) -T $(LINKER_SCRIPT) -o $@ $^ $(OUTPUT) $(BASE_LIBS) 79 80 EOF_MAKEFILE_TAIL
Note:
See TracChangeset
for help on using the changeset viewer.