public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Ramalingam C <ramalingam.c@intel.com>
To: igt-dev <igt-dev@lists.freedesktop.org>
Subject: [igt-dev] [RFC 2/2] tests/dumb_duffer: extending for lmem coverage.
Date: Sat,  4 Jan 2020 15:38:26 +0530	[thread overview]
Message-ID: <20200104100826.21067-2-ramalingam.c@intel.com> (raw)
In-Reply-To: <20200104100826.21067-1-ramalingam.c@intel.com>

if lmem is available on intel platforms, dumb buffers are created out of
lmem. Hence tests are extended to cover the dumb buffers from lmem.

Signed-off-by: Ramalingam C <ramalingam.c@intel.com>
---
 tests/dumb_buffer.c | 80 ++++++++++++++++++++++++++++++---------------
 1 file changed, 54 insertions(+), 26 deletions(-)

diff --git a/tests/dumb_buffer.c b/tests/dumb_buffer.c
index 3d2dc9966d0b..9717ac7641a2 100644
--- a/tests/dumb_buffer.c
+++ b/tests/dumb_buffer.c
@@ -43,6 +43,9 @@
 #include <getopt.h>
 #include <pthread.h>
 #include <stdatomic.h>
+#include <igt_debugfs.h>
+
+#include <i915/intel_memory_region.h>
 
 #include <drm.h>
 
@@ -52,7 +55,12 @@
 
 IGT_TEST_DESCRIPTION("This is a test for the generic dumb buffer interface.");
 
-#define PAGE_SIZE 4096
+static struct dumb_buffer_data {
+	int drm_fd;
+	bool lmem;
+	_Atomic(uint64_t) max;
+	int page_size;
+} data;
 
 static int __dumb_create(int fd, struct drm_mode_create_dumb *create)
 {
@@ -212,13 +220,13 @@ static void valid_nonaligned_size(int fd)
 		.height = 24,
 		.bpp = 32,
 	};
-	char buf[PAGE_SIZE];
+	char buf[data.page_size];
 
 	igt_require(is_i915_device(fd));
 
 	dumb_create(fd, &create);
 
-	gem_write(fd, create.handle, PAGE_SIZE / 2, buf, PAGE_SIZE / 2);
+	gem_write(fd, create.handle, data.page_size / 2, buf, data.page_size / 2);
 
 	dumb_destroy(fd, create.handle);
 }
@@ -235,14 +243,15 @@ static void invalid_nonaligned_size(int fd)
 		.height = 24,
 		.bpp = 32,
 	};
-	char buf[PAGE_SIZE];
+	char buf[data.page_size];
 
 	igt_require(is_i915_device(fd));
 
 	dumb_create(fd, &create);
+
 	/* This should fail. Hence cannot use gem_write. */
 	igt_assert(__gem_write(fd, create.handle,
-			       create.size - (PAGE_SIZE / 2), buf, PAGE_SIZE));
+			       create.size - (data.page_size / 2), buf, data.page_size));
 	dumb_destroy(fd, create.handle);
 }
 
@@ -273,13 +282,15 @@ struct thread_clear {
 	int fd;
 };
 
-#define MAX_PAGE_TO_REQUEST	102400
+#define MAX_SMEM_PAGE	102400
+#define MAX_LMEM_PAGE	1024
 
