[i-g-t] kms_crash: Check that KMS client crashes are properly handled
diff mbox

Message ID 1443106806-15706-1-git-send-email-tvrtko.ursulin@linux.intel.com
State New
Headers show

Commit Message

Tvrtko Ursulin Sept. 24, 2015, 3 p.m. UTC
From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

Check that frame buffers are torn down when a client dies.

Later could be extended with a CRC based test to check whether a later
client can inherit a plane left from an earlier one. There could be
some interesting data or images on that plane.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
 tests/.gitignore       |   1 +
 tests/Makefile.sources |   1 +
 tests/kms_crash.c      | 146 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 148 insertions(+)
 create mode 100644 tests/kms_crash.c

Patch
diff mbox

diff --git a/tests/.gitignore b/tests/.gitignore
index dc8bb539a754..a7dc10713b42 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -125,6 +125,7 @@  gen3_render_tiledy_blits
 gen7_forcewake_mt
 kms_3d
 kms_addfb_basic
+kms_crash
 kms_crtc_background_color
 kms_cursor_crc
 kms_draw_crc
diff --git a/tests/Makefile.sources b/tests/Makefile.sources
index 2e2e088a3aa1..8a2119d3df8f 100644
--- a/tests/Makefile.sources
+++ b/tests/Makefile.sources
@@ -63,6 +63,7 @@  TESTS_progs_M = \
 	gem_userptr_blits \
 	gem_write_read_ring_switch \
 	kms_addfb_basic \
+	kms_crash \
 	kms_cursor_crc \
 	kms_draw_crc \
 	kms_fbc_crc \
diff --git a/tests/kms_crash.c b/tests/kms_crash.c
new file mode 100644
index 000000000000..121bad121922
--- /dev/null
+++ b/tests/kms_crash.c
@@ -0,0 +1,146 @@ 
+/*
+ * Copyright © 2015 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.
+ *
+ * Authors:
+ *   Tvrtko Ursulin <tvrtko.ursulin@intel.com>
+ */
+
+#include "igt.h"
+#include <errno.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+
+
+IGT_TEST_DESCRIPTION("Test that crash of KMS clients is handled properly");
+
+typedef struct {
+	int drm_fd;
+	igt_display_t display;
+	int gen;
+} data_t;
+
+static void
+fill_fb(struct igt_fb *fb, data_t *data, drmModeModeInfo *mode)
+{
+	cairo_t *cr;
+
+	cr = igt_get_cairo_ctx(data->drm_fd, fb);
+	igt_paint_test_pattern(cr, mode->hdisplay, mode->vdisplay);
+	cairo_destroy(cr);
+}
+
+static int count_framebuffers(void)
+{
+	FILE *fh;
+	int cnt = 0;
+	size_t n = 0;
+	char *line = NULL;
+
+	fh = igt_debugfs_fopen("i915_gem_framebuffer", O_RDONLY);
+	igt_assert(fh);
+
+	while (getline(&line, &n, fh) >= 0)
+		cnt++;
+
+	free(line)
+	fclose(fh);
+
+	return cnt;
+}
+
+static void
+crash_child(data_t *data)
+{
+	drmModeModeInfo *mode;
+	igt_output_t *output = NULL;
+	igt_plane_t *primary, *secondary;
+	struct igt_fb fb[2];
+	int fb_id, pipe;
+
+	data->drm_fd = drm_open_driver_master(DRIVER_INTEL);
+	igt_assert(data->drm_fd >= 0);
+	data->gen = intel_gen(intel_get_drm_devid(data->drm_fd));
+
+	igt_display_init(&data->display, data->drm_fd);
+
+	for_each_connected_output(&data->display, output)
+		break;
+	igt_require(output);
+
+	pipe = output->config.pipe;
+	igt_output_set_pipe(output, pipe);
+
+	mode = igt_output_get_mode(output);
+	primary = igt_output_get_plane(output, 0);
+	secondary = igt_output_get_plane(output, 1);
+	igt_assert(primary);
+	igt_require(secondary);
+
+	fb_id = igt_create_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
+			      DRM_FORMAT_XRGB8888, LOCAL_DRM_FORMAT_MOD_NONE,
+			      &fb[0]);
+	igt_assert(fb_id);
+
+	fb_id = igt_create_fb(data->drm_fd, mode->hdisplay, mode->vdisplay,
+			      DRM_FORMAT_XRGB8888, LOCAL_DRM_FORMAT_MOD_NONE,
+			      &fb[1]);
+	igt_assert(fb_id);
+
+	fill_fb(&fb[0], data, mode);
+	fill_fb(&fb[1], data, mode);
+
+	igt_plane_set_fb(primary, &fb[0]);
+	igt_plane_set_fb(secodary, &fb[1]);
+	igt_display_commit(&data->display);
+
+	_exit(0);
+}
+
+static data_t data;
+
+igt_main
+{
+	igt_skip_on_simulation();
+
+	igt_fixture {
+		kmstest_set_vt_graphics_mode();
+	}
+
+	igt_subtest_f("crash-test") {
+		int fb_start, fb_end;
+
+		fb_start = count_framebuffers();
+
+		igt_fork(child, 1) {
+			crash_child(&data);
+		}
+		igt_waitchildren();
+
+		fb_end = count_framebuffers();
+		igt_assert_eq(fb_start, fb_end);
+	}
+
+	igt_fixture {
+		igt_display_fini(&data.display);
+	}
+}