All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Zbigniew Kempczyński" <zbigniew.kempczynski@intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t v5 4/4] tests/i915/gem_mmap_offset: Add new API test for gem_mmap_offset
Date: Fri, 22 Nov 2019 09:13:57 +0100	[thread overview]
Message-ID: <20191122081357.20401-5-zbigniew.kempczynski@intel.com> (raw)
In-Reply-To: <20191122081357.20401-1-zbigniew.kempczynski@intel.com>

From: Lukasz Kalamarz <lukasz.kalamarz@intel.com>

Few simple tests which tries to create / mmap buffer objects
in system / device memory regions.

Signed-off-by: Lukasz Kalamarz <lukasz.kalamarz@intel.com>
Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Vanshidhar Konda <vanshidhar.r.konda@intel.com>
---
 tests/Makefile.sources       |   3 +
 tests/i915/gem_mmap_offset.c | 163 +++++++++++++++++++++++++++++++++++
 tests/meson.build            |   1 +
 3 files changed, 167 insertions(+)
 create mode 100644 tests/i915/gem_mmap_offset.c

diff --git a/tests/Makefile.sources b/tests/Makefile.sources
index 27801c89..9c6c3933 100644
--- a/tests/Makefile.sources
+++ b/tests/Makefile.sources
@@ -320,6 +320,9 @@ gem_mmap_SOURCES = i915/gem_mmap.c
 TESTS_progs += gem_mmap_gtt
 gem_mmap_gtt_SOURCES = i915/gem_mmap_gtt.c
 
+TESTS_progs += gem_mmap_offset
+gem_mmap_offset_SOURCES = i915/gem_mmap_offset.c
+
 TESTS_progs += gem_mmap_offset_exhaustion
 gem_mmap_offset_exhaustion_SOURCES = i915/gem_mmap_offset_exhaustion.c
 
