[igt-dev] [PATCH i-g-t v2 1/5] i915/gem_exec_bad_domains.c: Replace with gem_exec_reloc at negative

Dominik Grzegorzek dominik.grzegorzek at intel.com
Fri Jul 10 12:19:17 UTC 2020


Replace gem_exec_bad_domains with negative test in gem_exec_reloc.

Signed-off-by: Dominik Grzegorzek <dominik.grzegorzek at intel.com>
Cc: Chris Wilson <chris at chris-wilson.co.uk>
Cc: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
---
 tests/Makefile.sources            |   3 -
 tests/i915/gem_exec_bad_domains.c | 230 ------------------------------
 tests/i915/gem_exec_reloc.c       |  62 ++++++++
 tests/meson.build                 |   1 -
 4 files changed, 62 insertions(+), 234 deletions(-)
 delete mode 100644 tests/i915/gem_exec_bad_domains.c

diff --git a/tests/Makefile.sources b/tests/Makefile.sources
index 3b897bc5..d810b781 100644
--- a/tests/Makefile.sources
+++ b/tests/Makefile.sources
@@ -215,9 +215,6 @@ gem_exec_async_SOURCES = i915/gem_exec_async.c
 TESTS_progs += gem_exec_await
 gem_exec_await_SOURCES = i915/gem_exec_await.c
 
-TESTS_progs += gem_exec_bad_domains
-gem_exec_bad_domains_SOURCES = i915/gem_exec_bad_domains.c
-
 TESTS_progs += gem_exec_balancer
 gem_exec_balancer_SOURCES = i915/gem_exec_balancer.c
 
