lib/igt.cocci: Add s/assert/igt_assert/
[platform/upstream/intel-gpu-tools.git] / tests / kms_force_connector.c
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_core.h"
26 #include "igt_kms.h"
27 #include "drmtest.h"
28 #include "igt_edid.h"
29
30 int
31 main (int argc, char **argv)
32 {
33         /* force the VGA output and test that it worked */
34         int drm_fd;
35         drmModeRes *res;
36         drmModeConnector *connector, *temp;
37         igt_display_t display;
38
39         igt_simple_init(argc, argv);
40
41         drm_fd = drm_open_any();
42         res = drmModeGetResources(drm_fd);
43
44         /* find the vga connector */
45         for (int i = 0; i < res->count_connectors; i++) {
46
47                 connector = drmModeGetConnector(drm_fd, res->connectors[i]);
48
49                 if (connector->connector_type == DRM_MODE_CONNECTOR_VGA)
50                         break;
51
52                 drmModeFreeConnector(connector);
53
54                 connector = NULL;
55         }
56
57         igt_assert(connector);
58
59         /* force the connector on and check the reported values */
60         kmstest_force_connector(drm_fd, connector, FORCE_CONNECTOR_ON);
61         temp = drmModeGetConnector(drm_fd, connector->connector_id);
62         igt_assert(temp->connection == DRM_MODE_CONNECTED);
63         igt_assert(temp->count_modes > 0);
64         drmModeFreeConnector(temp);
65
66         /* attempt to use the display */
67         igt_set_vt_graphics_mode();
68
69         igt_display_init(&display, drm_fd);
70         igt_display_commit(&display);
71
72         /* test edid forcing */
73         kmstest_force_edid(drm_fd, connector, generic_edid[EDID_FHD],
74                            EDID_LENGTH);
75         temp = drmModeGetConnector(drm_fd, connector->connector_id);
76
77         igt_assert(temp->count_modes == 1);
78         igt_assert(temp->modes[0].vrefresh == 60
79                    && temp->modes[0].hdisplay == 1920
80                    && temp->modes[0].vdisplay == 1080);
81
82         drmModeFreeConnector(temp);
83
84         /* custom edid */
85         kmstest_force_edid(drm_fd, connector, generic_edid[EDID_WSXGA],
86                            EDID_LENGTH);
87         temp = drmModeGetConnector(drm_fd, connector->connector_id);
88
89         igt_assert(temp->count_modes == 1);
90         igt_assert(temp->modes[0].vrefresh == 60
91                    && temp->modes[0].hdisplay == 1680
92                    && temp->modes[0].vdisplay == 1050);
93
94         drmModeFreeConnector(temp);
95
96         /* remove edid */
97         kmstest_force_edid(drm_fd, connector, NULL, 0);
98         temp = drmModeGetConnector(drm_fd, connector->connector_id);
99         /* the connector should now have the 5 default modes */
100         igt_assert(temp->count_modes == 5);
101         drmModeFreeConnector(temp);
102
103         /* force the connector off */
104         kmstest_force_connector(drm_fd, connector, FORCE_CONNECTOR_OFF);
105         temp = drmModeGetConnector(drm_fd, connector->connector_id);
106         igt_assert(temp->connection == DRM_MODE_DISCONNECTED);
107         igt_assert(temp->count_modes == 0);
108         drmModeFreeConnector(temp);
109
110
111         /* check that the previous state is restored */
112         kmstest_force_connector(drm_fd, connector, FORCE_CONNECTOR_UNSPECIFIED);
113         temp = drmModeGetConnector(drm_fd, connector->connector_id);
114         igt_assert(temp->connection == connector->connection);
115         drmModeFreeConnector(temp);
116
117         drmModeFreeConnector(connector);
118
119         igt_success();
120 }