1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
/*
* Copyright © 2013 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
*/
#include "igt.h"
#include <errno.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include "drm_fourcc.h"
#define CRC_BLACK "000000000000"
enum color {
RED,
GREEN,
};
typedef struct {
int drm_fd;
igt_display_t display;
struct igt_fb fb_green, fb_red;
igt_plane_t *primary;
} data_t;
static void get_crc(char *crc) {
int ret;
FILE *file;
file = igt_debugfs_fopen("i915_sink_crc_eDP1", "r");
igt_require(file);
ret = fscanf(file, "%s\n", crc);
igt_require(ret > 0);
fclose(file);
/* Black screen is always invalid */
igt_assert(strcmp(crc, CRC_BLACK) != 0);
}
static void assert_color(const char *crc, enum color color)
{
unsigned int r, g, b;
int ret;
ret = sscanf(crc, "%4x%4x%4x", &r, &g, &b);
igt_assert_eq(ret, 3);
switch (color) {
case RED:
igt_assert_lt(0, r);
igt_assert_eq(0, g);
igt_assert_eq(0, b);
break;
case GREEN:
igt_assert_eq(0, r);
igt_assert_lt(0, g);
igt_assert_eq(0, b);
break;
default:
igt_fail(IGT_EXIT_FAILURE);
}
}
static void basic_sink_crc_check(data_t *data)
{
char crc[13];
/* Go Green */
igt_plane_set_fb(data->primary, &data->fb_green);
igt_display_commit(&data->display);
/* It should be Green */
get_crc(crc);
assert_color(crc, GREEN);
/* Go Red */
igt_plane_set_fb(data->primary, &data->fb_red);
igt_display_commit(&data->display);
/* It should be Red */
get_crc(crc);
assert_color(crc, RED);
}
static void run_test(data_t *data)
{
igt_display_t *display = &data->display;
igt_output_t *output;
drmModeModeInfo *mode;
enum pipe pipe;
for_each_pipe_with_valid_output(display, pipe, output) {
drmModeConnectorPtr c = output->config.connector;
if (c->connector_type != DRM_MODE_CONNECTOR_eDP)
continue;
igt_output_set_pipe(output, pipe);
mode = igt_output_get_mode(output);
igt_create_color_fb(data->drm_fd,
mode->hdisplay, mode->vdisplay,
DRM_FORMAT_XRGB8888,
LOCAL_I915_FORMAT_MOD_X_TILED,
0.0, 1.0, 0.0,
&data->fb_green);
igt_create_color_fb(data->drm_fd,
mode->hdisplay, mode->vdisplay,
DRM_FORMAT_XRGB8888,
LOCAL_I915_FORMAT_MOD_X_TILED,
1.0, 0.0, 0.0,
&data->fb_red);
data->primary = igt_output_get_plane(output, IGT_PLANE_PRIMARY);
basic_sink_crc_check(data);
return;
}
igt_skip("no eDP with CRC support found\n");
}
igt_simple_main
{
data_t data = {};
igt_skip_on_simulation();
data.drm_fd = drm_open_driver_master(DRIVER_INTEL);
kmstest_set_vt_graphics_mode();
igt_display_init(&data.display, data.drm_fd);
run_test(&data);
igt_display_fini(&data.display);
}
|