diff --git a/tests/i915/gem_exec_bad_domains.c b/tests/i915/gem_exec_bad_domains.c
deleted file mode 100644
index 733964f4..00000000
--- a/tests/i915/gem_exec_bad_domains.c
+++ /dev/null
@@ -1,230 +0,0 @@
-/*
- * Copyright © 2011 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:
- *    Daniel Vetter <daniel.vetter at ffwll.ch>
- *
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <fcntl.h>
-#include <inttypes.h>
-#include <errno.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-
-#include "drm.h"
-#include "i915/gem.h"
-#include "igt.h"
-#include "intel_bufmgr.h"
-
-/* Testcase: Test whether the kernel rejects relocations with non-gpu domains
- *
- * If it does not, it'll oops somewhen later on because we don't expect that.
- */
-
-IGT_TEST_DESCRIPTION("Test whether the kernel rejects relocations with non-gpu"
-		     " domains.");
-
-static drm_intel_bufmgr *bufmgr;
-struct intel_batchbuffer *batch;
-
-#define BAD_GTT_DEST ((512*1024*1024)) /* past end of aperture */
-
-static int
-run_batch(void)
-{
-	unsigned int used = batch->ptr - batch->buffer;
-	int ret;
-
-	if (used == 0)
-		return 0;
-
-	/* Round batchbuffer usage to 2 DWORDs. */
-	if ((used & 4) == 0) {
-		*(uint32_t *) (batch->ptr) = 0; /* noop */
-		batch->ptr += 4;
-	}
-
-	/* Mark the end of the buffer. */
-	*(uint32_t *)(batch->ptr) = MI_BATCH_BUFFER_END; /* noop */
-	batch->ptr += 4;
-	used = batch->ptr - batch->buffer;
-
-	ret = drm_intel_bo_subdata(batch->bo, 0, used, batch->buffer);
-	igt_assert_eq(ret, 0);
-
-	batch->ptr = NULL;
-
-	ret = drm_intel_bo_mrb_exec(batch->bo, used, NULL, 0, 0, 0);
-
-	intel_batchbuffer_reset(batch);
-
-	return ret;
-}
-
-#define I915_GEM_GPU_DOMAINS \
-	(I915_GEM_DOMAIN_RENDER | \
-	 I915_GEM_DOMAIN_SAMPLER | \
-	 I915_GEM_DOMAIN_COMMAND | \
-	 I915_GEM_DOMAIN_INSTRUCTION | \
-	 I915_GEM_DOMAIN_VERTEX)
-
-static void multi_write_domain(int fd)
-{
-	struct drm_i915_gem_execbuffer2 execbuf;
-	struct drm_i915_gem_exec_object2 exec[2];
-	struct drm_i915_gem_relocation_entry reloc[1];
-	uint32_t handle, handle_target;
-
-	handle = gem_create(fd, 4096);
-	handle_target = gem_create(fd, 4096);
-
-	exec[0].handle = handle_target;
-	exec[0].relocation_count = 0;
-	exec[0].relocs_ptr = 0;
-	exec[0].alignment = 0;
-	exec[0].offset = 0;
-	exec[0].flags = 0;
-	exec[0].rsvd1 = 0;
-	exec[0].rsvd2 = 0;
-
-	exec[1].handle = handle;
-	exec[1].relocation_count = 1;
-	exec[1].relocs_ptr = to_user_pointer(reloc);
-	exec[1].alignment = 0;
-	exec[1].offset = 0;
-	exec[1].flags = 0;
-	exec[1].rsvd1 = 0;
-	exec[1].rsvd2 = 0;
-
-	reloc[0].offset = 4;
-	reloc[0].delta = 0;
-	reloc[0].target_handle = handle_target;
-	reloc[0].read_domains = I915_GEM_DOMAIN_RENDER | I915_GEM_DOMAIN_INSTRUCTION;
-	reloc[0].write_domain = I915_GEM_DOMAIN_RENDER | I915_GEM_DOMAIN_INSTRUCTION;
-	reloc[0].presumed_offset = 0;
-
-	execbuf.buffers_ptr = to_user_pointer(exec);
-	execbuf.buffer_count = 2;
-	execbuf.batch_start_offset = 0;
-	execbuf.batch_len = 8;
-	execbuf.cliprects_ptr = 0;
-	execbuf.num_cliprects = 0;
-	execbuf.DR1 = 0;
-	execbuf.DR4 = 0;
-	execbuf.flags = 0;
-	i915_execbuffer2_set_context_id(execbuf, 0);
-	execbuf.rsvd2 = 0;
-
-	igt_assert_eq(__gem_execbuf(fd, &execbuf), -EINVAL);
-
-	gem_close(fd, handle);
-	gem_close(fd, handle_target);
-}
-
-int fd;
-drm_intel_bo *tmp;
-
-igt_main
-{
-	igt_fixture {
-		fd = drm_open_driver(DRIVER_INTEL);
-		igt_require_gem(fd);
-
-		bufmgr = drm_intel_bufmgr_gem_init(fd, 4096);
-		drm_intel_bufmgr_gem_enable_reuse(bufmgr);
-		batch = intel_batchbuffer_alloc(bufmgr, intel_get_drm_devid(fd));
-
-		tmp = drm_intel_bo_alloc(bufmgr, "tmp", 128 * 128, 4096);
-	}
-
-	igt_subtest("cpu-domain") {
-		BEGIN_BATCH(2, 1);
-		OUT_BATCH(0);
-		OUT_RELOC(tmp, I915_GEM_DOMAIN_CPU, 0, 0);
-		ADVANCE_BATCH();
-		igt_assert(run_batch() == -EINVAL);
-
-		BEGIN_BATCH(2, 1);
-		OUT_BATCH(0);
-		OUT_RELOC(tmp, I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU, 0);
-		ADVANCE_BATCH();
-		igt_assert(run_batch() == -EINVAL);
-	}
-
-	igt_subtest("gtt-domain") {
-		BEGIN_BATCH(2, 1);
-		OUT_BATCH(0);
-		OUT_RELOC(tmp, I915_GEM_DOMAIN_GTT, 0, 0);
-		ADVANCE_BATCH();
-		igt_assert(run_batch() == -EINVAL);
-
-		BEGIN_BATCH(2, 1);
-		OUT_BATCH(0);
-		OUT_RELOC(tmp, I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT, 0);
-		ADVANCE_BATCH();
-		igt_assert(run_batch() == -EINVAL);
-	}
-
-	/* Note: Older kernels disallow this. Punt on the skip check though
-	 * since this is too old. */
-	igt_subtest("conflicting-write-domain") {
-		BEGIN_BATCH(4, 2);
-		OUT_BATCH(0);
-		OUT_RELOC(tmp, I915_GEM_DOMAIN_RENDER,
-			  I915_GEM_DOMAIN_RENDER, 0);
-		OUT_BATCH(0);
-		OUT_RELOC(tmp, I915_GEM_DOMAIN_INSTRUCTION,
-			  I915_GEM_DOMAIN_INSTRUCTION, 0);
-		ADVANCE_BATCH();
-		igt_assert(run_batch() == 0);
-	}
-
-	igt_subtest("double-write-domain")
-		multi_write_domain(fd);
-
-	igt_subtest("invalid-gpu-domain") {
-		BEGIN_BATCH(2, 1);
-		OUT_BATCH(0);
-		OUT_RELOC(tmp, ~(I915_GEM_GPU_DOMAINS | I915_GEM_DOMAIN_GTT | I915_GEM_DOMAIN_CPU),
-			  0, 0);
-		ADVANCE_BATCH();
-		igt_assert(run_batch() == -EINVAL);
-
-		BEGIN_BATCH(2, 1);
-		OUT_BATCH(0);
-		OUT_RELOC(tmp, I915_GEM_DOMAIN_GTT << 1,
-			  I915_GEM_DOMAIN_GTT << 1, 0);
-		ADVANCE_BATCH();
-		igt_assert(run_batch() == -EINVAL);
-	}
-
-	igt_fixture {
-		intel_batchbuffer_free(batch);
-		drm_intel_bufmgr_destroy(bufmgr);
-
-		close(fd);
-	}
-}
diff --git a/tests/i915/gem_exec_reloc.c b/tests/i915/gem_exec_reloc.c
index 2d416407..5e740f3e 100644
--- a/tests/i915/gem_exec_reloc.c
+++ b/tests/i915/gem_exec_reloc.c
@@ -1280,6 +1280,65 @@ static void concurrent(int i915, int num_common)
 	igt_assert_eq(result, 0);
 }
 