-static void *thread_clear(void *data)
+static void *thread_clear(void *thread_data)
 {
-	struct thread_clear *arg = data;
+	struct thread_clear *arg = thread_data;
 	unsigned long checked = 0;
 	int fd = arg->fd;
+	int max_page = data.lmem ? MAX_LMEM_PAGE : MAX_SMEM_PAGE;
 	void *ptr;
 
 	igt_until_timeout(arg->timeout) {
@@ -293,16 +304,14 @@ static void *thread_clear(void *data)
 
 		for (uint64_t _npages = npages; npages > 0; npages -= _npages) {
 			create.bpp = 32;
-			create.width = PAGE_SIZE / (create.bpp / 8);
-			_npages = npages <= MAX_PAGE_TO_REQUEST ? npages :
-				  MAX_PAGE_TO_REQUEST;
+			create.width = data.page_size / (create.bpp / 8);
+			_npages = npages <= max_page ? npages : max_page;
 			create.height = _npages;
 
 			dumb_create(fd, &create);
-			igt_assert_eq(PAGE_SIZE * create.height, create.size);
+			igt_assert_eq(data.page_size * create.height, create.size);
 
-			ptr = dumb_map(fd,
-				       create.handle, create.size,
+			ptr = dumb_map(fd, create.handle, create.size,
 				       PROT_WRITE);
 
 			for (uint64_t page = 0; page < create.height; page++) {
@@ -330,7 +339,7 @@ static void always_clear(int fd, int timeout)
 	struct thread_clear arg = {
 		.fd = fd,
 		.timeout = timeout,
-		.max = intel_get_avail_ram_mb() << (20 - 12), /* in pages */
+		.max = data.max, /* in pages */
 	};
 	const int ncpus = sysconf(_SC_NPROCESSORS_ONLN);
 	unsigned long checked;
@@ -348,35 +357,54 @@ static void always_clear(int fd, int timeout)
 	igt_info("Checked %'lu page allocations\n", checked);
 }
 
-igt_main
+static int parse_lmem_details(void)
 {
-	int fd = -1;
+	if (gem_has_lmem(data.drm_fd)) {
+		data.lmem = true;
+		data.page_size = 65536;
+		data.max = gem_lmem_total_size(data.drm_fd);
+		igt_assert_f(data.max, "Lmem with 0Bytes\n");
+		data.max = data.max / data.page_size;
+	}
 
+	return 0;
+}
+
+igt_main
+{
 	igt_fixture {
-		fd = drm_open_driver(DRIVER_ANY);
+		data.drm_fd = drm_open_driver(DRIVER_ANY);
+		data.lmem = false;
+		data.page_size = 4096;
+		if (is_i915_device(data.drm_fd)) {
+			igt_assert(parse_lmem_details() == 0);
+			if (!data.lmem)
+				/* In pages */
+				data.max = intel_get_avail_ram_mb() << 8;
+		}
 	}
 
 	igt_subtest("invalid-bpp")
-		invalid_dimensions_test(fd);
+		invalid_dimensions_test(data.drm_fd);
 
 	igt_subtest("create-valid-dumb")
-		valid_dumb_creation_test(fd);
+		valid_dumb_creation_test(data.drm_fd);
 
 	igt_subtest("create-valid-nonaligned")
-		valid_nonaligned_size(fd);
+		valid_nonaligned_size(data.drm_fd);
 
 	igt_subtest("create-invalid-nonaligned")
-		invalid_nonaligned_size(fd);
+		invalid_nonaligned_size(data.drm_fd);
 
 	igt_subtest("map-valid")
-		valid_map(fd);
+		valid_map(data.drm_fd);
 
 	igt_subtest("map-uaf")
-		uaf_map(fd);
+		uaf_map(data.drm_fd);
 
 	igt_subtest("map-invalid-size")
-		invalid_size_map(fd);
+		invalid_size_map(data.drm_fd);
 
 	igt_subtest("create-clear")
-		always_clear(fd, 30);
+		always_clear(data.drm_fd, 30);
 }
-- 
2.20.1

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

  reply	other threads:[~2020-01-04 10:09 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-04 10:08 [igt-dev] [RFC 1/2] lib/i915/intel_memory_region: wrappers for memory regions ops Ramalingam C
2020-01-04 10:08 ` Ramalingam C [this message]
2020-01-04 11:07   ` [igt-dev] [RFC 2/2] tests/dumb_duffer: extending for lmem coverage Chris Wilson
2020-01-06  6:43     ` Ramalingam C
2020-01-06 12:00       ` Chris Wilson
2020-01-04 10:42 ` [igt-dev] ✗ Fi.CI.BAT: failure for series starting with [RFC,1/2] lib/i915/intel_memory_region: wrappers for memory regions ops 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=20200104100826.21067-2-ramalingam.c@intel.com \
    --to=ramalingam.c@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox