[igt-dev] [PATCH i-g-t v5 2/2] tests/kms_async_flips: Test Cleanup
Karthik B S
karthik.b.s at intel.com
Mon May 30 06:29:59 UTC 2022
-Replace drm function call with existing library functions
-igt_display_reset() before all subtests
v2: -Move conversion to dynamic subtest to a separate patch (Bhanu)
-Use igt_output_get_mode to get default mode (Bhanu)
-Add 'is_atomic' check before igt_display_commit2 (Bhanu)
v3: -Move test_init after the checks to skip subtest (Bhanu)
-Update the logic to call make_fb() in test_init()
v4: -Move patch after patch to convert tests to dynamic to avoid code
duplicaton. (Bhanu)
v5: -Update commit message. (Bhanu)
-Move skip checks in the dynamic subtests before the start of the
subtest to optimize the test. (Bhanu)
-Close drm_fd at the end of the subtest.
Signed-off-by: Karthik B S <karthik.b.s at intel.com>
---
tests/kms_async_flips.c | 223 +++++++++++++++++++++-------------------
1 file changed, 117 insertions(+), 106 deletions(-)
diff --git a/tests/kms_async_flips.c b/tests/kms_async_flips.c
index b1bd5186..cfffaeb1 100644
--- a/tests/kms_async_flips.c
+++ b/tests/kms_async_flips.c
@@ -50,7 +50,6 @@ typedef struct {
uint32_t refresh_rate;
struct igt_fb bufs[4];
igt_display_t display;
- drmModeConnectorPtr connector;
igt_output_t *output;
unsigned long flip_timestamp_us;
double flip_interval;
@@ -63,22 +62,6 @@ typedef struct {
enum pipe pipe;
} data_t;
-static drmModeConnectorPtr find_connector_for_modeset(data_t *data)
-{
- igt_output_t *output;
- drmModeConnectorPtr ret = NULL;
-
- for_each_connected_output(&data->display, output) {
- if (output->config.connector->count_modes > 0) {
- ret = output->config.connector;
- break;
- }
- }
-
- igt_assert_f(ret, "Connector NOT found\n");
- return ret;
-}
-
static void flip_handler(int fd_, unsigned int sequence, unsigned int tv_sec,
unsigned int tv_usec, void *_data)
{
@@ -132,15 +115,11 @@ static void wait_flip_event(data_t *data)
}
static void make_fb(data_t *data, struct igt_fb *fb,
- drmModeConnectorPtr connector, int index)
+ uint32_t width, uint32_t height, int index)
{
- uint32_t width, height;
int rec_width;
cairo_t *cr;
- width = connector->modes[0].hdisplay;
- height = connector->modes[0].vdisplay;
-
rec_width = width / (ARRAY_SIZE(data->bufs) * 2);
if (is_i915_device(data->drm_fd)) {
@@ -162,13 +141,52 @@ static void require_monotonic_timestamp(int fd)
"Monotonic timestamps not supported\n");
}
+static void test_init(data_t *data)
+{
+ int i;
+ uint32_t width, height;
+ igt_plane_t *plane;
+ static uint32_t prev_output_id;
+ drmModeModeInfo *mode;
+
+ igt_display_reset(&data->display);
+ igt_display_commit(&data->display);
+
+ mode = igt_output_get_mode(data->output);
+ width = mode->hdisplay;
+ height = mode->vdisplay;
+
+ data->crtc_id = data->display.pipes[data->pipe].crtc_id;
+ data->refresh_rate = mode->vrefresh;
+
+ igt_output_set_pipe(data->output, data->pipe);
+ plane = igt_output_get_plane_type(data->output, DRM_PLANE_TYPE_PRIMARY);
+
+ if (prev_output_id != data->output->id) {
+ prev_output_id = data->output->id;
+
+ if (data->bufs[0].fb_id) {
+ for (i = 0; i < ARRAY_SIZE(data->bufs); i++)
+ igt_remove_fb(data->drm_fd, &data->bufs[i]);
+ }
+
+ for (i = 0; i < ARRAY_SIZE(data->bufs); i++)
+ make_fb(data, &data->bufs[i], width, height, i);
+ }
+
+ igt_plane_set_fb(plane, &data->bufs[0]);
+ igt_plane_set_size(plane, width, height);
+
+ igt_display_commit2(&data->display, data->display.is_atomic ? COMMIT_ATOMIC : COMMIT_LEGACY);
+}
+
static void test_async_flip(data_t *data, bool alternate_sync_async)
{
int ret, frame;
long long int fps;
struct timeval start, end, diff;
- require_monotonic_timestamp(data->drm_fd);
+ test_init(data);
gettimeofday(&start, NULL);
frame = 1;
@@ -261,7 +279,7 @@ static void test_timestamp(data_t *data)
unsigned int seq, seq1;
int ret;
- require_monotonic_timestamp(data->drm_fd);
+ test_init(data);
/*
* In older platforms(<= gen10), async address update bit is double buffered.
@@ -320,6 +338,8 @@ static void test_cursor(data_t *data)
do_or_die(drmGetCap(data->drm_fd, DRM_CAP_CURSOR_WIDTH, &width));
do_or_die(drmGetCap(data->drm_fd, DRM_CAP_CURSOR_WIDTH, &height));
+ test_init(data);
+
igt_create_color_fb(data->drm_fd, width, height, DRM_FORMAT_ARGB8888,
DRM_FORMAT_MOD_LINEAR, 1., 1., 1., &cursor_fb);
@@ -354,15 +374,13 @@ static void test_invalid(data_t *data)
int ret;
uint32_t width, height;
struct igt_fb fb;
+ drmModeModeInfo *mode;
- /* TODO: support more vendors */
- igt_require(is_i915_device(data->drm_fd));
-
- width = data->connector->modes[0].hdisplay;
- height = data->connector->modes[0].vdisplay;
+ mode = igt_output_get_mode(data->output);
+ width = mode->hdisplay;
+ height = mode->vdisplay;
- igt_require(igt_display_has_format_mod(&data->display, DRM_FORMAT_XRGB8888,
- I915_FORMAT_MOD_Y_TILED));
+ test_init(data);
igt_create_fb(data->drm_fd, width, height, DRM_FORMAT_XRGB8888,
I915_FORMAT_MOD_Y_TILED, &fb);
@@ -378,33 +396,6 @@ static void test_invalid(data_t *data)
igt_remove_fb(data->drm_fd, &fb);
}
-static void test_init(data_t *data)
-{
- drmModeResPtr res;
- int i, ret;
-
- res = drmModeGetResources(data->drm_fd);
- igt_assert(res);
-
- kmstest_unset_all_crtcs(data->drm_fd, res);
-
- data->connector = find_connector_for_modeset(data);
- data->crtc_id = kmstest_find_crtc_for_connector(data->drm_fd,
- res, data->connector, 0);
-
- data->refresh_rate = data->connector->modes[0].vrefresh;
-
- for (i = 0; i < ARRAY_SIZE(data->bufs); i++)
- make_fb(data, &data->bufs[i], data->connector, i);
-
- ret = drmModeSetCrtc(data->drm_fd, data->crtc_id, data->bufs[0].fb_id, 0, 0,
- &data->connector->connector_id, 1, &data->connector->modes[0]);
-
- igt_assert(ret == 0);
-
- drmModeFreeResources(res);
-}
-
static void queue_vblank(data_t *data)
{
int pipe = kmstest_get_pipe_from_crtc_id(data->drm_fd, data->crtc_id);
@@ -490,13 +481,12 @@ static void test_crc(data_t *data)
cairo_t *cr;
int ret;
- /* Devices without CRC can't run this test */
- igt_require_pipe_crc(data->drm_fd);
-
data->flip_count = 0;
data->frame_count = 0;
data->flip_pending = false;
+ test_init(data);
+
cr = igt_get_cairo_ctx(data->drm_fd, &data->bufs[frame]);
igt_paint_color(cr, 0, 0, data->bufs[frame].width, data->bufs[frame].height, 1.0, 0.0, 0.0);
@@ -504,7 +494,8 @@ static void test_crc(data_t *data)
igt_paint_color(cr, 0, 0, data->bufs[!frame].width, data->bufs[!frame].height, 1.0, 0.0, 0.0);
ret = drmModeSetCrtc(data->drm_fd, data->crtc_id, data->bufs[frame].fb_id, 0, 0,
- &data->connector->connector_id, 1, &data->connector->modes[0]);
+ &data->output->config.connector->connector_id, 1,
+ &data->output->config.connector->modes[0]);
igt_assert_eq(ret, 0);
data->pipe_crc = igt_pipe_crc_new(data->drm_fd,
@@ -557,7 +548,7 @@ static int opt_handler(int opt, int opt_index, void *_data)
}
static const char help_str[] =
-" --e \t\tRun the extended tests\n";
+ " --e \t\tRun the extended tests\n";
static data_t data;
@@ -580,7 +571,7 @@ igt_main_args("e", NULL, help_str, opt_handler, &data)
igt_describe("Verify the async flip functionality and the fps during async flips");
igt_subtest_group {
igt_fixture
- test_init(&data);
+ require_monotonic_timestamp(data.drm_fd);
igt_describe("Wait for page flip events in between successive asynchronous flips");
igt_subtest_with_dynamic("async-flip-with-page-flip-events") {
@@ -629,61 +620,81 @@ igt_main_args("e", NULL, help_str, opt_handler, &data)
}
}
}
+ }
- igt_describe("Verify that the DRM_IOCTL_MODE_CURSOR passes after async flip");
- igt_subtest_with_dynamic("test-cursor") {
- for_each_pipe(&data.display, pipe) {
- for_each_valid_output_on_pipe(&data.display, pipe, output) {
- igt_dynamic_f("pipe-%s-%s", kmstest_pipe_name(pipe), output->name) {
- data.output = output;
- data.pipe = pipe;
- test_cursor(&data);
- }
-
- if (!data.extended)
- break;
+ igt_describe("Verify that the DRM_IOCTL_MODE_CURSOR passes after async flip");
+ igt_subtest_with_dynamic("test-cursor") {
+ /*
+ * Intel's PSR2 selective fetch adds other planes to state when
+ * necessary, causing the async flip to fail because async flip is not
+ * supported in cursor plane.
+ */
+ igt_skip_on_f(i915_psr2_selective_fetch_check(data.drm_fd),
+ "PSR2 sel fetch causes cursor to be added to primary plane " \
+ "pages flips and async flip is not supported in cursor\n");
+
+ for_each_pipe(&data.display, pipe) {
+ for_each_valid_output_on_pipe(&data.display, pipe, output) {
+ igt_dynamic_f("pipe-%s-%s", kmstest_pipe_name(pipe), output->name) {
+ data.output = output;
+ data.pipe = pipe;
+ test_cursor(&data);
}
+
+ if (!data.extended)
+ break;
}
}
+ }
- igt_describe("Negative case to verify if changes in fb are rejected from kernel as expected");
- igt_subtest_with_dynamic("invalid-async-flip") {
- for_each_pipe(&data.display, pipe) {
- for_each_valid_output_on_pipe(&data.display, pipe, output) {
- igt_dynamic_f("pipe-%s-%s", kmstest_pipe_name(pipe), output->name) {
- data.output = output;
- data.pipe = pipe;
- test_invalid(&data);
- }
+ igt_describe("Negative case to verify if changes in fb are rejected from kernel as expected");
+ igt_subtest_with_dynamic("invalid-async-flip") {
+ /* TODO: support more vendors */
+ igt_require(is_i915_device(data.drm_fd));
- if (!data.extended)
- break;
- }
- }
- }
+ igt_require(igt_display_has_format_mod(&data.display, DRM_FORMAT_XRGB8888,
+ I915_FORMAT_MOD_Y_TILED));
- igt_describe("Use CRC to verify async flip scans out the correct framebuffer");
- igt_subtest_with_dynamic("crc") {
- for_each_pipe(&data.display, pipe) {
- for_each_valid_output_on_pipe(&data.display, pipe, output) {
- igt_dynamic_f("pipe-%s-%s", kmstest_pipe_name(pipe), output->name) {
- data.output = output;
- data.pipe = pipe;
- test_crc(&data);
- }
+ for_each_pipe(&data.display, pipe) {
+ for_each_valid_output_on_pipe(&data.display, pipe, output) {
+ igt_dynamic_f("pipe-%s-%s", kmstest_pipe_name(pipe), output->name) {
+ data.output = output;
+ data.pipe = pipe;
+ test_invalid(&data);
+ }
if (!data.extended)
- break;
- }
+ break;
}
}
+ }
- igt_fixture {
- for (i = 0; i < ARRAY_SIZE(data.bufs); i++)
- igt_remove_fb(data.drm_fd, &data.bufs[i]);
- }
+ igt_describe("Use CRC to verify async flip scans out the correct framebuffer");
+ igt_subtest_with_dynamic("crc") {
+ /* Devices without CRC can't run this test */
+ igt_require_pipe_crc(data.drm_fd);
+
+ for_each_pipe(&data.display, pipe) {
+ for_each_valid_output_on_pipe(&data.display, pipe, output) {
+ igt_dynamic_f("pipe-%s-%s", kmstest_pipe_name(pipe), output->name) {
+ data.output = output;
+ data.pipe = pipe;
+ test_crc(&data);
+ }
+
+ if (!data.extended)
+ break;
+ }
+ }
}
- igt_fixture
+ igt_fixture {
+ for (i = 0; i < ARRAY_SIZE(data.bufs); i++)
+ igt_remove_fb(data.drm_fd, &data.bufs[i]);
+
+ igt_display_reset(&data.display);
+ igt_display_commit(&data.display);
igt_display_fini(&data.display);
+ close(data.drm_fd);
+ }
}
--
2.22.0
More information about the igt-dev
mailing list