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 "igt.h"
26 #include <errno.h>
27 #include <stdbool.h>
28 #include <stdio.h>
29 #include <string.h>
30 
31 #include "igt_device.h"
32 
33 typedef struct {
34 	int drm_fd;
35 	igt_display_t display;
36 } data_t;
37 
38 IGT_TEST_DESCRIPTION(
39     "This test tries to provoke the kernel into leaking a pending page flip "
40     "event when the fd is closed before the flip has completed. The test "
41     "itself won't fail even if the kernel leaks the event, but the resulting "
42     "dmesg WARN will indicate a failure.");
43 
test(data_t * data,enum pipe pipe,igt_output_t * output)44 static void test(data_t *data, enum pipe pipe, igt_output_t *output)
45 {
46 	igt_plane_t *primary;
47 	drmModeModeInfo *mode;
48 	struct igt_fb fb[2];
49 	int fd, ret;
50 
51 	/* select the pipe we want to use */
52 	igt_output_set_pipe(output, pipe);
53 
54 	primary = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY);
55 	mode = igt_output_get_mode(output);
56 
57 	igt_create_color_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
58 			    DRM_FORMAT_XRGB8888,
59 			    LOCAL_DRM_FORMAT_MOD_NONE,
60 			    0.0, 0.0, 0.0, &fb[0]);
61 
62 	igt_plane_set_fb(primary, &fb[0]);
63 	igt_display_commit2(&data->display, COMMIT_LEGACY);
64 
65 	fd = drm_open_driver(DRIVER_ANY);
66 
67 	igt_device_drop_master(data->drm_fd);
68 
69 	igt_device_set_master(fd);
70 
71 	igt_create_color_fb(fd, mode->hdisplay, mode->vdisplay,
72 			    DRM_FORMAT_XRGB8888,
73 			    LOCAL_DRM_FORMAT_MOD_NONE,
74 			    0.0, 0.0, 0.0, &fb[1]);
75 	ret = drmModePageFlip(fd, output->config.crtc->crtc_id,
76 			      fb[1].fb_id, DRM_MODE_PAGE_FLIP_EVENT,
77 			      data);
78 	igt_assert_eq(ret, 0);
79 
80 	ret = close(fd);
81 	igt_assert_eq(ret, 0);
82 
83 	igt_device_set_master(data->drm_fd);
84 
85 	igt_plane_set_fb(primary, NULL);
86 	igt_output_set_pipe(output, PIPE_ANY);
87 	igt_display_commit(&data->display);
88 
89 	igt_remove_fb(data->drm_fd, &fb[0]);
90 }
91 
92 igt_simple_main
93 {
94 	data_t data = {};
95 	igt_output_t *output;
96 	int valid_tests = 0;
97 	enum pipe pipe;
98 
99 	igt_skip_on_simulation();
100 
101 	data.drm_fd = drm_open_driver_master(DRIVER_ANY);
102 	kmstest_set_vt_graphics_mode();
103 
104 	igt_display_require(&data.display, data.drm_fd);
105 
106 	for_each_pipe_with_valid_output(&data.display, pipe, output) {
107 		test(&data, pipe, output);
108 		valid_tests++;
109 	}
110 
111 	igt_require_f(valid_tests, "no valid crtc/connector combinations found\n");
112 
113 	igt_display_fini(&data.display);
114 }
115