[igt-dev] [PATCH i-g-t 4/4] tests: Add VC4 load tracker tests

Paul Kocialkowski
2019-01-08T15:02:42Z

This introduces tests for the VC4 load tracking mechanism, with two
flavors. One checks that the load limitation is reached after adding
"as many planes as possible" in the mode resolution. The other checks
the consistency between the underrun indication and load tracking
indication while doing that.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
---
tests/Makefile.sources | 1 +
tests/meson.build | 1 +
tests/vc4_load_tracker.c | 249 +++++++++++++++++++++++++++++++++++++++
3 files changed, 251 insertions(+)
create mode 100644 tests/vc4_load_tracker.c

diff --git a/tests/Makefile.sources b/tests/Makefile.sources
index eedde1e817cb..5ea4f940129e 100644
--- a/tests/Makefile.sources
+++ b/tests/Makefile.sources
@@ -8,6 +8,7 @@ VC4_TESTS = \
vc4_create_bo \
vc4_dmabuf_poll \
vc4_lookup_fail \
+ vc4_load_tracker \
vc4_label_bo \
vc4_purgeable_bo \
vc4_tiling \
diff --git a/tests/meson.build b/tests/meson.build
index b8a6e61b3404..f6c71ff97574 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -85,6 +85,7 @@ test_progs = [
'vc4_create_bo',
'vc4_dmabuf_poll',
'vc4_label_bo',
+ 'vc4_load_tracker',
'vc4_lookup_fail',
'vc4_purgeable_bo',
'vc4_tiling',
diff --git a/tests/vc4_load_tracker.c b/tests/vc4_load_tracker.c
new file mode 100644
index 000000000000..10301a1ecde3
--- /dev/null
+++ b/tests/vc4_load_tracker.c
@@ -0,0 +1,249 @@
+/*
+ * Copyright © 2018 Bootlin
+ * Copyright © 2018 Broadcom
+ *
+ * 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 "igt_vc4.h"
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <inttypes.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <poll.h>
+#include "vc4_drm.h"
+
+static igt_output_t *select_output(igt_display_t *display)
+{
+ igt_output_t *output;
+ enum pipe pipe;
+
+ for_each_pipe(display, pipe) {
+ for_each_valid_output_on_pipe(display, pipe, output) {
+ drmModeConnector *connector = output->config.connector;
+
+ if (connector->connection != DRM_MODE_CONNECTED)
+ continue;
+
+ igt_output_set_pipe(output, pipe);
+
+ return output;
+ }
+ }
+
+ return NULL;
+}
+
+static void setup_primary_plane(int drm_fd, igt_output_t *output,
+ uint32_t width, uint32_t height,
+ igt_plane_t **plane, struct igt_fb *fb)
+{
+ unsigned int fb_id;
+
+ *plane = igt_output_get_plane_type(output, DRM_PLANE_TYPE_PRIMARY);
+ igt_assert(*plane);
+
+ fb_id = igt_create_pattern_fb(drm_fd, width, height,
+ DRM_FORMAT_ARGB8888,
+ LOCAL_DRM_FORMAT_MOD_NONE, fb);
+ igt_assert(fb_id > 0);
+
+ igt_plane_set_fb(*plane, fb);
+}
+
+static void setup_overlay_plane(int drm_fd, igt_output_t *output,
+ unsigned int index, uint32_t width,
+ uint32_t height, struct igt_fb *fbs)
+{
+ unsigned int fb_id;
+ struct igt_fb *fb = &fbs[index];
+ igt_plane_t *plane =
+ igt_output_get_plane_type_index(output, DRM_PLANE_TYPE_OVERLAY,
+ index);
+ igt_assert(plane);
+
+ fb_id = igt_create_pattern_fb(drm_fd, width, height,
+ DRM_FORMAT_ARGB8888,
+ LOCAL_DRM_FORMAT_MOD_NONE, fb);
+ igt_assert(fb_id > 0);
+
+ igt_plane_set_fb(plane, fb);
+ igt_plane_set_position(plane, 10 * (index + 1), 10 * (index + 1));
+}
+
+static void cleanup_overlay_plane(int drm_fd, igt_output_t *output,
+ unsigned int index, struct igt_fb *fbs,
+ bool cleanup_fb)
+{
+ struct igt_fb *fb = &fbs[index];
+ igt_plane_t *plane =
+ igt_output_get_plane_type_index(output, DRM_PLANE_TYPE_OVERLAY,
+ index);
+ igt_assert(plane);
+
+ if (cleanup_fb)
+ igt_remove_fb(drm_fd, fb);
+ else
+ igt_plane_set_fb(plane, NULL);
+}
+
+static void load_tracker_test(int drm_fd, igt_display_t *display,
+ bool test_consistency)
+{
+ igt_output_t *output;
+ drmModeModeInfo *mode;
+ struct igt_fb primary_fb;
+ igt_plane_t *primary_plane;
+ struct igt_fb *overlay_fbs;
+ uint32_t overlay_width, overlay_height;
+ unsigned int overlay_planes_count;
+ unsigned int count;
+ unsigned int index;
+ bool load_tracker_initial = false;
+ bool bandwidth_exceeded = false;
+ bool underrun_detected = false;
+ int underrun_count;
+ int debugfs;
+ int ret;
+
+ debugfs = igt_debugfs_dir(drm_fd);
+ igt_assert(debugfs >= 0);
+
+ underrun_count = igt_vc4_get_underrun_count(debugfs);
+ load_tracker_initial = igt_vc4_get_load_tracker(debugfs);
+
+ output = select_output(display);
+ igt_assert(output);
+
+ igt_debug("Selected connector %s\n",
+ kmstest_connector_type_str(output->config.connector->connector_type));
+
+ mode = igt_output_get_mode(output);
+ igt_assert(mode);
+
+ setup_primary_plane(drm_fd, output, mode->hdisplay, mode->vdisplay,
+ &primary_plane, &primary_fb);
+
+ overlay_planes_count =
+ igt_output_count_plane_type(output, DRM_PLANE_TYPE_OVERLAY);
+
+ overlay_fbs = calloc(sizeof(struct igt_fb), overlay_planes_count);
+
+ overlay_width = mode->hdisplay;
+ overlay_height = mode->vdisplay;
+
+ for (count = 1; count <= overlay_planes_count; count++) {
+ int underrun_update;
+
+ igt_debug("Using %d overlay planes with resolution %dx%d\n",
+ overlay_planes_count, overlay_width, overlay_height);
+
+ for (index = 0; index < count; index++)
+ setup_overlay_plane(drm_fd, output, index,
+ overlay_width, overlay_height,
+ overlay_fbs);
+
+ igt_vc4_set_load_tracker(debugfs, true);
+
+ ret = igt_display_try_commit2(display, COMMIT_ATOMIC);
+ bandwidth_exceeded = (ret < 0 && errno == ENOSPC);
+
+ igt_debug("Bandwidth limitation exeeded: %s\n",
+ bandwidth_exceeded ? "Yes" : "No");
+
+ igt_vc4_set_load_tracker(debugfs, false);
+
+ igt_display_commit2(display, COMMIT_ATOMIC);
+
+ igt_wait_for_vblank(drm_fd, output->pending_pipe);
+
+ underrun_update = igt_vc4_get_underrun_count(debugfs);
+
+ underrun_detected = (underrun_update > underrun_count);
+ underrun_count = underrun_update;
+
+ igt_debug("Underrun detected: %s\n",
+ underrun_detected ? "Yes" : "No");
+
+ if (test_consistency)
+ igt_assert(bandwidth_exceeded == underrun_detected);
+
+ for (index = 0; index < count; index++)
+ cleanup_overlay_plane(drm_fd, output, index,
+ overlay_fbs, false);
+
+ igt_display_commit2(display, COMMIT_ATOMIC);
+
+ for (index = 0; index < count; index++)
+ cleanup_overlay_plane(drm_fd, output, index,
+ overlay_fbs, true);
+
+
+ if (bandwidth_exceeded)
+ break;
+ }
+
+ if (!test_consistency)
+ igt_assert(bandwidth_exceeded);
+
+ free(overlay_fbs);
+
+ igt_plane_set_fb(primary_plane, NULL);
+
+ igt_display_commit2(display, COMMIT_ATOMIC);
+
+ igt_remove_fb(drm_fd, &primary_fb);
+
+ igt_vc4_set_load_tracker(debugfs, load_tracker_initial);
+ close(debugfs);
+}
+
+igt_main
+{
+ igt_display_t display;
+ int drm_fd;
+
+ igt_fixture {
+ drm_fd = drm_open_driver(DRIVER_VC4);
+
+ kmstest_set_vt_graphics_mode();
+
+ igt_display_require(&display, drm_fd);
+ igt_require(display.is_atomic);
+ }
+
+ igt_subtest("detection")
+ load_tracker_test(drm_fd, &display, false);
+
+ igt_subtest("consistency")
+ load_tracker_test(drm_fd, &display, true);
+
+ igt_fixture {
+ igt_display_fini(&display);
+ kmstest_restore_vt_mode();
+ close(drm_fd);
+ }