[igt-dev] [PATCH v2 i-g-t 2/2] tests/i915/gem_madvise: Use gem_mmap_offset

Vinay Belgaumkar vinay.belgaumkar at intel.com
Thu Jan 30 21:44:55 UTC 2020


Update test to use mmap_offset which allows test execution
on platforms without aperture. Iterate the test for GTT and
WC mapping types.

Signed-off-by: Antonio Argenziano <antonio.argenziano at intel.com>
Signed-off-by: Vinay Belgaumkar <vinay.belgaumkar at intel.com>
Cc: Chris Wilson <chris at chris-wilson.co.uk>
---
 tests/i915/gem_madvise.c | 114 ++++++++++++++++++++++++++-------------
 1 file changed, 76 insertions(+), 38 deletions(-)

diff --git a/tests/i915/gem_madvise.c b/tests/i915/gem_madvise.c
index 7162a5c3..ee38e023 100644
--- a/tests/i915/gem_madvise.c
+++ b/tests/i915/gem_madvise.c
@@ -51,62 +51,100 @@ static jmp_buf jmp;
 
 static void __attribute__((noreturn)) sigtrap(int sig)
 {
-	longjmp(jmp, sig);
+	siglongjmp(jmp, sig);
 }
 
+enum mode { GTT, WC };
+const char* modes[] = {[GTT] = "gtt", [WC] = "wc"};
+
 static void
 dontneed_before_mmap(void)
 {
-	int fd = drm_open_driver(DRIVER_INTEL);
+	int fd;
 	uint32_t handle;
 	char *ptr;
 
-	handle = gem_create(fd, OBJECT_SIZE);
-	gem_madvise(fd, handle, I915_MADV_DONTNEED);
-	ptr = gem_mmap__gtt(fd, handle, OBJECT_SIZE, PROT_READ | PROT_WRITE);
-	close(fd);
-
-	signal(SIGSEGV, sigtrap);
-	signal(SIGBUS, sigtrap);
-	switch (setjmp(jmp)) {
-	case SIGBUS:
-		break;
-	case 0:
-		*ptr = 0;
-	default:
-		igt_assert(!"reached");
-		break;
+	for (unsigned mode = GTT; mode <= WC; mode++) {
+		igt_debug("Mapping mode: %s\n", modes[mode]);
+
+		fd = drm_open_driver(DRIVER_INTEL);
+		handle = gem_create(fd, OBJECT_SIZE);
+		gem_madvise(fd, handle, I915_MADV_DONTNEED);
+
+		switch (mode) {
+			case GTT:
+				ptr = __gem_mmap_offset(fd, handle, 0, OBJECT_SIZE,
+					PROT_READ | PROT_WRITE, I915_MMAP_OFFSET_GTT);
+				break;
+			case WC:
+				ptr = __gem_mmap_offset(fd, handle, 0, OBJECT_SIZE,
+					PROT_READ | PROT_WRITE, I915_MMAP_OFFSET_WC);
+				break;
+		}
+
+		close(fd);
+
+		signal(SIGSEGV, sigtrap);
+		signal(SIGBUS, sigtrap);
+		switch (sigsetjmp(jmp, SIGBUS | SIGSEGV)) {
+		case SIGBUS:
+			break;
+		case 0:
+			*ptr = 0;
+		default:
+			igt_assert(!"reached");
+			break;
+		}
+		munmap(ptr, OBJECT_SIZE);
+		signal(SIGBUS, SIG_DFL);
+		signal(SIGSEGV, SIG_DFL);
 	}
-	munmap(ptr, OBJECT_SIZE);
-	signal(SIGBUS, SIG_DFL);
-	signal(SIGSEGV, SIG_DFL);
 }
 
 static void
 dontneed_after_mmap(void)
 {
-	int fd = drm_open_driver(DRIVER_INTEL);
+	int fd;
 	uint32_t handle;
 	char *ptr;
 
-	handle = gem_create(fd, OBJECT_SIZE);
-	ptr = gem_mmap__gtt(fd, handle, OBJECT_SIZE, PROT_READ | PROT_WRITE);
-	igt_assert(ptr);
-	gem_madvise(fd, handle, I915_MADV_DONTNEED);
-	close(fd);
-
-	signal(SIGBUS, sigtrap);
-	switch (setjmp(jmp)) {
-	case SIGBUS:
-		break;
-	case 0:
-		*ptr = 0;
-	default:
-		igt_assert(!"reached");
-		break;
+	for (unsigned mode = GTT; mode <= WC; mode++) {
+		igt_debug("Mapping mode: %s\n", modes[mode]);
+
+		fd = drm_open_driver(DRIVER_INTEL);
+		handle = gem_create(fd, OBJECT_SIZE);
+
+		switch (mode) {
+			case GTT:
+				ptr = __gem_mmap_offset(fd, handle, 0, OBJECT_SIZE,
+					PROT_READ | PROT_WRITE, I915_MMAP_OFFSET_GTT);
+				break;
+			case WC:
+				ptr = __gem_mmap_offset(fd, handle, 0, OBJECT_SIZE,
+					PROT_READ | PROT_WRITE, I915_MMAP_OFFSET_WC);
+				break;
+		}
+
+		igt_assert(ptr);
+		gem_madvise(fd, handle, I915_MADV_DONTNEED);
+		close(fd);
+
+		signal(SIGSEGV, sigtrap);
+		signal(SIGBUS, sigtrap);
+		switch (sigsetjmp(jmp, SIGBUS | SIGSEGV)) {
+		case SIGBUS:
+			break;
+		case 0:
+			*ptr = 0;
+		default:
+			igt_assert(!"reached");
+			break;
+		}
+		munmap(ptr, OBJECT_SIZE);
+		signal(SIGBUS, SIG_DFL);
+		signal(SIGSEGV, SIG_DFL);
 	}
-	munmap(ptr, OBJECT_SIZE);
-	signal(SIGBUS, SIG_DFL);
+
 }
 
 static void
-- 
2.22.0.245.g4d8ec15c66



More information about the igt-dev mailing list