[igt-dev] [PATCH i-g-t v2 3/3] tests/i915/gem_mmap_wc: Add invalid params tests

Antonio Argenziano antonio.argenziano at intel.com
Wed Mar 13 23:27:21 UTC 2019


Add some invalid parameters tests for the MMAP IOCTL when the MMAP_WC
flag is supplied.

v2:
	- Expand test space. (Chris)

Signed-off-by: Antonio Argenziano <antonio.argenziano at intel.com>
---
 tests/i915/gem_mmap_wc.c | 90 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)

diff --git a/tests/i915/gem_mmap_wc.c b/tests/i915/gem_mmap_wc.c
index baa68aa8..ba05bb50 100644
--- a/tests/i915/gem_mmap_wc.c
+++ b/tests/i915/gem_mmap_wc.c
@@ -463,6 +463,96 @@ igt_main
 		gem_require_mmap_wc(fd);
 	}
 
+	igt_subtest_group {
+
+		igt_subtest("bad-object") {
+			int ret;
+			struct drm_i915_gem_mmap arg;
+			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--) {
+
+				memset(&arg, 0, sizeof(arg));
+				arg.handle = handles[i];
+				arg.offset = 0;
+				arg.size = 4096;
+				arg.flags = I915_MMAP_WC;
+
+				errno = 0;
+
+				ret = ioctl(fd, DRM_IOCTL_I915_GEM_MMAP, &arg);
+				igt_assert_eq(errno, EINVAL);
+				igt_assert_eq(ret, -1);
+			}
+		}
+
+		igt_subtest("bad-offset") {
+			int ret;
+			struct drm_i915_gem_mmap arg;
+			struct bad_offset {
+				uint64_t size;
+				uint64_t offset;
+			} bad_offsets[] = {
+				{4096, 4096 + 1},
+				{4096, -4096},
+				{ 2 * 4096, -4096},
+				{ 4096, ~0},
+				{}
+			};
+
+			for (int i = 0; i < ARRAY_SIZE(bad_offsets); i++) {
+
+				memset(&arg, 0, sizeof(arg));
+				arg.handle = gem_create(fd, 4096);
+
+				arg.offset = bad_offsets[i].offset;
+				arg.size = bad_offsets[i].size;
+
+				arg.flags = I915_MMAP_WC;
+
+				errno = 0;
+				ret = ioctl(fd, DRM_IOCTL_I915_GEM_MMAP, &arg);
+
+				igt_assert_eq(errno, EINVAL);
+				igt_assert_eq(ret, -1);
+			}
+		}
+
+		igt_subtest("bad-size") {
+			int ret;
+			struct drm_i915_gem_mmap arg;
+			uint64_t bad_size[] = {
+				0,
+				-4096,
+				4096 + 1,
+				2 * 4096,
+				~0,
+			};
+
+			for (int i = 0; i < ARRAY_SIZE(bad_size); i++) {
+
+				memset(&arg, 0, sizeof(arg));
+				arg.handle = gem_create(fd, 4096);
+				arg.offset = 4096;
+				arg.size = bad_size[i];
+				arg.flags = I915_MMAP_WC;
+
+				errno = 0;
+
+				ret = ioctl(fd, DRM_IOCTL_I915_GEM_MMAP, &arg);
+				igt_assert_eq(errno, EINVAL);
+				igt_assert_eq(ret, -1);
+			}
+		}
+	}
+
 	igt_subtest("invalid-flags")
 		test_invalid_flags(fd);
 	igt_subtest("close")
-- 
2.20.1



More information about the igt-dev mailing list