Eric Anholt | 8c64183 | 2009-03-26 17:15:11 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2007 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 | * |
| 26 | */ |
| 27 | |
Chris Wilson | d0ed912 | 2013-08-29 15:11:47 +0100 | [diff] [blame] | 28 | #ifndef DRMTEST_H |
| 29 | #define DRMTEST_H |
| 30 | |
Eric Anholt | 8c64183 | 2009-03-26 17:15:11 -0700 | [diff] [blame] | 31 | #include <stdio.h> |
| 32 | #include <stdlib.h> |
| 33 | #include <unistd.h> |
| 34 | #include <assert.h> |
| 35 | #include <errno.h> |
Daniel Vetter | afbdc7a | 2012-03-22 13:47:57 +0100 | [diff] [blame] | 36 | #include <stdbool.h> |
Daniel Vetter | 662d732 | 2012-05-22 14:37:19 +0200 | [diff] [blame] | 37 | #include <cairo.h> |
Daniel Vetter | ba0d2ac | 2013-08-12 09:31:55 +0200 | [diff] [blame] | 38 | #include <setjmp.h> |
Daniel Vetter | 225a91b | 2013-09-03 10:38:29 +0200 | [diff] [blame] | 39 | #include <sys/mman.h> |
Eric Anholt | 8c64183 | 2009-03-26 17:15:11 -0700 | [diff] [blame] | 40 | |
| 41 | #include "xf86drm.h" |
Daniel Vetter | 17787f3 | 2012-05-22 16:15:15 +0200 | [diff] [blame] | 42 | #include "xf86drmMode.h" |
Daniel Vetter | 8f5387e | 2013-08-13 13:20:58 +0200 | [diff] [blame] | 43 | #include "i915_drm.h" |
Daniel Vetter | d75d69d | 2012-01-15 18:32:11 +0100 | [diff] [blame] | 44 | #include "intel_batchbuffer.h" |
Daniel Vetter | 7847ea2 | 2013-08-12 11:03:29 +0200 | [diff] [blame] | 45 | #include "intel_chipset.h" |
| 46 | #include "intel_gpu_tools.h" |
Eric Anholt | 8c64183 | 2009-03-26 17:15:11 -0700 | [diff] [blame] | 47 | |
Daniel Vetter | df7edaa | 2012-10-02 10:32:10 +0200 | [diff] [blame] | 48 | drm_intel_bo * gem_handle_to_libdrm_bo(drm_intel_bufmgr *bufmgr, int fd, |
| 49 | const char *name, uint32_t handle); |
| 50 | |
Daniel Vetter | 5951ffb | 2013-08-19 10:34:34 +0200 | [diff] [blame] | 51 | int drm_get_card(void); |
Eric Anholt | 8c64183 | 2009-03-26 17:15:11 -0700 | [diff] [blame] | 52 | int drm_open_any(void); |
Daniel Vetter | aa67b22 | 2012-01-10 14:59:58 +0100 | [diff] [blame] | 53 | |
Daniel Vetter | 9f87660 | 2012-01-11 17:19:53 +0100 | [diff] [blame] | 54 | void gem_quiescent_gpu(int fd); |
Daniel Vetter | aa67b22 | 2012-01-10 14:59:58 +0100 | [diff] [blame] | 55 | |
Daniel Vetter | d75d69d | 2012-01-15 18:32:11 +0100 | [diff] [blame] | 56 | /* ioctl wrappers and similar stuff for bare metal testing */ |
Daniel Vetter | aa67b22 | 2012-01-10 14:59:58 +0100 | [diff] [blame] | 57 | void gem_set_tiling(int fd, uint32_t handle, int tiling, int stride); |
Zhong Li | 8ddf84d | 2013-05-03 15:54:48 +0800 | [diff] [blame] | 58 | bool gem_has_enable_ring(int fd,int param); |
| 59 | bool gem_has_bsd(int fd); |
| 60 | bool gem_has_blt(int fd); |
| 61 | bool gem_has_vebox(int fd); |
| 62 | int gem_get_num_rings(int fd); |
Daniel Vetter | 7847ea2 | 2013-08-12 11:03:29 +0200 | [diff] [blame] | 63 | |
Daniel Vetter | 7553ad6 | 2013-08-12 10:43:59 +0200 | [diff] [blame] | 64 | void gem_set_caching(int fd, uint32_t handle, int caching); |
Daniel Vetter | 40ea6f4 | 2013-08-12 08:41:05 +0200 | [diff] [blame] | 65 | uint32_t gem_get_caching(int fd, uint32_t handle); |
Daniel Vetter | 8e46c38 | 2013-07-23 22:43:30 +0200 | [diff] [blame] | 66 | uint32_t gem_flink(int fd, uint32_t handle); |
| 67 | uint32_t gem_open(int fd, uint32_t name); |
Daniel Vetter | 5dd17d3 | 2012-01-10 15:07:19 +0100 | [diff] [blame] | 68 | void gem_close(int fd, uint32_t handle); |
Daniel Vetter | 319638b | 2012-01-10 15:31:11 +0100 | [diff] [blame] | 69 | void gem_write(int fd, uint32_t handle, uint32_t offset, const void *buf, uint32_t size); |
Daniel Vetter | bd5cf9a | 2012-01-10 15:37:53 +0100 | [diff] [blame] | 70 | void gem_read(int fd, uint32_t handle, uint32_t offset, void *buf, uint32_t size); |
Daniel Vetter | 673e6b2 | 2012-01-10 16:05:34 +0100 | [diff] [blame] | 71 | void gem_set_domain(int fd, uint32_t handle, |
| 72 | uint32_t read_domains, uint32_t write_domain); |
| 73 | void gem_sync(int fd, uint32_t handle); |
Daniel Vetter | 7a6042e | 2012-01-10 18:29:30 +0100 | [diff] [blame] | 74 | uint32_t gem_create(int fd, int size); |
Daniel Vetter | 9cc16e8 | 2013-09-03 10:37:14 +0200 | [diff] [blame] | 75 | void gem_execbuf(int fd, struct drm_i915_gem_execbuffer2 *execbuf); |
Chris Wilson | 77586dc | 2012-06-04 17:29:20 +0100 | [diff] [blame] | 76 | |
| 77 | void *gem_mmap__gtt(int fd, uint32_t handle, int size, int prot); |
| 78 | void *gem_mmap__cpu(int fd, uint32_t handle, int size, int prot); |
| 79 | #define gem_mmap gem_mmap__gtt |
| 80 | |
Daniel Vetter | 7f94434 | 2012-01-15 17:14:56 +0100 | [diff] [blame] | 81 | uint64_t gem_aperture_size(int fd); |
Daniel Vetter | 7b14b09 | 2012-01-15 17:40:41 +0100 | [diff] [blame] | 82 | uint64_t gem_mappable_aperture_size(void); |
Daniel Vetter | 16c4f52 | 2012-03-20 14:24:14 +0100 | [diff] [blame] | 83 | int gem_madvise(int fd, uint32_t handle, int state); |
Daniel Vetter | cbaa8a3 | 2012-01-11 15:33:00 +0100 | [diff] [blame] | 84 | |
Daniel Vetter | 9ad062d | 2013-08-19 10:55:28 +0200 | [diff] [blame] | 85 | uint32_t gem_context_create(int fd); |
| 86 | |
Daniel Vetter | afbdc7a | 2012-03-22 13:47:57 +0100 | [diff] [blame] | 87 | /* feature test helpers */ |
| 88 | bool gem_uses_aliasing_ppgtt(int fd); |
Daniel Vetter | cf72da5 | 2012-04-22 12:35:23 +0200 | [diff] [blame] | 89 | int gem_available_fences(int fd); |
Daniel Vetter | afbdc7a | 2012-03-22 13:47:57 +0100 | [diff] [blame] | 90 | |
Daniel Vetter | 6bc22e3 | 2012-07-23 09:49:06 +0200 | [diff] [blame] | 91 | /* prime */ |
| 92 | int prime_handle_to_fd(int fd, uint32_t handle); |
| 93 | uint32_t prime_fd_to_handle(int fd, int dma_buf_fd); |
Daniel Vetter | e58891d | 2013-08-15 14:00:23 +0200 | [diff] [blame] | 94 | off_t prime_get_size(int dma_buf_fd); |
Daniel Vetter | 6bc22e3 | 2012-07-23 09:49:06 +0200 | [diff] [blame] | 95 | |
Daniel Vetter | d75d69d | 2012-01-15 18:32:11 +0100 | [diff] [blame] | 96 | /* generally useful helpers */ |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 97 | void igt_fork_signal_helper(void); |
| 98 | void igt_stop_signal_helper(void); |
| 99 | void igt_exchange_int(void *array, unsigned i, unsigned j); |
| 100 | void igt_permute_array(void *array, unsigned size, |
Daniel Vetter | fbfe374 | 2012-01-22 20:09:54 +0100 | [diff] [blame] | 101 | void (*exchange_func)(void *array, |
| 102 | unsigned i, |
| 103 | unsigned j)); |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 104 | void igt_progress(const char *header, uint64_t i, uint64_t total); |
Daniel Vetter | 5bc0324 | 2013-07-19 19:08:43 +0200 | [diff] [blame] | 105 | |
| 106 | /* subtest infrastructure */ |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 107 | jmp_buf igt_subtest_jmpbuf; |
| 108 | void igt_subtest_init(int argc, char **argv); |
Imre Deak | 5cabaae | 2013-08-03 02:10:11 +0300 | [diff] [blame] | 109 | typedef int (*igt_opt_handler_t)(int opt, int opt_index); |
| 110 | struct option; |
| 111 | int igt_subtest_init_parse_opts(int argc, char **argv, |
| 112 | const char *extra_short_opts, |
| 113 | struct option *extra_long_opts, |
| 114 | const char *help_str, |
| 115 | igt_opt_handler_t opt_handler); |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 116 | bool __igt_run_subtest(const char *subtest_name); |
Daniel Vetter | f8c0dfe | 2013-08-14 16:51:26 +0200 | [diff] [blame] | 117 | /** |
| 118 | * igt_subtest/_f - Denote a subtest code block |
| 119 | * |
| 120 | * Magic control flow which denotes a subtest code block. Within that codeblock |
| 121 | * igt_skip|success will only bail out of the subtest. The _f variant accepts a |
| 122 | * printf format string, which is useful for constructing combinatorial tests. |
| 123 | */ |
Daniel Vetter | 6234658 | 2013-08-14 13:47:47 +0200 | [diff] [blame] | 124 | #define igt_tokencat2(x, y) x ## y |
| 125 | #define igt_tokencat(x, y) igt_tokencat2(x, y) |
Daniel Vetter | e5cdd62 | 2013-09-19 16:37:07 +0200 | [diff] [blame] | 126 | #define __igt_subtest_f(tmp, format...) \ |
Daniel Vetter | 6234658 | 2013-08-14 13:47:47 +0200 | [diff] [blame] | 127 | for (char tmp [256]; \ |
| 128 | snprintf( tmp , sizeof( tmp ), \ |
Daniel Vetter | e5cdd62 | 2013-09-19 16:37:07 +0200 | [diff] [blame] | 129 | format), \ |
Daniel Vetter | 6234658 | 2013-08-14 13:47:47 +0200 | [diff] [blame] | 130 | __igt_run_subtest( tmp ) && \ |
| 131 | (setjmp(igt_subtest_jmpbuf) == 0); \ |
| 132 | igt_success()) |
Daniel Vetter | e5cdd62 | 2013-09-19 16:37:07 +0200 | [diff] [blame] | 133 | #define igt_subtest_f(f...) \ |
| 134 | __igt_subtest_f(igt_tokencat(__tmpchar, __LINE__), f) |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 135 | #define igt_subtest(name) for (; __igt_run_subtest((name)) && \ |
| 136 | (setjmp(igt_subtest_jmpbuf) == 0); \ |
| 137 | igt_success()) |
Daniel Vetter | 15c1922 | 2013-08-14 18:03:09 +0200 | [diff] [blame] | 138 | const char *igt_subtest_name(void); |
Daniel Vetter | f8c0dfe | 2013-08-14 16:51:26 +0200 | [diff] [blame] | 139 | /** |
| 140 | * igt_skip - subtest aware test skipping |
| 141 | * |
| 142 | * For tests with subtests this will either bail out of the current subtest or |
| 143 | * mark all subsequent subtests as SKIP (in case some global setup code failed). |
| 144 | * |
| 145 | * For normal tests without subtest it will directly exit. |
| 146 | */ |
Daniel Vetter | 8dbd1fb | 2013-08-19 11:09:25 +0200 | [diff] [blame] | 147 | __attribute__((format(printf, 1, 2))) void igt_skip(const char *f, ...); |
Daniel Vetter | e5cdd62 | 2013-09-19 16:37:07 +0200 | [diff] [blame] | 148 | __attribute__((format(printf, 5, 6))) |
Daniel Vetter | 8f5387e | 2013-08-13 13:20:58 +0200 | [diff] [blame] | 149 | void __igt_skip_check(const char *file, const int line, |
Daniel Vetter | e5cdd62 | 2013-09-19 16:37:07 +0200 | [diff] [blame] | 150 | const char *func, const char *check, |
| 151 | const char *format, ...); |
Daniel Vetter | f8c0dfe | 2013-08-14 16:51:26 +0200 | [diff] [blame] | 152 | /** |
| 153 | * igt_success - complete a (subtest) as successfull |
| 154 | * |
| 155 | * This bails out of a subtests and marks it as successful. For global tests it |
| 156 | * it won't bail out of anything. |
| 157 | */ |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 158 | void igt_success(void); |
Daniel Vetter | f8c0dfe | 2013-08-14 16:51:26 +0200 | [diff] [blame] | 159 | /** |
| 160 | * igt_fail - fail a testcase |
| 161 | * |
| 162 | * For subtest it just bails out of the subtest, when run in global context it |
| 163 | * will exit. Note that it won't attempt to keep on running further tests, |
| 164 | * presuming that some mandatory setup failed. |
| 165 | */ |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 166 | void igt_fail(int exitcode) __attribute__((noreturn)); |
Daniel Vetter | e5cdd62 | 2013-09-19 16:37:07 +0200 | [diff] [blame] | 167 | __attribute__((format(printf, 6, 7))) |
Daniel Vetter | 646a6fe | 2013-08-13 11:52:01 +0200 | [diff] [blame] | 168 | void __igt_fail_assert(int exitcode, const char *file, |
Daniel Vetter | e5cdd62 | 2013-09-19 16:37:07 +0200 | [diff] [blame] | 169 | const int line, const char *func, const char *assertion, |
| 170 | const char *format, ...) |
Daniel Vetter | 646a6fe | 2013-08-13 11:52:01 +0200 | [diff] [blame] | 171 | __attribute__((noreturn)); |
Daniel Vetter | f8c0dfe | 2013-08-14 16:51:26 +0200 | [diff] [blame] | 172 | /** |
| 173 | * igt_exit - exit() for igts |
| 174 | * |
| 175 | * This will exit the test with the right exit code when subtests have been |
| 176 | * skipped. For normal tests it exits with a successful exit code, presuming |
| 177 | * everything has worked out. For subtests it also checks that at least one |
| 178 | * subtest has been run (save when only listing subtests. |
| 179 | */ |
| 180 | void igt_exit(void) __attribute__((noreturn)); |
Daniel Vetter | 8f5387e | 2013-08-13 13:20:58 +0200 | [diff] [blame] | 181 | /** |
| 182 | * igt_assert - fails (sub-)test if a condition is not met |
| 183 | * |
| 184 | * Should be used everywhere where a test checks results. |
| 185 | */ |
Daniel Vetter | e5cdd62 | 2013-09-19 16:37:07 +0200 | [diff] [blame] | 186 | #define igt_assert(expr) \ |
| 187 | do { if (!(expr)) \ |
| 188 | __igt_fail_assert(99, __FILE__, __LINE__, __func__, #expr , NULL); \ |
| 189 | } while (0) |
| 190 | #define igt_assert_f(expr, f...) \ |
| 191 | do { if (!(expr)) \ |
| 192 | __igt_fail_assert(99, __FILE__, __LINE__, __func__, #expr , f); \ |
| 193 | } while (0) |
Daniel Vetter | 8f5387e | 2013-08-13 13:20:58 +0200 | [diff] [blame] | 194 | /** |
| 195 | * igt_require - skip a (sub-)test if a condition is not met |
| 196 | * |
| 197 | * This is useful to streamline the skip logic since it allows for a more flat |
| 198 | * code control flow. |
| 199 | */ |
Daniel Vetter | 5113df7 | 2013-09-04 13:19:42 +0200 | [diff] [blame] | 200 | #define igt_require(expr) igt_skip_on(!(expr)) |
Daniel Vetter | e5cdd62 | 2013-09-19 16:37:07 +0200 | [diff] [blame] | 201 | #define igt_skip_on(expr) \ |
| 202 | do { if ((expr)) \ |
| 203 | __igt_skip_check(__FILE__, __LINE__, __func__, #expr , NULL); \ |
| 204 | } while (0) |
| 205 | #define igt_require_f(expr, f...) igt_skip_on_f(!(expr), f) |
| 206 | #define igt_skip_on_f(expr, f...) \ |
| 207 | do { if ((expr)) \ |
| 208 | __igt_skip_check(__FILE__, __LINE__, __func__, #expr , f); \ |
| 209 | } while (0) |
Daniel Vetter | d75d69d | 2012-01-15 18:32:11 +0100 | [diff] [blame] | 210 | |
Daniel Vetter | 7886584 | 2013-08-19 07:23:49 +0200 | [diff] [blame] | 211 | bool __igt_fixture(void); |
Daniel Vetter | 8869e1e | 2013-08-26 20:52:14 +0200 | [diff] [blame] | 212 | void __igt_fixture_complete(void); |
Daniel Vetter | 7886584 | 2013-08-19 07:23:49 +0200 | [diff] [blame] | 213 | void __igt_fixture_end(void) __attribute__((noreturn)); |
Daniel Vetter | 696c8f6 | 2013-08-14 18:30:03 +0200 | [diff] [blame] | 214 | /** |
| 215 | * igt_fixture - annote global test fixture code |
| 216 | * |
| 217 | * Testcase with subtests often need to set up a bunch of global state as the |
| 218 | * common test fixture. To avoid such code interferring with the subtest |
| 219 | * enumeration (e.g. when enumerating on systemes without an intel gpu) such |
| 220 | * blocks should be annotated with igt_fixture. |
| 221 | */ |
Daniel Vetter | 8869e1e | 2013-08-26 20:52:14 +0200 | [diff] [blame] | 222 | #define igt_fixture for (int igt_tokencat(__tmpint,__LINE__) = 0; \ |
| 223 | igt_tokencat(__tmpint,__LINE__) < 1 && \ |
| 224 | __igt_fixture() && \ |
Daniel Vetter | 7886584 | 2013-08-19 07:23:49 +0200 | [diff] [blame] | 225 | (setjmp(igt_subtest_jmpbuf) == 0); \ |
Daniel Vetter | 8869e1e | 2013-08-26 20:52:14 +0200 | [diff] [blame] | 226 | igt_tokencat(__tmpint,__LINE__) ++, \ |
| 227 | __igt_fixture_complete()) |
Daniel Vetter | 2dbd998 | 2013-08-14 15:48:54 +0200 | [diff] [blame] | 228 | |
Daniel Vetter | cd1f220 | 2013-08-29 10:06:51 +0200 | [diff] [blame] | 229 | bool __igt_fork(void); |
| 230 | /** |
| 231 | * igt_fork - fork parallel test threads with fork() |
| 232 | * @child: name of the int variable with the child number |
| 233 | * @num_children: number of children to fork |
| 234 | * |
| 235 | * Joining all test threads should be done with igt_waitchildren to ensure that |
| 236 | * the exit codes of all children are properly reflected in the test status. |
| 237 | */ |
| 238 | #define igt_fork(child, num_children) \ |
| 239 | for (int child = 0; child < (num_children); child++) \ |
| 240 | for (; __igt_fork(); exit(0)) |
| 241 | void igt_waitchildren(void); |
| 242 | |
Daniel Vetter | edd7234 | 2013-09-10 15:46:08 +0200 | [diff] [blame] | 243 | struct igt_helper_process { |
| 244 | bool running; |
| 245 | pid_t pid; |
Daniel Vetter | e73c1a0 | 2013-09-10 15:44:37 +0200 | [diff] [blame] | 246 | int id; |
Daniel Vetter | edd7234 | 2013-09-10 15:46:08 +0200 | [diff] [blame] | 247 | }; |
| 248 | bool __igt_fork_helper(struct igt_helper_process *proc); |
| 249 | void igt_stop_helper(struct igt_helper_process *proc); |
| 250 | #define igt_fork_helper(proc) \ |
| 251 | for (; __igt_fork_helper(proc); exit(0)) |
| 252 | |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 253 | /* check functions which auto-skip tests by calling igt_skip() */ |
Daniel Vetter | 8f5387e | 2013-08-13 13:20:58 +0200 | [diff] [blame] | 254 | void gem_require_caching(int fd); |
| 255 | static inline void gem_require_ring(int fd, int ring_id) |
Daniel Vetter | 7847ea2 | 2013-08-12 11:03:29 +0200 | [diff] [blame] | 256 | { |
Daniel Vetter | 8f5387e | 2013-08-13 13:20:58 +0200 | [diff] [blame] | 257 | switch (ring_id) { |
| 258 | case I915_EXEC_RENDER: |
| 259 | return; |
| 260 | case I915_EXEC_BLT: |
| 261 | igt_require(HAS_BLT_RING(intel_get_drm_devid(fd))); |
| 262 | return; |
| 263 | case I915_EXEC_BSD: |
| 264 | igt_require(HAS_BSD_RING(intel_get_drm_devid(fd))); |
| 265 | return; |
Chris Wilson | 55b8c33 | 2013-08-19 18:15:04 +0100 | [diff] [blame] | 266 | #ifdef I915_EXEC_VEBOX |
Daniel Vetter | 8f5387e | 2013-08-13 13:20:58 +0200 | [diff] [blame] | 267 | case I915_EXEC_VEBOX: |
| 268 | igt_require(gem_has_vebox(fd)); |
| 269 | return; |
Chris Wilson | 55b8c33 | 2013-08-19 18:15:04 +0100 | [diff] [blame] | 270 | #endif |
Daniel Vetter | 8f5387e | 2013-08-13 13:20:58 +0200 | [diff] [blame] | 271 | default: |
| 272 | assert(0); |
| 273 | return; |
| 274 | } |
Daniel Vetter | 7847ea2 | 2013-08-12 11:03:29 +0200 | [diff] [blame] | 275 | } |
| 276 | |
Daniel Vetter | 5bc0324 | 2013-07-19 19:08:43 +0200 | [diff] [blame] | 277 | /* helpers to automatically reduce test runtime in simulation */ |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 278 | bool igt_run_in_simulation(void); |
| 279 | #define SLOW_QUICK(slow,quick) (igt_run_in_simulation() ? (quick) : (slow)) |
Daniel Vetter | f8c0dfe | 2013-08-14 16:51:26 +0200 | [diff] [blame] | 280 | /** |
| 281 | * igt_skip_on_simulation - skip tests when INTEL_SIMULATION env war is set |
| 282 | * |
| 283 | * Skip the test when running on simulation (and that's relevant only when |
| 284 | * we're not in the mode where we list the subtests). |
| 285 | * |
| 286 | * This function is subtest aware (since it uses igt_skip) and so can be used to |
| 287 | * skip specific subtests or all subsequent subtests. |
| 288 | */ |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 289 | void igt_skip_on_simulation(void); |
Damien Lespiau | bb33d08 | 2013-02-13 16:29:01 +0000 | [diff] [blame] | 290 | |
Daniel Vetter | d75d69d | 2012-01-15 18:32:11 +0100 | [diff] [blame] | 291 | /* helpers based upon the libdrm buffer manager */ |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 292 | void igt_init_aperture_trashers(drm_intel_bufmgr *bufmgr); |
| 293 | void igt_trash_aperture(void); |
| 294 | void igt_cleanup_aperture_trashers(void); |
Chris Wilson | b7bd183 | 2012-03-29 12:45:59 +0100 | [diff] [blame] | 295 | |
Imre Deak | bfb0cdd | 2013-05-31 00:21:43 +0300 | [diff] [blame] | 296 | struct kmstest_connector_config { |
| 297 | drmModeCrtc *crtc; |
| 298 | drmModeConnector *connector; |
| 299 | drmModeEncoder *encoder; |
| 300 | drmModeModeInfo default_mode; |
| 301 | int crtc_idx; |
| 302 | int pipe; |
| 303 | }; |
| 304 | |
Imre Deak | 9a9f131 | 2013-08-01 15:08:19 +0300 | [diff] [blame] | 305 | int kmstest_get_connector_default_mode(int drm_fd, drmModeConnector *connector, |
| 306 | drmModeModeInfo *mode); |
Imre Deak | bfb0cdd | 2013-05-31 00:21:43 +0300 | [diff] [blame] | 307 | int kmstest_get_connector_config(int drm_fd, uint32_t connector_id, |
| 308 | unsigned long crtc_idx_mask, |
| 309 | struct kmstest_connector_config *config); |
| 310 | void kmstest_free_connector_config(struct kmstest_connector_config *config); |
| 311 | |
Daniel Vetter | 662d732 | 2012-05-22 14:37:19 +0200 | [diff] [blame] | 312 | /* helpers to create nice-looking framebuffers */ |
| 313 | struct kmstest_fb { |
| 314 | uint32_t fb_id; |
| 315 | uint32_t gem_handle; |
Imre Deak | f68d964 | 2013-05-24 17:26:54 +0300 | [diff] [blame] | 316 | uint32_t drm_format; |
| 317 | int width; |
| 318 | int height; |
| 319 | int depth; |
Daniel Vetter | 662d732 | 2012-05-22 14:37:19 +0200 | [diff] [blame] | 320 | unsigned stride; |
Chris Wilson | d0ed912 | 2013-08-29 15:11:47 +0100 | [diff] [blame] | 321 | unsigned tiling; |
Daniel Vetter | 662d732 | 2012-05-22 14:37:19 +0200 | [diff] [blame] | 322 | unsigned size; |
Imre Deak | f68d964 | 2013-05-24 17:26:54 +0300 | [diff] [blame] | 323 | cairo_t *cairo_ctx; |
Daniel Vetter | 662d732 | 2012-05-22 14:37:19 +0200 | [diff] [blame] | 324 | }; |
| 325 | |
Imre Deak | 542a40c | 2013-05-30 15:03:48 +0300 | [diff] [blame] | 326 | enum kmstest_text_align { |
| 327 | align_left, |
| 328 | align_bottom = align_left, |
| 329 | align_right = 0x01, |
| 330 | align_top = 0x02, |
| 331 | align_vcenter = 0x04, |
| 332 | align_hcenter = 0x08, |
| 333 | }; |
| 334 | |
| 335 | int kmstest_cairo_printf_line(cairo_t *cr, enum kmstest_text_align align, |
| 336 | double yspacing, const char *fmt, ...) |
| 337 | __attribute__((format (printf, 4, 5))); |
| 338 | |
Daniel Vetter | 662d732 | 2012-05-22 14:37:19 +0200 | [diff] [blame] | 339 | unsigned int kmstest_create_fb(int fd, int width, int height, int bpp, |
| 340 | int depth, bool tiled, |
Imre Deak | f68d964 | 2013-05-24 17:26:54 +0300 | [diff] [blame] | 341 | struct kmstest_fb *fb_info); |
Imre Deak | 528b1f3 | 2013-05-30 22:59:59 +0300 | [diff] [blame] | 342 | unsigned int kmstest_create_fb2(int fd, int width, int height, uint32_t format, |
| 343 | bool tiled, struct kmstest_fb *fb); |
Imre Deak | f68d964 | 2013-05-24 17:26:54 +0300 | [diff] [blame] | 344 | void kmstest_remove_fb(int fd, struct kmstest_fb *fb_info); |
| 345 | cairo_t *kmstest_get_cairo_ctx(int fd, struct kmstest_fb *fb); |
Imre Deak | 528b1f3 | 2013-05-30 22:59:59 +0300 | [diff] [blame] | 346 | void kmstest_paint_color_gradient(cairo_t *cr, int x, int y, int w, int h, |
| 347 | int r, int g, int b); |
Imre Deak | f68d964 | 2013-05-24 17:26:54 +0300 | [diff] [blame] | 348 | void kmstest_paint_test_pattern(cairo_t *cr, int width, int height); |
Damien Lespiau | bde7060 | 2013-08-23 16:46:45 +0100 | [diff] [blame] | 349 | void kmstest_paint_image(cairo_t *cr, const char *filename, |
| 350 | int dst_x, int dst_y, int dst_width, int dst_height); |
Damien Lespiau | 79f4cfe | 2013-09-06 18:22:53 +0100 | [diff] [blame] | 351 | void kmstest_write_fb(int fd, struct kmstest_fb *fb, const char *filename); |
Daniel Vetter | 17787f3 | 2012-05-22 16:15:15 +0200 | [diff] [blame] | 352 | void kmstest_dump_mode(drmModeModeInfo *mode); |
Daniel Vetter | 0af2b18 | 2012-12-15 01:06:11 +0100 | [diff] [blame] | 353 | int kmstest_get_pipe_from_crtc_id(int fd, int crtc_id); |
Imre Deak | 528b1f3 | 2013-05-30 22:59:59 +0300 | [diff] [blame] | 354 | const char *kmstest_format_str(uint32_t drm_format); |
| 355 | const char *kmstest_pipe_str(int pipe); |
| 356 | void kmstest_get_all_formats(const uint32_t **formats, int *format_count); |
Imre Deak | 3a2aed1 | 2013-05-30 22:53:53 +0300 | [diff] [blame] | 357 | const char *kmstest_encoder_type_str(int type); |
| 358 | const char *kmstest_connector_status_str(int type); |
| 359 | const char *kmstest_connector_type_str(int type); |
Daniel Vetter | 662d732 | 2012-05-22 14:37:19 +0200 | [diff] [blame] | 360 | |
Imre Deak | 24de8ba | 2013-07-29 17:19:58 +0300 | [diff] [blame] | 361 | uint32_t drm_format_to_bpp(uint32_t drm_format); |
| 362 | |
Daniel Vetter | 79abed3 | 2013-08-15 11:55:32 +0200 | [diff] [blame] | 363 | #define do_or_die(x) igt_assert((x) == 0) |
| 364 | #define do_ioctl(fd, ptr, sz) igt_assert(drmIoctl((fd), (ptr), (sz)) == 0) |
Imre Deak | cf26435 | 2013-05-08 19:06:42 +0300 | [diff] [blame] | 365 | |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 366 | typedef void (*igt_exit_handler_t)(int sig); |
Imre Deak | bce7d8a | 2013-05-22 17:40:46 +0300 | [diff] [blame] | 367 | |
Daniel Vetter | 5bc0324 | 2013-07-19 19:08:43 +0200 | [diff] [blame] | 368 | /* reliable atexit helpers, also work when killed by a signal (if possible) */ |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 369 | int igt_install_exit_handler(igt_exit_handler_t fn); |
| 370 | void igt_enable_exit_handler(void); |
| 371 | void igt_disable_exit_handler(void); |
Imre Deak | bce7d8a | 2013-05-22 17:40:46 +0300 | [diff] [blame] | 372 | |
Daniel Vetter | 5bc0324 | 2013-07-19 19:08:43 +0200 | [diff] [blame] | 373 | /* set vt into graphics mode, required to prevent fbcon from interfering */ |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 374 | int igt_set_vt_graphics_mode(void); |
Xiong Zhang | 7ea2983 | 2013-07-19 18:42:51 +0800 | [diff] [blame] | 375 | |
Daniel Vetter | 5bc0324 | 2013-07-19 19:08:43 +0200 | [diff] [blame] | 376 | /* prefault disabling, needs the corresponding debugfs interface */ |
Daniel Vetter | f4b9378 | 2013-09-03 12:22:09 +0200 | [diff] [blame] | 377 | void igt_disable_prefault(void); |
| 378 | void igt_enable_prefault(void); |
Daniel Vetter | 10834f8 | 2013-07-22 09:24:43 +0200 | [diff] [blame] | 379 | |
| 380 | /* suspend and auto-resume system */ |
Daniel Vetter | 1caaf0a | 2013-08-12 12:17:35 +0200 | [diff] [blame] | 381 | void igt_system_suspend_autoresume(void); |
Chris Wilson | d0ed912 | 2013-08-29 15:11:47 +0100 | [diff] [blame] | 382 | |
| 383 | #endif /* DRMTEST_H */ |