+#define I915_GEM_GPU_DOMAINS \
+	(I915_GEM_DOMAIN_RENDER | \
+	 I915_GEM_DOMAIN_SAMPLER | \
+	 I915_GEM_DOMAIN_COMMAND | \
+	 I915_GEM_DOMAIN_INSTRUCTION | \
+	 I915_GEM_DOMAIN_VERTEX)
+
+static void negative(int fd)
+{
+	struct drm_i915_gem_execbuffer2 execbuf;
+	struct drm_i915_gem_exec_object2 obj[2];
+	struct drm_i915_gem_relocation_entry reloc[1];
+	uint32_t handle, handle_target, i;
+	uint32_t bbe = MI_BATCH_BUFFER_END;
+	struct bad_domain {
+		uint32_t read_domains;
+		uint32_t write_domains;
+		uint32_t expected;
+	} bd[] = {
+		{I915_GEM_DOMAIN_CPU, 0, -EINVAL},
+		{I915_GEM_DOMAIN_CPU, I915_GEM_DOMAIN_CPU, -EINVAL},
+		{I915_GEM_DOMAIN_GTT, 0, -EINVAL},
+		{I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT, -EINVAL},
+		{I915_GEM_DOMAIN_RENDER | I915_GEM_DOMAIN_INSTRUCTION,
+		 I915_GEM_DOMAIN_RENDER | I915_GEM_DOMAIN_INSTRUCTION, -EINVAL},
+		{~(I915_GEM_GPU_DOMAINS | I915_GEM_DOMAIN_GTT | I915_GEM_DOMAIN_CPU),
+		 0, -EINVAL},
+		{I915_GEM_DOMAIN_GTT << 1, I915_GEM_DOMAIN_GTT << 1, -EINVAL},
+	};
+
+	handle = gem_create(fd, 4096);
+	handle_target = gem_create(fd, 4096);
+
+	memset(obj, 0, sizeof(obj));
+	obj[0].handle = handle_target;
+	obj[1].handle = handle;
+	obj[1].relocation_count = 1;
+	obj[1].relocs_ptr = to_user_pointer(reloc);
+	gem_write(fd, obj[1].handle, 0, &bbe, sizeof(bbe));
+
+	memset(reloc, 0, sizeof(reloc));
+	reloc[0].offset = 4;
+	reloc[0].target_handle = handle_target;
+
+	memset(&execbuf, 0, sizeof(execbuf));
+	execbuf.buffers_ptr = to_user_pointer(obj);
+	execbuf.buffer_count = 2;
+
+	for (i = 0; i < ARRAY_SIZE(bd); i++) {
+		reloc[0].read_domains = bd[i].read_domains;
+		reloc[0].write_domain = bd[i].write_domains;
+		igt_assert_eq(__gem_execbuf(fd, &execbuf), bd[i].expected);
+	}
+
+	gem_close(fd, handle);
+	gem_close(fd, handle_target);
+}
+
+
 igt_main
 {
 	const struct intel_execution_engine2 *e;
@@ -1431,6 +1490,9 @@ igt_main
 	igt_subtest("basic-concurrent16")
 		concurrent(fd, 16);
 
+	igt_subtest("negative")
+		negative(fd);
+
 	igt_fixture
 		close(fd);
 }
diff --git a/tests/meson.build b/tests/meson.build
index 172d18e5..b526c906 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -136,7 +136,6 @@ i915_progs = [
 	'gem_exec_alignment',
 	'gem_exec_async',
 	'gem_exec_await',
-	'gem_exec_bad_domains',
 	'gem_exec_basic',
 	'gem_exec_big',
 	'gem_exec_capture',
-- 
2.20.1



More information about the igt-dev mailing list