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