Ville Syrjälä | eda904c | 2014-08-05 23:06:04 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 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 | */ |
| 24 | |
| 25 | #include <errno.h> |
| 26 | #include <stdbool.h> |
| 27 | #include <stdio.h> |
| 28 | #include <string.h> |
| 29 | |
| 30 | #include "drmtest.h" |
| 31 | #include "igt_debugfs.h" |
| 32 | #include "igt_kms.h" |
| 33 | #include "intel_chipset.h" |
| 34 | #include "intel_batchbuffer.h" |
| 35 | #include "ioctl_wrappers.h" |
| 36 | |
| 37 | typedef struct { |
| 38 | int drm_fd; |
| 39 | igt_display_t display; |
| 40 | } data_t; |
| 41 | |
Thomas Wood | 3d0dca4 | 2014-10-13 11:40:12 +0100 | [diff] [blame^] | 42 | IGT_TEST_DESCRIPTION( |
| 43 | "This test tries to provoke the kernel into leaking a pending page flip " |
| 44 | "event when the fd is closed before the flip has completed. The test " |
| 45 | "itself won't fail even if the kernel leaks the event, but the resulting " |
| 46 | "dmesg WARN will indicate a failure."); |
| 47 | |
Ville Syrjälä | eda904c | 2014-08-05 23:06:04 +0300 | [diff] [blame] | 48 | static bool test(data_t *data, enum pipe pipe, igt_output_t *output) |
| 49 | { |
| 50 | igt_plane_t *primary; |
| 51 | drmModeModeInfo *mode; |
| 52 | struct igt_fb fb[2]; |
| 53 | int fd, ret; |
| 54 | |
| 55 | /* select the pipe we want to use */ |
| 56 | igt_output_set_pipe(output, pipe); |
| 57 | igt_display_commit(&data->display); |
| 58 | |
| 59 | if (!output->valid) { |
| 60 | igt_output_set_pipe(output, PIPE_ANY); |
| 61 | igt_display_commit(&data->display); |
| 62 | return false; |
| 63 | } |
| 64 | |
| 65 | primary = igt_output_get_plane(output, IGT_PLANE_PRIMARY); |
| 66 | mode = igt_output_get_mode(output); |
| 67 | |
| 68 | igt_create_color_fb(data->drm_fd, mode->hdisplay, mode->vdisplay, |
| 69 | DRM_FORMAT_XRGB8888, |
| 70 | true, /* tiled */ |
| 71 | 0.0, 0.0, 0.0, &fb[0]); |
| 72 | |
| 73 | igt_plane_set_fb(primary, &fb[0]); |
| 74 | igt_display_commit2(&data->display, COMMIT_LEGACY); |
| 75 | |
| 76 | fd = drm_open_any(); |
| 77 | |
| 78 | ret = drmDropMaster(data->drm_fd); |
| 79 | igt_assert(ret == 0); |
| 80 | |
| 81 | ret = drmSetMaster(fd); |
| 82 | igt_assert(ret == 0); |
| 83 | |
| 84 | igt_create_color_fb(fd, mode->hdisplay, mode->vdisplay, |
| 85 | DRM_FORMAT_XRGB8888, |
| 86 | true, /* tiled */ |
| 87 | 0.0, 0.0, 0.0, &fb[1]); |
| 88 | ret = drmModePageFlip(fd, output->config.crtc->crtc_id, |
| 89 | fb[1].fb_id, DRM_MODE_PAGE_FLIP_EVENT, |
| 90 | data); |
| 91 | igt_assert(ret == 0); |
| 92 | |
| 93 | ret = close(fd); |
| 94 | igt_assert(ret == 0); |
| 95 | |
| 96 | ret = drmSetMaster(data->drm_fd); |
| 97 | igt_assert(ret == 0); |
| 98 | |
| 99 | igt_plane_set_fb(primary, NULL); |
| 100 | igt_output_set_pipe(output, PIPE_ANY); |
| 101 | igt_display_commit(&data->display); |
| 102 | |
| 103 | igt_remove_fb(data->drm_fd, &fb[0]); |
| 104 | |
| 105 | return true; |
| 106 | } |
| 107 | |
| 108 | igt_simple_main |
| 109 | { |
| 110 | data_t data = {}; |
| 111 | igt_output_t *output; |
| 112 | int valid_tests = 0; |
| 113 | enum pipe pipe; |
| 114 | |
| 115 | igt_skip_on_simulation(); |
| 116 | |
Imre Deak | c256af5 | 2014-09-18 18:31:29 +0300 | [diff] [blame] | 117 | data.drm_fd = drm_open_any_master(); |
Daniel Vetter | 33f0884 | 2014-08-12 11:23:09 +0200 | [diff] [blame] | 118 | kmstest_set_vt_graphics_mode(); |
Ville Syrjälä | eda904c | 2014-08-05 23:06:04 +0300 | [diff] [blame] | 119 | |
| 120 | igt_display_init(&data.display, data.drm_fd); |
| 121 | |
| 122 | for (pipe = 0; pipe < 3; pipe++) { |
| 123 | for_each_connected_output(&data.display, output) { |
| 124 | if (test(&data, pipe, output)) |
| 125 | valid_tests++; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | igt_require_f(valid_tests, "no valid crtc/connector combinations found\n"); |
| 130 | |
| 131 | igt_display_fini(&data.display); |
| 132 | } |