blob: f8543d6587b5cccc21bf3e56ee6156f52948e69c [file] [log] [blame]
Daniel Vetterd63fe152014-03-12 01:29:52 +01001/*
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 Vetter924115b2014-03-22 20:18:51 +010033#include <setjmp.h>
Daniel Vetter6cfcd712014-03-22 20:07:35 +010034#include <stdbool.h>
Chris Wilsondcb39b52016-03-18 09:04:07 +000035#include <stdint.h>
Daniel Vetter254f19b2014-03-22 21:29:01 +010036#include <stdlib.h>
Joonas Lahtinena95033f2015-03-31 15:53:17 +030037#include <stdio.h>
Daniel Vetter924115b2014-03-22 20:18:51 +010038#include <string.h>
39#include <sys/types.h>
Daniel Vetter254f19b2014-03-22 21:29:01 +010040#include <stdarg.h>
Thomas Wood80d2c9b2014-07-21 15:57:16 +010041#include <getopt.h>
Petri Latvala474fae62016-11-15 13:52:52 +020042#include <unistd.h>
Daniel Vetter6cfcd712014-03-22 20:07:35 +010043
Thomas Wood01676192014-12-17 11:37:31 +000044#ifndef IGT_LOG_DOMAIN
45#define IGT_LOG_DOMAIN (NULL)
46#endif
47
48
Thomas Woodf8b3c702014-10-10 16:56:20 +010049extern const char* __igt_test_description __attribute__((weak));
Thomas Wood790f1f82015-11-09 17:17:24 +000050extern bool __igt_plain_output;
Daniel Vettera3a3e0f2017-09-05 14:36:08 +020051extern char *igt_frame_dump_path;
Thomas Woodf8b3c702014-10-10 16:56:20 +010052
53/**
54 * IGT_TEST_DESCRIPTION:
55 * @str: description string
56 *
57 * Defines a description for a test. This is used as the output for the
58 * "--help-description" option and is also included in the generated
59 * documentation.
60 */
61#define IGT_TEST_DESCRIPTION(str) const char* __igt_test_description = str
62
Thomas Wood17eb0622014-05-13 15:22:52 +010063/**
64 * IGT_EXIT_TIMEOUT:
65 *
66 * Exit status indicating a timeout occurred.
67 */
68#define IGT_EXIT_TIMEOUT 78
69
70/**
71 * IGT_EXIT_SKIP:
72 *
73 * Exit status indicating the test was skipped.
74 */
75#define IGT_EXIT_SKIP 77
76
77/**
78 * IGT_EXIT_SUCCESS
79 *
80 * Exit status indicating the test executed successfully.
81 */
82#define IGT_EXIT_SUCCESS 0
83
Thomas Wood784344e2014-07-23 16:29:39 +010084/**
85 * IGT_EXIT_INVALID
86 *
87 * Exit status indicating an invalid option or subtest was specified
88 */
89#define IGT_EXIT_INVALID 79
90
Thomas Woodb47032e2015-04-09 09:24:12 +010091/**
92 * IGT_EXIT_FAILURE
93 *
94 * Exit status indicating a test failure
95 */
96#define IGT_EXIT_FAILURE 99
Thomas Wood17eb0622014-05-13 15:22:52 +010097
Daniel Vetterd63fe152014-03-12 01:29:52 +010098bool __igt_fixture(void);
99void __igt_fixture_complete(void);
100void __igt_fixture_end(void) __attribute__((noreturn));
101/**
102 * igt_fixture:
103 *
104 * Annotate global test fixture code
105 *
106 * Testcase with subtests often need to set up a bunch of global state as the
Thomas Woodd01ebbd2015-06-29 16:47:14 +0100107 * common test fixture. To avoid such code interfering with the subtest
108 * enumeration (e.g. when enumerating on systems without an intel gpu) such
Daniel Vetterd63fe152014-03-12 01:29:52 +0100109 * blocks should be annotated with igt_fixture.
110 */
Tomeu Vizoso3450cba2016-04-15 14:00:04 +0200111#define igt_fixture for (volatile int igt_tokencat(__tmpint,__LINE__) = 0; \
Daniel Vetterd63fe152014-03-12 01:29:52 +0100112 igt_tokencat(__tmpint,__LINE__) < 1 && \
113 __igt_fixture() && \
Chris Wilson578795f2015-05-08 14:35:37 +0100114 (sigsetjmp(igt_subtest_jmpbuf, 1) == 0); \
Daniel Vetterd63fe152014-03-12 01:29:52 +0100115 igt_tokencat(__tmpint,__LINE__) ++, \
116 __igt_fixture_complete())
117
118/* subtest infrastructure */
119jmp_buf igt_subtest_jmpbuf;
Damien Lespiaufd6846c2015-05-14 14:19:01 +0100120typedef int (*igt_opt_handler_t)(int opt, int opt_index, void *data);
Daniel Vetter55e64982014-03-12 02:34:40 +0100121#ifndef __GTK_DOC_IGNORE__ /* gtkdoc wants to document this forward decl */
Daniel Vetterd63fe152014-03-12 01:29:52 +0100122struct option;
Daniel Vetter55e64982014-03-12 02:34:40 +0100123#endif
Thomas Wood8fb19782015-02-18 16:19:59 +0000124int igt_subtest_init_parse_opts(int *argc, char **argv,
Daniel Vetterd63fe152014-03-12 01:29:52 +0100125 const char *extra_short_opts,
Ville Syrjälä793aff12015-12-18 19:25:45 +0200126 const struct option *extra_long_opts,
Daniel Vetterd63fe152014-03-12 01:29:52 +0100127 const char *help_str,
Damien Lespiaufd6846c2015-05-14 14:19:01 +0100128 igt_opt_handler_t extra_opt_handler,
129 void *handler_data);
Daniel Vetterd63fe152014-03-12 01:29:52 +0100130
Thomas Wood55cc1322015-02-17 15:10:13 +0000131
132/**
133 * igt_subtest_init:
134 * @argc: argc from the test's main()
135 * @argv: argv from the test's main()
136 *
137 * This initializes the for tests with subtests without the need for additional
Thomas Woodd01ebbd2015-06-29 16:47:14 +0100138 * command line options. It is just a simplified version of
Thomas Wood55cc1322015-02-17 15:10:13 +0000139 * igt_subtest_init_parse_opts().
140 *
141 * If there's not a reason to the contrary it's less error prone to just use an
142 * #igt_main block instead of stitching the test's main() function together
143 * manually.
144 */
Damien Lespiaufd6846c2015-05-14 14:19:01 +0100145#define igt_subtest_init(argc, argv) \
146 igt_subtest_init_parse_opts(&argc, argv, NULL, NULL, NULL, NULL, NULL);
Thomas Wood55cc1322015-02-17 15:10:13 +0000147
Daniel Vetterd63fe152014-03-12 01:29:52 +0100148bool __igt_run_subtest(const char *subtest_name);
Daniel Vetter55e64982014-03-12 02:34:40 +0100149#define __igt_tokencat2(x, y) x ## y
150
151/**
152 * igt_tokencat:
153 * @x: first variable
154 * @y: second variable
155 *
156 * C preprocessor helper to concatenate two variables while properly expanding
157 * them.
158 */
159#define igt_tokencat(x, y) __igt_tokencat2(x, y)
160
Daniel Vetterd63fe152014-03-12 01:29:52 +0100161/**
162 * igt_subtest:
Daniel Vetter55e64982014-03-12 02:34:40 +0100163 * @name: name of the subtest
Daniel Vetterd63fe152014-03-12 01:29:52 +0100164 *
Daniel Vetter55e64982014-03-12 02:34:40 +0100165 * This is a magic control flow block which denotes a subtest code block. Within
Thomas Wood519f3772014-09-26 14:24:52 +0100166 * that code block igt_skip|success will only bail out of the subtest. The _f
Daniel Vetter55e64982014-03-12 02:34:40 +0100167 * variant accepts a printf format string, which is useful for constructing
168 * combinatorial tests.
Daniel Vetterd63fe152014-03-12 01:29:52 +0100169 *
Daniel Vetter55e64982014-03-12 02:34:40 +0100170 * This is a simpler version of igt_subtest_f()
Daniel Vetterd63fe152014-03-12 01:29:52 +0100171 */
Daniel Vetter55e64982014-03-12 02:34:40 +0100172#define igt_subtest(name) for (; __igt_run_subtest((name)) && \
Chris Wilson578795f2015-05-08 14:35:37 +0100173 (sigsetjmp(igt_subtest_jmpbuf, 1) == 0); \
Daniel Vetter55e64982014-03-12 02:34:40 +0100174 igt_success())
Daniel Vetterd63fe152014-03-12 01:29:52 +0100175#define __igt_subtest_f(tmp, format...) \
176 for (char tmp [256]; \
177 snprintf( tmp , sizeof( tmp ), \
178 format), \
179 __igt_run_subtest( tmp ) && \
Chris Wilson578795f2015-05-08 14:35:37 +0100180 (sigsetjmp(igt_subtest_jmpbuf, 1) == 0); \
Daniel Vetterd63fe152014-03-12 01:29:52 +0100181 igt_success())
182
183/**
184 * igt_subtest_f:
Daniel Vetter55e64982014-03-12 02:34:40 +0100185 * @...: format string and optional arguments
Daniel Vetterd63fe152014-03-12 01:29:52 +0100186 *
Daniel Vetter55e64982014-03-12 02:34:40 +0100187 * This is a magic control flow block which denotes a subtest code block. Within
Thomas Wood519f3772014-09-26 14:24:52 +0100188 * that code block igt_skip|success will only bail out of the subtest. The _f
Daniel Vetter55e64982014-03-12 02:34:40 +0100189 * variant accepts a printf format string, which is useful for constructing
190 * combinatorial tests.
Daniel Vetterd63fe152014-03-12 01:29:52 +0100191 *
Daniel Vetter55e64982014-03-12 02:34:40 +0100192 * Like igt_subtest(), but also accepts a printf format string instead of a
193 * static string.
Daniel Vetterd63fe152014-03-12 01:29:52 +0100194 */
195#define igt_subtest_f(f...) \
196 __igt_subtest_f(igt_tokencat(__tmpchar, __LINE__), f)
Daniel Vetter55e64982014-03-12 02:34:40 +0100197
Daniel Vetterd63fe152014-03-12 01:29:52 +0100198const char *igt_subtest_name(void);
Daniel Vetter55e64982014-03-12 02:34:40 +0100199bool igt_only_list_subtests(void);
200
Daniel Vetter72d04b82016-03-18 21:46:54 +0100201void __igt_subtest_group_save(int *);
202void __igt_subtest_group_restore(int);
203/**
204 * igt_subtest_group:
205 *
206 * Group a set of subtests together with their common setup code
207 *
208 * Testcase with subtests often need to set up a bunch of shared state as the
209 * common test fixture. But if there are multiple with different requirements
210 * the commont setup code can't be extracted, since a test condition failure in
211 * e.g. igt_require() would result in all subsequent tests skipping. Even those
212 * from a different group.
213 *
214 * This macro allows to group together a set of #igt_fixture and #igt_subtest
215 * clauses. If any common setup in a fixture fails, only the subtests in this
216 * group will fail or skip. Subtest groups can be arbitrarily nested.
217 */
218#define igt_subtest_group for (int igt_tokencat(__tmpint,__LINE__) = 0, \
219 igt_tokencat(__save,__LINE__) = 0; \
220 igt_tokencat(__tmpint,__LINE__) < 1 && \
221 (__igt_subtest_group_save(& igt_tokencat(__save,__LINE__) ), true); \
222 igt_tokencat(__tmpint,__LINE__) ++, \
223 __igt_subtest_group_restore(igt_tokencat(__save,__LINE__) ))
224
Daniel Vetter55e64982014-03-12 02:34:40 +0100225/**
226 * igt_main:
227 *
228 * This is a magic control flow block used instead of a main() function for
229 * tests with subtests. Open-coding the main() function is only recommended if
Thomas Woodd01ebbd2015-06-29 16:47:14 +0100230 * the test needs to parse additional command line arguments of its own.
Daniel Vetter55e64982014-03-12 02:34:40 +0100231 */
Daniel Vetterd63fe152014-03-12 01:29:52 +0100232#define igt_main \
233 static void igt_tokencat(__real_main, __LINE__)(void); \
234 int main(int argc, char **argv) { \
Damien Lespiaufd6846c2015-05-14 14:19:01 +0100235 igt_subtest_init_parse_opts(&argc, argv, NULL, NULL, NULL, \
236 NULL, NULL); \
Daniel Vetterd63fe152014-03-12 01:29:52 +0100237 igt_tokencat(__real_main, __LINE__)(); \
238 igt_exit(); \
239 } \
240 static void igt_tokencat(__real_main, __LINE__)(void) \
241
Thomas Wood55cc1322015-02-17 15:10:13 +0000242
Chris Wilson77633492015-03-26 08:11:43 +0000243const char *igt_test_name(void);
Thomas Wood8fb19782015-02-18 16:19:59 +0000244void igt_simple_init_parse_opts(int *argc, char **argv,
Thomas Woode2cef002014-07-18 16:49:07 +0100245 const char *extra_short_opts,
Ville Syrjälä793aff12015-12-18 19:25:45 +0200246 const struct option *extra_long_opts,
Thomas Woode2cef002014-07-18 16:49:07 +0100247 const char *help_str,
Damien Lespiaufd6846c2015-05-14 14:19:01 +0100248 igt_opt_handler_t extra_opt_handler,
249 void *handler_data);
Daniel Vetter55e64982014-03-12 02:34:40 +0100250
251/**
Thomas Wood55cc1322015-02-17 15:10:13 +0000252 * igt_simple_init:
253 * @argc: argc from the test's main()
254 * @argv: argv from the test's main()
255 *
256 * This initializes a simple test without any support for subtests.
257 *
258 * If there's not a reason to the contrary it's less error prone to just use an
259 * #igt_simple_main block instead of stitching the test's main() function together
260 * manually.
261 */
Damien Lespiaufd6846c2015-05-14 14:19:01 +0100262#define igt_simple_init(argc, argv) \
263 igt_simple_init_parse_opts(&argc, argv, NULL, NULL, NULL, NULL, NULL);
Thomas Wood55cc1322015-02-17 15:10:13 +0000264
265/**
Daniel Vetter55e64982014-03-12 02:34:40 +0100266 * igt_simple_main:
267 *
268 * This is a magic control flow block used instead of a main() function for
269 * simple tests. Open-coding the main() function is only recommended if
Thomas Woodd01ebbd2015-06-29 16:47:14 +0100270 * the test needs to parse additional command line arguments of its own.
Daniel Vetter55e64982014-03-12 02:34:40 +0100271 */
Daniel Vetterd63fe152014-03-12 01:29:52 +0100272#define igt_simple_main \
273 static void igt_tokencat(__real_main, __LINE__)(void); \
274 int main(int argc, char **argv) { \
Damien Lespiaufd6846c2015-05-14 14:19:01 +0100275 igt_simple_init_parse_opts(&argc, argv, NULL, NULL, NULL, \
276 NULL, NULL); \
Daniel Vetterd63fe152014-03-12 01:29:52 +0100277 igt_tokencat(__real_main, __LINE__)(); \
Tim Goref33fa712014-09-29 13:34:30 +0100278 igt_exit(); \
Daniel Vetterd63fe152014-03-12 01:29:52 +0100279 } \
280 static void igt_tokencat(__real_main, __LINE__)(void) \
281
Lyude31811f42016-12-21 14:00:54 -0500282/**
283 * igt_constructor:
284 *
285 * Convenience macro to run the provided code block when igt first starts,
286 * before any tests have been run. This should be used for parts of the igt
287 * library that require initialization of objects with global context.
288 *
289 * This code block will be executed exactly once.
290 */
291#define igt_constructor \
292 __attribute__((constructor)) \
293 static void igt_tokencat(__igt_constructor_l, __LINE__)(void)
294
Daniel Vetterd63fe152014-03-12 01:29:52 +0100295__attribute__((format(printf, 1, 2)))
296void igt_skip(const char *f, ...) __attribute__((noreturn));
297__attribute__((format(printf, 5, 6)))
298void __igt_skip_check(const char *file, const int line,
299 const char *func, const char *check,
300 const char *format, ...) __attribute__((noreturn));
Chris Wilsonfb9c9e32014-09-06 12:21:25 +0100301#define igt_skip_check(E, F...) \
Thomas Woode6228502014-10-29 12:26:09 +0000302 __igt_skip_check(__FILE__, __LINE__, __func__, E, F)
Daniel Vetterd63fe152014-03-12 01:29:52 +0100303void igt_success(void);
304
Daniel Vetter2459b802017-08-14 11:32:04 +0200305bool igt_can_fail(void);
306
Daniel Vetterd63fe152014-03-12 01:29:52 +0100307void igt_fail(int exitcode) __attribute__((noreturn));
Thomas Woodb47032e2015-04-09 09:24:12 +0100308__attribute__((format(printf, 6, 7)))
309void __igt_fail_assert(const char *domain, const char *file,
Daniel Vetterd63fe152014-03-12 01:29:52 +0100310 const int line, const char *func, const char *assertion,
311 const char *format, ...)
312 __attribute__((noreturn));
Daniel Vetterd63fe152014-03-12 01:29:52 +0100313void igt_exit(void) __attribute__((noreturn));
Daniel Vetter55e64982014-03-12 02:34:40 +0100314
Daniel Vetterd63fe152014-03-12 01:29:52 +0100315/**
Chris Wilsond86d6eb2016-06-23 21:07:36 +0100316 * igt_ignore_warn:
317 * @expr: condition to ignore
318 *
319 *
320 * Stops the compiler warning about an unused return value.
321 */
322static inline void igt_ignore_warn(bool value)
323{
324}
325
326/**
Daniel Vetterd63fe152014-03-12 01:29:52 +0100327 * igt_assert:
Daniel Vetter55e64982014-03-12 02:34:40 +0100328 * @expr: condition to test
Daniel Vetterd63fe152014-03-12 01:29:52 +0100329 *
Daniel Vetter2347e6d2014-06-13 18:01:33 +0200330 * Fails (sub-)test if the condition is not met.
Daniel Vetterd63fe152014-03-12 01:29:52 +0100331 *
332 * Should be used everywhere where a test checks results.
333 */
334#define igt_assert(expr) \
335 do { if (!(expr)) \
Thomas Woodb47032e2015-04-09 09:24:12 +0100336 __igt_fail_assert(IGT_LOG_DOMAIN, __FILE__, __LINE__, __func__, #expr , NULL); \
Daniel Vetterd63fe152014-03-12 01:29:52 +0100337 } while (0)
Daniel Vetter55e64982014-03-12 02:34:40 +0100338
339/**
340 * igt_assert_f:
341 * @expr: condition to test
342 * @...: format string and optional arguments
343 *
Daniel Vetter2347e6d2014-06-13 18:01:33 +0200344 * Fails (sub-)test if the condition is not met.
Daniel Vetter55e64982014-03-12 02:34:40 +0100345 *
346 * Should be used everywhere where a test checks results.
347 *
348 * In addition to the plain igt_assert() helper this allows to print additional
349 * information to help debugging test failures.
350 */
Daniel Vetterd63fe152014-03-12 01:29:52 +0100351#define igt_assert_f(expr, f...) \
352 do { if (!(expr)) \
Thomas Woodb47032e2015-04-09 09:24:12 +0100353 __igt_fail_assert(IGT_LOG_DOMAIN, __FILE__, __LINE__, __func__, #expr , f); \
Daniel Vetterd63fe152014-03-12 01:29:52 +0100354 } while (0)
Daniel Vetter55e64982014-03-12 02:34:40 +0100355
Daniel Vetterd63fe152014-03-12 01:29:52 +0100356/**
Daniel Vetter2347e6d2014-06-13 18:01:33 +0200357 * igt_fail_on:
358 * @expr: condition to test
359 *
360 * Fails (sub-)test if the condition is met.
361 *
362 * Should be used everywhere where a test checks results.
363 */
364#define igt_fail_on(expr) igt_assert(!(expr))
365
366/**
Thomas Woodae3a9462014-11-25 11:59:37 +0000367 * igt_fail_on_f:
Daniel Vetter2347e6d2014-06-13 18:01:33 +0200368 * @expr: condition to test
369 * @...: format string and optional arguments
370 *
371 * Fails (sub-)test if the condition is met.
372 *
373 * Should be used everywhere where a test checks results.
374 *
375 * In addition to the plain igt_assert() helper this allows to print additional
376 * information to help debugging test failures.
377 */
378#define igt_fail_on_f(expr, f...) igt_assert_f(!(expr), f)
379
380/**
Daniel Vetter55e64982014-03-12 02:34:40 +0100381 * igt_assert_cmpint:
382 * @n1: first value
383 * @cmp: compare operator
Thomas Woodd4e3b6a2014-10-08 17:06:58 +0100384 * @ncmp: negated version of @cmp
Daniel Vetter55e64982014-03-12 02:34:40 +0100385 * @n2: second value
Daniel Vetterd63fe152014-03-12 01:29:52 +0100386 *
Daniel Vetter55e64982014-03-12 02:34:40 +0100387 * Fails (sub-)test if the condition is not met
388 *
389 * Should be used everywhere where a test compares two integer values.
390 *
391 * Like igt_assert(), but displays the values being compared on failure instead
392 * of simply printing the stringified expression.
Daniel Vetterd63fe152014-03-12 01:29:52 +0100393 */
Chris Wilson3b94d3f2014-08-29 13:11:40 +0100394#define igt_assert_cmpint(n1, cmp, ncmp, n2) \
Daniel Vetterd63fe152014-03-12 01:29:52 +0100395 do { \
396 int __n1 = (n1), __n2 = (n2); \
397 if (__n1 cmp __n2) ; else \
Thomas Woodb47032e2015-04-09 09:24:12 +0100398 __igt_fail_assert(IGT_LOG_DOMAIN, __FILE__, __LINE__, __func__, \
Daniel Vetterd63fe152014-03-12 01:29:52 +0100399 #n1 " " #cmp " " #n2, \
Chris Wilsond28b9d22014-08-29 17:30:40 +0100400 "error: %d " #ncmp " %d\n", __n1, __n2); \
Chris Wilson3b94d3f2014-08-29 13:11:40 +0100401 } while (0)
402
Damien Lespiau23888522015-06-27 15:26:13 +0100403/**
404 * igt_assert_cmpuint:
405 * @n1: first value
406 * @cmp: compare operator
407 * @ncmp: negated version of @cmp
408 * @n2: second value
409 *
Thomas Woodd01ebbd2015-06-29 16:47:14 +0100410 * Like igt_assert_cmpint(), but for unsigned ints.
Damien Lespiau23888522015-06-27 15:26:13 +0100411 */
Chris Wilson3b94d3f2014-08-29 13:11:40 +0100412#define igt_assert_cmpuint(n1, cmp, ncmp, n2) \
413 do { \
414 uint32_t __n1 = (n1), __n2 = (n2); \
415 if (__n1 cmp __n2) ; else \
Thomas Woodb47032e2015-04-09 09:24:12 +0100416 __igt_fail_assert(IGT_LOG_DOMAIN, __FILE__, __LINE__, __func__, \
Chris Wilson3b94d3f2014-08-29 13:11:40 +0100417 #n1 " " #cmp " " #n2, \
Chris Wilsond28b9d22014-08-29 17:30:40 +0100418 "error: %#x " #ncmp " %#x\n", __n1, __n2); \
Daniel Vetterd63fe152014-03-12 01:29:52 +0100419 } while (0)
420
421/**
Chris Wilson9c2be692016-10-12 14:41:46 +0100422 * igt_assert_cmps64:
423 * @n1: first value
424 * @cmp: compare operator
425 * @ncmp: negated version of @cmp
426 * @n2: second value
427 *
428 * Like igt_assert_cmpuint(), but for larger signed ints.
429 */
430#define igt_assert_cmps64(n1, cmp, ncmp, n2) \
431 do { \
432 int64_t __n1 = (n1), __n2 = (n2); \
433 if (__n1 cmp __n2) ; else \
434 __igt_fail_assert(IGT_LOG_DOMAIN, __FILE__, __LINE__, __func__, \
435 #n1 " " #cmp " " #n2, \
436 "error: %lld " #ncmp " %lld\n", (long long)__n1, (long long)__n2); \
437 } while (0)
438
439/**
Chris Wilson40ebf952015-07-28 18:59:47 +0100440 * igt_assert_cmpu64:
441 * @n1: first value
442 * @cmp: compare operator
443 * @ncmp: negated version of @cmp
444 * @n2: second value
445 *
446 * Like igt_assert_cmpuint(), but for larger ints.
447 */
448#define igt_assert_cmpu64(n1, cmp, ncmp, n2) \
449 do { \
450 uint64_t __n1 = (n1), __n2 = (n2); \
451 if (__n1 cmp __n2) ; else \
452 __igt_fail_assert(IGT_LOG_DOMAIN, __FILE__, __LINE__, __func__, \
453 #n1 " " #cmp " " #n2, \
454 "error: %#llx " #ncmp " %#llx\n", (long long)__n1, (long long)__n2); \
455 } while (0)
456
457/**
Damien Lespiau0a38e972015-06-27 15:26:50 +0100458 * igt_assert_cmpdouble:
459 * @n1: first value
460 * @cmp: compare operator
461 * @ncmp: negated version of @cmp
462 * @n2: second value
463 *
Thomas Woodd01ebbd2015-06-29 16:47:14 +0100464 * Like igt_assert_cmpint(), but for doubles.
Damien Lespiau0a38e972015-06-27 15:26:50 +0100465 */
466#define igt_assert_cmpdouble(n1, cmp, ncmp, n2) \
467 do { \
468 double __n1 = (n1), __n2 = (n2); \
469 if (__n1 cmp __n2) ; else \
470 __igt_fail_assert(IGT_LOG_DOMAIN, __FILE__, __LINE__, __func__, \
471 #n1 " " #cmp " " #n2, \
472 "error: %#lf " #ncmp " %#lf\n", __n1, __n2); \
473 } while (0)
474
475/**
Daniel Vetter3448b5a2014-06-13 10:46:55 +0200476 * igt_assert_eq:
477 * @n1: first integer
478 * @n2: second integer
479 *
480 * Fails (sub-)test if the two integers are not equal. Beware that for now this
481 * only works on integers.
482 *
483 * Like igt_assert(), but displays the values being compared on failure instead
484 * of simply printing the stringified expression.
485 */
Chris Wilson3b94d3f2014-08-29 13:11:40 +0100486#define igt_assert_eq(n1, n2) igt_assert_cmpint(n1, ==, !=, n2)
Damien Lespiauf660d0a2015-06-27 15:16:22 +0100487
488/**
489 * igt_assert_eq_u32:
490 * @n1: first integer
491 * @n2: second integer
492 *
493 * Like igt_assert_eq(), but for uint32_t.
494 */
Chris Wilson3b94d3f2014-08-29 13:11:40 +0100495#define igt_assert_eq_u32(n1, n2) igt_assert_cmpuint(n1, ==, !=, n2)
496
497/**
Chris Wilson9c2be692016-10-12 14:41:46 +0100498 * igt_assert_eq_s64:
499 * @n1: first integer
500 * @n2: second integer
501 *
502 * Like igt_assert_eq_u32(), but for int64_t.
503 */
504#define igt_assert_eq_s64(n1, n2) igt_assert_cmps64(n1, ==, !=, n2)
505
506/**
Chris Wilson40ebf952015-07-28 18:59:47 +0100507 * igt_assert_eq_u64:
508 * @n1: first integer
509 * @n2: second integer
510 *
511 * Like igt_assert_eq_u32(), but for uint64_t.
512 */
513#define igt_assert_eq_u64(n1, n2) igt_assert_cmpu64(n1, ==, !=, n2)
514
515/**
Damien Lespiau0a38e972015-06-27 15:26:50 +0100516 * igt_assert_eq_double:
517 * @n1: first double
518 * @n2: second double
519 *
520 * Like igt_assert_eq(), but for doubles.
521 */
522#define igt_assert_eq_double(n1, n2) igt_assert_cmpdouble(n1, ==, !=, n2)
523
524/**
Chris Wilson3b94d3f2014-08-29 13:11:40 +0100525 * igt_assert_neq:
526 * @n1: first integer
527 * @n2: second integer
528 *
529 * Fails (sub-)test if the two integers are equal. Beware that for now this
530 * only works on integers.
531 *
532 * Like igt_assert(), but displays the values being compared on failure instead
533 * of simply printing the stringified expression.
534 */
535#define igt_assert_neq(n1, n2) igt_assert_cmpint(n1, !=, ==, n2)
536
537/**
Daniel Stone715a17b2015-10-01 13:00:12 +0100538 * igt_assert_neq_u32:
539 * @n1: first integer
540 * @n2: second integer
541 *
542 * Like igt_assert_neq(), but for uint32_t.
543 */
544#define igt_assert_neq_u32(n1, n2) igt_assert_cmpuint(n1, !=, ==, n2)
545
546/**
547 * igt_assert_neq_u64:
548 * @n1: first integer
549 * @n2: second integer
550 *
551 * Like igt_assert_neq_u32(), but for uint64_t.
552 */
553#define igt_assert_neq_u64(n1, n2) igt_assert_cmpu64(n1, !=, ==, n2)
554
555/**
556 * igt_assert_neq_double:
557 * @n1: first double
558 * @n2: second double
559 *
560 * Like igt_assert_neq(), but for doubles.
561 */
562#define igt_assert_neq_double(n1, n2) igt_assert_cmpdouble(n1, !=, ==, n2)
563
564/**
Chris Wilson3b94d3f2014-08-29 13:11:40 +0100565 * igt_assert_lte:
566 * @n1: first integer
567 * @n2: second integer
568 *
Daniel Vetterc9112dc2015-10-02 12:56:16 +0200569 * Fails (sub-)test if the second integer is strictly smaller than the first.
Chris Wilson3b94d3f2014-08-29 13:11:40 +0100570 * Beware that for now this only works on integers.
571 *
572 * Like igt_assert(), but displays the values being compared on failure instead
573 * of simply printing the stringified expression.
574 */
575#define igt_assert_lte(n1, n2) igt_assert_cmpint(n1, <=, >, n2)
Daniel Vetter3448b5a2014-06-13 10:46:55 +0200576
577/**
Daniel Vetter305fb1d2015-02-27 16:24:25 +0100578 * igt_assert_lt:
579 * @n1: first integer
580 * @n2: second integer
581 *
Daniel Vetterc9112dc2015-10-02 12:56:16 +0200582 * Fails (sub-)test if the second integer is smaller than or equal to the first.
Daniel Vetter305fb1d2015-02-27 16:24:25 +0100583 * Beware that for now this only works on integers.
584 *
585 * Like igt_assert(), but displays the values being compared on failure instead
586 * of simply printing the stringified expression.
587 */
588#define igt_assert_lt(n1, n2) igt_assert_cmpint(n1, <, >=, n2)
589
590/**
Daniel Stone6ead44d2015-10-01 13:26:36 +0100591 * igt_assert_fd:
592 * @fd: file descriptor
593 *
594 * Fails (sub-) test if the given file descriptor is invalid.
595 *
596 * Like igt_assert(), but displays the values being compared on failure instead
597 * of simply printing the stringified expression.
598 */
599#define igt_assert_fd(fd) \
600 igt_assert_f(fd >= 0, "file descriptor " #fd " failed\n");
601
602/**
Daniel Vetterd63fe152014-03-12 01:29:52 +0100603 * igt_require:
Daniel Vetter55e64982014-03-12 02:34:40 +0100604 * @expr: condition to test
Daniel Vetterd63fe152014-03-12 01:29:52 +0100605 *
Daniel Vetter55e64982014-03-12 02:34:40 +0100606 * Skip a (sub-)test if a condition is not met.
Daniel Vetterd63fe152014-03-12 01:29:52 +0100607 *
Daniel Vetter55e64982014-03-12 02:34:40 +0100608 * Should be used everywhere where a test checks results to decide about
609 * skipping. This is useful to streamline the skip logic since it allows for a more flat
610 * code control flow, similar to igt_assert()
Daniel Vetterd63fe152014-03-12 01:29:52 +0100611 */
Chris Wilsonfb9c9e32014-09-06 12:21:25 +0100612#define igt_require(expr) do { \
613 if (!(expr)) igt_skip_check(#expr , NULL); \
Paulo Zanonia1fce742015-08-13 13:49:42 -0300614 else igt_debug("Test requirement passed: %s\n", #expr); \
Chris Wilsonfb9c9e32014-09-06 12:21:25 +0100615} while (0)
Daniel Vetter55e64982014-03-12 02:34:40 +0100616
617/**
618 * igt_skip_on:
619 * @expr: condition to test
620 *
621 * Skip a (sub-)test if a condition is met.
622 *
623 * Should be used everywhere where a test checks results to decide about
624 * skipping. This is useful to streamline the skip logic since it allows for a more flat
625 * code control flow, similar to igt_assert()
626 */
Chris Wilsonfb9c9e32014-09-06 12:21:25 +0100627#define igt_skip_on(expr) do { \
628 if ((expr)) igt_skip_check("!(" #expr ")" , NULL); \
Paulo Zanonia1fce742015-08-13 13:49:42 -0300629 else igt_debug("Test requirement passed: !(%s)\n", #expr); \
Chris Wilsonfb9c9e32014-09-06 12:21:25 +0100630} while (0)
Daniel Vetter55e64982014-03-12 02:34:40 +0100631
632/**
633 * igt_require_f:
634 * @expr: condition to test
635 * @...: format string and optional arguments
636 *
637 * Skip a (sub-)test if a condition is not met.
638 *
639 * Should be used everywhere where a test checks results to decide about
640 * skipping. This is useful to streamline the skip logic since it allows for a more flat
641 * code control flow, similar to igt_assert()
642 *
643 * In addition to the plain igt_require() helper this allows to print additional
644 * information to help debugging test failures.
645 */
Chris Wilsonfb9c9e32014-09-06 12:21:25 +0100646#define igt_require_f(expr, f...) do { \
647 if (!(expr)) igt_skip_check(#expr , f); \
Paulo Zanonia1fce742015-08-13 13:49:42 -0300648 else igt_debug("Test requirement passed: %s\n", #expr); \
Chris Wilsonfb9c9e32014-09-06 12:21:25 +0100649} while (0)
Daniel Vetter55e64982014-03-12 02:34:40 +0100650
651/**
652 * igt_skip_on_f:
653 * @expr: condition to test
654 * @...: format string and optional arguments
655 *
656 * Skip a (sub-)test if a condition is met.
657 *
658 * Should be used everywhere where a test checks results to decide about
659 * skipping. This is useful to streamline the skip logic since it allows for a more flat
660 * code control flow, similar to igt_assert()
661 *
662 * In addition to the plain igt_skip_on() helper this allows to print additional
663 * information to help debugging test failures.
664 */
Chris Wilsonfb9c9e32014-09-06 12:21:25 +0100665#define igt_skip_on_f(expr, f...) do { \
Thomas Woodd950f372014-10-29 12:03:22 +0000666 if ((expr)) igt_skip_check("!("#expr")", f); \
Paulo Zanonia1fce742015-08-13 13:49:42 -0300667 else igt_debug("Test requirement passed: !(%s)\n", #expr); \
Chris Wilsonfb9c9e32014-09-06 12:21:25 +0100668} while (0)
Daniel Vetterd63fe152014-03-12 01:29:52 +0100669
670/* fork support code */
671bool __igt_fork(void);
Daniel Vetter55e64982014-03-12 02:34:40 +0100672
Daniel Vetterd63fe152014-03-12 01:29:52 +0100673/**
674 * igt_fork:
675 * @child: name of the int variable with the child number
676 * @num_children: number of children to fork
677 *
Daniel Vetter55e64982014-03-12 02:34:40 +0100678 * This is a magic control flow block which spawns parallel test threads with
679 * fork().
Daniel Vetterd63fe152014-03-12 01:29:52 +0100680 *
Daniel Vetter55e64982014-03-12 02:34:40 +0100681 * The test children execute in parallel to the main test thread. Joining all
682 * test threads should be done with igt_waitchildren to ensure that the exit
683 * codes of all children are properly reflected in the test status.
684 *
685 * Note that igt_skip() will not be forwarded, feature tests need to be done
686 * before spawning threads with igt_fork().
Daniel Vetterd63fe152014-03-12 01:29:52 +0100687 */
688#define igt_fork(child, num_children) \
689 for (int child = 0; child < (num_children); child++) \
690 for (; __igt_fork(); exit(0))
Tvrtko Ursulin054eb1a2017-03-30 14:32:29 +0100691void igt_child_done(pid_t pid);
Daniel Vetterd63fe152014-03-12 01:29:52 +0100692void igt_waitchildren(void);
Chris Wilson75487632016-02-26 22:11:10 +0000693void igt_waitchildren_timeout(int seconds, const char *reason);
Daniel Vetterd63fe152014-03-12 01:29:52 +0100694
Daniel Vetter55e64982014-03-12 02:34:40 +0100695/**
Thomas Wood26f40812015-02-20 11:31:01 +0000696 * igt_helper_process:
Daniel Vetter55e64982014-03-12 02:34:40 +0100697 * @running: indicates whether the process is currently running
Chris Wilson4f7d4dc2014-07-21 07:54:29 +0100698 * @use_SIGKILL: whether the helper should be terminated with SIGKILL or SIGTERM
Daniel Vetter55e64982014-03-12 02:34:40 +0100699 * @pid: pid of the helper if @running is true
700 * @id: internal id
701 *
702 * Tracking structure for helper processes. Users of the i-g-t library should
703 * only set @use_SIGKILL directly.
704 */
Daniel Vetterd63fe152014-03-12 01:29:52 +0100705struct igt_helper_process {
706 bool running;
707 bool use_SIGKILL;
708 pid_t pid;
709 int id;
710};
711bool __igt_fork_helper(struct igt_helper_process *proc);
Daniel Vetter55e64982014-03-12 02:34:40 +0100712
713/**
714 * igt_fork_helper:
715 * @proc: #igt_helper_process structure
716 *
717 * This is a magic control flow block which denotes an asynchronous helper
718 * process block. The difference compared to igt_fork() is that failures from
719 * the child process will not be forwarded, making this construct more suitable
720 * for background processes. Common use cases are regular interference of the
721 * main test thread through e.g. sending signals or evicting objects through
722 * debugfs. Through the explicit #igt_helper_process they can also be controlled
723 * in a more fine-grained way than test children spawned through igt_fork().
724 *
725 * For tests with subtest helper process can be started outside of a
726 * #igt_subtest block.
727 *
728 * Calling igt_wait_helper() joins a helper process and igt_stop_helper()
729 * forcefully terminates it.
730 */
Daniel Vetterd63fe152014-03-12 01:29:52 +0100731#define igt_fork_helper(proc) \
732 for (; __igt_fork_helper(proc); exit(0))
Chris Wilson74594552014-07-24 11:44:45 +0100733int igt_wait_helper(struct igt_helper_process *proc);
Daniel Vetter55e64982014-03-12 02:34:40 +0100734void igt_stop_helper(struct igt_helper_process *proc);
Daniel Vetterd63fe152014-03-12 01:29:52 +0100735
736/* exit handler code */
Daniel Vetter55e64982014-03-12 02:34:40 +0100737
738/**
739 * igt_exit_handler_t:
740 * @sig: Signal number which caused the exit or 0.
741 *
742 * Exit handler type used by igt_install_exit_handler(). Note that exit handlers
743 * can potentially be run from signal handling contexts, the @sig parameter can
744 * be used to figure this out and act accordingly.
745 */
Daniel Vetterd63fe152014-03-12 01:29:52 +0100746typedef void (*igt_exit_handler_t)(int sig);
747
748/* reliable atexit helpers, also work when killed by a signal (if possible) */
749void igt_install_exit_handler(igt_exit_handler_t fn);
Daniel Vetterd63fe152014-03-12 01:29:52 +0100750
751/* helpers to automatically reduce test runtime in simulation */
752bool igt_run_in_simulation(void);
Daniel Vetterd63fe152014-03-12 01:29:52 +0100753/**
Daniel Vetter55e64982014-03-12 02:34:40 +0100754 * SLOW_QUICK:
755 * @slow: value in simulation mode
756 * @quick: value in normal mode
Daniel Vetterd63fe152014-03-12 01:29:52 +0100757 *
Daniel Vetter55e64982014-03-12 02:34:40 +0100758 * Simple macro to select between two values (e.g. number of test rounds or test
759 * buffer size) depending upon whether i-g-t is run in simulation mode or not.
Daniel Vetterd63fe152014-03-12 01:29:52 +0100760 */
Daniel Vetter55e64982014-03-12 02:34:40 +0100761#define SLOW_QUICK(slow,quick) (igt_run_in_simulation() ? (quick) : (slow))
762
Daniel Vetterd63fe152014-03-12 01:29:52 +0100763void igt_skip_on_simulation(void);
764
Thomas Wooda6c40c72015-03-12 14:59:20 +0000765extern const char *igt_interactive_debug;
Rodrigo Vivi3d65ff72015-01-12 10:21:58 -0800766
Daniel Vetter6d63c882016-07-27 14:16:07 +0200767/**
768 * igt_log_level:
769 * @IGT_LOG_DEBUG: debug information, not printed by default
770 * @IGT_LOG_INFO: informational message, printed by default
771 * @IGT_LOG_WARN: non-fatal warnings which should be treated as test failures
772 * @IGT_LOG_CRITICAL: critical errors which lead to immediate termination of tests
773 * @IGT_LOG_NONE: unused
774 *
775 * Log levels used by functions like igt_log().
776 */
Daniel Vetterd63fe152014-03-12 01:29:52 +0100777enum igt_log_level {
778 IGT_LOG_DEBUG,
779 IGT_LOG_INFO,
780 IGT_LOG_WARN,
Thomas Wooddf11a0f2014-12-16 15:18:20 +0000781 IGT_LOG_CRITICAL,
Daniel Vetterd63fe152014-03-12 01:29:52 +0100782 IGT_LOG_NONE,
783};
Thomas Wood8161a212014-12-02 10:54:54 +0000784__attribute__((format(printf, 3, 4)))
785void igt_log(const char *domain, enum igt_log_level level, const char *format, ...);
786__attribute__((format(printf, 3, 0)))
787void igt_vlog(const char *domain, enum igt_log_level level, const char *format, va_list args);
Daniel Vetter55e64982014-03-12 02:34:40 +0100788
789/**
790 * igt_debug:
791 * @...: format string and optional arguments
792 *
Daniel Vetter3f505982014-07-14 23:02:18 +0200793 * Wrapper for igt_log() for message at the IGT_LOG_DEBUG level.
Daniel Vetter55e64982014-03-12 02:34:40 +0100794 */
Thomas Wood8161a212014-12-02 10:54:54 +0000795#define igt_debug(f...) igt_log(IGT_LOG_DOMAIN, IGT_LOG_DEBUG, f)
Daniel Vetter55e64982014-03-12 02:34:40 +0100796
797/**
798 * igt_info:
799 * @...: format string and optional arguments
800 *
Daniel Vetter3f505982014-07-14 23:02:18 +0200801 * Wrapper for igt_log() for message at the IGT_LOG_INFO level.
Daniel Vetter55e64982014-03-12 02:34:40 +0100802 */
Thomas Wood8161a212014-12-02 10:54:54 +0000803#define igt_info(f...) igt_log(IGT_LOG_DOMAIN, IGT_LOG_INFO, f)
Daniel Vetter55e64982014-03-12 02:34:40 +0100804
805/**
806 * igt_warn:
807 * @...: format string and optional arguments
808 *
Daniel Vetter3f505982014-07-14 23:02:18 +0200809 * Wrapper for igt_log() for message at the IGT_LOG_WARN level.
Daniel Vetter55e64982014-03-12 02:34:40 +0100810 */
Thomas Wood8161a212014-12-02 10:54:54 +0000811#define igt_warn(f...) igt_log(IGT_LOG_DOMAIN, IGT_LOG_WARN, f)
Thomas Wooddf11a0f2014-12-16 15:18:20 +0000812
813/**
814 * igt_critical:
815 * @...: format string and optional arguments
816 *
817 * Wrapper for igt_log() for message at the IGT_LOG_CRITICAL level.
818 */
819#define igt_critical(f...) igt_log(IGT_LOG_DOMAIN, IGT_LOG_CRITICAL, f)
820
Abdiel Janulgueef48fc82017-04-13 16:18:37 +0300821typedef bool (*igt_buffer_log_handler_t)(const char *line, void *data);
822void igt_log_buffer_inspect(igt_buffer_log_handler_t check, void *data);
823
Daniel Vetterd63fe152014-03-12 01:29:52 +0100824extern enum igt_log_level igt_log_level;
825
Daniel Vetter55e64982014-03-12 02:34:40 +0100826/**
827 * igt_warn_on:
828 * @condition: condition to test
829 *
830 * Print a IGT_LOG_WARN level message if a condition is not met.
831 *
832 * Should be used everywhere where a test checks results to decide about
833 * printing warnings. This is useful to streamline the test logic since it
834 * allows for a more flat code control flow, similar to igt_assert()
Lyudebcd7ed62017-02-07 12:50:47 -0500835 *
836 * This macro also returns the value of @condition.
Daniel Vetter55e64982014-03-12 02:34:40 +0100837 */
Lyudebcd7ed62017-02-07 12:50:47 -0500838#define igt_warn_on(condition) ({ \
839 typeof(condition) ret__ = (condition); \
840 if (ret__) \
841 igt_warn("Warning on condition %s in function %s, file %s:%i\n", \
Daniel Vetterd63fe152014-03-12 01:29:52 +0100842 #condition, __func__, __FILE__, __LINE__); \
Lyudebcd7ed62017-02-07 12:50:47 -0500843 ret__; \
844 })
Daniel Vetter55e64982014-03-12 02:34:40 +0100845
846/**
847 * igt_warn_on_f:
848 * @condition: condition to test
849 * @...: format string and optional arguments
850 *
851 * Skip a (sub-)test if a condition is not met.
852 *
853 * Print a IGT_LOG_WARN level message if a condition is not met.
854 *
855 * Should be used everywhere where a test checks results to decide about
856 * printing warnings. This is useful to streamline the test logic since it
857 * allows for a more flat code control flow, similar to igt_assert()
858 *
859 * In addition to the plain igt_warn_on_f() helper this allows to print
860 * additional information (again as warnings) to help debugging test failures.
Lyudebcd7ed62017-02-07 12:50:47 -0500861 *
862 * It also returns the value of @condition.
Daniel Vetter55e64982014-03-12 02:34:40 +0100863 */
Lyudebcd7ed62017-02-07 12:50:47 -0500864#define igt_warn_on_f(condition, f...) ({ \
865 typeof(condition) ret__ = (condition); \
866 if (ret__) {\
867 igt_warn("Warning on condition %s in function %s, file %s:%i\n", \
Daniel Vetterd63fe152014-03-12 01:29:52 +0100868 #condition, __func__, __FILE__, __LINE__); \
869 igt_warn(f); \
870 } \
Lyudebcd7ed62017-02-07 12:50:47 -0500871 ret__; \
872 })
Daniel Vetterd63fe152014-03-12 01:29:52 +0100873
Daniel Vetter370c9892015-08-07 19:01:23 +0200874void igt_set_timeout(unsigned int seconds,
875 const char *op);
Thomas Woodd8e53132014-05-12 10:19:52 +0100876
Chris Wilsondcb39b52016-03-18 09:04:07 +0000877/**
878 * igt_nsec_elapsed:
879 * @start: measure from this point in time
880 *
881 * Reports the difference in the monotonic clock from the start time
882 * in nanoseconds. On the first invocation, start should be zeroed and will
883 * be set by the call.
884 *
885 * Typical use would be:
886 *
887 * igt_subtest("test") {
888 * struct timespec start = {};
889 * while (igt_nsec_elapsed(&start) < test_timeout_ns)
890 * do_test();
891 * }
892 *
893 * A handy approximation is to use nsec >> 30 to convert to seconds,
894 * nsec >> 20 to convert to milliseconds - the error is about 8%, acceptable
895 * for test run times.
896 */
897uint64_t igt_nsec_elapsed(struct timespec *start);
898
899/**
900 * igt_seconds_elapsed:
901 * @start: measure from this point in time
902 *
903 * A wrapper around igt_nsec_elapsed that reports the approximate (8% error)
904 * number of seconds since the start point.
905 */
906static inline uint32_t igt_seconds_elapsed(struct timespec *start)
907{
908 return igt_nsec_elapsed(start) >> 30;
909}
910
Daniel Vetter5b0a8432015-08-07 19:12:07 +0200911void igt_reset_timeout(void);
912
Joonas Lahtinena95033f2015-03-31 15:53:17 +0300913FILE *__igt_fopen_data(const char* igt_srcdir, const char* igt_datadir,
914 const char* filename);
915/**
916 * igt_fopen_data:
917 * @filename: filename to open.
918 *
Matt Roper303b3802016-05-26 16:02:05 -0700919 * Open a datafile for test, first try from installation directory,
920 * then from build directory, and finally from current directory.
Joonas Lahtinena95033f2015-03-31 15:53:17 +0300921 */
922#define igt_fopen_data(filename) \
923 __igt_fopen_data(IGT_SRCDIR, IGT_DATADIR, filename)
924
Abdiel Janulgue51f4f9f2017-04-13 13:43:20 +0300925int igt_system(const char *command);
926int igt_system_quiet(const char *command);
927#define igt_system_cmd(status, format...) \
928 do { \
929 char *buf = 0; \
930 igt_assert(asprintf(&buf, format) != -1); \
931 status = igt_system(buf); \
932 free(buf); \
933 } while (0)
934
Daniel Vetterd63fe152014-03-12 01:29:52 +0100935#endif /* IGT_CORE_H */