* [PATCH i-g-t v4] tests/kms_plane_lowres: Plane visibility after atomic modesets
@ 2016-12-30 12:47 Mika Kahola
2017-01-12 10:00 ` Maarten Lankhorst
0 siblings, 1 reply; 3+ messages in thread
From: Mika Kahola @ 2016-12-30 12:47 UTC (permalink / raw)
To: intel-gfx
Testcase for plane visibility after atomic modesets. The idea of the test
is the following:
- draw a blue screen with high resolution
- enable a yellow plane, visible, in lower-left corner
- set a new lower resolution mode (1024x768) that makes plane invisible
- check from debugfs 'i915_display_info' that the plane is invisible
- switch back to higher resolution mode
- check from debugfs 'i915_display_info' that the plane is visible again
- repeat number of iterations, default 64
v2: allow test to be run on non-Intel drivers (Daniel)
moved test for plane visibility to as helper function (Daniel)
moved get_vblank() function to be part of helper functions (Daniel)
rename 'tiling' parameter as 'modifier' (Daniel)
select a mode from a list so that the plane should be invisible.
use default 1024x768 mode only as a fallback if decent mode has not
been found (Daniel)
add tiling MODE_NONE (Daniel)
v3: draw as many overlay planes as the platform supports + cursor plane
on top of each other on lower-left corner
skip the test if i915_display_info file is not available
test plane visibility with igt_assert_plane_visibility() function
drop option for multiple test iterations (Daniel Vetter)
v4: switch 'for_each_connected_output()' to
'for_each_valid_output_on_pipe()' (Maarten)
Cc: Daniel Stone <daniel@fooishbar.org>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Signed-off-by: Mika Kahola <mika.kahola@intel.com>
---
lib/igt_kms.c | 161 ++++++++++++++++++++++
lib/igt_kms.h | 23 ++++
tests/Makefile.sources | 1 +
tests/kms_plane_lowres.c | 344 +++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 529 insertions(+)
create mode 100644 tests/kms_plane_lowres.c
diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index 5312f8d8..c823a3b 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -324,6 +324,24 @@ const char *kmstest_pipe_name(enum pipe pipe)
}
/**
+ * kmstest_pipe_to_index:
+ *@pipe: display pipe in string format
+ *
+ * Returns: index to corresponding pipe
+ */
+int kmstest_pipe_to_index(char pipe)
+{
+ if (pipe == 'A')
+ return 0;
+ else if (pipe == 'B')
+ return 1;
+ else if (pipe == 'C')
+ return 2;
+ else
+ return -EINVAL;
+}
+
+/**
* kmstest_plane_name:
* @plane: display plane
*
@@ -1181,6 +1199,149 @@ int kmstest_get_crtc_idx(drmModeRes *res, uint32_t crtc_id)
igt_assert(false);
}
+static inline uint32_t pipe_select(int pipe)
+{
+ if (pipe > 1)
+ return pipe << DRM_VBLANK_HIGH_CRTC_SHIFT;
+ else if (pipe > 0)
+ return DRM_VBLANK_SECONDARY;
+ else
+ return 0;
+}
+
+unsigned int kmstest_get_vblank(int fd, int pipe, unsigned int flags)
+{
+ union drm_wait_vblank vbl;
+
+ memset(&vbl, 0, sizeof(vbl));
+ vbl.request.type = DRM_VBLANK_RELATIVE | pipe_select(pipe) | flags;
+ if (drmIoctl(fd, DRM_IOCTL_WAIT_VBLANK, &vbl))
+ return 0;
+
+ return vbl.reply.sequence;
+}
+
+static void get_plane(char *str, int type, struct kmstest_plane *plane)
+{
+ int ret;
+ char buf[256];
+
+ plane->plane = type;
+ ret = sscanf(str + 12, "%d%*c %*s %[^n]s",
+ &plane->id,
+ buf);
+ igt_assert_eq(ret, 2);
+
+ ret = sscanf(buf + 9, "%4d%*c%4d%*c", &plane->pos_x, &plane->pos_y);
+ igt_assert_eq(ret, 2);
+
+ ret = sscanf(buf + 30, "%4d%*c%4d%*c", &plane->width, &plane->height);
+ igt_assert_eq(ret, 2);
+}
+
+static int parse_planes(FILE *fid, struct kmstest_plane *plane)
+{
+ char tmp[256];
+ int nplanes;
+ int ovl;
+
+ ovl = 0;
+ nplanes = 0;
+ while (fgets(tmp, 256, fid) != NULL) {
+ igt_assert_neq(nplanes, IGT_MAX_PLANES);
+ if (strstr(tmp, "type=PRI") != NULL) {
+ get_plane(tmp, IGT_PLANE_PRIMARY, &plane[nplanes]);
+ nplanes++;
+ } else if (strstr(tmp, "type=OVL") != NULL) {
+ get_plane(tmp, IGT_PLANE_2 + ovl, &plane[nplanes]);
+ ovl++;
+ nplanes++;
+ } else if (strstr(tmp, "type=CUR") != NULL) {
+ get_plane(tmp, IGT_PLANE_CURSOR, &plane[nplanes]);
+ nplanes++;
+ break;
+ }
+ }
+
+ return nplanes;
+}
+
+static void parse_crtc(char *info, struct kmstest_crtc *crtc)
+{
+ char buf[256];
+ int ret;
+ char pipe;
+
+ ret = sscanf(info + 4, "%d%*c %*s %c%*c %*s %s%*c",
+ &crtc->id, &pipe, buf);
+ igt_assert_eq(ret, 3);
+
+ crtc->pipe = kmstest_pipe_to_index(pipe);
+ igt_assert(crtc->pipe >= 0);
+
+ ret = sscanf(buf + 6, "%d%*c%d%*c",
+ &crtc->width, &crtc->height);
+ igt_assert_eq(ret, 2);
+}
+
+void kmstest_get_crtc(enum pipe pipe, struct kmstest_crtc *crtc)
+{
+ char tmp[256];
+ FILE *fid;
+ const char *mode = "r";
+ int ncrtc;
+ int line;
+
+ fid = igt_debugfs_fopen("i915_display_info", mode);
+
+ igt_skip_on(fid == NULL);
+
+ ncrtc = 0;
+ line = 0;
+ while (fgets(tmp, 256, fid) != NULL) {
+ if ((strstr(tmp, "CRTC") != NULL) && (line > 0)) {
+ if (strstr(tmp, "active=yes") != NULL) {
+ crtc->active = true;
+ parse_crtc(tmp, crtc);
+ crtc->nplanes = parse_planes(fid, crtc->plane);
+
+ if (crtc->pipe != pipe)
+ crtc = NULL;
+ else
+ ncrtc++;
+ }
+ }
+
+ line++;
+ }
+
+ fclose(fid);
+
+ igt_skip_on(ncrtc == 0);
+}
+
+void igt_assert_plane_visible(enum pipe pipe, bool visibility)
+{
+ struct kmstest_crtc crtc;
+ int i;
+ bool visible;
+
+ kmstest_get_crtc(pipe, &crtc);
+
+ visible = true;
+ for (i = IGT_PLANE_2; i < crtc.nplanes; i++) {
+ if (crtc.plane[i].pos_x > crtc.width) {
+ visible = false;
+ break;
+ } else if (crtc.plane[i].pos_y > crtc.height) {
+ visible = false;
+ break;
+ }
+ }
+
+ igt_assert_eq(visible, visibility);
+}
+
/*
* A small modeset API
*/
diff --git a/lib/igt_kms.h b/lib/igt_kms.h
index 5234f6c..2da4ad9 100644
--- a/lib/igt_kms.h
+++ b/lib/igt_kms.h
@@ -57,6 +57,7 @@ enum pipe {
I915_MAX_PIPES
};
const char *kmstest_pipe_name(enum pipe pipe);
+int kmstest_pipe_to_index(char pipe);
/* We namespace this enum to not conflict with the Android i915_drm.h */
enum igt_plane {
@@ -132,6 +133,25 @@ struct kmstest_connector_config {
unsigned valid_crtc_idx_mask;
};
+struct kmstest_plane {
+ int id;
+ int plane;
+ int pos_x;
+ int pos_y;
+ int width;
+ int height;
+};
+
+struct kmstest_crtc {
+ int id;
+ int pipe;
+ bool active;
+ int width;
+ int height;
+ int nplanes;
+ struct kmstest_plane plane[IGT_MAX_PLANES];
+};
+
/**
* kmstest_force_connector_state:
* @FORCE_CONNECTOR_UNSPECIFIED: Unspecified
@@ -177,6 +197,9 @@ uint32_t kmstest_dumb_create(int fd, int width, int height, int bpp,
void *kmstest_dumb_map_buffer(int fd, uint32_t handle, uint64_t size,
unsigned prot);
+unsigned int kmstest_get_vblank(int fd, int pipe, unsigned int flags);
+void kmstest_get_crtc(enum pipe pipe, struct kmstest_crtc *crtc);
+void igt_assert_plane_visible(enum pipe pipe, bool visibility);
/*
* A small modeset API
diff --git a/tests/Makefile.sources b/tests/Makefile.sources
index f6e08d6..6316ea6 100644
--- a/tests/Makefile.sources
+++ b/tests/Makefile.sources
@@ -111,6 +111,7 @@ TESTS_progs_M = \
kms_pipe_crc_basic \
kms_plane \
kms_plane_multiple \
+ kms_plane_lowres \
kms_properties \
kms_psr_sink_crc \
kms_render \
diff --git a/tests/kms_plane_lowres.c b/tests/kms_plane_lowres.c
new file mode 100644
index 0000000..21f8282
--- /dev/null
+++ b/tests/kms_plane_lowres.c
@@ -0,0 +1,344 @@
+/*
+ * Copyright © 2016 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 "drmtest.h"
+#include <errno.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+
+IGT_TEST_DESCRIPTION("Test atomic mode setting with a plane by switching between high and low resolutions");
+
+#define MAX_CRCS 1
+#define SIZE 256
+#define LOOP_FOREVER -1
+
+typedef struct {
+ int drm_fd;
+ igt_display_t display;
+ igt_pipe_crc_t *pipe_crc;
+ igt_plane_t *plane[IGT_MAX_PLANES];
+ struct igt_fb fb[IGT_MAX_PLANES];
+} data_t;
+
+static drmModeModeInfo
+get_lowres_mode(int drmfd, drmModeModeInfo *mode_default)
+{
+ drmModeRes *mode_resources = drmModeGetResources(drmfd);
+ drmModeModeInfo mode;
+ drmModeModeInfo std_1024_mode = {
+ .clock = 65000,
+ .hdisplay = 1024,
+ .hsync_start = 1048,
+ .hsync_end = 1184,
+ .htotal = 1344,
+ .hskew = 0,
+ .vdisplay = 768,
+ .vsync_start = 771,
+ .vsync_end = 777,
+ .vtotal = 806,
+ .vscan = 0,
+ .vrefresh = 60,
+ .flags = 0xA,
+ .type = 0x40,
+ .name = "Custom 1024x768",
+ };
+ bool found;
+ int limit = mode_default->vdisplay-SIZE;
+ int i, j;
+
+ if (!mode_resources) {
+ igt_warn("drmModeGetResources failed: %s\n", strerror(errno));
+ return std_1024_mode;
+ }
+
+ found = false;
+ for (i = 0; i < mode_resources->count_connectors; i++) {
+ drmModeConnector *connector;
+
+ connector = drmModeGetConnectorCurrent(drmfd,
+ mode_resources->connectors[i]);
+ if (!connector) {
+ igt_warn("could not get connector %i: %s\n",
+ mode_resources->connectors[i], strerror(errno));
+ continue;
+ }
+
+ if (!connector->count_modes)
+ continue;
+
+ for (j = 0; j < connector->count_modes; j++) {
+ mode = connector->modes[j];
+ if (mode.vdisplay < limit) {
+ found = true;
+ break;
+ }
+ }
+
+ drmModeFreeConnector(connector);
+ }
+
+ drmModeFreeResources(mode_resources);
+
+ if (!found)
+ return std_1024_mode;
+
+ return mode;
+}
+
+static void
+test_init(data_t *data, enum pipe pipe)
+{
+ data->pipe_crc = igt_pipe_crc_new(pipe, INTEL_PIPE_CRC_SOURCE_AUTO);
+}
+
+static void
+test_fini(data_t *data, igt_output_t *output)
+{
+ /* restore original mode */
+ igt_output_override_mode(output, NULL);
+
+ for (int i = 0; i < 2; i++)
+ igt_plane_set_fb(data->plane[i], NULL);
+
+ /* reset the constraint on the pipe */
+ igt_output_set_pipe(output, PIPE_ANY);
+
+ igt_pipe_crc_free(data->pipe_crc);
+}
+
+static int
+display_commit_mode(data_t *data, enum pipe pipe, int flags, igt_crc_t *crc)
+{
+ char buf[256];
+ struct drm_event *e = (void *)buf;
+ unsigned int vblank_start, vblank_stop;
+ int n, ret;
+
+ vblank_start = kmstest_get_vblank(data->display.drm_fd, pipe,
+ DRM_VBLANK_NEXTONMISS);
+
+ ret = igt_display_try_commit_atomic(&data->display,
+ flags,
+ NULL);
+ igt_skip_on(ret != 0);
+
+ igt_set_timeout(1, "Stuck on page flip");
+ ret = read(data->display.drm_fd, buf, sizeof(buf));
+ igt_assert(ret >= 0);
+
+ vblank_stop = kmstest_get_vblank(data->display.drm_fd, pipe, 0);
+ igt_assert_eq(e->type, DRM_EVENT_FLIP_COMPLETE);
+ igt_reset_timeout();
+
+ n = igt_pipe_crc_get_crcs(data->pipe_crc, vblank_stop - vblank_start,
+ &crc);
+ igt_assert_eq(n, vblank_stop - vblank_start);
+
+ return n;
+}
+
+static void
+check_mode(drmModeModeInfo *mode1, drmModeModeInfo *mode2)
+{
+ igt_assert_eq(mode1->hdisplay, mode2->hdisplay);
+ igt_assert_eq(mode1->vdisplay, mode2->vdisplay);
+ igt_assert_eq(mode1->vrefresh, mode2->vrefresh);
+}
+
+static drmModeModeInfo *
+test_setup(data_t *data, enum pipe pipe, uint64_t modifier, int flags,
+ igt_output_t *output)
+{
+ struct kmstest_crtc crtc;
+ drmModeModeInfo *mode;
+ int size;
+ int i, x, y;
+
+ igt_output_set_pipe(output, pipe);
+
+ kmstest_get_crtc(pipe, &crtc);
+ igt_skip_on(crtc.nplanes > data->display.pipes[pipe].n_planes);
+ igt_skip_on(crtc.nplanes == 0);
+
+ for (i = 0; i < crtc.nplanes; i++)
+ data->plane[i] = igt_output_get_plane(output, crtc.plane[i].plane);
+
+ mode = igt_output_get_mode(output);
+
+ igt_create_color_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
+ DRM_FORMAT_XRGB8888,
+ modifier,
+ 0.0, 0.0, 1.0,
+ &data->fb[0]);
+
+ igt_plane_set_fb(data->plane[0], &data->fb[0]);
+
+ /* yellow sprite plane in lower left corner */
+ for (i = IGT_PLANE_2; i < crtc.nplanes; i++) {
+ if (data->plane[i]->is_cursor)
+ size = 64;
+ else
+ size = SIZE;
+
+ x = 0;
+ y = mode->vdisplay - size;
+
+ igt_create_color_fb(data->drm_fd,
+ size, size,
+ data->plane[i]->is_cursor ? DRM_FORMAT_ARGB8888 : DRM_FORMAT_XRGB8888,
+ data->plane[i]->is_cursor ? LOCAL_DRM_FORMAT_MOD_NONE : modifier,
+ 1.0, 1.0, 0.0,
+ &data->fb[i]);
+
+ igt_plane_set_position(data->plane[i], x, y);
+ igt_plane_set_fb(data->plane[i], &data->fb[i]);
+ }
+
+ return mode;
+}
+
+static void
+test_plane_position_with_output(data_t *data, enum pipe pipe,
+ igt_output_t *output, uint64_t modifier)
+{
+ igt_crc_t *crc_hires1, *crc_hires2;
+ igt_crc_t *crc_lowres;
+ drmModeModeInfo mode_lowres;
+ drmModeModeInfo *mode1, *mode2, *mode3;
+ int ret, n;
+ int flags = DRM_MODE_PAGE_FLIP_EVENT | DRM_MODE_ATOMIC_ALLOW_MODESET;
+
+ igt_info("Testing connector %s using pipe %s\n",
+ igt_output_name(output), kmstest_pipe_name(pipe));
+
+ test_init(data, pipe);
+
+ mode1 = test_setup(data, pipe, modifier, flags, output);
+
+ mode_lowres = get_lowres_mode(data->drm_fd, mode1);
+
+ igt_pipe_crc_start(data->pipe_crc);
+ ret = igt_display_try_commit2(&data->display, COMMIT_ATOMIC);
+ igt_skip_on(ret != 0);
+
+ n = igt_pipe_crc_get_crcs(data->pipe_crc, 1, &crc_hires1);
+ igt_assert_eq(1, n);
+
+ igt_assert_plane_visible(pipe, true);
+
+ /* switch to lower resolution */
+ igt_output_override_mode(output, &mode_lowres);
+ igt_output_set_pipe(output, pipe);
+
+ mode2 = igt_output_get_mode(output);
+
+ check_mode(&mode_lowres, mode2);
+
+ display_commit_mode(data, pipe, flags, crc_lowres);
+
+ igt_assert_plane_visible(pipe, false);
+
+ /* switch back to higher resolution */
+ igt_output_override_mode(output, NULL);
+ igt_output_set_pipe(output, pipe);
+
+ mode3 = igt_output_get_mode(output);
+
+ check_mode(mode1, mode3);
+
+ display_commit_mode(data, pipe, flags, crc_hires2);
+
+ igt_assert_plane_visible(pipe, true);
+
+ igt_pipe_crc_stop(data->pipe_crc);
+
+ test_fini(data, output);
+}
+
+static void
+test_plane_position(data_t *data, enum pipe pipe, uint64_t modifier)
+{
+ igt_output_t *output;
+ int connected_outs;
+
+ igt_require(data->display.is_atomic);
+ igt_skip_on(pipe >= data->display.n_pipes);
+
+ connected_outs = 0;
+ for_each_valid_output_on_pipe(&data->display, pipe, output) {
+ test_plane_position_with_output(data, pipe, output, modifier);
+ connected_outs++;
+ }
+
+ igt_skip_on(connected_outs == 0);
+
+}
+
+static void
+run_tests_for_pipe(data_t *data, enum pipe pipe)
+{
+ igt_subtest_f("pipe-%s-tiling-none",
+ kmstest_pipe_name(pipe))
+ test_plane_position(data, pipe, LOCAL_DRM_FORMAT_MOD_NONE);
+
+ igt_subtest_f("pipe-%s-tiling-x",
+ kmstest_pipe_name(pipe))
+ test_plane_position(data, pipe, LOCAL_I915_FORMAT_MOD_X_TILED);
+
+ igt_subtest_f("pipe-%s-tiling-y",
+ kmstest_pipe_name(pipe))
+ test_plane_position(data, pipe, LOCAL_I915_FORMAT_MOD_Y_TILED);
+
+ igt_subtest_f("pipe-%s-tiling-yf",
+ kmstest_pipe_name(pipe))
+ test_plane_position(data, pipe, LOCAL_I915_FORMAT_MOD_Yf_TILED);
+}
+
+static data_t data;
+
+igt_main
+{
+ igt_skip_on_simulation();
+
+ igt_fixture {
+ data.drm_fd = drm_open_driver_master(DRIVER_ANY);
+
+ kmstest_set_vt_graphics_mode();
+
+ igt_require_pipe_crc();
+ igt_display_init(&data.display, data.drm_fd);
+ }
+
+ for (int pipe = 0; pipe < I915_MAX_PIPES; pipe++)
+ run_tests_for_pipe(&data, pipe);
+
+ igt_fixture {
+ igt_display_fini(&data.display);
+ }
+
+ igt_exit();
+}
--
2.7.4
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH i-g-t v4] tests/kms_plane_lowres: Plane visibility after atomic modesets
2016-12-30 12:47 [PATCH i-g-t v4] tests/kms_plane_lowres: Plane visibility after atomic modesets Mika Kahola
@ 2017-01-12 10:00 ` Maarten Lankhorst
2017-01-12 10:07 ` Mika Kahola
0 siblings, 1 reply; 3+ messages in thread
From: Maarten Lankhorst @ 2017-01-12 10:00 UTC (permalink / raw)
To: Mika Kahola, intel-gfx
Op 30-12-16 om 13:47 schreef Mika Kahola:
> Testcase for plane visibility after atomic modesets. The idea of the test
> is the following:
>
> - draw a blue screen with high resolution
> - enable a yellow plane, visible, in lower-left corner
> - set a new lower resolution mode (1024x768) that makes plane invisible
> - check from debugfs 'i915_display_info' that the plane is invisible
> - switch back to higher resolution mode
> - check from debugfs 'i915_display_info' that the plane is visible again
> - repeat number of iterations, default 64
>
> v2: allow test to be run on non-Intel drivers (Daniel)
> moved test for plane visibility to as helper function (Daniel)
> moved get_vblank() function to be part of helper functions (Daniel)
> rename 'tiling' parameter as 'modifier' (Daniel)
> select a mode from a list so that the plane should be invisible.
> use default 1024x768 mode only as a fallback if decent mode has not
> been found (Daniel)
> add tiling MODE_NONE (Daniel)
>
> v3: draw as many overlay planes as the platform supports + cursor plane
> on top of each other on lower-left corner
> skip the test if i915_display_info file is not available
> test plane visibility with igt_assert_plane_visibility() function
> drop option for multiple test iterations (Daniel Vetter)
>
> v4: switch 'for_each_connected_output()' to
> 'for_each_valid_output_on_pipe()' (Maarten)
>
> Cc: Daniel Stone <daniel@fooishbar.org>
> Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
>
> Signed-off-by: Mika Kahola <mika.kahola@intel.com>
> ---
> lib/igt_kms.c | 161 ++++++++++++++++++++++
> lib/igt_kms.h | 23 ++++
> tests/Makefile.sources | 1 +
> tests/kms_plane_lowres.c | 344 +++++++++++++++++++++++++++++++++++++++++++++++
> 4 files changed, 529 insertions(+)
> create mode 100644 tests/kms_plane_lowres.c
>
> diff --git a/lib/igt_kms.c b/lib/igt_kms.c
> index 5312f8d8..c823a3b 100644
> --- a/lib/igt_kms.c
> +++ b/lib/igt_kms.c
> @@ -324,6 +324,24 @@ const char *kmstest_pipe_name(enum pipe pipe)
> }
>
> /**
> + * kmstest_pipe_to_index:
> + *@pipe: display pipe in string format
> + *
> + * Returns: index to corresponding pipe
> + */
> +int kmstest_pipe_to_index(char pipe)
> +{
> + if (pipe == 'A')
> + return 0;
> + else if (pipe == 'B')
> + return 1;
> + else if (pipe == 'C')
> + return 2;
> + else
> + return -EINVAL;
> +}
> +
> +/**
> * kmstest_plane_name:
> * @plane: display plane
> *
> @@ -1181,6 +1199,149 @@ int kmstest_get_crtc_idx(drmModeRes *res, uint32_t crtc_id)
> igt_assert(false);
> }
>
> +static inline uint32_t pipe_select(int pipe)
> +{
> + if (pipe > 1)
> + return pipe << DRM_VBLANK_HIGH_CRTC_SHIFT;
> + else if (pipe > 0)
> + return DRM_VBLANK_SECONDARY;
> + else
> + return 0;
> +}
> +
> +unsigned int kmstest_get_vblank(int fd, int pipe, unsigned int flags)
> +{
> + union drm_wait_vblank vbl;
> +
> + memset(&vbl, 0, sizeof(vbl));
> + vbl.request.type = DRM_VBLANK_RELATIVE | pipe_select(pipe) | flags;
> + if (drmIoctl(fd, DRM_IOCTL_WAIT_VBLANK, &vbl))
> + return 0;
> +
> + return vbl.reply.sequence;
> +}
> +
> +static void get_plane(char *str, int type, struct kmstest_plane *plane)
> +{
> + int ret;
> + char buf[256];
> +
> + plane->plane = type;
> + ret = sscanf(str + 12, "%d%*c %*s %[^n]s",
> + &plane->id,
> + buf);
> + igt_assert_eq(ret, 2);
> +
> + ret = sscanf(buf + 9, "%4d%*c%4d%*c", &plane->pos_x, &plane->pos_y);
> + igt_assert_eq(ret, 2);
> +
> + ret = sscanf(buf + 30, "%4d%*c%4d%*c", &plane->width, &plane->height);
> + igt_assert_eq(ret, 2);
> +}
> +
> +static int parse_planes(FILE *fid, struct kmstest_plane *plane)
> +{
> + char tmp[256];
> + int nplanes;
> + int ovl;
> +
> + ovl = 0;
> + nplanes = 0;
> + while (fgets(tmp, 256, fid) != NULL) {
> + igt_assert_neq(nplanes, IGT_MAX_PLANES);
> + if (strstr(tmp, "type=PRI") != NULL) {
> + get_plane(tmp, IGT_PLANE_PRIMARY, &plane[nplanes]);
> + nplanes++;
> + } else if (strstr(tmp, "type=OVL") != NULL) {
> + get_plane(tmp, IGT_PLANE_2 + ovl, &plane[nplanes]);
> + ovl++;
> + nplanes++;
> + } else if (strstr(tmp, "type=CUR") != NULL) {
> + get_plane(tmp, IGT_PLANE_CURSOR, &plane[nplanes]);
> + nplanes++;
> + break;
> + }
> + }
> +
> + return nplanes;
> +}
> +
> +static void parse_crtc(char *info, struct kmstest_crtc *crtc)
> +{
> + char buf[256];
> + int ret;
> + char pipe;
> +
> + ret = sscanf(info + 4, "%d%*c %*s %c%*c %*s %s%*c",
> + &crtc->id, &pipe, buf);
> + igt_assert_eq(ret, 3);
> +
> + crtc->pipe = kmstest_pipe_to_index(pipe);
> + igt_assert(crtc->pipe >= 0);
> +
> + ret = sscanf(buf + 6, "%d%*c%d%*c",
> + &crtc->width, &crtc->height);
> + igt_assert_eq(ret, 2);
> +}
> +
> +void kmstest_get_crtc(enum pipe pipe, struct kmstest_crtc *crtc)
> +{
> + char tmp[256];
> + FILE *fid;
> + const char *mode = "r";
> + int ncrtc;
> + int line;
> +
> + fid = igt_debugfs_fopen("i915_display_info", mode);
> +
> + igt_skip_on(fid == NULL);
> +
> + ncrtc = 0;
> + line = 0;
> + while (fgets(tmp, 256, fid) != NULL) {
> + if ((strstr(tmp, "CRTC") != NULL) && (line > 0)) {
> + if (strstr(tmp, "active=yes") != NULL) {
> + crtc->active = true;
> + parse_crtc(tmp, crtc);
> + crtc->nplanes = parse_planes(fid, crtc->plane);
> +
> + if (crtc->pipe != pipe)
> + crtc = NULL;
> + else
> + ncrtc++;
> + }
> + }
> +
> + line++;
> + }
> +
> + fclose(fid);
> +
> + igt_skip_on(ncrtc == 0);
> +}
> +
> +void igt_assert_plane_visible(enum pipe pipe, bool visibility)
> +{
> + struct kmstest_crtc crtc;
> + int i;
> + bool visible;
> +
> + kmstest_get_crtc(pipe, &crtc);
> +
> + visible = true;
> + for (i = IGT_PLANE_2; i < crtc.nplanes; i++) {
> + if (crtc.plane[i].pos_x > crtc.width) {
> + visible = false;
> + break;
> + } else if (crtc.plane[i].pos_y > crtc.height) {
> + visible = false;
> + break;
> + }
> + }
> +
> + igt_assert_eq(visible, visibility);
> +}
> +
> /*
> * A small modeset API
> */
> diff --git a/lib/igt_kms.h b/lib/igt_kms.h
> index 5234f6c..2da4ad9 100644
> --- a/lib/igt_kms.h
> +++ b/lib/igt_kms.h
> @@ -57,6 +57,7 @@ enum pipe {
> I915_MAX_PIPES
> };
> const char *kmstest_pipe_name(enum pipe pipe);
> +int kmstest_pipe_to_index(char pipe);
>
> /* We namespace this enum to not conflict with the Android i915_drm.h */
> enum igt_plane {
> @@ -132,6 +133,25 @@ struct kmstest_connector_config {
> unsigned valid_crtc_idx_mask;
> };
>
> +struct kmstest_plane {
> + int id;
> + int plane;
> + int pos_x;
> + int pos_y;
> + int width;
> + int height;
> +};
> +
> +struct kmstest_crtc {
> + int id;
> + int pipe;
> + bool active;
> + int width;
> + int height;
> + int nplanes;
> + struct kmstest_plane plane[IGT_MAX_PLANES];
> +};
> +
> /**
> * kmstest_force_connector_state:
> * @FORCE_CONNECTOR_UNSPECIFIED: Unspecified
> @@ -177,6 +197,9 @@ uint32_t kmstest_dumb_create(int fd, int width, int height, int bpp,
>
> void *kmstest_dumb_map_buffer(int fd, uint32_t handle, uint64_t size,
> unsigned prot);
> +unsigned int kmstest_get_vblank(int fd, int pipe, unsigned int flags);
> +void kmstest_get_crtc(enum pipe pipe, struct kmstest_crtc *crtc);
> +void igt_assert_plane_visible(enum pipe pipe, bool visibility);
>
> /*
> * A small modeset API
> diff --git a/tests/Makefile.sources b/tests/Makefile.sources
> index f6e08d6..6316ea6 100644
> --- a/tests/Makefile.sources
> +++ b/tests/Makefile.sources
> @@ -111,6 +111,7 @@ TESTS_progs_M = \
> kms_pipe_crc_basic \
> kms_plane \
> kms_plane_multiple \
> + kms_plane_lowres \
> kms_properties \
> kms_psr_sink_crc \
> kms_render \
> diff --git a/tests/kms_plane_lowres.c b/tests/kms_plane_lowres.c
> new file mode 100644
> index 0000000..21f8282
> --- /dev/null
> +++ b/tests/kms_plane_lowres.c
> @@ -0,0 +1,344 @@
> +/*
> + * Copyright © 2016 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 "drmtest.h"
> +#include <errno.h>
> +#include <stdbool.h>
> +#include <stdio.h>
> +#include <string.h>
> +#include <time.h>
> +
> +IGT_TEST_DESCRIPTION("Test atomic mode setting with a plane by switching between high and low resolutions");
> +
> +#define MAX_CRCS 1
> +#define SIZE 256
> +#define LOOP_FOREVER -1
> +
> +typedef struct {
> + int drm_fd;
> + igt_display_t display;
> + igt_pipe_crc_t *pipe_crc;
> + igt_plane_t *plane[IGT_MAX_PLANES];
> + struct igt_fb fb[IGT_MAX_PLANES];
> +} data_t;
> +
> +static drmModeModeInfo
> +get_lowres_mode(int drmfd, drmModeModeInfo *mode_default)
> +{
> + drmModeRes *mode_resources = drmModeGetResources(drmfd);
> + drmModeModeInfo mode;
> + drmModeModeInfo std_1024_mode = {
> + .clock = 65000,
> + .hdisplay = 1024,
> + .hsync_start = 1048,
> + .hsync_end = 1184,
> + .htotal = 1344,
> + .hskew = 0,
> + .vdisplay = 768,
> + .vsync_start = 771,
> + .vsync_end = 777,
> + .vtotal = 806,
> + .vscan = 0,
> + .vrefresh = 60,
> + .flags = 0xA,
> + .type = 0x40,
> + .name = "Custom 1024x768",
> + };
> + bool found;
> + int limit = mode_default->vdisplay-SIZE;
> + int i, j;
> +
> + if (!mode_resources) {
> + igt_warn("drmModeGetResources failed: %s\n", strerror(errno));
> + return std_1024_mode;
> + }
> +
> + found = false;
> + for (i = 0; i < mode_resources->count_connectors; i++) {
> + drmModeConnector *connector;
> +
> + connector = drmModeGetConnectorCurrent(drmfd,
> + mode_resources->connectors[i]);
> + if (!connector) {
> + igt_warn("could not get connector %i: %s\n",
> + mode_resources->connectors[i], strerror(errno));
> + continue;
> + }
> +
> + if (!connector->count_modes)
> + continue;
> +
> + for (j = 0; j < connector->count_modes; j++) {
> + mode = connector->modes[j];
> + if (mode.vdisplay < limit) {
> + found = true;
> + break;
> + }
> + }
> +
> + drmModeFreeConnector(connector);
> + }
> +
> + drmModeFreeResources(mode_resources);
> +
> + if (!found)
> + return std_1024_mode;
> +
> + return mode;
> +}
> +
> +static void
> +test_init(data_t *data, enum pipe pipe)
> +{
> + data->pipe_crc = igt_pipe_crc_new(pipe, INTEL_PIPE_CRC_SOURCE_AUTO);
> +}
> +
> +static void
> +test_fini(data_t *data, igt_output_t *output)
> +{
> + /* restore original mode */
> + igt_output_override_mode(output, NULL);
> +
> + for (int i = 0; i < 2; i++)
> + igt_plane_set_fb(data->plane[i], NULL);
> +
> + /* reset the constraint on the pipe */
> + igt_output_set_pipe(output, PIPE_ANY);
> +
> + igt_pipe_crc_free(data->pipe_crc);
> +}
> +
> +static int
> +display_commit_mode(data_t *data, enum pipe pipe, int flags, igt_crc_t *crc)
> +{
> + char buf[256];
> + struct drm_event *e = (void *)buf;
> + unsigned int vblank_start, vblank_stop;
> + int n, ret;
> +
> + vblank_start = kmstest_get_vblank(data->display.drm_fd, pipe,
> + DRM_VBLANK_NEXTONMISS);
> +
> + ret = igt_display_try_commit_atomic(&data->display,
> + flags,
> + NULL);
> + igt_skip_on(ret != 0);
> +
> + igt_set_timeout(1, "Stuck on page flip");
> + ret = read(data->display.drm_fd, buf, sizeof(buf));
> + igt_assert(ret >= 0);
> +
> + vblank_stop = kmstest_get_vblank(data->display.drm_fd, pipe, 0);
> + igt_assert_eq(e->type, DRM_EVENT_FLIP_COMPLETE);
> + igt_reset_timeout();
> +
> + n = igt_pipe_crc_get_crcs(data->pipe_crc, vblank_stop - vblank_start,
> + &crc);
> + igt_assert_eq(n, vblank_stop - vblank_start);
> +
> + return n;
> +}
> +
> +static void
> +check_mode(drmModeModeInfo *mode1, drmModeModeInfo *mode2)
> +{
> + igt_assert_eq(mode1->hdisplay, mode2->hdisplay);
> + igt_assert_eq(mode1->vdisplay, mode2->vdisplay);
> + igt_assert_eq(mode1->vrefresh, mode2->vrefresh);
> +}
> +
> +static drmModeModeInfo *
> +test_setup(data_t *data, enum pipe pipe, uint64_t modifier, int flags,
> + igt_output_t *output)
> +{
> + struct kmstest_crtc crtc;
> + drmModeModeInfo *mode;
> + int size;
> + int i, x, y;
> +
> + igt_output_set_pipe(output, pipe);
> +
> + kmstest_get_crtc(pipe, &crtc);
> + igt_skip_on(crtc.nplanes > data->display.pipes[pipe].n_planes);
> + igt_skip_on(crtc.nplanes == 0);
> +
> + for (i = 0; i < crtc.nplanes; i++)
> + data->plane[i] = igt_output_get_plane(output, crtc.plane[i].plane);
> +
> + mode = igt_output_get_mode(output);
> +
> + igt_create_color_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
> + DRM_FORMAT_XRGB8888,
> + modifier,
> + 0.0, 0.0, 1.0,
> + &data->fb[0]);
> +
> + igt_plane_set_fb(data->plane[0], &data->fb[0]);
> +
> + /* yellow sprite plane in lower left corner */
> + for (i = IGT_PLANE_2; i < crtc.nplanes; i++) {
> + if (data->plane[i]->is_cursor)
> + size = 64;
> + else
> + size = SIZE;
> +
> + x = 0;
> + y = mode->vdisplay - size;
> +
> + igt_create_color_fb(data->drm_fd,
> + size, size,
> + data->plane[i]->is_cursor ? DRM_FORMAT_ARGB8888 : DRM_FORMAT_XRGB8888,
> + data->plane[i]->is_cursor ? LOCAL_DRM_FORMAT_MOD_NONE : modifier,
> + 1.0, 1.0, 0.0,
> + &data->fb[i]);
> +
> + igt_plane_set_position(data->plane[i], x, y);
> + igt_plane_set_fb(data->plane[i], &data->fb[i]);
> + }
> +
> + return mode;
> +}
> +
> +static void
> +test_plane_position_with_output(data_t *data, enum pipe pipe,
> + igt_output_t *output, uint64_t modifier)
> +{
> + igt_crc_t *crc_hires1, *crc_hires2;
> + igt_crc_t *crc_lowres;
> + drmModeModeInfo mode_lowres;
> + drmModeModeInfo *mode1, *mode2, *mode3;
> + int ret, n;
> + int flags = DRM_MODE_PAGE_FLIP_EVENT | DRM_MODE_ATOMIC_ALLOW_MODESET;
> +
> + igt_info("Testing connector %s using pipe %s\n",
> + igt_output_name(output), kmstest_pipe_name(pipe));
> +
> + test_init(data, pipe);
> +
> + mode1 = test_setup(data, pipe, modifier, flags, output);
> +
> + mode_lowres = get_lowres_mode(data->drm_fd, mode1);
> +
> + igt_pipe_crc_start(data->pipe_crc);
> + ret = igt_display_try_commit2(&data->display, COMMIT_ATOMIC);
> + igt_skip_on(ret != 0);
> +
> + n = igt_pipe_crc_get_crcs(data->pipe_crc, 1, &crc_hires1);
> + igt_assert_eq(1, n);
> +
> + igt_assert_plane_visible(pipe, true);
> +
> + /* switch to lower resolution */
> + igt_output_override_mode(output, &mode_lowres);
> + igt_output_set_pipe(output, pipe);
> +
> + mode2 = igt_output_get_mode(output);
> +
> + check_mode(&mode_lowres, mode2);
> +
> + display_commit_mode(data, pipe, flags, crc_lowres);
> +
> + igt_assert_plane_visible(pipe, false);
> +
> + /* switch back to higher resolution */
> + igt_output_override_mode(output, NULL);
> + igt_output_set_pipe(output, pipe);
> +
> + mode3 = igt_output_get_mode(output);
> +
> + check_mode(mode1, mode3);
> +
> + display_commit_mode(data, pipe, flags, crc_hires2);
> +
> + igt_assert_plane_visible(pipe, true);
> +
> + igt_pipe_crc_stop(data->pipe_crc);
> +
> + test_fini(data, output);
> +}
> +
> +static void
> +test_plane_position(data_t *data, enum pipe pipe, uint64_t modifier)
> +{
> + igt_output_t *output;
> + int connected_outs;
> +
> + igt_require(data->display.is_atomic);
> + igt_skip_on(pipe >= data->display.n_pipes);
> +
> + connected_outs = 0;
> + for_each_valid_output_on_pipe(&data->display, pipe, output) {
> + test_plane_position_with_output(data, pipe, output, modifier);
> + connected_outs++;
> + }
> +
> + igt_skip_on(connected_outs == 0);
> +
> +}
> +
> +static void
> +run_tests_for_pipe(data_t *data, enum pipe pipe)
> +{
> + igt_subtest_f("pipe-%s-tiling-none",
> + kmstest_pipe_name(pipe))
> + test_plane_position(data, pipe, LOCAL_DRM_FORMAT_MOD_NONE);
> +
> + igt_subtest_f("pipe-%s-tiling-x",
> + kmstest_pipe_name(pipe))
> + test_plane_position(data, pipe, LOCAL_I915_FORMAT_MOD_X_TILED);
> +
> + igt_subtest_f("pipe-%s-tiling-y",
> + kmstest_pipe_name(pipe))
> + test_plane_position(data, pipe, LOCAL_I915_FORMAT_MOD_Y_TILED);
> +
> + igt_subtest_f("pipe-%s-tiling-yf",
> + kmstest_pipe_name(pipe))
> + test_plane_position(data, pipe, LOCAL_I915_FORMAT_MOD_Yf_TILED);
> +}
These tests require some changes to run succesfully on gen < 9.
from kms_flip_tiling.c it seems that
Y and Yf tiling requires gen >= 9, else tests fail with -EINVAL in addfb.
If fixed:
Reviewed-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH i-g-t v4] tests/kms_plane_lowres: Plane visibility after atomic modesets
2017-01-12 10:00 ` Maarten Lankhorst
@ 2017-01-12 10:07 ` Mika Kahola
0 siblings, 0 replies; 3+ messages in thread
From: Mika Kahola @ 2017-01-12 10:07 UTC (permalink / raw)
To: Maarten Lankhorst, intel-gfx
On Thu, 2017-01-12 at 11:00 +0100, Maarten Lankhorst wrote:
> Op 30-12-16 om 13:47 schreef Mika Kahola:
> >
> > Testcase for plane visibility after atomic modesets. The idea of
> > the test
> > is the following:
> >
> > - draw a blue screen with high resolution
> > - enable a yellow plane, visible, in lower-left corner
> > - set a new lower resolution mode (1024x768) that makes plane
> > invisible
> > - check from debugfs 'i915_display_info' that the plane is
> > invisible
> > - switch back to higher resolution mode
> > - check from debugfs 'i915_display_info' that the plane is visible
> > again
> > - repeat number of iterations, default 64
> >
> > v2: allow test to be run on non-Intel drivers (Daniel)
> > moved test for plane visibility to as helper function (Daniel)
> > moved get_vblank() function to be part of helper functions
> > (Daniel)
> > rename 'tiling' parameter as 'modifier' (Daniel)
> > select a mode from a list so that the plane should be
> > invisible.
> > use default 1024x768 mode only as a fallback if decent mode has
> > not
> > been found (Daniel)
> > add tiling MODE_NONE (Daniel)
> >
> > v3: draw as many overlay planes as the platform supports + cursor
> > plane
> > on top of each other on lower-left corner
> > skip the test if i915_display_info file is not available
> > test plane visibility with igt_assert_plane_visibility()
> > function
> > drop option for multiple test iterations (Daniel Vetter)
> >
> > v4: switch 'for_each_connected_output()' to
> > 'for_each_valid_output_on_pipe()' (Maarten)
> >
> > Cc: Daniel Stone <daniel@fooishbar.org>
> > Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
> >
> > Signed-off-by: Mika Kahola <mika.kahola@intel.com>
> > ---
> > lib/igt_kms.c | 161 ++++++++++++++++++++++
> > lib/igt_kms.h | 23 ++++
> > tests/Makefile.sources | 1 +
> > tests/kms_plane_lowres.c | 344
> > +++++++++++++++++++++++++++++++++++++++++++++++
> > 4 files changed, 529 insertions(+)
> > create mode 100644 tests/kms_plane_lowres.c
> >
> > diff --git a/lib/igt_kms.c b/lib/igt_kms.c
> > index 5312f8d8..c823a3b 100644
> > --- a/lib/igt_kms.c
> > +++ b/lib/igt_kms.c
> > @@ -324,6 +324,24 @@ const char *kmstest_pipe_name(enum pipe pipe)
> > }
> >
> > /**
> > + * kmstest_pipe_to_index:
> > + *@pipe: display pipe in string format
> > + *
> > + * Returns: index to corresponding pipe
> > + */
> > +int kmstest_pipe_to_index(char pipe)
> > +{
> > + if (pipe == 'A')
> > + return 0;
> > + else if (pipe == 'B')
> > + return 1;
> > + else if (pipe == 'C')
> > + return 2;
> > + else
> > + return -EINVAL;
> > +}
> > +
> > +/**
> > * kmstest_plane_name:
> > * @plane: display plane
> > *
> > @@ -1181,6 +1199,149 @@ int kmstest_get_crtc_idx(drmModeRes *res,
> > uint32_t crtc_id)
> > igt_assert(false);
> > }
> >
> > +static inline uint32_t pipe_select(int pipe)
> > +{
> > + if (pipe > 1)
> > + return pipe << DRM_VBLANK_HIGH_CRTC_SHIFT;
> > + else if (pipe > 0)
> > + return DRM_VBLANK_SECONDARY;
> > + else
> > + return 0;
> > +}
> > +
> > +unsigned int kmstest_get_vblank(int fd, int pipe, unsigned int
> > flags)
> > +{
> > + union drm_wait_vblank vbl;
> > +
> > + memset(&vbl, 0, sizeof(vbl));
> > + vbl.request.type = DRM_VBLANK_RELATIVE | pipe_select(pipe)
> > | flags;
> > + if (drmIoctl(fd, DRM_IOCTL_WAIT_VBLANK, &vbl))
> > + return 0;
> > +
> > + return vbl.reply.sequence;
> > +}
> > +
> > +static void get_plane(char *str, int type, struct kmstest_plane
> > *plane)
> > +{
> > + int ret;
> > + char buf[256];
> > +
> > + plane->plane = type;
> > + ret = sscanf(str + 12, "%d%*c %*s %[^n]s",
> > + &plane->id,
> > + buf);
> > + igt_assert_eq(ret, 2);
> > +
> > + ret = sscanf(buf + 9, "%4d%*c%4d%*c", &plane->pos_x,
> > &plane->pos_y);
> > + igt_assert_eq(ret, 2);
> > +
> > + ret = sscanf(buf + 30, "%4d%*c%4d%*c", &plane->width,
> > &plane->height);
> > + igt_assert_eq(ret, 2);
> > +}
> > +
> > +static int parse_planes(FILE *fid, struct kmstest_plane *plane)
> > +{
> > + char tmp[256];
> > + int nplanes;
> > + int ovl;
> > +
> > + ovl = 0;
> > + nplanes = 0;
> > + while (fgets(tmp, 256, fid) != NULL) {
> > + igt_assert_neq(nplanes, IGT_MAX_PLANES);
> > + if (strstr(tmp, "type=PRI") != NULL) {
> > + get_plane(tmp, IGT_PLANE_PRIMARY,
> > &plane[nplanes]);
> > + nplanes++;
> > + } else if (strstr(tmp, "type=OVL") != NULL) {
> > + get_plane(tmp, IGT_PLANE_2 + ovl,
> > &plane[nplanes]);
> > + ovl++;
> > + nplanes++;
> > + } else if (strstr(tmp, "type=CUR") != NULL) {
> > + get_plane(tmp, IGT_PLANE_CURSOR,
> > &plane[nplanes]);
> > + nplanes++;
> > + break;
> > + }
> > + }
> > +
> > + return nplanes;
> > +}
> > +
> > +static void parse_crtc(char *info, struct kmstest_crtc *crtc)
> > +{
> > + char buf[256];
> > + int ret;
> > + char pipe;
> > +
> > + ret = sscanf(info + 4, "%d%*c %*s %c%*c %*s %s%*c",
> > + &crtc->id, &pipe, buf);
> > + igt_assert_eq(ret, 3);
> > +
> > + crtc->pipe = kmstest_pipe_to_index(pipe);
> > + igt_assert(crtc->pipe >= 0);
> > +
> > + ret = sscanf(buf + 6, "%d%*c%d%*c",
> > + &crtc->width, &crtc->height);
> > + igt_assert_eq(ret, 2);
> > +}
> > +
> > +void kmstest_get_crtc(enum pipe pipe, struct kmstest_crtc *crtc)
> > +{
> > + char tmp[256];
> > + FILE *fid;
> > + const char *mode = "r";
> > + int ncrtc;
> > + int line;
> > +
> > + fid = igt_debugfs_fopen("i915_display_info", mode);
> > +
> > + igt_skip_on(fid == NULL);
> > +
> > + ncrtc = 0;
> > + line = 0;
> > + while (fgets(tmp, 256, fid) != NULL) {
> > + if ((strstr(tmp, "CRTC") != NULL) && (line > 0)) {
> > + if (strstr(tmp, "active=yes") != NULL) {
> > + crtc->active = true;
> > + parse_crtc(tmp, crtc);
> > + crtc->nplanes = parse_planes(fid,
> > crtc->plane);
> > +
> > + if (crtc->pipe != pipe)
> > + crtc = NULL;
> > + else
> > + ncrtc++;
> > + }
> > + }
> > +
> > + line++;
> > + }
> > +
> > + fclose(fid);
> > +
> > + igt_skip_on(ncrtc == 0);
> > +}
> > +
> > +void igt_assert_plane_visible(enum pipe pipe, bool visibility)
> > +{
> > + struct kmstest_crtc crtc;
> > + int i;
> > + bool visible;
> > +
> > + kmstest_get_crtc(pipe, &crtc);
> > +
> > + visible = true;
> > + for (i = IGT_PLANE_2; i < crtc.nplanes; i++) {
> > + if (crtc.plane[i].pos_x > crtc.width) {
> > + visible = false;
> > + break;
> > + } else if (crtc.plane[i].pos_y > crtc.height) {
> > + visible = false;
> > + break;
> > + }
> > + }
> > +
> > + igt_assert_eq(visible, visibility);
> > +}
> > +
> > /*
> > * A small modeset API
> > */
> > diff --git a/lib/igt_kms.h b/lib/igt_kms.h
> > index 5234f6c..2da4ad9 100644
> > --- a/lib/igt_kms.h
> > +++ b/lib/igt_kms.h
> > @@ -57,6 +57,7 @@ enum pipe {
> > I915_MAX_PIPES
> > };
> > const char *kmstest_pipe_name(enum pipe pipe);
> > +int kmstest_pipe_to_index(char pipe);
> >
> > /* We namespace this enum to not conflict with the Android
> > i915_drm.h */
> > enum igt_plane {
> > @@ -132,6 +133,25 @@ struct kmstest_connector_config {
> > unsigned valid_crtc_idx_mask;
> > };
> >
> > +struct kmstest_plane {
> > + int id;
> > + int plane;
> > + int pos_x;
> > + int pos_y;
> > + int width;
> > + int height;
> > +};
> > +
> > +struct kmstest_crtc {
> > + int id;
> > + int pipe;
> > + bool active;
> > + int width;
> > + int height;
> > + int nplanes;
> > + struct kmstest_plane plane[IGT_MAX_PLANES];
> > +};
> > +
> > /**
> > * kmstest_force_connector_state:
> > * @FORCE_CONNECTOR_UNSPECIFIED: Unspecified
> > @@ -177,6 +197,9 @@ uint32_t kmstest_dumb_create(int fd, int width,
> > int height, int bpp,
> >
> > void *kmstest_dumb_map_buffer(int fd, uint32_t handle, uint64_t
> > size,
> > unsigned prot);
> > +unsigned int kmstest_get_vblank(int fd, int pipe, unsigned int
> > flags);
> > +void kmstest_get_crtc(enum pipe pipe, struct kmstest_crtc *crtc);
> > +void igt_assert_plane_visible(enum pipe pipe, bool visibility);
> >
> > /*
> > * A small modeset API
> > diff --git a/tests/Makefile.sources b/tests/Makefile.sources
> > index f6e08d6..6316ea6 100644
> > --- a/tests/Makefile.sources
> > +++ b/tests/Makefile.sources
> > @@ -111,6 +111,7 @@ TESTS_progs_M = \
> > kms_pipe_crc_basic \
> > kms_plane \
> > kms_plane_multiple \
> > + kms_plane_lowres \
> > kms_properties \
> > kms_psr_sink_crc \
> > kms_render \
> > diff --git a/tests/kms_plane_lowres.c b/tests/kms_plane_lowres.c
> > new file mode 100644
> > index 0000000..21f8282
> > --- /dev/null
> > +++ b/tests/kms_plane_lowres.c
> > @@ -0,0 +1,344 @@
> > +/*
> > + * Copyright © 2016 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 "drmtest.h"
> > +#include <errno.h>
> > +#include <stdbool.h>
> > +#include <stdio.h>
> > +#include <string.h>
> > +#include <time.h>
> > +
> > +IGT_TEST_DESCRIPTION("Test atomic mode setting with a plane by
> > switching between high and low resolutions");
> > +
> > +#define MAX_CRCS 1
> > +#define SIZE 256
> > +#define LOOP_FOREVER -1
> > +
> > +typedef struct {
> > + int drm_fd;
> > + igt_display_t display;
> > + igt_pipe_crc_t *pipe_crc;
> > + igt_plane_t *plane[IGT_MAX_PLANES];
> > + struct igt_fb fb[IGT_MAX_PLANES];
> > +} data_t;
> > +
> > +static drmModeModeInfo
> > +get_lowres_mode(int drmfd, drmModeModeInfo *mode_default)
> > +{
> > + drmModeRes *mode_resources = drmModeGetResources(drmfd);
> > + drmModeModeInfo mode;
> > + drmModeModeInfo std_1024_mode = {
> > + .clock = 65000,
> > + .hdisplay = 1024,
> > + .hsync_start = 1048,
> > + .hsync_end = 1184,
> > + .htotal = 1344,
> > + .hskew = 0,
> > + .vdisplay = 768,
> > + .vsync_start = 771,
> > + .vsync_end = 777,
> > + .vtotal = 806,
> > + .vscan = 0,
> > + .vrefresh = 60,
> > + .flags = 0xA,
> > + .type = 0x40,
> > + .name = "Custom 1024x768",
> > + };
> > + bool found;
> > + int limit = mode_default->vdisplay-SIZE;
> > + int i, j;
> > +
> > + if (!mode_resources) {
> > + igt_warn("drmModeGetResources failed: %s\n",
> > strerror(errno));
> > + return std_1024_mode;
> > + }
> > +
> > + found = false;
> > + for (i = 0; i < mode_resources->count_connectors; i++) {
> > + drmModeConnector *connector;
> > +
> > + connector = drmModeGetConnectorCurrent(drmfd,
> > + mode_resour
> > ces->connectors[i]);
> > + if (!connector) {
> > + igt_warn("could not get connector %i:
> > %s\n",
> > + mode_resources->connectors[i],
> > strerror(errno));
> > + continue;
> > + }
> > +
> > + if (!connector->count_modes)
> > + continue;
> > +
> > + for (j = 0; j < connector->count_modes; j++) {
> > + mode = connector->modes[j];
> > + if (mode.vdisplay < limit) {
> > + found = true;
> > + break;
> > + }
> > + }
> > +
> > + drmModeFreeConnector(connector);
> > + }
> > +
> > + drmModeFreeResources(mode_resources);
> > +
> > + if (!found)
> > + return std_1024_mode;
> > +
> > + return mode;
> > +}
> > +
> > +static void
> > +test_init(data_t *data, enum pipe pipe)
> > +{
> > + data->pipe_crc = igt_pipe_crc_new(pipe,
> > INTEL_PIPE_CRC_SOURCE_AUTO);
> > +}
> > +
> > +static void
> > +test_fini(data_t *data, igt_output_t *output)
> > +{
> > + /* restore original mode */
> > + igt_output_override_mode(output, NULL);
> > +
> > + for (int i = 0; i < 2; i++)
> > + igt_plane_set_fb(data->plane[i], NULL);
> > +
> > + /* reset the constraint on the pipe */
> > + igt_output_set_pipe(output, PIPE_ANY);
> > +
> > + igt_pipe_crc_free(data->pipe_crc);
> > +}
> > +
> > +static int
> > +display_commit_mode(data_t *data, enum pipe pipe, int flags,
> > igt_crc_t *crc)
> > +{
> > + char buf[256];
> > + struct drm_event *e = (void *)buf;
> > + unsigned int vblank_start, vblank_stop;
> > + int n, ret;
> > +
> > + vblank_start = kmstest_get_vblank(data->display.drm_fd,
> > pipe,
> > + DRM_VBLANK_NEXTONMISS);
> > +
> > + ret = igt_display_try_commit_atomic(&data->display,
> > + flags,
> > + NULL);
> > + igt_skip_on(ret != 0);
> > +
> > + igt_set_timeout(1, "Stuck on page flip");
> > + ret = read(data->display.drm_fd, buf, sizeof(buf));
> > + igt_assert(ret >= 0);
> > +
> > + vblank_stop = kmstest_get_vblank(data->display.drm_fd,
> > pipe, 0);
> > + igt_assert_eq(e->type, DRM_EVENT_FLIP_COMPLETE);
> > + igt_reset_timeout();
> > +
> > + n = igt_pipe_crc_get_crcs(data->pipe_crc, vblank_stop -
> > vblank_start,
> > + &crc);
> > + igt_assert_eq(n, vblank_stop - vblank_start);
> > +
> > + return n;
> > +}
> > +
> > +static void
> > +check_mode(drmModeModeInfo *mode1, drmModeModeInfo *mode2)
> > +{
> > + igt_assert_eq(mode1->hdisplay, mode2->hdisplay);
> > + igt_assert_eq(mode1->vdisplay, mode2->vdisplay);
> > + igt_assert_eq(mode1->vrefresh, mode2->vrefresh);
> > +}
> > +
> > +static drmModeModeInfo *
> > +test_setup(data_t *data, enum pipe pipe, uint64_t modifier, int
> > flags,
> > + igt_output_t *output)
> > +{
> > + struct kmstest_crtc crtc;
> > + drmModeModeInfo *mode;
> > + int size;
> > + int i, x, y;
> > +
> > + igt_output_set_pipe(output, pipe);
> > +
> > + kmstest_get_crtc(pipe, &crtc);
> > + igt_skip_on(crtc.nplanes > data-
> > >display.pipes[pipe].n_planes);
> > + igt_skip_on(crtc.nplanes == 0);
> > +
> > + for (i = 0; i < crtc.nplanes; i++)
> > + data->plane[i] = igt_output_get_plane(output,
> > crtc.plane[i].plane);
> > +
> > + mode = igt_output_get_mode(output);
> > +
> > + igt_create_color_fb(data->drm_fd, mode->hdisplay, mode-
> > >vdisplay,
> > + DRM_FORMAT_XRGB8888,
> > + modifier,
> > + 0.0, 0.0, 1.0,
> > + &data->fb[0]);
> > +
> > + igt_plane_set_fb(data->plane[0], &data->fb[0]);
> > +
> > + /* yellow sprite plane in lower left corner */
> > + for (i = IGT_PLANE_2; i < crtc.nplanes; i++) {
> > + if (data->plane[i]->is_cursor)
> > + size = 64;
> > + else
> > + size = SIZE;
> > +
> > + x = 0;
> > + y = mode->vdisplay - size;
> > +
> > + igt_create_color_fb(data->drm_fd,
> > + size, size,
> > + data->plane[i]->is_cursor ?
> > DRM_FORMAT_ARGB8888 : DRM_FORMAT_XRGB8888,
> > + data->plane[i]->is_cursor ?
> > LOCAL_DRM_FORMAT_MOD_NONE : modifier,
> > + 1.0, 1.0, 0.0,
> > + &data->fb[i]);
> > +
> > + igt_plane_set_position(data->plane[i], x, y);
> > + igt_plane_set_fb(data->plane[i], &data->fb[i]);
> > + }
> > +
> > + return mode;
> > +}
> > +
> > +static void
> > +test_plane_position_with_output(data_t *data, enum pipe pipe,
> > + igt_output_t *output, uint64_t
> > modifier)
> > +{
> > + igt_crc_t *crc_hires1, *crc_hires2;
> > + igt_crc_t *crc_lowres;
> > + drmModeModeInfo mode_lowres;
> > + drmModeModeInfo *mode1, *mode2, *mode3;
> > + int ret, n;
> > + int flags = DRM_MODE_PAGE_FLIP_EVENT |
> > DRM_MODE_ATOMIC_ALLOW_MODESET;
> > +
> > + igt_info("Testing connector %s using pipe %s\n",
> > + igt_output_name(output),
> > kmstest_pipe_name(pipe));
> > +
> > + test_init(data, pipe);
> > +
> > + mode1 = test_setup(data, pipe, modifier, flags, output);
> > +
> > + mode_lowres = get_lowres_mode(data->drm_fd, mode1);
> > +
> > + igt_pipe_crc_start(data->pipe_crc);
> > + ret = igt_display_try_commit2(&data->display,
> > COMMIT_ATOMIC);
> > + igt_skip_on(ret != 0);
> > +
> > + n = igt_pipe_crc_get_crcs(data->pipe_crc, 1, &crc_hires1);
> > + igt_assert_eq(1, n);
> > +
> > + igt_assert_plane_visible(pipe, true);
> > +
> > + /* switch to lower resolution */
> > + igt_output_override_mode(output, &mode_lowres);
> > + igt_output_set_pipe(output, pipe);
> > +
> > + mode2 = igt_output_get_mode(output);
> > +
> > + check_mode(&mode_lowres, mode2);
> > +
> > + display_commit_mode(data, pipe, flags, crc_lowres);
> > +
> > + igt_assert_plane_visible(pipe, false);
> > +
> > + /* switch back to higher resolution */
> > + igt_output_override_mode(output, NULL);
> > + igt_output_set_pipe(output, pipe);
> > +
> > + mode3 = igt_output_get_mode(output);
> > +
> > + check_mode(mode1, mode3);
> > +
> > + display_commit_mode(data, pipe, flags, crc_hires2);
> > +
> > + igt_assert_plane_visible(pipe, true);
> > +
> > + igt_pipe_crc_stop(data->pipe_crc);
> > +
> > + test_fini(data, output);
> > +}
> > +
> > +static void
> > +test_plane_position(data_t *data, enum pipe pipe, uint64_t
> > modifier)
> > +{
> > + igt_output_t *output;
> > + int connected_outs;
> > +
> > + igt_require(data->display.is_atomic);
> > + igt_skip_on(pipe >= data->display.n_pipes);
> > +
> > + connected_outs = 0;
> > + for_each_valid_output_on_pipe(&data->display, pipe,
> > output) {
> > + test_plane_position_with_output(data, pipe,
> > output, modifier);
> > + connected_outs++;
> > + }
> > +
> > + igt_skip_on(connected_outs == 0);
> > +
> > +}
> > +
> > +static void
> > +run_tests_for_pipe(data_t *data, enum pipe pipe)
> > +{
> > + igt_subtest_f("pipe-%s-tiling-none",
> > + kmstest_pipe_name(pipe))
> > + test_plane_position(data, pipe,
> > LOCAL_DRM_FORMAT_MOD_NONE);
> > +
> > + igt_subtest_f("pipe-%s-tiling-x",
> > + kmstest_pipe_name(pipe))
> > + test_plane_position(data, pipe,
> > LOCAL_I915_FORMAT_MOD_X_TILED);
> > +
> > + igt_subtest_f("pipe-%s-tiling-y",
> > + kmstest_pipe_name(pipe))
> > + test_plane_position(data, pipe,
> > LOCAL_I915_FORMAT_MOD_Y_TILED);
> > +
> > + igt_subtest_f("pipe-%s-tiling-yf",
> > + kmstest_pipe_name(pipe))
> > + test_plane_position(data, pipe,
> > LOCAL_I915_FORMAT_MOD_Yf_TILED);
> > +}
> These tests require some changes to run succesfully on gen < 9.
>
> from kms_flip_tiling.c it seems that
>
> Y and Yf tiling requires gen >= 9, else tests fail with -EINVAL in
> addfb.
Ah, right. I'll fix this.
>
> If fixed:
>
> Reviewed-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Thanks for the review!
--
Mika Kahola - Intel OTC
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-01-12 10:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-30 12:47 [PATCH i-g-t v4] tests/kms_plane_lowres: Plane visibility after atomic modesets Mika Kahola
2017-01-12 10:00 ` Maarten Lankhorst
2017-01-12 10:07 ` Mika Kahola
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).