Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2007,2014 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 | * IN THE SOFTWARE. |
| 22 | * |
| 23 | * Authors: |
| 24 | * Eric Anholt <eric@anholt.net> |
| 25 | * Daniel Vetter <daniel.vetter@ffwll.ch> |
| 26 | * |
| 27 | */ |
| 28 | |
| 29 | |
| 30 | #ifndef IGT_CORE_H |
| 31 | #define IGT_CORE_H |
| 32 | |
Daniel Vetter | 924115b | 2014-03-22 20:18:51 +0100 | [diff] [blame] | 33 | #include <setjmp.h> |
Daniel Vetter | 6cfcd71 | 2014-03-22 20:07:35 +0100 | [diff] [blame] | 34 | #include <stdbool.h> |
Chris Wilson | dcb39b5 | 2016-03-18 09:04:07 +0000 | [diff] [blame] | 35 | #include <stdint.h> |
Daniel Vetter | 254f19b | 2014-03-22 21:29:01 +0100 | [diff] [blame] | 36 | #include <stdlib.h> |
Joonas Lahtinen | a95033f | 2015-03-31 15:53:17 +0300 | [diff] [blame] | 37 | #include <stdio.h> |
Daniel Vetter | 924115b | 2014-03-22 20:18:51 +0100 | [diff] [blame] | 38 | #include <string.h> |
| 39 | #include <sys/types.h> |
Daniel Vetter | 254f19b | 2014-03-22 21:29:01 +0100 | [diff] [blame] | 40 | #include <stdarg.h> |
Thomas Wood | 80d2c9b | 2014-07-21 15:57:16 +0100 | [diff] [blame] | 41 | #include <getopt.h> |
Daniel Vetter | 6cfcd71 | 2014-03-22 20:07:35 +0100 | [diff] [blame] | 42 | |
Thomas Wood | 0167619 | 2014-12-17 11:37:31 +0000 | [diff] [blame] | 43 | #ifndef IGT_LOG_DOMAIN |
| 44 | #define IGT_LOG_DOMAIN (NULL) |
| 45 | #endif |
| 46 | |
| 47 | |
Thomas Wood | f8b3c70 | 2014-10-10 16:56:20 +0100 | [diff] [blame] | 48 | extern const char* __igt_test_description __attribute__((weak)); |
Thomas Wood | 790f1f8 | 2015-11-09 17:17:24 +0000 | [diff] [blame] | 49 | extern bool __igt_plain_output; |
| 50 | |
Thomas Wood | f8b3c70 | 2014-10-10 16:56:20 +0100 | [diff] [blame] | 51 | |
| 52 | /** |
| 53 | * IGT_TEST_DESCRIPTION: |
| 54 | * @str: description string |
| 55 | * |
| 56 | * Defines a description for a test. This is used as the output for the |
| 57 | * "--help-description" option and is also included in the generated |
| 58 | * documentation. |
| 59 | */ |
| 60 | #define IGT_TEST_DESCRIPTION(str) const char* __igt_test_description = str |
| 61 | |
Thomas Wood | 17eb062 | 2014-05-13 15:22:52 +0100 | [diff] [blame] | 62 | /** |
| 63 | * IGT_EXIT_TIMEOUT: |
| 64 | * |
| 65 | * Exit status indicating a timeout occurred. |
| 66 | */ |
| 67 | #define IGT_EXIT_TIMEOUT 78 |
| 68 | |
| 69 | /** |
| 70 | * IGT_EXIT_SKIP: |
| 71 | * |
| 72 | * Exit status indicating the test was skipped. |
| 73 | */ |
| 74 | #define IGT_EXIT_SKIP 77 |
| 75 | |
| 76 | /** |
| 77 | * IGT_EXIT_SUCCESS |
| 78 | * |
| 79 | * Exit status indicating the test executed successfully. |
| 80 | */ |
| 81 | #define IGT_EXIT_SUCCESS 0 |
| 82 | |
Thomas Wood | 784344e | 2014-07-23 16:29:39 +0100 | [diff] [blame] | 83 | /** |
| 84 | * IGT_EXIT_INVALID |
| 85 | * |
| 86 | * Exit status indicating an invalid option or subtest was specified |
| 87 | */ |
| 88 | #define IGT_EXIT_INVALID 79 |
| 89 | |
Thomas Wood | b47032e | 2015-04-09 09:24:12 +0100 | [diff] [blame] | 90 | /** |
| 91 | * IGT_EXIT_FAILURE |
| 92 | * |
| 93 | * Exit status indicating a test failure |
| 94 | */ |
| 95 | #define IGT_EXIT_FAILURE 99 |
Thomas Wood | 17eb062 | 2014-05-13 15:22:52 +0100 | [diff] [blame] | 96 | |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 97 | bool __igt_fixture(void); |
| 98 | void __igt_fixture_complete(void); |
| 99 | void __igt_fixture_end(void) __attribute__((noreturn)); |
| 100 | /** |
| 101 | * igt_fixture: |
| 102 | * |
| 103 | * Annotate global test fixture code |
| 104 | * |
| 105 | * Testcase with subtests often need to set up a bunch of global state as the |
Thomas Wood | d01ebbd | 2015-06-29 16:47:14 +0100 | [diff] [blame] | 106 | * common test fixture. To avoid such code interfering with the subtest |
| 107 | * enumeration (e.g. when enumerating on systems without an intel gpu) such |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 108 | * blocks should be annotated with igt_fixture. |
| 109 | */ |
Tomeu Vizoso | 3450cba | 2016-04-15 14:00:04 +0200 | [diff] [blame] | 110 | #define igt_fixture for (volatile int igt_tokencat(__tmpint,__LINE__) = 0; \ |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 111 | igt_tokencat(__tmpint,__LINE__) < 1 && \ |
| 112 | __igt_fixture() && \ |
Chris Wilson | 578795f | 2015-05-08 14:35:37 +0100 | [diff] [blame] | 113 | (sigsetjmp(igt_subtest_jmpbuf, 1) == 0); \ |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 114 | igt_tokencat(__tmpint,__LINE__) ++, \ |
| 115 | __igt_fixture_complete()) |
| 116 | |
| 117 | /* subtest infrastructure */ |
| 118 | jmp_buf igt_subtest_jmpbuf; |
Damien Lespiau | fd6846c | 2015-05-14 14:19:01 +0100 | [diff] [blame] | 119 | typedef int (*igt_opt_handler_t)(int opt, int opt_index, void *data); |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 120 | #ifndef __GTK_DOC_IGNORE__ /* gtkdoc wants to document this forward decl */ |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 121 | struct option; |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 122 | #endif |
Thomas Wood | 8fb1978 | 2015-02-18 16:19:59 +0000 | [diff] [blame] | 123 | int igt_subtest_init_parse_opts(int *argc, char **argv, |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 124 | const char *extra_short_opts, |
Ville Syrjälä | 793aff1 | 2015-12-18 19:25:45 +0200 | [diff] [blame] | 125 | const struct option *extra_long_opts, |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 126 | const char *help_str, |
Damien Lespiau | fd6846c | 2015-05-14 14:19:01 +0100 | [diff] [blame] | 127 | igt_opt_handler_t extra_opt_handler, |
| 128 | void *handler_data); |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 129 | |
Thomas Wood | 55cc132 | 2015-02-17 15:10:13 +0000 | [diff] [blame] | 130 | |
| 131 | /** |
| 132 | * igt_subtest_init: |
| 133 | * @argc: argc from the test's main() |
| 134 | * @argv: argv from the test's main() |
| 135 | * |
| 136 | * This initializes the for tests with subtests without the need for additional |
Thomas Wood | d01ebbd | 2015-06-29 16:47:14 +0100 | [diff] [blame] | 137 | * command line options. It is just a simplified version of |
Thomas Wood | 55cc132 | 2015-02-17 15:10:13 +0000 | [diff] [blame] | 138 | * igt_subtest_init_parse_opts(). |
| 139 | * |
| 140 | * If there's not a reason to the contrary it's less error prone to just use an |
| 141 | * #igt_main block instead of stitching the test's main() function together |
| 142 | * manually. |
| 143 | */ |
Damien Lespiau | fd6846c | 2015-05-14 14:19:01 +0100 | [diff] [blame] | 144 | #define igt_subtest_init(argc, argv) \ |
| 145 | igt_subtest_init_parse_opts(&argc, argv, NULL, NULL, NULL, NULL, NULL); |
Thomas Wood | 55cc132 | 2015-02-17 15:10:13 +0000 | [diff] [blame] | 146 | |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 147 | bool __igt_run_subtest(const char *subtest_name); |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 148 | #define __igt_tokencat2(x, y) x ## y |
| 149 | |
| 150 | /** |
| 151 | * igt_tokencat: |
| 152 | * @x: first variable |
| 153 | * @y: second variable |
| 154 | * |
| 155 | * C preprocessor helper to concatenate two variables while properly expanding |
| 156 | * them. |
| 157 | */ |
| 158 | #define igt_tokencat(x, y) __igt_tokencat2(x, y) |
| 159 | |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 160 | /** |
| 161 | * igt_subtest: |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 162 | * @name: name of the subtest |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 163 | * |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 164 | * This is a magic control flow block which denotes a subtest code block. Within |
Thomas Wood | 519f377 | 2014-09-26 14:24:52 +0100 | [diff] [blame] | 165 | * that code block igt_skip|success will only bail out of the subtest. The _f |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 166 | * variant accepts a printf format string, which is useful for constructing |
| 167 | * combinatorial tests. |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 168 | * |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 169 | * This is a simpler version of igt_subtest_f() |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 170 | */ |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 171 | #define igt_subtest(name) for (; __igt_run_subtest((name)) && \ |
Chris Wilson | 578795f | 2015-05-08 14:35:37 +0100 | [diff] [blame] | 172 | (sigsetjmp(igt_subtest_jmpbuf, 1) == 0); \ |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 173 | igt_success()) |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 174 | #define __igt_subtest_f(tmp, format...) \ |
| 175 | for (char tmp [256]; \ |
| 176 | snprintf( tmp , sizeof( tmp ), \ |
| 177 | format), \ |
| 178 | __igt_run_subtest( tmp ) && \ |
Chris Wilson | 578795f | 2015-05-08 14:35:37 +0100 | [diff] [blame] | 179 | (sigsetjmp(igt_subtest_jmpbuf, 1) == 0); \ |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 180 | igt_success()) |
| 181 | |
| 182 | /** |
| 183 | * igt_subtest_f: |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 184 | * @...: format string and optional arguments |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 185 | * |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 186 | * This is a magic control flow block which denotes a subtest code block. Within |
Thomas Wood | 519f377 | 2014-09-26 14:24:52 +0100 | [diff] [blame] | 187 | * that code block igt_skip|success will only bail out of the subtest. The _f |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 188 | * variant accepts a printf format string, which is useful for constructing |
| 189 | * combinatorial tests. |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 190 | * |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 191 | * Like igt_subtest(), but also accepts a printf format string instead of a |
| 192 | * static string. |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 193 | */ |
| 194 | #define igt_subtest_f(f...) \ |
| 195 | __igt_subtest_f(igt_tokencat(__tmpchar, __LINE__), f) |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 196 | |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 197 | const char *igt_subtest_name(void); |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 198 | bool igt_only_list_subtests(void); |
| 199 | |
Daniel Vetter | 72d04b8 | 2016-03-18 21:46:54 +0100 | [diff] [blame] | 200 | void __igt_subtest_group_save(int *); |
| 201 | void __igt_subtest_group_restore(int); |
| 202 | /** |
| 203 | * igt_subtest_group: |
| 204 | * |
| 205 | * Group a set of subtests together with their common setup code |
| 206 | * |
| 207 | * Testcase with subtests often need to set up a bunch of shared state as the |
| 208 | * common test fixture. But if there are multiple with different requirements |
| 209 | * the commont setup code can't be extracted, since a test condition failure in |
| 210 | * e.g. igt_require() would result in all subsequent tests skipping. Even those |
| 211 | * from a different group. |
| 212 | * |
| 213 | * This macro allows to group together a set of #igt_fixture and #igt_subtest |
| 214 | * clauses. If any common setup in a fixture fails, only the subtests in this |
| 215 | * group will fail or skip. Subtest groups can be arbitrarily nested. |
| 216 | */ |
| 217 | #define igt_subtest_group for (int igt_tokencat(__tmpint,__LINE__) = 0, \ |
| 218 | igt_tokencat(__save,__LINE__) = 0; \ |
| 219 | igt_tokencat(__tmpint,__LINE__) < 1 && \ |
| 220 | (__igt_subtest_group_save(& igt_tokencat(__save,__LINE__) ), true); \ |
| 221 | igt_tokencat(__tmpint,__LINE__) ++, \ |
| 222 | __igt_subtest_group_restore(igt_tokencat(__save,__LINE__) )) |
| 223 | |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 224 | /** |
| 225 | * igt_main: |
| 226 | * |
| 227 | * This is a magic control flow block used instead of a main() function for |
| 228 | * tests with subtests. Open-coding the main() function is only recommended if |
Thomas Wood | d01ebbd | 2015-06-29 16:47:14 +0100 | [diff] [blame] | 229 | * the test needs to parse additional command line arguments of its own. |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 230 | */ |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 231 | #define igt_main \ |
| 232 | static void igt_tokencat(__real_main, __LINE__)(void); \ |
| 233 | int main(int argc, char **argv) { \ |
Damien Lespiau | fd6846c | 2015-05-14 14:19:01 +0100 | [diff] [blame] | 234 | igt_subtest_init_parse_opts(&argc, argv, NULL, NULL, NULL, \ |
| 235 | NULL, NULL); \ |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 236 | igt_tokencat(__real_main, __LINE__)(); \ |
| 237 | igt_exit(); \ |
| 238 | } \ |
| 239 | static void igt_tokencat(__real_main, __LINE__)(void) \ |
| 240 | |
Thomas Wood | 55cc132 | 2015-02-17 15:10:13 +0000 | [diff] [blame] | 241 | |
Chris Wilson | 7763349 | 2015-03-26 08:11:43 +0000 | [diff] [blame] | 242 | const char *igt_test_name(void); |
Thomas Wood | 8fb1978 | 2015-02-18 16:19:59 +0000 | [diff] [blame] | 243 | void igt_simple_init_parse_opts(int *argc, char **argv, |
Thomas Wood | e2cef00 | 2014-07-18 16:49:07 +0100 | [diff] [blame] | 244 | const char *extra_short_opts, |
Ville Syrjälä | 793aff1 | 2015-12-18 19:25:45 +0200 | [diff] [blame] | 245 | const struct option *extra_long_opts, |
Thomas Wood | e2cef00 | 2014-07-18 16:49:07 +0100 | [diff] [blame] | 246 | const char *help_str, |
Damien Lespiau | fd6846c | 2015-05-14 14:19:01 +0100 | [diff] [blame] | 247 | igt_opt_handler_t extra_opt_handler, |
| 248 | void *handler_data); |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 249 | |
| 250 | /** |
Thomas Wood | 55cc132 | 2015-02-17 15:10:13 +0000 | [diff] [blame] | 251 | * igt_simple_init: |
| 252 | * @argc: argc from the test's main() |
| 253 | * @argv: argv from the test's main() |
| 254 | * |
| 255 | * This initializes a simple test without any support for subtests. |
| 256 | * |
| 257 | * If there's not a reason to the contrary it's less error prone to just use an |
| 258 | * #igt_simple_main block instead of stitching the test's main() function together |
| 259 | * manually. |
| 260 | */ |
Damien Lespiau | fd6846c | 2015-05-14 14:19:01 +0100 | [diff] [blame] | 261 | #define igt_simple_init(argc, argv) \ |
| 262 | igt_simple_init_parse_opts(&argc, argv, NULL, NULL, NULL, NULL, NULL); |
Thomas Wood | 55cc132 | 2015-02-17 15:10:13 +0000 | [diff] [blame] | 263 | |
| 264 | /** |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 265 | * igt_simple_main: |
| 266 | * |
| 267 | * This is a magic control flow block used instead of a main() function for |
| 268 | * simple tests. Open-coding the main() function is only recommended if |
Thomas Wood | d01ebbd | 2015-06-29 16:47:14 +0100 | [diff] [blame] | 269 | * the test needs to parse additional command line arguments of its own. |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 270 | */ |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 271 | #define igt_simple_main \ |
| 272 | static void igt_tokencat(__real_main, __LINE__)(void); \ |
| 273 | int main(int argc, char **argv) { \ |
Damien Lespiau | fd6846c | 2015-05-14 14:19:01 +0100 | [diff] [blame] | 274 | igt_simple_init_parse_opts(&argc, argv, NULL, NULL, NULL, \ |
| 275 | NULL, NULL); \ |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 276 | igt_tokencat(__real_main, __LINE__)(); \ |
Tim Gore | f33fa71 | 2014-09-29 13:34:30 +0100 | [diff] [blame] | 277 | igt_exit(); \ |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 278 | } \ |
| 279 | static void igt_tokencat(__real_main, __LINE__)(void) \ |
| 280 | |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 281 | __attribute__((format(printf, 1, 2))) |
| 282 | void igt_skip(const char *f, ...) __attribute__((noreturn)); |
| 283 | __attribute__((format(printf, 5, 6))) |
| 284 | void __igt_skip_check(const char *file, const int line, |
| 285 | const char *func, const char *check, |
| 286 | const char *format, ...) __attribute__((noreturn)); |
Chris Wilson | fb9c9e3 | 2014-09-06 12:21:25 +0100 | [diff] [blame] | 287 | #define igt_skip_check(E, F...) \ |
Thomas Wood | e622850 | 2014-10-29 12:26:09 +0000 | [diff] [blame] | 288 | __igt_skip_check(__FILE__, __LINE__, __func__, E, F) |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 289 | void igt_success(void); |
| 290 | |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 291 | void igt_fail(int exitcode) __attribute__((noreturn)); |
Thomas Wood | b47032e | 2015-04-09 09:24:12 +0100 | [diff] [blame] | 292 | __attribute__((format(printf, 6, 7))) |
| 293 | void __igt_fail_assert(const char *domain, const char *file, |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 294 | const int line, const char *func, const char *assertion, |
| 295 | const char *format, ...) |
| 296 | __attribute__((noreturn)); |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 297 | void igt_exit(void) __attribute__((noreturn)); |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 298 | |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 299 | /** |
Chris Wilson | d86d6eb | 2016-06-23 21:07:36 +0100 | [diff] [blame] | 300 | * igt_ignore_warn: |
| 301 | * @expr: condition to ignore |
| 302 | * |
| 303 | * |
| 304 | * Stops the compiler warning about an unused return value. |
| 305 | */ |
| 306 | static inline void igt_ignore_warn(bool value) |
| 307 | { |
| 308 | } |
| 309 | |
| 310 | /** |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 311 | * igt_assert: |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 312 | * @expr: condition to test |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 313 | * |
Daniel Vetter | 2347e6d | 2014-06-13 18:01:33 +0200 | [diff] [blame] | 314 | * Fails (sub-)test if the condition is not met. |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 315 | * |
| 316 | * Should be used everywhere where a test checks results. |
| 317 | */ |
| 318 | #define igt_assert(expr) \ |
| 319 | do { if (!(expr)) \ |
Thomas Wood | b47032e | 2015-04-09 09:24:12 +0100 | [diff] [blame] | 320 | __igt_fail_assert(IGT_LOG_DOMAIN, __FILE__, __LINE__, __func__, #expr , NULL); \ |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 321 | } while (0) |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 322 | |
| 323 | /** |
| 324 | * igt_assert_f: |
| 325 | * @expr: condition to test |
| 326 | * @...: format string and optional arguments |
| 327 | * |
Daniel Vetter | 2347e6d | 2014-06-13 18:01:33 +0200 | [diff] [blame] | 328 | * Fails (sub-)test if the condition is not met. |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 329 | * |
| 330 | * Should be used everywhere where a test checks results. |
| 331 | * |
| 332 | * In addition to the plain igt_assert() helper this allows to print additional |
| 333 | * information to help debugging test failures. |
| 334 | */ |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 335 | #define igt_assert_f(expr, f...) \ |
| 336 | do { if (!(expr)) \ |
Thomas Wood | b47032e | 2015-04-09 09:24:12 +0100 | [diff] [blame] | 337 | __igt_fail_assert(IGT_LOG_DOMAIN, __FILE__, __LINE__, __func__, #expr , f); \ |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 338 | } while (0) |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 339 | |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 340 | /** |
Daniel Vetter | 2347e6d | 2014-06-13 18:01:33 +0200 | [diff] [blame] | 341 | * igt_fail_on: |
| 342 | * @expr: condition to test |
| 343 | * |
| 344 | * Fails (sub-)test if the condition is met. |
| 345 | * |
| 346 | * Should be used everywhere where a test checks results. |
| 347 | */ |
| 348 | #define igt_fail_on(expr) igt_assert(!(expr)) |
| 349 | |
| 350 | /** |
Thomas Wood | ae3a946 | 2014-11-25 11:59:37 +0000 | [diff] [blame] | 351 | * igt_fail_on_f: |
Daniel Vetter | 2347e6d | 2014-06-13 18:01:33 +0200 | [diff] [blame] | 352 | * @expr: condition to test |
| 353 | * @...: format string and optional arguments |
| 354 | * |
| 355 | * Fails (sub-)test if the condition is met. |
| 356 | * |
| 357 | * Should be used everywhere where a test checks results. |
| 358 | * |
| 359 | * In addition to the plain igt_assert() helper this allows to print additional |
| 360 | * information to help debugging test failures. |
| 361 | */ |
| 362 | #define igt_fail_on_f(expr, f...) igt_assert_f(!(expr), f) |
| 363 | |
| 364 | /** |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 365 | * igt_assert_cmpint: |
| 366 | * @n1: first value |
| 367 | * @cmp: compare operator |
Thomas Wood | d4e3b6a | 2014-10-08 17:06:58 +0100 | [diff] [blame] | 368 | * @ncmp: negated version of @cmp |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 369 | * @n2: second value |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 370 | * |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 371 | * Fails (sub-)test if the condition is not met |
| 372 | * |
| 373 | * Should be used everywhere where a test compares two integer values. |
| 374 | * |
| 375 | * Like igt_assert(), but displays the values being compared on failure instead |
| 376 | * of simply printing the stringified expression. |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 377 | */ |
Chris Wilson | 3b94d3f | 2014-08-29 13:11:40 +0100 | [diff] [blame] | 378 | #define igt_assert_cmpint(n1, cmp, ncmp, n2) \ |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 379 | do { \ |
| 380 | int __n1 = (n1), __n2 = (n2); \ |
| 381 | if (__n1 cmp __n2) ; else \ |
Thomas Wood | b47032e | 2015-04-09 09:24:12 +0100 | [diff] [blame] | 382 | __igt_fail_assert(IGT_LOG_DOMAIN, __FILE__, __LINE__, __func__, \ |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 383 | #n1 " " #cmp " " #n2, \ |
Chris Wilson | d28b9d2 | 2014-08-29 17:30:40 +0100 | [diff] [blame] | 384 | "error: %d " #ncmp " %d\n", __n1, __n2); \ |
Chris Wilson | 3b94d3f | 2014-08-29 13:11:40 +0100 | [diff] [blame] | 385 | } while (0) |
| 386 | |
Damien Lespiau | 2388852 | 2015-06-27 15:26:13 +0100 | [diff] [blame] | 387 | /** |
| 388 | * igt_assert_cmpuint: |
| 389 | * @n1: first value |
| 390 | * @cmp: compare operator |
| 391 | * @ncmp: negated version of @cmp |
| 392 | * @n2: second value |
| 393 | * |
Thomas Wood | d01ebbd | 2015-06-29 16:47:14 +0100 | [diff] [blame] | 394 | * Like igt_assert_cmpint(), but for unsigned ints. |
Damien Lespiau | 2388852 | 2015-06-27 15:26:13 +0100 | [diff] [blame] | 395 | */ |
Chris Wilson | 3b94d3f | 2014-08-29 13:11:40 +0100 | [diff] [blame] | 396 | #define igt_assert_cmpuint(n1, cmp, ncmp, n2) \ |
| 397 | do { \ |
| 398 | uint32_t __n1 = (n1), __n2 = (n2); \ |
| 399 | if (__n1 cmp __n2) ; else \ |
Thomas Wood | b47032e | 2015-04-09 09:24:12 +0100 | [diff] [blame] | 400 | __igt_fail_assert(IGT_LOG_DOMAIN, __FILE__, __LINE__, __func__, \ |
Chris Wilson | 3b94d3f | 2014-08-29 13:11:40 +0100 | [diff] [blame] | 401 | #n1 " " #cmp " " #n2, \ |
Chris Wilson | d28b9d2 | 2014-08-29 17:30:40 +0100 | [diff] [blame] | 402 | "error: %#x " #ncmp " %#x\n", __n1, __n2); \ |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 403 | } while (0) |
| 404 | |
| 405 | /** |
Chris Wilson | 40ebf95 | 2015-07-28 18:59:47 +0100 | [diff] [blame] | 406 | * igt_assert_cmpu64: |
| 407 | * @n1: first value |
| 408 | * @cmp: compare operator |
| 409 | * @ncmp: negated version of @cmp |
| 410 | * @n2: second value |
| 411 | * |
| 412 | * Like igt_assert_cmpuint(), but for larger ints. |
| 413 | */ |
| 414 | #define igt_assert_cmpu64(n1, cmp, ncmp, n2) \ |
| 415 | do { \ |
| 416 | uint64_t __n1 = (n1), __n2 = (n2); \ |
| 417 | if (__n1 cmp __n2) ; else \ |
| 418 | __igt_fail_assert(IGT_LOG_DOMAIN, __FILE__, __LINE__, __func__, \ |
| 419 | #n1 " " #cmp " " #n2, \ |
| 420 | "error: %#llx " #ncmp " %#llx\n", (long long)__n1, (long long)__n2); \ |
| 421 | } while (0) |
| 422 | |
| 423 | /** |
Damien Lespiau | 0a38e97 | 2015-06-27 15:26:50 +0100 | [diff] [blame] | 424 | * igt_assert_cmpdouble: |
| 425 | * @n1: first value |
| 426 | * @cmp: compare operator |
| 427 | * @ncmp: negated version of @cmp |
| 428 | * @n2: second value |
| 429 | * |
Thomas Wood | d01ebbd | 2015-06-29 16:47:14 +0100 | [diff] [blame] | 430 | * Like igt_assert_cmpint(), but for doubles. |
Damien Lespiau | 0a38e97 | 2015-06-27 15:26:50 +0100 | [diff] [blame] | 431 | */ |
| 432 | #define igt_assert_cmpdouble(n1, cmp, ncmp, n2) \ |
| 433 | do { \ |
| 434 | double __n1 = (n1), __n2 = (n2); \ |
| 435 | if (__n1 cmp __n2) ; else \ |
| 436 | __igt_fail_assert(IGT_LOG_DOMAIN, __FILE__, __LINE__, __func__, \ |
| 437 | #n1 " " #cmp " " #n2, \ |
| 438 | "error: %#lf " #ncmp " %#lf\n", __n1, __n2); \ |
| 439 | } while (0) |
| 440 | |
| 441 | /** |
Daniel Vetter | 3448b5a | 2014-06-13 10:46:55 +0200 | [diff] [blame] | 442 | * igt_assert_eq: |
| 443 | * @n1: first integer |
| 444 | * @n2: second integer |
| 445 | * |
| 446 | * Fails (sub-)test if the two integers are not equal. Beware that for now this |
| 447 | * only works on integers. |
| 448 | * |
| 449 | * Like igt_assert(), but displays the values being compared on failure instead |
| 450 | * of simply printing the stringified expression. |
| 451 | */ |
Chris Wilson | 3b94d3f | 2014-08-29 13:11:40 +0100 | [diff] [blame] | 452 | #define igt_assert_eq(n1, n2) igt_assert_cmpint(n1, ==, !=, n2) |
Damien Lespiau | f660d0a | 2015-06-27 15:16:22 +0100 | [diff] [blame] | 453 | |
| 454 | /** |
| 455 | * igt_assert_eq_u32: |
| 456 | * @n1: first integer |
| 457 | * @n2: second integer |
| 458 | * |
| 459 | * Like igt_assert_eq(), but for uint32_t. |
| 460 | */ |
Chris Wilson | 3b94d3f | 2014-08-29 13:11:40 +0100 | [diff] [blame] | 461 | #define igt_assert_eq_u32(n1, n2) igt_assert_cmpuint(n1, ==, !=, n2) |
| 462 | |
| 463 | /** |
Chris Wilson | 40ebf95 | 2015-07-28 18:59:47 +0100 | [diff] [blame] | 464 | * igt_assert_eq_u64: |
| 465 | * @n1: first integer |
| 466 | * @n2: second integer |
| 467 | * |
| 468 | * Like igt_assert_eq_u32(), but for uint64_t. |
| 469 | */ |
| 470 | #define igt_assert_eq_u64(n1, n2) igt_assert_cmpu64(n1, ==, !=, n2) |
| 471 | |
| 472 | /** |
Damien Lespiau | 0a38e97 | 2015-06-27 15:26:50 +0100 | [diff] [blame] | 473 | * igt_assert_eq_double: |
| 474 | * @n1: first double |
| 475 | * @n2: second double |
| 476 | * |
| 477 | * Like igt_assert_eq(), but for doubles. |
| 478 | */ |
| 479 | #define igt_assert_eq_double(n1, n2) igt_assert_cmpdouble(n1, ==, !=, n2) |
| 480 | |
| 481 | /** |
Chris Wilson | 3b94d3f | 2014-08-29 13:11:40 +0100 | [diff] [blame] | 482 | * igt_assert_neq: |
| 483 | * @n1: first integer |
| 484 | * @n2: second integer |
| 485 | * |
| 486 | * Fails (sub-)test if the two integers are equal. Beware that for now this |
| 487 | * only works on integers. |
| 488 | * |
| 489 | * Like igt_assert(), but displays the values being compared on failure instead |
| 490 | * of simply printing the stringified expression. |
| 491 | */ |
| 492 | #define igt_assert_neq(n1, n2) igt_assert_cmpint(n1, !=, ==, n2) |
| 493 | |
| 494 | /** |
Daniel Stone | 715a17b | 2015-10-01 13:00:12 +0100 | [diff] [blame] | 495 | * igt_assert_neq_u32: |
| 496 | * @n1: first integer |
| 497 | * @n2: second integer |
| 498 | * |
| 499 | * Like igt_assert_neq(), but for uint32_t. |
| 500 | */ |
| 501 | #define igt_assert_neq_u32(n1, n2) igt_assert_cmpuint(n1, !=, ==, n2) |
| 502 | |
| 503 | /** |
| 504 | * igt_assert_neq_u64: |
| 505 | * @n1: first integer |
| 506 | * @n2: second integer |
| 507 | * |
| 508 | * Like igt_assert_neq_u32(), but for uint64_t. |
| 509 | */ |
| 510 | #define igt_assert_neq_u64(n1, n2) igt_assert_cmpu64(n1, !=, ==, n2) |
| 511 | |
| 512 | /** |
| 513 | * igt_assert_neq_double: |
| 514 | * @n1: first double |
| 515 | * @n2: second double |
| 516 | * |
| 517 | * Like igt_assert_neq(), but for doubles. |
| 518 | */ |
| 519 | #define igt_assert_neq_double(n1, n2) igt_assert_cmpdouble(n1, !=, ==, n2) |
| 520 | |
| 521 | /** |
Chris Wilson | 3b94d3f | 2014-08-29 13:11:40 +0100 | [diff] [blame] | 522 | * igt_assert_lte: |
| 523 | * @n1: first integer |
| 524 | * @n2: second integer |
| 525 | * |
Daniel Vetter | c9112dc | 2015-10-02 12:56:16 +0200 | [diff] [blame] | 526 | * Fails (sub-)test if the second integer is strictly smaller than the first. |
Chris Wilson | 3b94d3f | 2014-08-29 13:11:40 +0100 | [diff] [blame] | 527 | * Beware that for now this only works on integers. |
| 528 | * |
| 529 | * Like igt_assert(), but displays the values being compared on failure instead |
| 530 | * of simply printing the stringified expression. |
| 531 | */ |
| 532 | #define igt_assert_lte(n1, n2) igt_assert_cmpint(n1, <=, >, n2) |
Daniel Vetter | 3448b5a | 2014-06-13 10:46:55 +0200 | [diff] [blame] | 533 | |
| 534 | /** |
Daniel Vetter | 305fb1d | 2015-02-27 16:24:25 +0100 | [diff] [blame] | 535 | * igt_assert_lt: |
| 536 | * @n1: first integer |
| 537 | * @n2: second integer |
| 538 | * |
Daniel Vetter | c9112dc | 2015-10-02 12:56:16 +0200 | [diff] [blame] | 539 | * Fails (sub-)test if the second integer is smaller than or equal to the first. |
Daniel Vetter | 305fb1d | 2015-02-27 16:24:25 +0100 | [diff] [blame] | 540 | * Beware that for now this only works on integers. |
| 541 | * |
| 542 | * Like igt_assert(), but displays the values being compared on failure instead |
| 543 | * of simply printing the stringified expression. |
| 544 | */ |
| 545 | #define igt_assert_lt(n1, n2) igt_assert_cmpint(n1, <, >=, n2) |
| 546 | |
| 547 | /** |
Daniel Stone | 6ead44d | 2015-10-01 13:26:36 +0100 | [diff] [blame] | 548 | * igt_assert_fd: |
| 549 | * @fd: file descriptor |
| 550 | * |
| 551 | * Fails (sub-) test if the given file descriptor is invalid. |
| 552 | * |
| 553 | * Like igt_assert(), but displays the values being compared on failure instead |
| 554 | * of simply printing the stringified expression. |
| 555 | */ |
| 556 | #define igt_assert_fd(fd) \ |
| 557 | igt_assert_f(fd >= 0, "file descriptor " #fd " failed\n"); |
| 558 | |
| 559 | /** |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 560 | * igt_require: |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 561 | * @expr: condition to test |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 562 | * |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 563 | * Skip a (sub-)test if a condition is not met. |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 564 | * |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 565 | * Should be used everywhere where a test checks results to decide about |
| 566 | * skipping. This is useful to streamline the skip logic since it allows for a more flat |
| 567 | * code control flow, similar to igt_assert() |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 568 | */ |
Chris Wilson | fb9c9e3 | 2014-09-06 12:21:25 +0100 | [diff] [blame] | 569 | #define igt_require(expr) do { \ |
| 570 | if (!(expr)) igt_skip_check(#expr , NULL); \ |
Paulo Zanoni | a1fce74 | 2015-08-13 13:49:42 -0300 | [diff] [blame] | 571 | else igt_debug("Test requirement passed: %s\n", #expr); \ |
Chris Wilson | fb9c9e3 | 2014-09-06 12:21:25 +0100 | [diff] [blame] | 572 | } while (0) |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 573 | |
| 574 | /** |
| 575 | * igt_skip_on: |
| 576 | * @expr: condition to test |
| 577 | * |
| 578 | * Skip a (sub-)test if a condition is met. |
| 579 | * |
| 580 | * Should be used everywhere where a test checks results to decide about |
| 581 | * skipping. This is useful to streamline the skip logic since it allows for a more flat |
| 582 | * code control flow, similar to igt_assert() |
| 583 | */ |
Chris Wilson | fb9c9e3 | 2014-09-06 12:21:25 +0100 | [diff] [blame] | 584 | #define igt_skip_on(expr) do { \ |
| 585 | if ((expr)) igt_skip_check("!(" #expr ")" , NULL); \ |
Paulo Zanoni | a1fce74 | 2015-08-13 13:49:42 -0300 | [diff] [blame] | 586 | else igt_debug("Test requirement passed: !(%s)\n", #expr); \ |
Chris Wilson | fb9c9e3 | 2014-09-06 12:21:25 +0100 | [diff] [blame] | 587 | } while (0) |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 588 | |
| 589 | /** |
| 590 | * igt_require_f: |
| 591 | * @expr: condition to test |
| 592 | * @...: format string and optional arguments |
| 593 | * |
| 594 | * Skip a (sub-)test if a condition is not met. |
| 595 | * |
| 596 | * Should be used everywhere where a test checks results to decide about |
| 597 | * skipping. This is useful to streamline the skip logic since it allows for a more flat |
| 598 | * code control flow, similar to igt_assert() |
| 599 | * |
| 600 | * In addition to the plain igt_require() helper this allows to print additional |
| 601 | * information to help debugging test failures. |
| 602 | */ |
Chris Wilson | fb9c9e3 | 2014-09-06 12:21:25 +0100 | [diff] [blame] | 603 | #define igt_require_f(expr, f...) do { \ |
| 604 | if (!(expr)) igt_skip_check(#expr , f); \ |
Paulo Zanoni | a1fce74 | 2015-08-13 13:49:42 -0300 | [diff] [blame] | 605 | else igt_debug("Test requirement passed: %s\n", #expr); \ |
Chris Wilson | fb9c9e3 | 2014-09-06 12:21:25 +0100 | [diff] [blame] | 606 | } while (0) |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 607 | |
| 608 | /** |
| 609 | * igt_skip_on_f: |
| 610 | * @expr: condition to test |
| 611 | * @...: format string and optional arguments |
| 612 | * |
| 613 | * Skip a (sub-)test if a condition is met. |
| 614 | * |
| 615 | * Should be used everywhere where a test checks results to decide about |
| 616 | * skipping. This is useful to streamline the skip logic since it allows for a more flat |
| 617 | * code control flow, similar to igt_assert() |
| 618 | * |
| 619 | * In addition to the plain igt_skip_on() helper this allows to print additional |
| 620 | * information to help debugging test failures. |
| 621 | */ |
Chris Wilson | fb9c9e3 | 2014-09-06 12:21:25 +0100 | [diff] [blame] | 622 | #define igt_skip_on_f(expr, f...) do { \ |
Thomas Wood | d950f37 | 2014-10-29 12:03:22 +0000 | [diff] [blame] | 623 | if ((expr)) igt_skip_check("!("#expr")", f); \ |
Paulo Zanoni | a1fce74 | 2015-08-13 13:49:42 -0300 | [diff] [blame] | 624 | else igt_debug("Test requirement passed: !(%s)\n", #expr); \ |
Chris Wilson | fb9c9e3 | 2014-09-06 12:21:25 +0100 | [diff] [blame] | 625 | } while (0) |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 626 | |
| 627 | /* fork support code */ |
| 628 | bool __igt_fork(void); |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 629 | |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 630 | /** |
| 631 | * igt_fork: |
| 632 | * @child: name of the int variable with the child number |
| 633 | * @num_children: number of children to fork |
| 634 | * |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 635 | * This is a magic control flow block which spawns parallel test threads with |
| 636 | * fork(). |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 637 | * |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 638 | * The test children execute in parallel to the main test thread. Joining all |
| 639 | * test threads should be done with igt_waitchildren to ensure that the exit |
| 640 | * codes of all children are properly reflected in the test status. |
| 641 | * |
| 642 | * Note that igt_skip() will not be forwarded, feature tests need to be done |
| 643 | * before spawning threads with igt_fork(). |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 644 | */ |
| 645 | #define igt_fork(child, num_children) \ |
| 646 | for (int child = 0; child < (num_children); child++) \ |
| 647 | for (; __igt_fork(); exit(0)) |
| 648 | void igt_waitchildren(void); |
Chris Wilson | 7548763 | 2016-02-26 22:11:10 +0000 | [diff] [blame] | 649 | void igt_waitchildren_timeout(int seconds, const char *reason); |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 650 | |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 651 | /** |
Thomas Wood | 26f4081 | 2015-02-20 11:31:01 +0000 | [diff] [blame] | 652 | * igt_helper_process: |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 653 | * @running: indicates whether the process is currently running |
Chris Wilson | 4f7d4dc | 2014-07-21 07:54:29 +0100 | [diff] [blame] | 654 | * @use_SIGKILL: whether the helper should be terminated with SIGKILL or SIGTERM |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 655 | * @pid: pid of the helper if @running is true |
| 656 | * @id: internal id |
| 657 | * |
| 658 | * Tracking structure for helper processes. Users of the i-g-t library should |
| 659 | * only set @use_SIGKILL directly. |
| 660 | */ |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 661 | struct igt_helper_process { |
| 662 | bool running; |
| 663 | bool use_SIGKILL; |
| 664 | pid_t pid; |
| 665 | int id; |
| 666 | }; |
| 667 | bool __igt_fork_helper(struct igt_helper_process *proc); |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 668 | |
| 669 | /** |
| 670 | * igt_fork_helper: |
| 671 | * @proc: #igt_helper_process structure |
| 672 | * |
| 673 | * This is a magic control flow block which denotes an asynchronous helper |
| 674 | * process block. The difference compared to igt_fork() is that failures from |
| 675 | * the child process will not be forwarded, making this construct more suitable |
| 676 | * for background processes. Common use cases are regular interference of the |
| 677 | * main test thread through e.g. sending signals or evicting objects through |
| 678 | * debugfs. Through the explicit #igt_helper_process they can also be controlled |
| 679 | * in a more fine-grained way than test children spawned through igt_fork(). |
| 680 | * |
| 681 | * For tests with subtest helper process can be started outside of a |
| 682 | * #igt_subtest block. |
| 683 | * |
| 684 | * Calling igt_wait_helper() joins a helper process and igt_stop_helper() |
| 685 | * forcefully terminates it. |
| 686 | */ |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 687 | #define igt_fork_helper(proc) \ |
| 688 | for (; __igt_fork_helper(proc); exit(0)) |
Chris Wilson | 7459455 | 2014-07-24 11:44:45 +0100 | [diff] [blame] | 689 | int igt_wait_helper(struct igt_helper_process *proc); |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 690 | void igt_stop_helper(struct igt_helper_process *proc); |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 691 | |
| 692 | /* exit handler code */ |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 693 | |
| 694 | /** |
| 695 | * igt_exit_handler_t: |
| 696 | * @sig: Signal number which caused the exit or 0. |
| 697 | * |
| 698 | * Exit handler type used by igt_install_exit_handler(). Note that exit handlers |
| 699 | * can potentially be run from signal handling contexts, the @sig parameter can |
| 700 | * be used to figure this out and act accordingly. |
| 701 | */ |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 702 | typedef void (*igt_exit_handler_t)(int sig); |
| 703 | |
| 704 | /* reliable atexit helpers, also work when killed by a signal (if possible) */ |
| 705 | void igt_install_exit_handler(igt_exit_handler_t fn); |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 706 | |
| 707 | /* helpers to automatically reduce test runtime in simulation */ |
| 708 | bool igt_run_in_simulation(void); |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 709 | /** |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 710 | * SLOW_QUICK: |
| 711 | * @slow: value in simulation mode |
| 712 | * @quick: value in normal mode |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 713 | * |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 714 | * Simple macro to select between two values (e.g. number of test rounds or test |
| 715 | * buffer size) depending upon whether i-g-t is run in simulation mode or not. |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 716 | */ |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 717 | #define SLOW_QUICK(slow,quick) (igt_run_in_simulation() ? (quick) : (slow)) |
| 718 | |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 719 | void igt_skip_on_simulation(void); |
| 720 | |
Thomas Wood | a6c40c7 | 2015-03-12 14:59:20 +0000 | [diff] [blame] | 721 | extern const char *igt_interactive_debug; |
Rodrigo Vivi | 3d65ff7 | 2015-01-12 10:21:58 -0800 | [diff] [blame] | 722 | |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 723 | /* structured logging */ |
| 724 | enum igt_log_level { |
| 725 | IGT_LOG_DEBUG, |
| 726 | IGT_LOG_INFO, |
| 727 | IGT_LOG_WARN, |
Thomas Wood | df11a0f | 2014-12-16 15:18:20 +0000 | [diff] [blame] | 728 | IGT_LOG_CRITICAL, |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 729 | IGT_LOG_NONE, |
| 730 | }; |
Thomas Wood | 8161a21 | 2014-12-02 10:54:54 +0000 | [diff] [blame] | 731 | __attribute__((format(printf, 3, 4))) |
| 732 | void igt_log(const char *domain, enum igt_log_level level, const char *format, ...); |
| 733 | __attribute__((format(printf, 3, 0))) |
| 734 | void igt_vlog(const char *domain, enum igt_log_level level, const char *format, va_list args); |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 735 | |
| 736 | /** |
| 737 | * igt_debug: |
| 738 | * @...: format string and optional arguments |
| 739 | * |
Daniel Vetter | 3f50598 | 2014-07-14 23:02:18 +0200 | [diff] [blame] | 740 | * Wrapper for igt_log() for message at the IGT_LOG_DEBUG level. |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 741 | */ |
Thomas Wood | 8161a21 | 2014-12-02 10:54:54 +0000 | [diff] [blame] | 742 | #define igt_debug(f...) igt_log(IGT_LOG_DOMAIN, IGT_LOG_DEBUG, f) |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 743 | |
| 744 | /** |
| 745 | * igt_info: |
| 746 | * @...: format string and optional arguments |
| 747 | * |
Daniel Vetter | 3f50598 | 2014-07-14 23:02:18 +0200 | [diff] [blame] | 748 | * Wrapper for igt_log() for message at the IGT_LOG_INFO level. |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 749 | */ |
Thomas Wood | 8161a21 | 2014-12-02 10:54:54 +0000 | [diff] [blame] | 750 | #define igt_info(f...) igt_log(IGT_LOG_DOMAIN, IGT_LOG_INFO, f) |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 751 | |
| 752 | /** |
| 753 | * igt_warn: |
| 754 | * @...: format string and optional arguments |
| 755 | * |
Daniel Vetter | 3f50598 | 2014-07-14 23:02:18 +0200 | [diff] [blame] | 756 | * Wrapper for igt_log() for message at the IGT_LOG_WARN level. |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 757 | */ |
Thomas Wood | 8161a21 | 2014-12-02 10:54:54 +0000 | [diff] [blame] | 758 | #define igt_warn(f...) igt_log(IGT_LOG_DOMAIN, IGT_LOG_WARN, f) |
Thomas Wood | df11a0f | 2014-12-16 15:18:20 +0000 | [diff] [blame] | 759 | |
| 760 | /** |
| 761 | * igt_critical: |
| 762 | * @...: format string and optional arguments |
| 763 | * |
| 764 | * Wrapper for igt_log() for message at the IGT_LOG_CRITICAL level. |
| 765 | */ |
| 766 | #define igt_critical(f...) igt_log(IGT_LOG_DOMAIN, IGT_LOG_CRITICAL, f) |
| 767 | |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 768 | extern enum igt_log_level igt_log_level; |
| 769 | |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 770 | /** |
| 771 | * igt_warn_on: |
| 772 | * @condition: condition to test |
| 773 | * |
| 774 | * Print a IGT_LOG_WARN level message if a condition is not met. |
| 775 | * |
| 776 | * Should be used everywhere where a test checks results to decide about |
| 777 | * printing warnings. This is useful to streamline the test logic since it |
| 778 | * allows for a more flat code control flow, similar to igt_assert() |
| 779 | */ |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 780 | #define igt_warn_on(condition) do {\ |
| 781 | if (condition) \ |
| 782 | igt_warn("Warning on condition %s in fucntion %s, file %s:%i\n", \ |
| 783 | #condition, __func__, __FILE__, __LINE__); \ |
| 784 | } while (0) |
Daniel Vetter | 55e6498 | 2014-03-12 02:34:40 +0100 | [diff] [blame] | 785 | |
| 786 | /** |
| 787 | * igt_warn_on_f: |
| 788 | * @condition: condition to test |
| 789 | * @...: format string and optional arguments |
| 790 | * |
| 791 | * Skip a (sub-)test if a condition is not met. |
| 792 | * |
| 793 | * Print a IGT_LOG_WARN level message if a condition is not met. |
| 794 | * |
| 795 | * Should be used everywhere where a test checks results to decide about |
| 796 | * printing warnings. This is useful to streamline the test logic since it |
| 797 | * allows for a more flat code control flow, similar to igt_assert() |
| 798 | * |
| 799 | * In addition to the plain igt_warn_on_f() helper this allows to print |
| 800 | * additional information (again as warnings) to help debugging test failures. |
| 801 | */ |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 802 | #define igt_warn_on_f(condition, f...) do {\ |
| 803 | if (condition) {\ |
| 804 | igt_warn("Warning on condition %s in fucntion %s, file %s:%i\n", \ |
| 805 | #condition, __func__, __FILE__, __LINE__); \ |
| 806 | igt_warn(f); \ |
| 807 | } \ |
| 808 | } while (0) |
| 809 | |
| 810 | |
Daniel Vetter | 370c989 | 2015-08-07 19:01:23 +0200 | [diff] [blame] | 811 | void igt_set_timeout(unsigned int seconds, |
| 812 | const char *op); |
Thomas Wood | d8e5313 | 2014-05-12 10:19:52 +0100 | [diff] [blame] | 813 | |
Chris Wilson | dcb39b5 | 2016-03-18 09:04:07 +0000 | [diff] [blame] | 814 | /** |
| 815 | * igt_nsec_elapsed: |
| 816 | * @start: measure from this point in time |
| 817 | * |
| 818 | * Reports the difference in the monotonic clock from the start time |
| 819 | * in nanoseconds. On the first invocation, start should be zeroed and will |
| 820 | * be set by the call. |
| 821 | * |
| 822 | * Typical use would be: |
| 823 | * |
| 824 | * igt_subtest("test") { |
| 825 | * struct timespec start = {}; |
| 826 | * while (igt_nsec_elapsed(&start) < test_timeout_ns) |
| 827 | * do_test(); |
| 828 | * } |
| 829 | * |
| 830 | * A handy approximation is to use nsec >> 30 to convert to seconds, |
| 831 | * nsec >> 20 to convert to milliseconds - the error is about 8%, acceptable |
| 832 | * for test run times. |
| 833 | */ |
| 834 | uint64_t igt_nsec_elapsed(struct timespec *start); |
| 835 | |
| 836 | /** |
| 837 | * igt_seconds_elapsed: |
| 838 | * @start: measure from this point in time |
| 839 | * |
| 840 | * A wrapper around igt_nsec_elapsed that reports the approximate (8% error) |
| 841 | * number of seconds since the start point. |
| 842 | */ |
| 843 | static inline uint32_t igt_seconds_elapsed(struct timespec *start) |
| 844 | { |
| 845 | return igt_nsec_elapsed(start) >> 30; |
| 846 | } |
| 847 | |
Daniel Vetter | 5b0a843 | 2015-08-07 19:12:07 +0200 | [diff] [blame] | 848 | void igt_reset_timeout(void); |
| 849 | |
Joonas Lahtinen | a95033f | 2015-03-31 15:53:17 +0300 | [diff] [blame] | 850 | FILE *__igt_fopen_data(const char* igt_srcdir, const char* igt_datadir, |
| 851 | const char* filename); |
| 852 | /** |
| 853 | * igt_fopen_data: |
| 854 | * @filename: filename to open. |
| 855 | * |
Matt Roper | 303b380 | 2016-05-26 16:02:05 -0700 | [diff] [blame] | 856 | * Open a datafile for test, first try from installation directory, |
| 857 | * then from build directory, and finally from current directory. |
Joonas Lahtinen | a95033f | 2015-03-31 15:53:17 +0300 | [diff] [blame] | 858 | */ |
| 859 | #define igt_fopen_data(filename) \ |
| 860 | __igt_fopen_data(IGT_SRCDIR, IGT_DATADIR, filename) |
| 861 | |
Daniel Vetter | d63fe15 | 2014-03-12 01:29:52 +0100 | [diff] [blame] | 862 | #endif /* IGT_CORE_H */ |