source: mainline/uspace/lib/pcut/src/internal.h@ 9b20126

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 9b20126 was 9b20126, checked in by Vojtech Horky <vojtechhorky@…>, 11 years ago

Update PCUT to newest version

  • Property mode set to 100644
File size: 6.2 KB
Line 
1/*
2 * Copyright (c) 2012-2013 Vojtech Horky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @file
30 * Common definitions internally used in PCUT.
31 */
32
33#ifndef PCUT_INTERNAL_H_GUARD
34#define PCUT_INTERNAL_H_GUARD
35
36#include <pcut/pcut.h>
37#include <stdlib.h>
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
63/** Mark a variable as unused. */
64#define PCUT_UNUSED(x) ((void)x)
65
66/** Forking mode for test execution.
67 *
68 * In this mode, each test is run in a separate process.
69 * This ensures that even SIGSEGV does not stop the framework itself.
70 */
71#define PCUT_RUN_MODE_FORKING 1
72
73/** Single-process mode for test execution.
74 *
75 * This mode is used when new process is launched when in forking-mode or
76 * this mode can be used if we are sure that no test would fail
77 * fatally (that is causing an unexpected program exit).
78 */
79#define PCUT_RUN_MODE_SINGLE 2
80
81/** Test outcome: test passed. */
82#define TEST_OUTCOME_PASS 1
83
84/** Test outcome: test failed. */
85#define TEST_OUTCOME_FAIL 2
86
87/** Test outcome: test failed unexpectedly. */
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
98
99extern int pcut_run_mode;
100
101
102pcut_item_t *pcut_fix_list_get_real_head(pcut_item_t *last);
103int pcut_count_tests(pcut_item_t *it);
104void pcut_print_items(pcut_item_t *first);
105
106pcut_item_t *pcut_get_real_next(pcut_item_t *item);
107pcut_item_t *pcut_get_real(pcut_item_t *item);
108void pcut_print_tests(pcut_item_t *first);
109int pcut_is_arg_with_number(const char *arg, const char *opt, int *value);
110
111void pcut_run_test_forking(const char *self_path, pcut_item_t *test);
112int pcut_run_test_forked(pcut_item_t *test);
113int pcut_run_test_single(pcut_item_t *test);
114
115int pcut_get_test_timeout(pcut_item_t *test);
116
117void pcut_failed_assertion(const char *message);
118void pcut_print_fail_message(const char *msg);
119
120/** Reporting callbacks structure. */
121typedef struct pcut_report_ops pcut_report_ops_t;
122
123/** @copydoc pcut_report_ops_t */
124struct pcut_report_ops {
125 /** Initialize the reporting, given all tests. */
126 void (*init)(pcut_item_t *);
127 /** Finalize the reporting. */
128 void (*done)(void);
129 /** Test suite just started. */
130 void (*suite_start)(pcut_item_t *);
131 /** Test suite completed. */
132 void (*suite_done)(pcut_item_t *);
133 /** Test is about to start. */
134 void (*test_start)(pcut_item_t *);
135 /** Test completed. */
136 void (*test_done)(pcut_item_t *, int, const char *, const char *,
137 const char *);
138};
139
140void pcut_report_register_handler(pcut_report_ops_t *ops);
141
142void pcut_report_init(pcut_item_t *all_items);
143void pcut_report_suite_start(pcut_item_t *suite);
144void pcut_report_suite_done(pcut_item_t *suite);
145void pcut_report_test_start(pcut_item_t *test);
146void pcut_report_test_done(pcut_item_t *test, int outcome,
147 const char *error_message, const char *teardown_error_message,
148 const char *extra_output);
149void pcut_report_test_done_unparsed(pcut_item_t *test, int outcome,
150 const char *unparsed_output, size_t unparsed_output_size);
151void pcut_report_done(void);
152
153/* OS-dependent functions. */
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 */
165void pcut_hook_before_test(pcut_item_t *test);
166
167/** Tell whether two strings start with the same prefix.
168 *
169 * @param a First string.
170 * @param b Second string.
171 * @param len Length of common prefix.
172 * @return Whether first @p len characters of @p a are the same as in @p b.
173 */
174int pcut_str_start_equals(const char *a, const char *b, int len);
175
176/** Get size of string in bytes.
177 *
178 * @param s String in question.
179 * @return Size of @p s in bytes.
180 */
181int pcut_str_size(const char *s);
182
183/** Convert string to integer.
184 *
185 * @param s String with integer.
186 * @return Converted integer.
187 */
188int pcut_str_to_int(const char *s);
189
190/** Find character in a string.
191 *
192 * @param haystack Where to look for the @p needle.
193 * @param needle Character to find.
194 * @return String starting with @p needle.
195 * @retval NULL there is no @p needle in @p haystack.
196 */
197char *pcut_str_find_char(const char *haystack, const char needle);
198
199
200#endif
Note: See TracBrowser for help on using the repository browser.