blob: 45280e4cad823884f927616bc1ea6ce0ee582cf2 [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
Thomas Wood804e11f2015-08-17 17:57:43 +010052#include "igt.h"
Jesse Barnes5406c632010-12-21 09:38:23 -080053#include <cairo.h>
54#include <errno.h>
Damien Lespiau7b8ba122015-03-03 14:11:05 +000055#include <getopt.h>
Jesse Barnes5406c632010-12-21 09:38:23 -080056#include <math.h>
57#include <stdint.h>
Damien Lespiau66477a22013-09-05 16:49:11 +010058#include <stdbool.h>
Damien Lespiau9a8fda72012-09-10 13:33:26 +010059#include <strings.h>
Jesse Barnes5406c632010-12-21 09:38:23 -080060#include <unistd.h>
Jesse Barnes7255a842014-03-26 11:02:48 -070061#include <termios.h>
Jesse Barnes5406c632010-12-21 09:38:23 -080062#include <sys/poll.h>
63#include <sys/time.h>
Chris Wilson5534cb12011-02-11 10:48:04 +000064#include <sys/ioctl.h>
Damien Lespiau9a8fda72012-09-10 13:33:26 +010065#include <sys/types.h>
66#include <sys/stat.h>
Jesse Barnes5406c632010-12-21 09:38:23 -080067
Daniel Vetter7f7cafe2012-01-24 10:50:05 +010068#include "testdisplay.h"
Jesse Barnes5406c632010-12-21 09:38:23 -080069
Yi Sun41fe8112012-07-26 14:23:36 +080070#include <stdlib.h>
71#include <signal.h>
72
Damien Lespiau7b8ba122015-03-03 14:11:05 +000073#define SUBTEST_OPTS 1
Thomas Wood895204f2014-10-30 15:54:02 +000074#define HELP_DESCRIPTION 2
Damien Lespiau7b8ba122015-03-03 14:11:05 +000075#define Yb_OPT 3
76#define Yf_OPT 4
Thomas Woodff6b0682014-07-31 16:26:55 +010077
Imre Deak63746412014-05-12 13:29:49 +030078static int tio_fd;
Jesse Barnes7255a842014-03-26 11:02:48 -070079struct termios saved_tio;
80
Jesse Barnes5406c632010-12-21 09:38:23 -080081drmModeRes *resources;
Daniel Vetter73d1b882012-01-10 18:20:39 +010082int drm_fd, modes;
Damien Lespiau66477a22013-09-05 16:49:11 +010083int test_all_modes = 0, test_preferred_mode = 0, force_mode = 0, test_plane,
Damien Lespiaud9ffb7d2014-06-20 12:02:09 +010084 test_stereo_modes;
Tvrtko Ursuline36091d2015-03-03 14:11:01 +000085uint64_t tiling = LOCAL_DRM_FORMAT_MOD_NONE;
Hai Lan62d51682011-02-11 11:14:15 -050086int sleep_between_modes = 5;
Daniel Vettercef9b312014-02-13 19:22:35 +010087int do_dpms = 0; /* This aliases to DPMS_ON */
Jesse Barnes5a9d82c2011-12-07 08:22:41 -080088uint32_t depth = 24, stride, bpp;
Yi Sun41fe8112012-07-26 14:23:36 +080089int qr_code = 0;
Yi Sun6157d242013-02-12 23:11:35 +080090int specified_mode_num = -1, specified_disp_id = -1;
Hai Lan62d51682011-02-11 11:14:15 -050091
Yi Sun4cceae72012-02-03 19:23:55 +080092drmModeModeInfo force_timing;
Jesse Barnes5406c632010-12-21 09:38:23 -080093
Jesse Barnes5a9d82c2011-12-07 08:22:41 -080094int crtc_x, crtc_y, crtc_w, crtc_h, width, height;
Jesse Barnes1f4c37a2011-10-28 05:25:53 +020095unsigned int plane_fb_id;
96unsigned int plane_crtc_id;
97unsigned int plane_id;
98int plane_width, plane_height;
Jesse Barnes5a9d82c2011-12-07 08:22:41 -080099static const uint32_t SPRITE_COLOR_KEY = 0x00aaaaaa;
Jesse Barnes24e60382011-10-24 17:15:34 +0200100
Jesse Barnes5406c632010-12-21 09:38:23 -0800101/*
102 * Mode setting with the kernel interfaces is a bit of a chore.
103 * First you have to find the connector in question and make sure the
104 * requested mode is available.
105 * Then you need to find the encoder attached to that connector so you
106 * can bind it with a free crtc.
107 */
108struct connector {
109 uint32_t id;
110 int mode_valid;
111 drmModeModeInfo mode;
112 drmModeEncoder *encoder;
113 drmModeConnector *connector;
114 int crtc;
Imre Deakbfb0cdd2013-05-31 00:21:43 +0300115 int crtc_idx;
Jesse Barnes9c29be42011-11-02 12:57:40 -0700116 int pipe;
Jesse Barnes5406c632010-12-21 09:38:23 -0800117};
118
Yi Sun3d46ca82012-02-03 22:45:39 +0800119static void dump_connectors_fd(int drmfd)
Hai Lan62d51682011-02-11 11:14:15 -0500120{
121 int i, j;
122
Yi Sun3d46ca82012-02-03 22:45:39 +0800123 drmModeRes *mode_resources = drmModeGetResources(drmfd);
124
125 if (!mode_resources) {
Daniel Vetterc9c55452014-06-13 18:27:59 +0200126 igt_warn("drmModeGetResources failed: %s\n", strerror(errno));
Yi Sun3d46ca82012-02-03 22:45:39 +0800127 return;
128 }
129
Daniel Vetterc9c55452014-06-13 18:27:59 +0200130 igt_info("Connectors:\n");
131 igt_info("id\tencoder\tstatus\t\ttype\tsize (mm)\tmodes\n");
Yi Sun3d46ca82012-02-03 22:45:39 +0800132 for (i = 0; i < mode_resources->count_connectors; i++) {
Hai Lan62d51682011-02-11 11:14:15 -0500133 drmModeConnector *connector;
134
Daniel Vetterdb4f83c2015-12-01 11:24:19 +0100135 connector = drmModeGetConnectorCurrent(drmfd,
136 mode_resources->connectors[i]);
Hai Lan62d51682011-02-11 11:14:15 -0500137 if (!connector) {
Daniel Vetterc9c55452014-06-13 18:27:59 +0200138 igt_warn("could not get connector %i: %s\n", mode_resources->connectors[i], strerror(errno));
Hai Lan62d51682011-02-11 11:14:15 -0500139 continue;
140 }
141
Daniel Vetterc9c55452014-06-13 18:27:59 +0200142 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 -0500143
144 if (!connector->count_modes)
145 continue;
146
Daniel Vetterc9c55452014-06-13 18:27:59 +0200147 igt_info(" modes:\n");
148 igt_info(" name refresh (Hz) hdisp hss hse htot vdisp ""vss vse vtot flags type clock\n");
Yi Sun53895ac2012-09-25 17:13:17 +0800149 for (j = 0; j < connector->count_modes; j++){
Daniel Vetterc9c55452014-06-13 18:27:59 +0200150 igt_info("[%d]", j);
Daniel Vetter17787f32012-05-22 16:15:15 +0200151 kmstest_dump_mode(&connector->modes[j]);
Yi Sun53895ac2012-09-25 17:13:17 +0800152 }
Hai Lan62d51682011-02-11 11:14:15 -0500153
154 drmModeFreeConnector(connector);
155 }
Daniel Vetterc9c55452014-06-13 18:27:59 +0200156 igt_info("\n");
Yi Sun3d46ca82012-02-03 22:45:39 +0800157
158 drmModeFreeResources(mode_resources);
Hai Lan62d51682011-02-11 11:14:15 -0500159}
160
Yi Sun3d46ca82012-02-03 22:45:39 +0800161static void dump_crtcs_fd(int drmfd)
Hai Lan62d51682011-02-11 11:14:15 -0500162{
163 int i;
Yi Sun3d46ca82012-02-03 22:45:39 +0800164 drmModeRes *mode_resources = drmModeGetResources(drmfd);
Hai Lan62d51682011-02-11 11:14:15 -0500165
Daniel Vetterc9c55452014-06-13 18:27:59 +0200166 igt_info("CRTCs:\n");
167 igt_info("id\tfb\tpos\tsize\n");
Yi Sun3d46ca82012-02-03 22:45:39 +0800168 for (i = 0; i < mode_resources->count_crtcs; i++) {
Hai Lan62d51682011-02-11 11:14:15 -0500169 drmModeCrtc *crtc;
170
Yi Sun3d46ca82012-02-03 22:45:39 +0800171 crtc = drmModeGetCrtc(drmfd, mode_resources->crtcs[i]);
Hai Lan62d51682011-02-11 11:14:15 -0500172 if (!crtc) {
Daniel Vetterc9c55452014-06-13 18:27:59 +0200173 igt_warn("could not get crtc %i: %s\n", mode_resources->crtcs[i], strerror(errno));
Hai Lan62d51682011-02-11 11:14:15 -0500174 continue;
175 }
Daniel Vetterc9c55452014-06-13 18:27:59 +0200176 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 +0200177 kmstest_dump_mode(&crtc->mode);
Hai Lan62d51682011-02-11 11:14:15 -0500178
179 drmModeFreeCrtc(crtc);
180 }
Daniel Vetterc9c55452014-06-13 18:27:59 +0200181 igt_info("\n");
Yi Sun3d46ca82012-02-03 22:45:39 +0800182
183 drmModeFreeResources(mode_resources);
Hai Lan62d51682011-02-11 11:14:15 -0500184}
185
Damien Lespiau66477a22013-09-05 16:49:11 +0100186static void dump_info(void)
187{
188 dump_connectors_fd(drm_fd);
189 dump_crtcs_fd(drm_fd);
190}
191
Imre Deakbfb0cdd2013-05-31 00:21:43 +0300192static void connector_find_preferred_mode(uint32_t connector_id,
193 unsigned long crtc_idx_mask,
Jesse Barnese28acef2016-01-14 14:03:53 -0800194 int mode_num, struct connector *c,
195 bool probe)
Jesse Barnes5406c632010-12-21 09:38:23 -0800196{
Imre Deakbfb0cdd2013-05-31 00:21:43 +0300197 struct kmstest_connector_config config;
Jesse Barnese28acef2016-01-14 14:03:53 -0800198 bool ret;
Jesse Barnes5406c632010-12-21 09:38:23 -0800199
Jesse Barnese28acef2016-01-14 14:03:53 -0800200 if (probe)
201 ret = kmstest_probe_connector_config(drm_fd, connector_id,
202 crtc_idx_mask, &config);
203 else
204 ret = kmstest_get_connector_config(drm_fd, connector_id,
205 crtc_idx_mask, &config);
206 if (!ret) {
Jesse Barnes5406c632010-12-21 09:38:23 -0800207 c->mode_valid = 0;
208 return;
209 }
210
Imre Deakbfb0cdd2013-05-31 00:21:43 +0300211 c->connector = config.connector;
212 c->encoder = config.encoder;
213 c->crtc = config.crtc->crtc_id;
214 c->crtc_idx = config.crtc_idx;
215 c->pipe = config.pipe;
216
217 if (mode_num != -1) {
Daniel Vetter83440952013-08-13 12:35:58 +0200218 igt_assert(mode_num < config.connector->count_modes);
Imre Deakbfb0cdd2013-05-31 00:21:43 +0300219 c->mode = config.connector->modes[mode_num];
220 } else {
221 c->mode = config.default_mode;
Jesse Barnes5406c632010-12-21 09:38:23 -0800222 }
Imre Deakbfb0cdd2013-05-31 00:21:43 +0300223 c->mode_valid = 1;
Jesse Barnes5406c632010-12-21 09:38:23 -0800224}
225
Jesse Barnes0d3043f2011-04-18 16:48:27 -0700226static void
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100227paint_color_key(struct igt_fb *fb_info)
Jesse Barnes5a9d82c2011-12-07 08:22:41 -0800228{
Tomeu Vizoso99bdf4f2016-05-06 15:36:22 +0200229 cairo_t *cr = igt_get_cairo_ctx(drm_fd, fb_info);
Damien Lespiau5a1d8432013-09-04 12:12:37 +0100230
Tomeu Vizoso99bdf4f2016-05-06 15:36:22 +0200231 cairo_rectangle(cr, crtc_x, crtc_y, crtc_w, crtc_h);
232 cairo_set_source_rgb(cr, .8, .8, .8);
233 cairo_fill(cr);
Jesse Barnes5a9d82c2011-12-07 08:22:41 -0800234
Tomeu Vizoso99bdf4f2016-05-06 15:36:22 +0200235 igt_assert(!cairo_status(cr));
Jesse Barnes5a9d82c2011-12-07 08:22:41 -0800236
Tomeu Vizoso99bdf4f2016-05-06 15:36:22 +0200237 cairo_destroy(cr);
Jesse Barnes5a9d82c2011-12-07 08:22:41 -0800238}
239
Yi Sun41fe8112012-07-26 14:23:36 +0800240static void paint_image(cairo_t *cr, const char *file)
241{
Thomas Woodecb03262015-04-13 17:37:22 +0100242 int img_x, img_y, img_w, img_h;
Yi Sun41fe8112012-07-26 14:23:36 +0800243
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
Thomas Woodecb03262015-04-13 17:37:22 +0100250 igt_paint_image(cr, file, img_x, img_y, img_h, img_w);
Yi Sun41fe8112012-07-26 14:23:36 +0800251}
252
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100253static void paint_output_info(struct connector *c, struct igt_fb *fb)
Jesse Barnes0d3043f2011-04-18 16:48:27 -0700254{
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100255 cairo_t *cr = igt_get_cairo_ctx(drm_fd, fb);
Imre Deakf68d9642013-05-24 17:26:54 +0300256 int l_width = fb->width;
257 int l_height = fb->height;
Imre Deak542a40c2013-05-30 15:03:48 +0300258 double str_width;
259 double x, y, top_y;
260 double max_width;
261 int i;
Jesse Barnes5406c632010-12-21 09:38:23 -0800262
Imre Deak542a40c2013-05-30 15:03:48 +0300263 cairo_move_to(cr, l_width / 2, l_height / 2);
Jesse Barnes5406c632010-12-21 09:38:23 -0800264
Imre Deak542a40c2013-05-30 15:03:48 +0300265 /* Print connector and mode name */
Jesse Barnes5406c632010-12-21 09:38:23 -0800266 cairo_set_font_size(cr, 48);
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100267 igt_cairo_printf_line(cr, align_hcenter, 10, "%s",
Imre Deak542a40c2013-05-30 15:03:48 +0300268 kmstest_connector_type_str(c->connector->connector_type));
Jesse Barnes5406c632010-12-21 09:38:23 -0800269
Jesse Barnes5406c632010-12-21 09:38:23 -0800270 cairo_set_font_size(cr, 36);
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100271 str_width = igt_cairo_printf_line(cr, align_hcenter, 10,
Imre Deak542a40c2013-05-30 15:03:48 +0300272 "%s @ %dHz on %s encoder", c->mode.name, c->mode.vrefresh,
273 kmstest_encoder_type_str(c->encoder->encoder_type));
274
275 cairo_rel_move_to(cr, -str_width / 2, 0);
Jesse Barnes5406c632010-12-21 09:38:23 -0800276
277 /* List available modes */
Jesse Barnes5406c632010-12-21 09:38:23 -0800278 cairo_set_font_size(cr, 18);
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100279 str_width = igt_cairo_printf_line(cr, align_left, 10,
Imre Deak542a40c2013-05-30 15:03:48 +0300280 "Available modes:");
281 cairo_rel_move_to(cr, str_width, 0);
282 cairo_get_current_point(cr, &x, &top_y);
Jesse Barnes5406c632010-12-21 09:38:23 -0800283
Imre Deak542a40c2013-05-30 15:03:48 +0300284 max_width = 0;
Jesse Barnes5406c632010-12-21 09:38:23 -0800285 for (i = 0; i < c->connector->count_modes; i++) {
Imre Deak542a40c2013-05-30 15:03:48 +0300286 cairo_get_current_point(cr, &x, &y);
287 if (y >= l_height) {
288 x += max_width + 10;
289 max_width = 0;
290 cairo_move_to(cr, x, top_y);
Jesse Barnes5406c632010-12-21 09:38:23 -0800291 }
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100292 str_width = igt_cairo_printf_line(cr, align_right, 10,
Imre Deak542a40c2013-05-30 15:03:48 +0300293 "%s @ %dHz", c->connector->modes[i].name,
294 c->connector->modes[i].vrefresh);
295 if (str_width > max_width)
296 max_width = str_width;
Jesse Barnes5406c632010-12-21 09:38:23 -0800297 }
Yi Sun41fe8112012-07-26 14:23:36 +0800298
299 if (qr_code)
Joonas Lahtinena95033f2015-03-31 15:53:17 +0300300 paint_image(cr, "pass.png");
Imre Deakf68d9642013-05-24 17:26:54 +0300301
Daniel Vetter83440952013-08-13 12:35:58 +0200302 igt_assert(!cairo_status(cr));
Damien Lespiau660a7ff2014-06-30 16:19:05 +0100303
304 cairo_destroy(cr);
Yi Sun41fe8112012-07-26 14:23:36 +0800305}
306
307static void sighandler(int signo)
308{
309 return;
310}
311
312static void set_single(void)
313{
314 int sigs[] = { SIGUSR1 };
315 struct sigaction sa;
316 sa.sa_handler = sighandler;
317
318 sigemptyset(&sa.sa_mask);
319
Daniel Vetterc9c55452014-06-13 18:27:59 +0200320 igt_warn_on_f(sigaction(sigs[0], &sa, NULL) == -1,
321 "Could not set signal handler");
Jesse Barnes5406c632010-12-21 09:38:23 -0800322}
323
Jesse Barnes5406c632010-12-21 09:38:23 -0800324static void
325set_mode(struct connector *c)
326{
Daniel Vetter434be472012-07-21 17:36:36 +0200327 unsigned int fb_id = 0;
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100328 struct igt_fb fb_info[2] = { };
Damien Lespiaueecd0062013-09-03 19:46:19 +0100329 int j, test_mode_num, current_fb = 0, old_fb = -1;
Jesse Barnesc56cd102011-04-19 11:50:16 -0700330
Chris Wilson5534cb12011-02-11 10:48:04 +0000331 test_mode_num = 1;
332 if (force_mode){
Yi Sun4cceae72012-02-03 19:23:55 +0800333 memcpy( &c->mode, &force_timing, sizeof(force_timing));
334 c->mode.vrefresh =(force_timing.clock*1e3)/(force_timing.htotal*force_timing.vtotal);
Chris Wilson5534cb12011-02-11 10:48:04 +0000335 c->mode_valid = 1;
Yi Sun4cceae72012-02-03 19:23:55 +0800336 sprintf(c->mode.name, "%dx%d", force_timing.hdisplay, force_timing.vdisplay);
Chris Wilson5534cb12011-02-11 10:48:04 +0000337 } else if (test_all_modes)
Hai Lan62d51682011-02-11 11:14:15 -0500338 test_mode_num = c->connector->count_modes;
Jesse Barnes5406c632010-12-21 09:38:23 -0800339
Hai Lan62d51682011-02-11 11:14:15 -0500340 for (j = 0; j < test_mode_num; j++) {
Chris Wilson5534cb12011-02-11 10:48:04 +0000341
Hai Lan62d51682011-02-11 11:14:15 -0500342 if (test_all_modes)
343 c->mode = c->connector->modes[j];
Chris Wilson5534cb12011-02-11 10:48:04 +0000344
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100345 /* set_mode() only tests 2D modes */
Damien Lespiaua7d19372013-09-26 17:56:01 +0100346 if (c->mode.flags & DRM_MODE_FLAG_3D_MASK)
347 continue;
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100348
Chris Wilson5534cb12011-02-11 10:48:04 +0000349 if (!c->mode_valid)
350 continue;
351
352 width = c->mode.hdisplay;
353 height = c->mode.vdisplay;
354
Ville Syrjälä5b113d32015-12-17 01:39:31 +0200355 fb_id = igt_create_pattern_fb(drm_fd, width, height,
356 igt_bpp_depth_to_drm_format(bpp, depth),
357 tiling, &fb_info[current_fb]);
Damien Lespiaueecd0062013-09-03 19:46:19 +0100358 paint_output_info(c, &fb_info[current_fb]);
359 paint_color_key(&fb_info[current_fb]);
Hai Lan62d51682011-02-11 11:14:15 -0500360
Daniel Vetterc9c55452014-06-13 18:27:59 +0200361 igt_info("CRTC(%u):[%d]", c->crtc, j);
Daniel Vetter17787f32012-05-22 16:15:15 +0200362 kmstest_dump_mode(&c->mode);
Daniel Vetter73d1b882012-01-10 18:20:39 +0100363 if (drmModeSetCrtc(drm_fd, c->crtc, fb_id, 0, 0,
Chris Wilson5534cb12011-02-11 10:48:04 +0000364 &c->id, 1, &c->mode)) {
Daniel Vetterc9c55452014-06-13 18:27:59 +0200365 igt_warn("failed to set mode (%dx%d@%dHz): %s\n", width, height, c->mode.vrefresh, strerror(errno));
Ander Conselvan de Oliveira571942f2015-05-27 10:33:41 +0300366 igt_remove_fb(drm_fd, &fb_info[current_fb]);
Chris Wilson5534cb12011-02-11 10:48:04 +0000367 continue;
Hai Lan62d51682011-02-11 11:14:15 -0500368 }
369
Damien Lespiaueecd0062013-09-03 19:46:19 +0100370 if (old_fb != -1)
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100371 igt_remove_fb(drm_fd, &fb_info[old_fb]);
Damien Lespiaueecd0062013-09-03 19:46:19 +0100372 old_fb = current_fb;
373 current_fb = 1 - current_fb;
374
Yi Sun41fe8112012-07-26 14:23:36 +0800375 if (sleep_between_modes && test_all_modes && !qr_code)
Hai Landac602b2011-02-11 23:25:36 -0500376 sleep(sleep_between_modes);
Yi Sun1f41a302011-12-01 18:57:16 +0800377
Daniel Vetter30cfde52014-02-13 19:15:38 +0100378 if (do_dpms) {
Daniel Vetter29ee36f2014-04-24 23:33:09 +0200379 kmstest_set_connector_dpms(drm_fd, c->connector, do_dpms);
Daniel Vetter30cfde52014-02-13 19:15:38 +0100380 sleep(sleep_between_modes);
Daniel Vetter29ee36f2014-04-24 23:33:09 +0200381 kmstest_set_connector_dpms(drm_fd, c->connector, DRM_MODE_DPMS_ON);
Daniel Vetter30cfde52014-02-13 19:15:38 +0100382 }
383
Yi Sun41fe8112012-07-26 14:23:36 +0800384 if (qr_code){
385 set_single();
386 pause();
387 }
Yi Sun1f41a302011-12-01 18:57:16 +0800388 }
389
Ander Conselvan de Oliveira571942f2015-05-27 10:33:41 +0300390 if (test_all_modes && old_fb != -1)
Daniel Vetter9aea7ae2014-03-26 09:18:11 +0100391 igt_remove_fb(drm_fd, &fb_info[old_fb]);
Chris Wilson5534cb12011-02-11 10:48:04 +0000392
Jesse Barnes5406c632010-12-21 09:38:23 -0800393 drmModeFreeEncoder(c->encoder);
394 drmModeFreeConnector(c->connector);
395}
396
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100397static void do_set_stereo_mode(struct connector *c)
398{
399 uint32_t fb_id;
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100400
Thomas Wood4cb19462014-08-04 16:14:51 +0100401 fb_id = igt_create_stereo_fb(drm_fd, &c->mode,
402 igt_bpp_depth_to_drm_format(bpp, depth),
403 tiling);
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100404
Daniel Vetterc9c55452014-06-13 18:27:59 +0200405 igt_warn_on_f(drmModeSetCrtc(drm_fd, c->crtc, fb_id, 0, 0, &c->id, 1, &c->mode),
406 "failed to set mode (%dx%d@%dHz): %s\n", width, height, c->mode.vrefresh, strerror(errno));
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100407}
408
409static void
410set_stereo_mode(struct connector *c)
411{
Damien Lespiaue836b602013-09-30 17:42:33 +0100412 int i, n;
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100413
Damien Lespiaue836b602013-09-30 17:42:33 +0100414
415 if (specified_mode_num != -1)
416 n = 1;
417 else
418 n = c->connector->count_modes;
419
420 for (i = 0; i < n; i++) {
421 if (specified_mode_num == -1)
422 c->mode = c->connector->modes[i];
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100423
424 if (!c->mode_valid)
425 continue;
426
Damien Lespiaua7d19372013-09-26 17:56:01 +0100427 if (!(c->mode.flags & DRM_MODE_FLAG_3D_MASK))
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100428 continue;
429
Daniel Vetterc9c55452014-06-13 18:27:59 +0200430 igt_info("CRTC(%u): [%d]", c->crtc, i);
Damien Lespiau6de613f2013-09-30 18:03:33 +0100431 kmstest_dump_mode(&c->mode);
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100432 do_set_stereo_mode(c);
433
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100434 if (qr_code) {
435 set_single();
436 pause();
437 } else if (sleep_between_modes)
438 sleep(sleep_between_modes);
Daniel Vetter30cfde52014-02-13 19:15:38 +0100439
440 if (do_dpms) {
Daniel Vetter29ee36f2014-04-24 23:33:09 +0200441 kmstest_set_connector_dpms(drm_fd, c->connector, DRM_MODE_DPMS_OFF);
Daniel Vetter30cfde52014-02-13 19:15:38 +0100442 sleep(sleep_between_modes);
Daniel Vetter29ee36f2014-04-24 23:33:09 +0200443 kmstest_set_connector_dpms(drm_fd, c->connector, DRM_MODE_DPMS_ON);
Daniel Vetter30cfde52014-02-13 19:15:38 +0100444 }
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100445 }
446
447 drmModeFreeEncoder(c->encoder);
448 drmModeFreeConnector(c->connector);
449}
450
Jesse Barnes5406c632010-12-21 09:38:23 -0800451/*
452 * Re-probe outputs and light up as many as possible.
453 *
454 * On Intel, we have two CRTCs that we can drive independently with
455 * different timings and scanout buffers.
456 *
457 * Each connector has a corresponding encoder, except in the SDVO case
458 * where an encoder may have multiple connectors.
459 */
Jesse Barnese28acef2016-01-14 14:03:53 -0800460int update_display(bool probe)
Jesse Barnes5406c632010-12-21 09:38:23 -0800461{
462 struct connector *connectors;
463 int c;
464
Daniel Vetter73d1b882012-01-10 18:20:39 +0100465 resources = drmModeGetResources(drm_fd);
Jesse Barnes5406c632010-12-21 09:38:23 -0800466 if (!resources) {
Daniel Vetterc9c55452014-06-13 18:27:59 +0200467 igt_warn("drmModeGetResources failed: %s\n", strerror(errno));
Paulo Zanoni7ead7ba2011-09-15 15:14:18 -0300468 return 0;
Jesse Barnes5406c632010-12-21 09:38:23 -0800469 }
470
471 connectors = calloc(resources->count_connectors,
472 sizeof(struct connector));
473 if (!connectors)
Paulo Zanoni7ead7ba2011-09-15 15:14:18 -0300474 return 0;
Jesse Barnes5406c632010-12-21 09:38:23 -0800475
Damien Lespiaue836b602013-09-30 17:42:33 +0100476 if (test_preferred_mode || test_all_modes ||
477 force_mode || specified_disp_id != -1) {
Imre Deakbfb0cdd2013-05-31 00:21:43 +0300478 unsigned long crtc_idx_mask = -1UL;
479
Hai Lan62d51682011-02-11 11:14:15 -0500480 /* Find any connected displays */
481 for (c = 0; c < resources->count_connectors; c++) {
Imre Deakbfb0cdd2013-05-31 00:21:43 +0300482 struct connector *connector = &connectors[c];
483
484 connector->id = resources->connectors[c];
485 if (specified_disp_id != -1 &&
486 connector->id != specified_disp_id)
Yi Sun05bfbf42012-12-26 17:12:39 +0800487 continue;
488
Imre Deakbfb0cdd2013-05-31 00:21:43 +0300489 connector_find_preferred_mode(connector->id,
490 crtc_idx_mask,
491 specified_mode_num,
Jesse Barnese28acef2016-01-14 14:03:53 -0800492 connector, probe);
Imre Deakbfb0cdd2013-05-31 00:21:43 +0300493 if (!connector->mode_valid)
494 continue;
495
496 set_mode(connector);
497
498 if (test_preferred_mode || force_mode ||
499 specified_mode_num != -1)
500 crtc_idx_mask &= ~(1 << connector->crtc_idx);
501
Hai Lan62d51682011-02-11 11:14:15 -0500502 }
Jesse Barnes5406c632010-12-21 09:38:23 -0800503 }
Damien Lespiau5d996342013-09-04 14:21:55 +0100504
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100505 if (test_stereo_modes) {
506 for (c = 0; c < resources->count_connectors; c++) {
507 struct connector *connector = &connectors[c];
508
509 connector->id = resources->connectors[c];
Damien Lespiauc128b732013-09-30 17:02:21 +0100510 if (specified_disp_id != -1 &&
511 connector->id != specified_disp_id)
512 continue;
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100513
514 connector_find_preferred_mode(connector->id,
515 -1UL,
516 specified_mode_num,
Jesse Barnese28acef2016-01-14 14:03:53 -0800517 connector, probe);
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100518 if (!connector->mode_valid)
519 continue;
520
521 set_stereo_mode(connector);
522 }
523 }
524
Damien Lespiau5d996342013-09-04 14:21:55 +0100525 free(connectors);
Jesse Barnes5406c632010-12-21 09:38:23 -0800526 drmModeFreeResources(resources);
Paulo Zanoni7ead7ba2011-09-15 15:14:18 -0300527 return 1;
Jesse Barnes5406c632010-12-21 09:38:23 -0800528}
529
Damien Lespiau7b8ba122015-03-03 14:11:05 +0000530static char optstr[] = "3hiaf:s:d:p:mrto:j:y";
Jesse Barnes5406c632010-12-21 09:38:23 -0800531
Thomas Wooddb425d62014-10-31 12:32:22 +0000532static void __attribute__((noreturn)) usage(char *name, char opt)
Jesse Barnes5406c632010-12-21 09:38:23 -0800533{
Daniel Vetterc9c55452014-06-13 18:27:59 +0200534 igt_info("usage: %s [-hiasdpmtf]\n", name);
535 igt_info("\t-i\tdump info\n");
536 igt_info("\t-a\ttest all modes\n");
537 igt_info("\t-s\t<duration>\tsleep between each mode test\n");
538 igt_info("\t-d\t<depth>\tbit depth of scanout buffer\n");
539 igt_info("\t-p\t<planew,h>,<crtcx,y>,<crtcw,h> test overlay plane\n");
540 igt_info("\t-m\ttest the preferred mode\n");
541 igt_info("\t-3\ttest all 3D modes\n");
542 igt_info("\t-t\tuse a tiled framebuffer\n");
543 igt_info("\t-j\tdo dpms off, optional arg to select dpms leve (1-3)\n");
544 igt_info("\t-r\tprint a QR code on the screen whose content is \"pass\" for the automatic test\n");
545 igt_info("\t-o\t<id of the display>,<number of the mode>\tonly test specified mode on the specified display\n");
546 igt_info("\t-f\t<clock MHz>,<hdisp>,<hsync-start>,<hsync-end>,<htotal>,\n");
547 igt_info("\t\t<vdisp>,<vsync-start>,<vsync-end>,<vtotal>\n");
548 igt_info("\t\ttest force mode\n");
549 igt_info("\tDefault is to test all modes.\n");
Thomas Wooddb425d62014-10-31 12:32:22 +0000550 exit((opt != 'h') ? -1 : 0);
Jesse Barnes5406c632010-12-21 09:38:23 -0800551}
552
Hai Lan62d51682011-02-11 11:14:15 -0500553#define dump_resource(res) if (res) dump_##res()
554
Thomas Wood36b81432015-11-02 10:02:08 +0000555static void __attribute__((noreturn)) cleanup_and_exit(int ret)
Jesse Barnes7255a842014-03-26 11:02:48 -0700556{
557 close(drm_fd);
Jesse Barnes7255a842014-03-26 11:02:48 -0700558 exit(ret);
559}
560
Jesse Barnes5406c632010-12-21 09:38:23 -0800561static gboolean input_event(GIOChannel *source, GIOCondition condition,
Yi Sun41fe8112012-07-26 14:23:36 +0800562 gpointer data)
Jesse Barnes5406c632010-12-21 09:38:23 -0800563{
Daniel Vetter74d65452011-12-18 00:24:45 +0100564 gchar buf[2];
Jesse Barnes5406c632010-12-21 09:38:23 -0800565 gsize count;
566
Chris Wilson28032382011-02-11 10:56:41 +0000567 count = read(g_io_channel_unix_get_fd(source), buf, sizeof(buf));
Jesse Barnes24e60382011-10-24 17:15:34 +0200568 if (buf[0] == 'q' && (count == 1 || buf[1] == '\n')) {
Jesse Barnes7255a842014-03-26 11:02:48 -0700569 cleanup_and_exit(0);
Jesse Barnesea416332012-02-27 12:46:11 -0800570 }
Jesse Barnes5406c632010-12-21 09:38:23 -0800571
572 return TRUE;
573}
574
Yi Sun41fe8112012-07-26 14:23:36 +0800575static void enter_exec_path( char **argv )
576{
577 char *exec_path = NULL;
578 char *pos = NULL;
579 short len_path = 0;
Imre Deak31dfc982012-10-10 16:04:45 +0300580 int ret;
Yi Sun41fe8112012-07-26 14:23:36 +0800581
582 len_path = strlen( argv[0] );
583 exec_path = (char*) malloc(len_path);
584
585 memcpy(exec_path, argv[0], len_path);
586 pos = strrchr(exec_path, '/');
587 if (pos != NULL)
588 *(pos+1) = '\0';
589
Imre Deak31dfc982012-10-10 16:04:45 +0300590 ret = chdir(exec_path);
Matt Roper07be8fe2015-03-05 15:01:00 -0800591 igt_assert_eq(ret, 0);
Yi Sun41fe8112012-07-26 14:23:36 +0800592 free(exec_path);
593}
594
Imre Deak63746412014-05-12 13:29:49 +0300595static void restore_termio_mode(int sig)
596{
597 tcsetattr(tio_fd, TCSANOW, &saved_tio);
598 close(tio_fd);
599}
600
Jesse Barnes7255a842014-03-26 11:02:48 -0700601static void set_termio_mode(void)
602{
603 struct termios tio;
604
Thomas Wood8408e002014-07-24 17:45:48 +0100605 /* don't attempt to set terminal attributes if not in the foreground
606 * process group */
607 if (getpgrp() != tcgetpgrp(STDOUT_FILENO))
608 return;
609
Imre Deak63746412014-05-12 13:29:49 +0300610 tio_fd = dup(STDIN_FILENO);
611 tcgetattr(tio_fd, &saved_tio);
612 igt_install_exit_handler(restore_termio_mode);
Jesse Barnes7255a842014-03-26 11:02:48 -0700613 tio = saved_tio;
Jesse Barnes7255a842014-03-26 11:02:48 -0700614 tio.c_lflag &= ~(ICANON | ECHO);
Imre Deak63746412014-05-12 13:29:49 +0300615 tcsetattr(tio_fd, TCSANOW, &tio);
Jesse Barnes7255a842014-03-26 11:02:48 -0700616}
617
Jesse Barnes5406c632010-12-21 09:38:23 -0800618int main(int argc, char **argv)
619{
620 int c;
Jesse Barnes5406c632010-12-21 09:38:23 -0800621 int ret = 0;
Daniel Vetter7f7cafe2012-01-24 10:50:05 +0100622 GIOChannel *stdinchannel;
Jesse Barnes5406c632010-12-21 09:38:23 -0800623 GMainLoop *mainloop;
Yi Sun4cceae72012-02-03 19:23:55 +0800624 float force_clock;
Damien Lespiau66477a22013-09-05 16:49:11 +0100625 bool opt_dump_info = false;
Thomas Woodff6b0682014-07-31 16:26:55 +0100626 struct option long_opts[] = {
627 {"list-subtests", 0, 0, SUBTEST_OPTS},
628 {"run-subtest", 1, 0, SUBTEST_OPTS},
Thomas Wood895204f2014-10-30 15:54:02 +0000629 {"help-description", 0, 0, HELP_DESCRIPTION},
Thomas Woodce0d34d2014-10-31 15:00:03 +0000630 {"help", 0, 0, 'h'},
Damien Lespiau7b8ba122015-03-03 14:11:05 +0000631 {"yb", 0, 0, Yb_OPT},
632 {"yf", 0, 0, Yf_OPT},
Thomas Woodff6b0682014-07-31 16:26:55 +0100633 { 0, 0, 0, 0 }
634 };
Jesse Barnes5406c632010-12-21 09:38:23 -0800635
Daniel Vetter1caaf0a2013-08-12 12:17:35 +0200636 igt_skip_on_simulation();
Damien Lespiau5fa15f72013-04-29 18:40:39 +0100637
Yi Sun41fe8112012-07-26 14:23:36 +0800638 enter_exec_path( argv );
639
Thomas Woodff6b0682014-07-31 16:26:55 +0100640 while ((c = getopt_long(argc, argv, optstr, long_opts, NULL)) != -1) {
Jesse Barnes5406c632010-12-21 09:38:23 -0800641 switch (c) {
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100642 case '3':
643 test_stereo_modes = 1;
644 break;
Hai Lan62d51682011-02-11 11:14:15 -0500645 case 'i':
Damien Lespiau66477a22013-09-05 16:49:11 +0100646 opt_dump_info = true;
Hai Lan62d51682011-02-11 11:14:15 -0500647 break;
648 case 'a':
649 test_all_modes = 1;
650 break;
651 case 'f':
652 force_mode = 1;
Yi Sun4cceae72012-02-03 19:23:55 +0800653 if(sscanf(optarg,"%f,%hu,%hu,%hu,%hu,%hu,%hu,%hu,%hu",
654 &force_clock,&force_timing.hdisplay, &force_timing.hsync_start,&force_timing.hsync_end,&force_timing.htotal,
655 &force_timing.vdisplay, &force_timing.vsync_start, &force_timing.vsync_end, &force_timing.vtotal)!= 9)
Thomas Wooddb425d62014-10-31 12:32:22 +0000656 usage(argv[0], c);
Yi Sun4cceae72012-02-03 19:23:55 +0800657 force_timing.clock = force_clock*1000;
658
Hai Lan62d51682011-02-11 11:14:15 -0500659 break;
660 case 's':
661 sleep_between_modes = atoi(optarg);
662 break;
Daniel Vetter30cfde52014-02-13 19:15:38 +0100663 case 'j':
Daniel Vettercef9b312014-02-13 19:22:35 +0100664 do_dpms = atoi(optarg);
665 if (do_dpms == 0)
666 do_dpms = DRM_MODE_DPMS_OFF;
Daniel Vetter30cfde52014-02-13 19:15:38 +0100667 break;
Jesse Barnesc56cd102011-04-19 11:50:16 -0700668 case 'd':
669 depth = atoi(optarg);
Daniel Vetterc9c55452014-06-13 18:27:59 +0200670 igt_info("using depth %d\n", depth);
Jesse Barnesc56cd102011-04-19 11:50:16 -0700671 break;
Jesse Barnes7230c012011-06-07 13:17:46 -0700672 case 'p':
Jesse Barnes5a9d82c2011-12-07 08:22:41 -0800673 if (sscanf(optarg, "%d,%d,%d,%d,%d,%d", &plane_width,
674 &plane_height, &crtc_x, &crtc_y,
675 &crtc_w, &crtc_h) != 6)
Thomas Wooddb425d62014-10-31 12:32:22 +0000676 usage(argv[0], c);
Jesse Barnes7230c012011-06-07 13:17:46 -0700677 test_plane = 1;
678 break;
Paulo Zanoni9fe11482011-09-15 15:13:41 -0300679 case 'm':
680 test_preferred_mode = 1;
681 break;
Jesse Barnesb707feb2011-06-07 13:27:35 -0700682 case 't':
Tvrtko Ursuline36091d2015-03-03 14:11:01 +0000683 tiling = LOCAL_I915_FORMAT_MOD_X_TILED;
Jesse Barnesb707feb2011-06-07 13:27:35 -0700684 break;
Damien Lespiau7b8ba122015-03-03 14:11:05 +0000685 case 'y':
686 case Yb_OPT:
687 tiling = LOCAL_I915_FORMAT_MOD_Y_TILED;
688 break;
689 case Yf_OPT:
690 tiling = LOCAL_I915_FORMAT_MOD_Yf_TILED;
691 break;
Yi Sun41fe8112012-07-26 14:23:36 +0800692 case 'r':
693 qr_code = 1;
694 break;
Yi Sun53895ac2012-09-25 17:13:17 +0800695 case 'o':
Yi Sun05bfbf42012-12-26 17:12:39 +0800696 sscanf(optarg, "%d,%d", &specified_disp_id, &specified_mode_num);
Yi Sun53895ac2012-09-25 17:13:17 +0800697 break;
Thomas Woodff6b0682014-07-31 16:26:55 +0100698 case SUBTEST_OPTS:
699 /* invalid subtest options */
700 exit(IGT_EXIT_INVALID);
701 break;
Thomas Wood895204f2014-10-30 15:54:02 +0000702 case HELP_DESCRIPTION:
Matt Roper07be8fe2015-03-05 15:01:00 -0800703 igt_info("Tests display functionality.");
Thomas Wood895204f2014-10-30 15:54:02 +0000704 exit(0);
705 break;
Jesse Barnes5406c632010-12-21 09:38:23 -0800706 default:
Jesse Barnes5406c632010-12-21 09:38:23 -0800707 /* fall through */
708 case 'h':
Thomas Wooddb425d62014-10-31 12:32:22 +0000709 usage(argv[0], c);
Jesse Barnes5406c632010-12-21 09:38:23 -0800710 break;
711 }
712 }
Damien Lespiau03962732013-09-03 14:57:31 +0100713
Jesse Barnes7255a842014-03-26 11:02:48 -0700714 set_termio_mode();
715
Damien Lespiau03962732013-09-03 14:57:31 +0100716 if (depth <= 8)
717 bpp = 8;
718 else if (depth <= 16)
719 bpp = 16;
720 else if (depth <= 32)
721 bpp = 32;
722
Damien Lespiau66477a22013-09-05 16:49:11 +0100723 if (!test_all_modes && !force_mode && !test_preferred_mode &&
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100724 specified_mode_num == -1 && !test_stereo_modes)
Paulo Zanoni9fe11482011-09-15 15:13:41 -0300725 test_all_modes = 1;
Jesse Barnes5406c632010-12-21 09:38:23 -0800726
Tomeu Vizoso7aee5112016-05-06 15:36:23 +0200727 drm_fd = drm_open_driver(DRIVER_ANY);
Jesse Barnes5406c632010-12-21 09:38:23 -0800728
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100729 if (test_stereo_modes &&
730 drmSetClientCap(drm_fd, DRM_CLIENT_CAP_STEREO_3D, 1) < 0) {
Daniel Vetterc9c55452014-06-13 18:27:59 +0200731 igt_warn("DRM_CLIENT_CAP_STEREO_3D failed\n");
Damien Lespiau9a8fda72012-09-10 13:33:26 +0100732 goto out_close;
733 }
734
Damien Lespiau66477a22013-09-05 16:49:11 +0100735 if (opt_dump_info) {
736 dump_info();
737 goto out_close;
738 }
739
Daniel Vetter33f08842014-08-12 11:23:09 +0200740 kmstest_set_vt_graphics_mode();
Imre Deak01b408e2013-05-08 19:06:44 +0300741
Jesse Barnes5406c632010-12-21 09:38:23 -0800742 mainloop = g_main_loop_new(NULL, FALSE);
743 if (!mainloop) {
Daniel Vetterc9c55452014-06-13 18:27:59 +0200744 igt_warn("failed to create glib mainloop\n");
Jesse Barnes5406c632010-12-21 09:38:23 -0800745 ret = -1;
Daniel Vetter7f7cafe2012-01-24 10:50:05 +0100746 goto out_close;
Jesse Barnes5406c632010-12-21 09:38:23 -0800747 }
748
Daniel Vetter7f7cafe2012-01-24 10:50:05 +0100749 if (!testdisplay_setup_hotplug()) {
Daniel Vetterc9c55452014-06-13 18:27:59 +0200750 igt_warn("failed to initialize hotplug support\n");
Daniel Vetter7f7cafe2012-01-24 10:50:05 +0100751 goto out_mainloop;
Jesse Barnes5406c632010-12-21 09:38:23 -0800752 }
753
754 stdinchannel = g_io_channel_unix_new(0);
755 if (!stdinchannel) {
Daniel Vetterc9c55452014-06-13 18:27:59 +0200756 igt_warn("failed to create stdin GIO channel\n");
Daniel Vetter7f7cafe2012-01-24 10:50:05 +0100757 goto out_hotplug;
Jesse Barnes5406c632010-12-21 09:38:23 -0800758 }
759
760 ret = g_io_add_watch(stdinchannel, G_IO_IN | G_IO_ERR, input_event,
761 NULL);
762 if (ret < 0) {
Daniel Vetterc9c55452014-06-13 18:27:59 +0200763 igt_warn("failed to add watch on stdin GIO channel\n");
Daniel Vetter7f7cafe2012-01-24 10:50:05 +0100764 goto out_stdio;
Jesse Barnes5406c632010-12-21 09:38:23 -0800765 }
766
Paulo Zanoni17cecce2011-09-16 18:06:27 -0300767 ret = 0;
768
Jesse Barnese28acef2016-01-14 14:03:53 -0800769 if (!update_display(false)) {
Paulo Zanoni7ead7ba2011-09-15 15:14:18 -0300770 ret = 1;
Daniel Vetter7f7cafe2012-01-24 10:50:05 +0100771 goto out_stdio;
Paulo Zanoni7ead7ba2011-09-15 15:14:18 -0300772 }
773
Damien Lespiau66477a22013-09-05 16:49:11 +0100774 if (test_all_modes)
Daniel Vetter7f7cafe2012-01-24 10:50:05 +0100775 goto out_stdio;
Paulo Zanoni7ead7ba2011-09-15 15:14:18 -0300776
Jesse Barnes5406c632010-12-21 09:38:23 -0800777 g_main_loop_run(mainloop);
778
Daniel Vetter7f7cafe2012-01-24 10:50:05 +0100779out_stdio:
Jesse Barnes5406c632010-12-21 09:38:23 -0800780 g_io_channel_shutdown(stdinchannel, TRUE, NULL);
Daniel Vetter7f7cafe2012-01-24 10:50:05 +0100781out_hotplug:
782 testdisplay_cleanup_hotplug();
783out_mainloop:
Jesse Barnes5406c632010-12-21 09:38:23 -0800784 g_main_loop_unref(mainloop);
Jesse Barnes5406c632010-12-21 09:38:23 -0800785out_close:
Daniel Vetter0732cc52012-05-22 12:01:36 +0200786 close(drm_fd);
787
Matt Roper07be8fe2015-03-05 15:01:00 -0800788 igt_assert_eq(ret, 0);
Daniel Vetter43065382014-10-02 11:18:20 +0200789
790 igt_exit();
Jesse Barnes5406c632010-12-21 09:38:23 -0800791}