blob: a3cba44eb93874322888fec633f9370b1da701c6 [file] [log] [blame]
Jesse Barnes5406c632010-12-21 09:38:23 -08001/*
2 * Copyright 2010 Intel Corporation
3 * Jesse Barnes <jesse.barnes@intel.com>
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the 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 THE
18 * 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 * This program is intended for testing of display functionality. It should
26 * allow for testing of
27 * - hotplug
28 * - mode setting
29 * - clone & twin modes
30 * - panel fitting
31 * - test patterns & pixel generators
32 * Additional programs can test the detected outputs against VBT provided
33 * device lists (both docked & undocked).
34 *
35 * TODO:
36 * - pixel generator in transcoder
37 * - test pattern reg in pipe
38 * - test patterns on outputs (e.g. TV)
39 * - handle hotplug (leaks crtcs, can't handle clones)
40 * - allow mode force
41 * - expose output specific controls
42 * - e.g. DDC-CI brightness
43 * - HDMI controls
44 * - panel brightness
45 * - DP commands (e.g. poweroff)
46 * - verify outputs against VBT/physical connectors
47 */
Damien Lespiau7ee278f2013-02-20 14:40:07 +000048#ifdef HAVE_CONFIG_H
Jesse Barnes5406c632010-12-21 09:38:23 -080049#include "config.h"
Damien Lespiau7ee278f2013-02-20 14:40:07 +000050#endif
Jesse Barnes5406c632010-12-21 09:38:23 -080051
Jesse Barnes5406c632010-12-21 09:38:23 -080052#include <cairo.h>
53#include <errno.h>
Jesse Barnes5406c632010-12-21 09:38:23 -080054#include <math.h>
55#include <stdint.h>
Damien Lespiau66477a22013-09-05 16:49:11 +010056#include <stdbool.h>
Damien Lespiau9a8fda72012-09-10 13:33:26 +010057#include <strings.h>
Jesse Barnes5406c632010-12-21 09:38:23 -080058#include <unistd.h>
Jesse Barnes7255a842014-03-26 11:02:48 -070059#include <termios.h>
Jesse Barnes5406c632010-12-21 09:38:23 -080060#include <sys/poll.h>
61#include <sys/time.h>
Chris Wilson5534cb12011-02-11 10:48:04 +000062#include <sys/ioctl.h>
Damien Lespiau9a8fda72012-09-10 13:33:26 +010063#include <sys/types.h>
64#include <sys/stat.h>
Jesse Barnes5406c632010-12-21 09:38:23 -080065
Daniel Vettere49ceb82014-03-22 21:07:37 +010066#include "ioctl_wrappers.h"
Daniel Vetter7a6042e2012-01-10 18:29:30 +010067#include "drmtest.h"
Daniel Vetter7f7cafe2012-01-24 10:50:05 +010068#include "testdisplay.h"
Oscar Mateo37f26d12013-11-12 11:50:38 +000069#include "igt_kms.h"
Jesse Barnes5406c632010-12-21 09:38:23 -080070
Yi Sun41fe8112012-07-26 14:23:36 +080071#include <stdlib.h>
72#include <signal.h>
73
Thomas Woodff6b0682014-07-31 16:26:55 +010074#define SUBTEST_OPTS 1
75
Imre Deak63746412014-05-12 13:29:49 +030076static int tio_fd;
Jesse Barnes7255a842014-03-26 11:02:48 -070077struct termios saved_tio;
78
Jesse Barnes5406c632010-12-21 09:38:23 -080079drmModeRes *resources;
Daniel Vetter73d1b882012-01-10 18:20:39 +010080int drm_fd, modes;
Damien Lespiau66477a22013-09-05 16:49:11 +010081int test_all_modes = 0, test_preferred_mode = 0, force_mode = 0, test_plane,
Damien Lespiaud9ffb7d2014-06-20 12:02:09 +010082 test_stereo_modes;
83unsigned int tiling = I915_TILING_NONE;
Hai Lan62d51682011-02-11 11:14:15 -050084int sleep_between_modes = 5;
Daniel Vettercef9b312014-02-13 19:22:35 +010085int do_dpms = 0; /* This aliases to DPMS_ON */
Jesse Barnes5a9d82c2011-12-07 08:22:41 -080086uint32_t depth = 24, stride, bpp;
Yi Sun41fe8112012-07-26 14:23:36 +080087int qr_code = 0;
Yi Sun6157d242013-02-12 23:11:35 +080088int specified_mode_num = -1, specified_disp_id = -1;
Hai Lan62d51682011-02-11 11:14:15 -050089
Yi Sun4cceae72012-02-03 19:23:55 +080090drmModeModeInfo force_timing;
Jesse Barnes5406c632010-12-21 09:38:23 -080091
Jesse Barnes5a9d82c2011-12-07 08:22:41 -080092int crtc_x, crtc_y, crtc_w, crtc_h, width, height;
Jesse Barnes1f4c37a2011-10-28 05:25:53 +020093unsigned int plane_fb_id;
94unsigned int plane_crtc_id;
95unsigned int plane_id;
96int plane_width, plane_height;
Jesse Barnes5a9d82c2011-12-07 08:22:41 -080097static const uint32_t SPRITE_COLOR_KEY = 0x00aaaaaa;
Jesse Barnes24e60382011-10-24 17:15:34 +020098
Jesse Barnes5406c632010-12-21 09:38:23 -080099/*
100 * Mode setting with the kernel interfaces is a bit of a chore.
101 * First you have to find the connector in question and make sure the
102 * requested mode is available.
103 * Then you need to find the encoder attached to that connector so you
104 * can bind it with a free crtc.
105 */
106struct connector {
107 uint32_t id;
108 int mode_valid;
109 drmModeModeInfo mode;
110 drmModeEncoder *encoder;
111 drmModeConnector *connector;
112 int crtc;
Imre Deakbfb0cdd2013-05-31 00:21:43 +0300113 int crtc_idx;
Jesse Barnes9c29be42011-11-02 12:57:40 -0700114 int pipe;
Jesse Barnes5406c632010-12-21 09:38:23 -0800115};
116
Yi Sun3d46ca82012-02-03 22:45:39 +0800117static void dump_connectors_fd(int drmfd)
Hai Lan62d51682011-02-11 11:14:15 -0500118{
119 int i, j;
120
Yi Sun3d46ca82012-02-03 22:45:39 +0800121 drmModeRes *mode_resources = drmModeGetResources(drmfd);
122
123 if (!mode_resources) {
Daniel Vetterc9c55452014-06-13 18:27:59 +0200124 igt_warn("drmModeGetResources failed: %s\n", strerror(errno));
Yi Sun3d46ca82012-02-03 22:45:39 +0800125 return;
126 }
127
Daniel Vetterc9c55452014-06-13 18:27:59 +0200128 igt_info("Connectors:\n");
129 igt_info("id\tencoder\tstatus\t\ttype\tsize (mm)\tmodes\n");
Yi Sun3d46ca82012-02-03 22:45:39 +0800130 for (i = 0; i < mode_resources->count_connectors; i++) {
Hai Lan62d51682011-02-11 11:14:15 -0500131 drmModeConnector *connector;
132
Yi Sun3d46ca82012-02-03 22:45:39 +0800133 connector = drmModeGetConnector(drmfd, mode_resources->connectors[i]);
Hai Lan62d51682011-02-11 11:14:15 -0500134 if (!connector) {
Daniel Vetterc9c55452014-06-13 18:27:59 +0200135 igt_warn("could not get connector %i: %s\n", mode_resources->connectors[i], strerror(errno));
Hai Lan62d51682011-02-11 11:14:15 -0500136 continue;
137 }
138
Daniel Vetterc9c55452014-06-13 18:27:59 +0200139 igt_info("%d\t%d\t%s\t%s\t%dx%d\t\t%d\n", connector->connector_id, connector->encoder_id, kmstest_connector_status_str(connector->connection), kmstest_connector_type_str(connector->connector_type), connector->mmWidth, connector->mmHeight, connector->count_modes);
Hai Lan62d51682011-02-11 11:14:15 -0500140
141 if (!connector->count_modes)
142 continue;
143
Daniel Vetterc9c55452014-06-13 18:27:59 +0200144 igt_info(" modes:\n");
145 igt_info(" name refresh (Hz) hdisp hss hse htot vdisp ""vss vse vtot flags type clock\n");
Yi Sun53895ac2012-09-25 17:13:17 +0800146 for (j = 0; j < connector->count_modes; j++){
Daniel Vetterc9c55452014-06-13 18:27:59 +0200147 igt_info("[%d]", j);
Daniel Vetter17787f32012-05-22 16:15:15 +0200148 kmstest_dump_mode(&connector->modes[j]);
Yi Sun53895ac2012-09-25 17:13:17 +0800149 }
Hai Lan62d51682011-02-11 11:14:15 -0500150
151 drmModeFreeConnector(connector);
152 }
Daniel Vetterc9c55452014-06-13 18:27:59 +0200153 igt_info("\n");
Yi Sun3d46ca82012-02-03 22:45:39 +0800154
155 drmModeFreeResources(mode_resources);
Hai Lan62d51682011-02-11 11:14:15 -0500156}
157
Yi Sun3d46ca82012-02-03 22:45:39 +0800158static void dump_crtcs_fd(int drmfd)
Hai Lan62d51682011-02-11 11:14:15 -0500159{
160 int i;
Yi Sun3d46ca82012-02-03 22:45:39 +0800161 drmModeRes *mode_resources = drmModeGetResources(drmfd);
Hai Lan62d51682011-02-11 11:14:15 -0500162
Daniel Vetterc9c55452014-06-13 18:27:59 +0200163 igt_info("CRTCs:\n");
164 igt_info("id\tfb\tpos\tsize\n");
Yi Sun3d46ca82012-02-03 22:45:39 +0800165 for (i = 0; i < mode_resources->count_crtcs; i++) {
Hai Lan62d51682011-02-11 11:14:15 -0500166 drmModeCrtc *crtc;
167
Yi Sun3d46ca82012-02-03 22:45:39 +0800168 crtc = drmModeGetCrtc(drmfd, mode_resources->crtcs[i]);
Hai Lan62d51682011-02-11 11:14:15 -0500169 if (!crtc) {
Daniel Vetterc9c55452014-06-13 18:27:59 +0200170 igt_warn("could not get crtc %i: %s\n", mode_resources->crtcs[i], strerror(errno));
Hai Lan62d51682011-02-11 11:14:15 -0500171 continue;
172 }
Daniel Vetterc9c55452014-06-13 18:27:59 +0200173 igt_info("%d\t%d\t(%d,%d)\t(%dx%d)\n", crtc->crtc_id, crtc->buffer_id, crtc->x, crtc->y, crtc->width, crtc->height);
Daniel Vetter17787f32012-05-22 16:15:15 +0200174 kmstest_dump_mode(&crtc->mode);
Hai Lan62d51682011-02-11 11:14:15 -0500175
176 drmModeFreeCrtc(crtc);
177 }
Daniel Vetterc9c55452014-06-13 18:27:59 +0200178 igt_info("\n");
Yi Sun3d46ca82012-02-03 22:45:39 +0800179
180 drmModeFreeResources(mode_resources);
Hai Lan62d51682011-02-11 11:14:15 -0500181}
182
Damien Lespiau66477a22013-09-05 16:49:11 +0100183static void dump_info(void)
184{
185 dump_connectors_fd(drm_fd);
186 dump_crtcs_fd(drm_fd);
187}
188
Imre Deakbfb0cdd2013-05-31 00:21:43 +0300189static void connector_find_preferred_mode(uint32_t connector_id,
190 unsigned long crtc_idx_mask,
191 int mode_num, struct connector *c)
Jesse Barnes5406c632010-12-21 09:38:23 -0800192{
Imre Deakbfb0cdd2013-05-31 00:21:43 +0300193 struct kmstest_connector_config config;
Jesse Barnes5406c632010-12-21 09:38:23 -0800194
Daniel Vetter1cad8342014-08-12 11:57:32 +0200195 if (!kmstest_get_connector_config(drm_fd, connector_id, crtc_idx_mask,
196 &config)) {
Jesse Barnes5406c632010-12-21 09:38:23 -0800197 c->mode_valid = 0;
198 return;
199 }
200
Imre Deakbfb0cdd2013-05-31 00:21:43 +0300201 c->connector = config.connector;
202 c->encoder = config.encoder;
203 c->crtc = config.crtc->crtc_id;
204 c->crtc_idx = config.crtc_idx;
205 c->pipe = config.pipe;
206
207 if (mode_num != -1) {
Daniel Vetter83440952013-08-13 12:35:58 +0200208 igt_assert(mode_num < config.connector->count_modes);
Imre Deakbfb0cdd2013-05-31 00:21:43 +0300209 c->mode = config.connector->modes[mode_num];
210 } else {
211 c->mode = config.default_mode;
Jesse Barnes5406c632010-12-21 09:38:23 -0800212 }
Imre Deakbfb0cdd2013-05-31 00:21:43 +0300213 c->mode_valid = 1;
Jesse Barnes5406c632010-12-21 09:38:23 -0800214}
215
Jesse Barnes0d3043f2011-04-18 16:48:27 -0700216static void
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100217paint_color_key(struct igt_fb *fb_info)
Jesse Barnes5a9d82c2011-12-07 08:22:41 -0800218{
219 int i, j;
Damien Lespiau5a1d8432013-09-04 12:12:37 +0100220 uint32_t *fb_ptr;
221
222 fb_ptr = gem_mmap(drm_fd, fb_info->gem_handle,
223 fb_info->size, PROT_READ | PROT_WRITE);
224 igt_assert(fb_ptr);
Jesse Barnes5a9d82c2011-12-07 08:22:41 -0800225
226 for (i = crtc_y; i < crtc_y + crtc_h; i++)
227 for (j = crtc_x; j < crtc_x + crtc_w; j++) {
228 uint32_t offset;
229
Damien Lespiaub1188772012-11-27 19:14:05 +0000230 offset = (i * fb_info->stride / 4) + j;
Jesse Barnes5a9d82c2011-12-07 08:22:41 -0800231 fb_ptr[offset] = SPRITE_COLOR_KEY;
232 }
Damien Lespiau5a1d8432013-09-04 12:12:37 +0100233
234 munmap(fb_ptr, fb_info->size);
Jesse Barnes5a9d82c2011-12-07 08:22:41 -0800235}
236
Yi Sun41fe8112012-07-26 14:23:36 +0800237static void paint_image(cairo_t *cr, const char *file)
238{
239 int img_x, img_y, img_w, img_h, img_w_o, img_h_o;
240 double img_w_scale, img_h_scale;
241
242 cairo_surface_t *image;
243
244 img_y = height * (0.10 );
245 img_h = height * 0.08 * 4;
246 img_w = img_h;
247
248 img_x = (width / 2) - (img_w / 2);
249
250 image = cairo_image_surface_create_from_png(file);
251
252 img_w_o = cairo_image_surface_get_width(image);
253 img_h_o = cairo_image_surface_get_height(image);
254
255 cairo_translate(cr, img_x, img_y);
256
Yi Sun41fe8112012-07-26 14:23:36 +0800257 img_w_scale = (double)img_w / (double)img_w_o;
258 img_h_scale = (double)img_h / (double)img_h_o;
259 cairo_scale(cr, img_w_scale, img_h_scale);
260
261 cairo_set_source_surface(cr, image, 0, 0);
262 cairo_scale(cr, 1, 1);
263
264 cairo_paint(cr);
265 cairo_surface_destroy(image);
266}
267
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100268static void paint_output_info(struct connector *c, struct igt_fb *fb)
Jesse Barnes0d3043f2011-04-18 16:48:27 -0700269{
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100270 cairo_t *cr = igt_get_cairo_ctx(drm_fd, fb);
Imre Deakf68d9642013-05-24 17:26:54 +0300271 int l_width = fb->width;
272 int l_height = fb->height;
Imre Deak542a40c2013-05-30 15:03:48 +0300273 double str_width;
274 double x, y, top_y;
275 double max_width;
276 int i;
Jesse Barnes5406c632010-12-21 09:38:23 -0800277
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100278 igt_paint_test_pattern(cr, l_width, l_height);
Imre Deakf68d9642013-05-24 17:26:54 +0300279
Imre Deak542a40c2013-05-30 15:03:48 +0300280 cairo_move_to(cr, l_width / 2, l_height / 2);
Jesse Barnes5406c632010-12-21 09:38:23 -0800281
Imre Deak542a40c2013-05-30 15:03:48 +0300282 /* Print connector and mode name */
Jesse Barnes5406c632010-12-21 09:38:23 -0800283 cairo_set_font_size(cr, 48);
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100284 igt_cairo_printf_line(cr, align_hcenter, 10, "%s",
Imre Deak542a40c2013-05-30 15:03:48 +0300285 kmstest_connector_type_str(c->connector->connector_type));
Jesse Barnes5406c632010-12-21 09:38:23 -0800286
Jesse Barnes5406c632010-12-21 09:38:23 -0800287 cairo_set_font_size(cr, 36);
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100288 str_width = igt_cairo_printf_line(cr, align_hcenter, 10,
Imre Deak542a40c2013-05-30 15:03:48 +0300289 "%s @ %dHz on %s encoder", c->mode.name, c->mode.vrefresh,
290 kmstest_encoder_type_str(c->encoder->encoder_type));
291
292 cairo_rel_move_to(cr, -str_width / 2, 0);
Jesse Barnes5406c632010-12-21 09:38:23 -0800293
294 /* List available modes */
Jesse Barnes5406c632010-12-21 09:38:23 -0800295 cairo_set_font_size(cr, 18);
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100296 str_width = igt_cairo_printf_line(cr, align_left, 10,
Imre Deak542a40c2013-05-30 15:03:48 +0300297 "Available modes:");
298 cairo_rel_move_to(cr, str_width, 0);
299 cairo_get_current_point(cr, &x, &top_y);
Jesse Barnes5406c632010-12-21 09:38:23 -0800300
Imre Deak542a40c2013-05-30 15:03:48 +0300301 max_width = 0;
Jesse Barnes5406c632010-12-21 09:38:23 -0800302 for (i = 0; i < c->connector->count_modes; i++) {
Imre Deak542a40c2013-05-30 15:03:48 +0300303 cairo_get_current_point(cr, &x, &y);
304 if (y >= l_height) {
305 x += max_width + 10;
306 max_width = 0;
307 cairo_move_to(cr, x, top_y);
Jesse Barnes5406c632010-12-21 09:38:23 -0800308 }
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100309 str_width = igt_cairo_printf_line(cr, align_right, 10,
Imre Deak542a40c2013-05-30 15:03:48 +0300310 "%s @ %dHz", c->connector->modes[i].name,
311 c->connector->modes[i].vrefresh);
312 if (str_width > max_width)
313 max_width = str_width;
Jesse Barnes5406c632010-12-21 09:38:23 -0800314 }
Yi Sun41fe8112012-07-26 14:23:36 +0800315
316 if (qr_code)
Damien Lespiau951b37e2013-09-06 11:44:41 +0100317 paint_image(cr, IGT_DATADIR"/pass.png");
Imre Deakf68d9642013-05-24 17:26:54 +0300318
Daniel Vetter83440952013-08-13 12:35:58 +0200319 igt_assert(!cairo_status(cr));
Damien Lespiau660a7ff2014-06-30 16:19:05 +0100320
321 cairo_destroy(cr);
Yi Sun41fe8112012-07-26 14:23:36 +0800322}
323
324static void sighandler(int signo)
325{
326 return;
327}
328
329static void set_single(void)
330{
331 int sigs[] = { SIGUSR1 };
332 struct sigaction sa;
333 sa.sa_handler = sighandler;
334
335 sigemptyset(&sa.sa_mask);
336
Daniel Vetterc9c55452014-06-13 18:27:59 +0200337 igt_warn_on_f(sigaction(sigs[0], &sa, NULL) == -1,
338 "Could not set signal handler");
Jesse Barnes5406c632010-12-21 09:38:23 -0800339}
340
Jesse Barnes5406c632010-12-21 09:38:23 -0800341static void
342set_mode(struct connector *c)
343{
Daniel Vetter434be472012-07-21 17:36:36 +0200344 unsigned int fb_id = 0;
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100345 struct igt_fb fb_info[2] = { };
Damien Lespiaueecd0062013-09-03 19:46:19 +0100346 int j, test_mode_num, current_fb = 0, old_fb = -1;
Jesse Barnesc56cd102011-04-19 11:50:16 -0700347
Chris Wilson5534cb12011-02-11 10:48:04 +0000348 test_mode_num = 1;
349 if (force_mode){
Yi Sun4cceae72012-02-03 19:23:55 +0800350 memcpy( &c->mode, &force_timing, sizeof(force_timing));
351 c->mode.vrefresh =(force_timing.clock*1e3)/(force_timing.htotal*force_timing.vtotal);
Chris Wilson5534cb12011-02-11 10:48:04 +0000352 c->mode_valid = 1;
Yi Sun4cceae72012-02-03 19:23:55 +0800353 sprintf(c->mode.name, "%dx%d", force_timing.hdisplay, force_timing.vdisplay);
Chris Wilson5534cb12011-02-11 10:48:04 +0000354 } else if (test_all_modes)
Hai Lan62d51682011-02-11 11:14:15 -0500355 test_mode_num = c->connector->count_modes;
Jesse Barnes5406c632010-12-21 09:38:23 -0800356
Hai Lan62d51682011-02-11 11:14:15 -0500357 for (j = 0; j < test_mode_num; j++) {
Chris Wilson5534cb12011-02-11 10:48:04 +0000358
Hai Lan62d51682011-02-11 11:14:15 -0500359 if (test_all_modes)
360 c->mode = c->connector->modes[j];
Chris Wilson5534cb12011-02-11 10:48:04 +0000361
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100362 /* set_mode() only tests 2D modes */
Damien Lespiaua7d19372013-09-26 17:56:01 +0100363 if (c->mode.flags & DRM_MODE_FLAG_3D_MASK)
364 continue;
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100365
Chris Wilson5534cb12011-02-11 10:48:04 +0000366 if (!c->mode_valid)
367 continue;
368
369 width = c->mode.hdisplay;
370 height = c->mode.vdisplay;
371
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100372 fb_id = igt_create_fb(drm_fd, width, height,
Damien Lespiaud9ffb7d2014-06-20 12:02:09 +0100373 igt_bpp_depth_to_drm_format(bpp, depth),
374 tiling, &fb_info[current_fb]);
Damien Lespiaueecd0062013-09-03 19:46:19 +0100375 paint_output_info(c, &fb_info[current_fb]);
376 paint_color_key(&fb_info[current_fb]);
Hai Lan62d51682011-02-11 11:14:15 -0500377
Daniel Vetterc9c55452014-06-13 18:27:59 +0200378 igt_info("CRTC(%u):[%d]", c->crtc, j);
Daniel Vetter17787f32012-05-22 16:15:15 +0200379 kmstest_dump_mode(&c->mode);
Daniel Vetter73d1b882012-01-10 18:20:39 +0100380 if (drmModeSetCrtc(drm_fd, c->crtc, fb_id, 0, 0,
Chris Wilson5534cb12011-02-11 10:48:04 +0000381 &c->id, 1, &c->mode)) {
Daniel Vetterc9c55452014-06-13 18:27:59 +0200382 igt_warn("failed to set mode (%dx%d@%dHz): %s\n", width, height, c->mode.vrefresh, strerror(errno));
Chris Wilson5534cb12011-02-11 10:48:04 +0000383 continue;
Hai Lan62d51682011-02-11 11:14:15 -0500384 }
385
Damien Lespiaueecd0062013-09-03 19:46:19 +0100386 if (old_fb != -1)
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100387 igt_remove_fb(drm_fd, &fb_info[old_fb]);
Damien Lespiaueecd0062013-09-03 19:46:19 +0100388 old_fb = current_fb;
389 current_fb = 1 - current_fb;
390
Yi Sun41fe8112012-07-26 14:23:36 +0800391 if (sleep_between_modes && test_all_modes && !qr_code)
Hai Landac602b2011-02-11 23:25:36 -0500392 sleep(sleep_between_modes);
Yi Sun1f41a302011-12-01 18:57:16 +0800393
Daniel Vetter30cfde52014-02-13 19:15:38 +0100394 if (do_dpms) {
Daniel Vetter29ee36f2014-04-24 23:33:09 +0200395 kmstest_set_connector_dpms(drm_fd, c->connector, do_dpms);
Daniel Vetter30cfde52014-02-13 19:15:38 +0100396 sleep(sleep_between_modes);
Daniel Vetter29ee36f2014-04-24 23:33:09 +0200397 kmstest_set_connector_dpms(drm_fd, c->connector, DRM_MODE_DPMS_ON);
Daniel Vetter30cfde52014-02-13 19:15:38 +0100398 }
399
Yi Sun41fe8112012-07-26 14:23:36 +0800400 if (qr_code){
401 set_single();
402 pause();
403 }
Yi Sun1f41a302011-12-01 18:57:16 +0800404 }
405
Damien Lespiaueecd0062013-09-03 19:46:19 +0100406 if (test_all_modes)
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100407 igt_remove_fb(drm_fd, &fb_info[old_fb]);
Chris Wilson5534cb12011-02-11 10:48:04 +0000408
Jesse Barnes5406c632010-12-21 09:38:23 -0800409 drmModeFreeEncoder(c->encoder);
410 drmModeFreeConnector(c->connector);
411}
412
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100413static void do_set_stereo_mode(struct connector *c)
414{
415 uint32_t fb_id;
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100416
Thomas Wood4cb19462014-08-04 16:14:51 +0100417 fb_id = igt_create_stereo_fb(drm_fd, &c->mode,
418 igt_bpp_depth_to_drm_format(bpp, depth),
419 tiling);
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100420
Daniel Vetterc9c55452014-06-13 18:27:59 +0200421 igt_warn_on_f(drmModeSetCrtc(drm_fd, c->crtc, fb_id, 0, 0, &c->id, 1, &c->mode),
422 "failed to set mode (%dx%d@%dHz): %s\n", width, height, c->mode.vrefresh, strerror(errno));
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100423}
424
425static void
426set_stereo_mode(struct connector *c)
427{
Damien Lespiaue836b602013-09-30 17:42:33 +0100428 int i, n;
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100429
Damien Lespiaue836b602013-09-30 17:42:33 +0100430
431 if (specified_mode_num != -1)
432 n = 1;
433 else
434 n = c->connector->count_modes;
435
436 for (i = 0; i < n; i++) {
437 if (specified_mode_num == -1)
438 c->mode = c->connector->modes[i];
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100439
440 if (!c->mode_valid)
441 continue;
442
Damien Lespiaua7d19372013-09-26 17:56:01 +0100443 if (!(c->mode.flags & DRM_MODE_FLAG_3D_MASK))
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100444 continue;
445
Daniel Vetterc9c55452014-06-13 18:27:59 +0200446 igt_info("CRTC(%u): [%d]", c->crtc, i);
Damien Lespiau6de613f2013-09-30 18:03:33 +0100447 kmstest_dump_mode(&c->mode);
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100448 do_set_stereo_mode(c);
449
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100450 if (qr_code) {
451 set_single();
452 pause();
453 } else if (sleep_between_modes)
454 sleep(sleep_between_modes);
Daniel Vetter30cfde52014-02-13 19:15:38 +0100455
456 if (do_dpms) {
Daniel Vetter29ee36f2014-04-24 23:33:09 +0200457 kmstest_set_connector_dpms(drm_fd, c->connector, DRM_MODE_DPMS_OFF);
Daniel Vetter30cfde52014-02-13 19:15:38 +0100458 sleep(sleep_between_modes);
Daniel Vetter29ee36f2014-04-24 23:33:09 +0200459 kmstest_set_connector_dpms(drm_fd, c->connector, DRM_MODE_DPMS_ON);
Daniel Vetter30cfde52014-02-13 19:15:38 +0100460 }
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100461 }
462
463 drmModeFreeEncoder(c->encoder);
464 drmModeFreeConnector(c->connector);
465}
466
Jesse Barnes5406c632010-12-21 09:38:23 -0800467/*
468 * Re-probe outputs and light up as many as possible.
469 *
470 * On Intel, we have two CRTCs that we can drive independently with
471 * different timings and scanout buffers.
472 *
473 * Each connector has a corresponding encoder, except in the SDVO case
474 * where an encoder may have multiple connectors.
475 */
Daniel Vetter7f7cafe2012-01-24 10:50:05 +0100476int update_display(void)
Jesse Barnes5406c632010-12-21 09:38:23 -0800477{
478 struct connector *connectors;
479 int c;
480
Daniel Vetter73d1b882012-01-10 18:20:39 +0100481 resources = drmModeGetResources(drm_fd);
Jesse Barnes5406c632010-12-21 09:38:23 -0800482 if (!resources) {
Daniel Vetterc9c55452014-06-13 18:27:59 +0200483 igt_warn("drmModeGetResources failed: %s\n", strerror(errno));
Paulo Zanoni7ead7ba2011-09-15 15:14:18 -0300484 return 0;
Jesse Barnes5406c632010-12-21 09:38:23 -0800485 }
486
487 connectors = calloc(resources->count_connectors,
488 sizeof(struct connector));
489 if (!connectors)
Paulo Zanoni7ead7ba2011-09-15 15:14:18 -0300490 return 0;
Jesse Barnes5406c632010-12-21 09:38:23 -0800491
Damien Lespiaue836b602013-09-30 17:42:33 +0100492 if (test_preferred_mode || test_all_modes ||
493 force_mode || specified_disp_id != -1) {
Imre Deakbfb0cdd2013-05-31 00:21:43 +0300494 unsigned long crtc_idx_mask = -1UL;
495
Hai Lan62d51682011-02-11 11:14:15 -0500496 /* Find any connected displays */
497 for (c = 0; c < resources->count_connectors; c++) {
Imre Deakbfb0cdd2013-05-31 00:21:43 +0300498 struct connector *connector = &connectors[c];
499
500 connector->id = resources->connectors[c];
501 if (specified_disp_id != -1 &&
502 connector->id != specified_disp_id)
Yi Sun05bfbf42012-12-26 17:12:39 +0800503 continue;
504
Imre Deakbfb0cdd2013-05-31 00:21:43 +0300505 connector_find_preferred_mode(connector->id,
506 crtc_idx_mask,
507 specified_mode_num,
508 connector);
509 if (!connector->mode_valid)
510 continue;
511
512 set_mode(connector);
513
514 if (test_preferred_mode || force_mode ||
515 specified_mode_num != -1)
516 crtc_idx_mask &= ~(1 << connector->crtc_idx);
517
Hai Lan62d51682011-02-11 11:14:15 -0500518 }
Jesse Barnes5406c632010-12-21 09:38:23 -0800519 }
Damien Lespiau5d996342013-09-04 14:21:55 +0100520
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100521 if (test_stereo_modes) {
522 for (c = 0; c < resources->count_connectors; c++) {
523 struct connector *connector = &connectors[c];
524
525 connector->id = resources->connectors[c];
Damien Lespiauc128b732013-09-30 17:02:21 +0100526 if (specified_disp_id != -1 &&
527 connector->id != specified_disp_id)
528 continue;
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100529
530 connector_find_preferred_mode(connector->id,
531 -1UL,
532 specified_mode_num,
533 connector);
534 if (!connector->mode_valid)
535 continue;
536
537 set_stereo_mode(connector);
538 }
539 }
540
Damien Lespiau5d996342013-09-04 14:21:55 +0100541 free(connectors);
Jesse Barnes5406c632010-12-21 09:38:23 -0800542 drmModeFreeResources(resources);
Paulo Zanoni7ead7ba2011-09-15 15:14:18 -0300543 return 1;
Jesse Barnes5406c632010-12-21 09:38:23 -0800544}
545
Daniel Vettercef9b312014-02-13 19:22:35 +0100546static char optstr[] = "3hiaf:s:d:p:mrto:j:";
Jesse Barnes5406c632010-12-21 09:38:23 -0800547
Ben Widawsky54ed9382012-08-30 14:03:54 -0700548static void __attribute__((noreturn)) usage(char *name)
Jesse Barnes5406c632010-12-21 09:38:23 -0800549{
Daniel Vetterc9c55452014-06-13 18:27:59 +0200550 igt_info("usage: %s [-hiasdpmtf]\n", name);
551 igt_info("\t-i\tdump info\n");
552 igt_info("\t-a\ttest all modes\n");
553 igt_info("\t-s\t<duration>\tsleep between each mode test\n");
554 igt_info("\t-d\t<depth>\tbit depth of scanout buffer\n");
555 igt_info("\t-p\t<planew,h>,<crtcx,y>,<crtcw,h> test overlay plane\n");
556 igt_info("\t-m\ttest the preferred mode\n");
557 igt_info("\t-3\ttest all 3D modes\n");
558 igt_info("\t-t\tuse a tiled framebuffer\n");
559 igt_info("\t-j\tdo dpms off, optional arg to select dpms leve (1-3)\n");
560 igt_info("\t-r\tprint a QR code on the screen whose content is \"pass\" for the automatic test\n");
561 igt_info("\t-o\t<id of the display>,<number of the mode>\tonly test specified mode on the specified display\n");
562 igt_info("\t-f\t<clock MHz>,<hdisp>,<hsync-start>,<hsync-end>,<htotal>,\n");
563 igt_info("\t\t<vdisp>,<vsync-start>,<vsync-end>,<vtotal>\n");
564 igt_info("\t\ttest force mode\n");
565 igt_info("\tDefault is to test all modes.\n");
Thomas Wood8fc41072014-07-25 15:35:36 +0100566 exit((optopt) ? -1 : 0);
Jesse Barnes5406c632010-12-21 09:38:23 -0800567}
568
Hai Lan62d51682011-02-11 11:14:15 -0500569#define dump_resource(res) if (res) dump_##res()
570
Jesse Barnes7255a842014-03-26 11:02:48 -0700571static void cleanup_and_exit(int ret)
572{
573 close(drm_fd);
Jesse Barnes7255a842014-03-26 11:02:48 -0700574 exit(ret);
575}
576
Jesse Barnes5406c632010-12-21 09:38:23 -0800577static gboolean input_event(GIOChannel *source, GIOCondition condition,
Yi Sun41fe8112012-07-26 14:23:36 +0800578 gpointer data)
Jesse Barnes5406c632010-12-21 09:38:23 -0800579{
Daniel Vetter74d65452011-12-18 00:24:45 +0100580 gchar buf[2];
Jesse Barnes5406c632010-12-21 09:38:23 -0800581 gsize count;
582
Chris Wilson28032382011-02-11 10:56:41 +0000583 count = read(g_io_channel_unix_get_fd(source), buf, sizeof(buf));
Jesse Barnes24e60382011-10-24 17:15:34 +0200584 if (buf[0] == 'q' && (count == 1 || buf[1] == '\n')) {
Jesse Barnes7255a842014-03-26 11:02:48 -0700585 cleanup_and_exit(0);
Jesse Barnesea416332012-02-27 12:46:11 -0800586 }
Jesse Barnes5406c632010-12-21 09:38:23 -0800587
588 return TRUE;
589}
590
Yi Sun41fe8112012-07-26 14:23:36 +0800591static void enter_exec_path( char **argv )
592{
593 char *exec_path = NULL;
594 char *pos = NULL;
595 short len_path = 0;
Imre Deak31dfc982012-10-10 16:04:45 +0300596 int ret;
Yi Sun41fe8112012-07-26 14:23:36 +0800597
598 len_path = strlen( argv[0] );
599 exec_path = (char*) malloc(len_path);
600
601 memcpy(exec_path, argv[0], len_path);
602 pos = strrchr(exec_path, '/');
603 if (pos != NULL)
604 *(pos+1) = '\0';
605
Imre Deak31dfc982012-10-10 16:04:45 +0300606 ret = chdir(exec_path);
Daniel Vetter83440952013-08-13 12:35:58 +0200607 igt_assert(ret == 0);
Yi Sun41fe8112012-07-26 14:23:36 +0800608 free(exec_path);
609}
610
Imre Deak63746412014-05-12 13:29:49 +0300611static void restore_termio_mode(int sig)
612{
613 tcsetattr(tio_fd, TCSANOW, &saved_tio);
614 close(tio_fd);
615}
616
Jesse Barnes7255a842014-03-26 11:02:48 -0700617static void set_termio_mode(void)
618{
619 struct termios tio;
620
Thomas Wood8408e002014-07-24 17:45:48 +0100621 /* don't attempt to set terminal attributes if not in the foreground
622 * process group */
623 if (getpgrp() != tcgetpgrp(STDOUT_FILENO))
624 return;
625
Imre Deak63746412014-05-12 13:29:49 +0300626 tio_fd = dup(STDIN_FILENO);
627 tcgetattr(tio_fd, &saved_tio);
628 igt_install_exit_handler(restore_termio_mode);
Jesse Barnes7255a842014-03-26 11:02:48 -0700629 tio = saved_tio;
Jesse Barnes7255a842014-03-26 11:02:48 -0700630 tio.c_lflag &= ~(ICANON | ECHO);
Imre Deak63746412014-05-12 13:29:49 +0300631 tcsetattr(tio_fd, TCSANOW, &tio);
Jesse Barnes7255a842014-03-26 11:02:48 -0700632}
633
Jesse Barnes5406c632010-12-21 09:38:23 -0800634int main(int argc, char **argv)
635{
636 int c;
Jesse Barnes5406c632010-12-21 09:38:23 -0800637 int ret = 0;
Daniel Vetter7f7cafe2012-01-24 10:50:05 +0100638 GIOChannel *stdinchannel;
Jesse Barnes5406c632010-12-21 09:38:23 -0800639 GMainLoop *mainloop;
Yi Sun4cceae72012-02-03 19:23:55 +0800640 float force_clock;
Damien Lespiau66477a22013-09-05 16:49:11 +0100641 bool opt_dump_info = false;
Thomas Woodff6b0682014-07-31 16:26:55 +0100642 struct option long_opts[] = {
643 {"list-subtests", 0, 0, SUBTEST_OPTS},
644 {"run-subtest", 1, 0, SUBTEST_OPTS},
645 { 0, 0, 0, 0 }
646 };
Jesse Barnes5406c632010-12-21 09:38:23 -0800647
Daniel Vetter1caaf0a2013-08-12 12:17:35 +0200648 igt_skip_on_simulation();
Damien Lespiau5fa15f72013-04-29 18:40:39 +0100649
Yi Sun41fe8112012-07-26 14:23:36 +0800650 enter_exec_path( argv );
651
Thomas Woodff6b0682014-07-31 16:26:55 +0100652 while ((c = getopt_long(argc, argv, optstr, long_opts, NULL)) != -1) {
Jesse Barnes5406c632010-12-21 09:38:23 -0800653 switch (c) {
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100654 case '3':
655 test_stereo_modes = 1;
656 break;
Hai Lan62d51682011-02-11 11:14:15 -0500657 case 'i':
Damien Lespiau66477a22013-09-05 16:49:11 +0100658 opt_dump_info = true;
Hai Lan62d51682011-02-11 11:14:15 -0500659 break;
660 case 'a':
661 test_all_modes = 1;
662 break;
663 case 'f':
664 force_mode = 1;
Yi Sun4cceae72012-02-03 19:23:55 +0800665 if(sscanf(optarg,"%f,%hu,%hu,%hu,%hu,%hu,%hu,%hu,%hu",
666 &force_clock,&force_timing.hdisplay, &force_timing.hsync_start,&force_timing.hsync_end,&force_timing.htotal,
667 &force_timing.vdisplay, &force_timing.vsync_start, &force_timing.vsync_end, &force_timing.vtotal)!= 9)
Hai Lan62d51682011-02-11 11:14:15 -0500668 usage(argv[0]);
Yi Sun4cceae72012-02-03 19:23:55 +0800669 force_timing.clock = force_clock*1000;
670
Hai Lan62d51682011-02-11 11:14:15 -0500671 break;
672 case 's':
673 sleep_between_modes = atoi(optarg);
674 break;
Daniel Vetter30cfde52014-02-13 19:15:38 +0100675 case 'j':
Daniel Vettercef9b312014-02-13 19:22:35 +0100676 do_dpms = atoi(optarg);
677 if (do_dpms == 0)
678 do_dpms = DRM_MODE_DPMS_OFF;
Daniel Vetter30cfde52014-02-13 19:15:38 +0100679 break;
Jesse Barnesc56cd102011-04-19 11:50:16 -0700680 case 'd':
681 depth = atoi(optarg);
Daniel Vetterc9c55452014-06-13 18:27:59 +0200682 igt_info("using depth %d\n", depth);
Jesse Barnesc56cd102011-04-19 11:50:16 -0700683 break;
Jesse Barnes7230c012011-06-07 13:17:46 -0700684 case 'p':
Jesse Barnes5a9d82c2011-12-07 08:22:41 -0800685 if (sscanf(optarg, "%d,%d,%d,%d,%d,%d", &plane_width,
686 &plane_height, &crtc_x, &crtc_y,
687 &crtc_w, &crtc_h) != 6)
Jesse Barnes24e60382011-10-24 17:15:34 +0200688 usage(argv[0]);
Jesse Barnes7230c012011-06-07 13:17:46 -0700689 test_plane = 1;
690 break;
Paulo Zanoni9fe11482011-09-15 15:13:41 -0300691 case 'm':
692 test_preferred_mode = 1;
693 break;
Jesse Barnesb707feb2011-06-07 13:27:35 -0700694 case 't':
Damien Lespiaud9ffb7d2014-06-20 12:02:09 +0100695 tiling = I915_TILING_X;
Jesse Barnesb707feb2011-06-07 13:27:35 -0700696 break;
Yi Sun41fe8112012-07-26 14:23:36 +0800697 case 'r':
698 qr_code = 1;
699 break;
Yi Sun53895ac2012-09-25 17:13:17 +0800700 case 'o':
Yi Sun05bfbf42012-12-26 17:12:39 +0800701 sscanf(optarg, "%d,%d", &specified_disp_id, &specified_mode_num);
Yi Sun53895ac2012-09-25 17:13:17 +0800702 break;
Thomas Woodff6b0682014-07-31 16:26:55 +0100703 case SUBTEST_OPTS:
704 /* invalid subtest options */
705 exit(IGT_EXIT_INVALID);
706 break;
Jesse Barnes5406c632010-12-21 09:38:23 -0800707 default:
Jesse Barnes5406c632010-12-21 09:38:23 -0800708 /* fall through */
709 case 'h':
710 usage(argv[0]);
711 break;
712 }
713 }
Damien Lespiau03962732013-09-03 14:57:31 +0100714
Jesse Barnes7255a842014-03-26 11:02:48 -0700715 set_termio_mode();
716
Damien Lespiau03962732013-09-03 14:57:31 +0100717 if (depth <= 8)
718 bpp = 8;
719 else if (depth <= 16)
720 bpp = 16;
721 else if (depth <= 32)
722 bpp = 32;
723
Damien Lespiau66477a22013-09-05 16:49:11 +0100724 if (!test_all_modes && !force_mode && !test_preferred_mode &&
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100725 specified_mode_num == -1 && !test_stereo_modes)
Paulo Zanoni9fe11482011-09-15 15:13:41 -0300726 test_all_modes = 1;
Jesse Barnes5406c632010-12-21 09:38:23 -0800727
Daniel Vetter0732cc52012-05-22 12:01:36 +0200728 drm_fd = drm_open_any();
Jesse Barnes5406c632010-12-21 09:38:23 -0800729
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100730 if (test_stereo_modes &&
731 drmSetClientCap(drm_fd, DRM_CLIENT_CAP_STEREO_3D, 1) < 0) {
Daniel Vetterc9c55452014-06-13 18:27:59 +0200732 igt_warn("DRM_CLIENT_CAP_STEREO_3D failed\n");
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100733 goto out_close;
734 }
735
Damien Lespiau66477a22013-09-05 16:49:11 +0100736 if (opt_dump_info) {
737 dump_info();
738 goto out_close;
739 }
740
Daniel Vetter33f08842014-08-12 11:23:09 +0200741 kmstest_set_vt_graphics_mode();
Imre Deak01b408e2013-05-08 19:06:44 +0300742
Jesse Barnes5406c632010-12-21 09:38:23 -0800743 mainloop = g_main_loop_new(NULL, FALSE);
744 if (!mainloop) {
Daniel Vetterc9c55452014-06-13 18:27:59 +0200745 igt_warn("failed to create glib mainloop\n");
Jesse Barnes5406c632010-12-21 09:38:23 -0800746 ret = -1;
Daniel Vetter7f7cafe2012-01-24 10:50:05 +0100747 goto out_close;
Jesse Barnes5406c632010-12-21 09:38:23 -0800748 }
749
Daniel Vetter7f7cafe2012-01-24 10:50:05 +0100750 if (!testdisplay_setup_hotplug()) {
Daniel Vetterc9c55452014-06-13 18:27:59 +0200751 igt_warn("failed to initialize hotplug support\n");
Daniel Vetter7f7cafe2012-01-24 10:50:05 +0100752 goto out_mainloop;
Jesse Barnes5406c632010-12-21 09:38:23 -0800753 }
754
755 stdinchannel = g_io_channel_unix_new(0);
756 if (!stdinchannel) {
Daniel Vetterc9c55452014-06-13 18:27:59 +0200757 igt_warn("failed to create stdin GIO channel\n");
Daniel Vetter7f7cafe2012-01-24 10:50:05 +0100758 goto out_hotplug;
Jesse Barnes5406c632010-12-21 09:38:23 -0800759 }
760
761 ret = g_io_add_watch(stdinchannel, G_IO_IN | G_IO_ERR, input_event,
762 NULL);
763 if (ret < 0) {
Daniel Vetterc9c55452014-06-13 18:27:59 +0200764 igt_warn("failed to add watch on stdin GIO channel\n");
Daniel Vetter7f7cafe2012-01-24 10:50:05 +0100765 goto out_stdio;
Jesse Barnes5406c632010-12-21 09:38:23 -0800766 }
767
Paulo Zanoni17cecce2011-09-16 18:06:27 -0300768 ret = 0;
769
Paulo Zanoni7ead7ba2011-09-15 15:14:18 -0300770 if (!update_display()) {
771 ret = 1;
Daniel Vetter7f7cafe2012-01-24 10:50:05 +0100772 goto out_stdio;
Paulo Zanoni7ead7ba2011-09-15 15:14:18 -0300773 }
774
Damien Lespiau66477a22013-09-05 16:49:11 +0100775 if (test_all_modes)
Daniel Vetter7f7cafe2012-01-24 10:50:05 +0100776 goto out_stdio;
Paulo Zanoni7ead7ba2011-09-15 15:14:18 -0300777
Jesse Barnes5406c632010-12-21 09:38:23 -0800778 g_main_loop_run(mainloop);
779
Daniel Vetter7f7cafe2012-01-24 10:50:05 +0100780out_stdio:
Jesse Barnes5406c632010-12-21 09:38:23 -0800781 g_io_channel_shutdown(stdinchannel, TRUE, NULL);
Daniel Vetter7f7cafe2012-01-24 10:50:05 +0100782out_hotplug:
783 testdisplay_cleanup_hotplug();
784out_mainloop:
Jesse Barnes5406c632010-12-21 09:38:23 -0800785 g_main_loop_unref(mainloop);
Jesse Barnes5406c632010-12-21 09:38:23 -0800786out_close:
Daniel Vetter0732cc52012-05-22 12:01:36 +0200787 close(drm_fd);
788
Jesse Barnes5406c632010-12-21 09:38:23 -0800789 return ret;
790}