[igt-dev] [PATCH i-g-t v3 2/3] tests/i915/gem_mmap: Add invalid parameters tests

Antonio Argenziano antonio.argenziano at intel.com
Thu Mar 14 20:21:32 UTC 2019


Add a couple of tests that supply invalid parameters to the mmap IOCTL.

v2:
	- Expand test space. (Chris)

v3:
	- Add local IOCTL wrapper. (Chris)

Signed-off-by: Antonio Argenziano <antonio.argenziano at intel.com>
Cc: Daniel Vetter <daniel.vetter at ffwll.ch>
Cc: Chris Wilson <chris at chris-wilson.co.uk>
---
 tests/i915/gem_mmap.c | 79 +++++++++++++++++++++++++++++++++++++++----
 1 file changed, 73 insertions(+), 6 deletions(-)

diff --git a/tests/i915/gem_mmap.c b/tests/i915/gem_mmap.c
index 0ed15878..636a9ba3 100644
--- a/tests/i915/gem_mmap.c
+++ b/tests/i915/gem_mmap.c
@@ -116,6 +116,23 @@ test_huge_bo(int huge)
 	free(cpu_pattern);
 }
 
+static int
+err_gem_mmap(int i915, uint32_t handle, uint64_t size, uint64_t offset)
+{
+	struct drm_i915_gem_mmap arg = {
+				.handle = handle,
+				.size = size,
+				.offset = offset
+	};
+	int err = 0;
+
+	if(ioctl(i915, DRM_IOCTL_I915_GEM_MMAP, &arg))
+		err = -errno;
+
+	errno = 0;
+	return err;
+}
+
 igt_main
 {
 	struct drm_i915_gem_mmap arg;
@@ -128,12 +145,62 @@ igt_main
 		fd = drm_open_driver(DRIVER_INTEL);
 
 	igt_subtest("bad-object") {
-		memset(&arg, 0, sizeof(arg));
-		arg.handle = 0x10101010;
-		arg.offset = 0;
-		arg.size = 4096;
-		ret = ioctl(fd, DRM_IOCTL_I915_GEM_MMAP, &arg);
-		igt_assert(ret == -1 && errno == ENOENT);
+		uint32_t real_handle = gem_create(fd, 4096);
+		uint32_t handles[20];
+		int i = 0;
+
+		handles[i++] = 0xdeadbeef;
+		for(int bit = 0; bit < 16; bit++)
+			handles[i++] = real_handle | (1 << (bit + 16));
+		handles[i] = real_handle + 1;
+
+		for (; i < 0; i--) {
+			igt_debug("Trying mmap a bad object. Handle %x\n", handles[i]);
+			ret = err_gem_mmap(fd, handles[i], 4096, 0);
+			igt_assert_eq(ret, -EINVAL);
+		}
+	}
+
+	igt_subtest("bad-offset") {
+		struct bad_offset {
+			uint64_t size;
+			uint64_t offset;
+		} bad_offsets[] = {
+				{4096, 4096 + 1},
+				{4096, -4096},
+				{ 2 * 4096, -4096},
+				{ 4096, ~0},
+		};
+		uint32_t handle = gem_create(fd, 4096);
+
+		for (int i = 0; i < ARRAY_SIZE(bad_offsets); i++) {
+			igt_debug("Trying to mmap bad offset; size: %lu, offset: %lu\n",
+					bad_offsets[i].size, bad_offsets[i].offset);
+			ret = err_gem_mmap(fd, handle,
+							bad_offsets[i].size, bad_offsets[i].offset);
+			igt_assert_eq(ret, -EINVAL);
+		}
+	}
+
+	igt_subtest("bad-size") {
+		uint64_t bad_size[] = {
+			0,
+			-4096,
+			4096 + 1,
+			2 * 4096,
+			~0,
+		};
+		uint32_t handle = gem_create(fd, 4096);
+		uint64_t offset;
+
+		for (int i = 0; i < ARRAY_SIZE(bad_size); i++) {
+			//offset = (bad_size[i] - 1) % bad_size[i];
+
+			igt_debug("Trying to mmap bad size; size: %lu, offset %lu\n",
+					bad_size[i], offset);
+			ret = err_gem_mmap(fd, handle, bad_size[i], offset);
+			igt_assert_eq(ret, -EINVAL);
+		}
 	}
 
 	igt_subtest("basic") {
-- 
2.20.1



More information about the igt-dev mailing list