diff --git a/tests/i915/gem_mmap_offset.c b/tests/i915/gem_mmap_offset.c
new file mode 100644
index 00000000..a4432f93
--- /dev/null
+++ b/tests/i915/gem_mmap_offset.c
@@ -0,0 +1,163 @@
+/*
+ * Copyright © 2019 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.
+ */
+
+#include "igt.h"
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include "drm.h"
+
+IGT_TEST_DESCRIPTION("Basic MMAP_OFFSET IOCTL tests for mem regions\n");
+
+static int mmap_offset_ioctl(int fd, struct local_i915_gem_mmap_offset *arg)
+{
+	int err = 0;
+
+	if (igt_ioctl(fd, LOCAL_IOCTL_I915_GEM_MMAP_OFFSET, arg))
+		err = -errno;
+
+	errno = 0;
+	return err;
+}
+
+static void
+mmap_offset_bad_object(int fd, struct local_i915_query_memory_region_info *regions)
+{
+	const char *region_name;
+	struct local_i915_memory_region_info *mem_region;
+	uint32_t region, obj_size, batch_size, real_handle;
+	uint32_t handles[20];
+
+	for_each_memory_region(regions, mem_region) {
+		int i = 0;
+
+		region = mem_region->id;
+		region_name = memory_region_name(region);
+		if (IS_STOLEN_MEMORY_REGION(region)) {
+			continue;
+		}
+		igt_debug("mmap-offset-bad-object: region name: %s, "
+			  "region: %08x\n", region_name, region);
+
+		batch_size = gem_get_batch_size(fd, region);
+		obj_size = 4 * batch_size;
+		real_handle = gem_create_in_memory_regions(fd, obj_size,
+							   region);
+		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--) {
+			struct local_i915_gem_mmap_offset arg = {
+				.handle = handles[i],
+				.flags = LOCAL_I915_MMAP_OFFSET_WC,
+			};
+
+			igt_debug("Trying MMAP IOCTL with handle %x\n",
+				  handles[i]);
+			igt_assert_eq(mmap_offset_ioctl(fd, &arg),
+				      -ENOENT);
+		}
+
+		gem_close(fd, real_handle);
+	}
+}
+
+static void
+mmap_offset_basic(int fd, struct local_i915_query_memory_region_info *regions)
+{
+	const char *region_name;
+	struct local_i915_memory_region_info *mem_region;
+	uint64_t flags;
+	uint32_t region, handle, obj_size;
+	uint8_t *expected, *buf, *addr;
+
+	for_each_memory_region(regions, mem_region) {
+		region = mem_region->id;
+		region_name = memory_region_name(region);
+		if (IS_STOLEN_MEMORY_REGION(region)) {
+			continue;
+		}
+		igt_debug("mmap-offset-basic: region name: %s, region: %08x\n",
+			  region_name, region);
+
+		obj_size = 4 * gem_get_batch_size(fd, region);
+		handle = gem_create_in_memory_regions(fd, obj_size,
+						      region);
+		flags = LOCAL_I915_MMAP_OFFSET_WC;
+		addr = __gem_mmap_offset(fd, handle, 0, obj_size,
+					 PROT_READ | PROT_WRITE,
+					 flags);
+		igt_assert(addr);
+
+		igt_debug("Testing contents of newly created object.\n");
+		expected = calloc(obj_size, sizeof(*expected));
+		igt_assert_eq(memcmp(addr, expected, obj_size), 0);
+		free(expected);
+
+		igt_debug("Testing coherency of writes and mmap reads.\n");
+		buf = calloc(obj_size, sizeof(*buf));
+		memset(buf + 1024, 0x01, 1024);
+		gem_write(fd, handle, 0, buf, obj_size);
+		igt_assert_eq(memcmp(buf, addr, obj_size), 0);
+
+		igt_debug("Testing that mapping stays after close\n");
+		gem_close(fd, handle);
+		igt_assert_eq(memcmp(buf, addr, obj_size), 0);
+		free(buf);
+
+		igt_debug("Testing unmapping\n");
+		munmap(addr, obj_size);
+	}
+}
+
+igt_main
+{	
+	int fd;
+	struct local_i915_query_memory_region_info *regions;
+
+	igt_fixture {
+		fd = drm_open_driver(DRIVER_INTEL);
+		gem_require_mmap_offset(fd);
+		igt_require(gem_mmap__has_wc(fd));
+
+		regions = gem_query_memory_regions(fd);
+		igt_assert(regions);
+	}
+
+	igt_describe("Verify mapping to invalid gem objects won't be created"
+		     " in different memory regions");
+	igt_subtest_f("mmap-offset-bad-object")
+		mmap_offset_bad_object(fd, regions);
+
+	igt_describe("Check buffer object mapping is coherent with "
+		     "data written by gem_write in all memory regions");
+	igt_subtest_f("mmap-offset-basic")
+		mmap_offset_basic(fd, regions);
+
+	igt_fixture {
+		free(regions);
+		close(fd);
+	}
+}
diff --git a/tests/meson.build b/tests/meson.build
index 755fc9e6..644b5504 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -174,6 +174,7 @@ i915_progs = [
 	'gem_media_vme',
 	'gem_mmap',
 	'gem_mmap_gtt',
+	'gem_mmap_offset',
 	'gem_mmap_offset_exhaustion',
 	'gem_mmap_wc',
 	'gem_partial_pwrite_pread',
-- 
2.23.0

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  parent reply	other threads:[~2019-11-22  8:14 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-22  8:13 [igt-dev] [PATCH i-g-t v5 0/4] Basic LMEM support in IGT Zbigniew Kempczyński
2019-11-22  8:13 ` [igt-dev] [PATCH i-g-t v5 1/4] include/drm-uapi/i915_drm: Add local defs for memory region uAPI Zbigniew Kempczyński
2019-11-22  8:56   ` Chris Wilson
2019-11-22  8:13 ` [igt-dev] [PATCH i-g-t v5 2/4] lib/i915/gem_mman: add mmap_offset support Zbigniew Kempczyński
2019-11-22  8:59   ` Chris Wilson
2019-11-22  9:12     ` Zbigniew Kempczyński
2019-11-22  8:13 ` [igt-dev] [PATCH i-g-t v5 3/4] lib/i915/intel_memory_region: Add lib to manage memory regions Zbigniew Kempczyński
2019-11-22  9:11   ` Chris Wilson
2019-11-22  9:33     ` Zbigniew Kempczyński
2019-11-22  9:46       ` Chris Wilson
2019-11-22 14:40         ` Zbigniew Kempczyński
2019-11-22 16:50           ` Chris Wilson
2019-11-22  8:13 ` Zbigniew Kempczyński [this message]
2019-11-22  9:16   ` [igt-dev] [PATCH i-g-t v5 4/4] tests/i915/gem_mmap_offset: Add new API test for gem_mmap_offset Chris Wilson
2019-11-22  8:54 ` [igt-dev] ✗ Fi.CI.BAT: failure for Basic LMEM support in IGT (rev5) Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191122081357.20401-5-zbigniew.kempczynski@intel.com \
    --to=zbigniew.kempczynski@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.