Skip to contentSkip to conversation

drmtest framework support for retval handling

PATCH In review Daniel Vetter 3 participants 14 messages Aug 12, 2013 Library code

lore
Share & tools
lore
#0 lore raw

cover drmtest framework support for retval handling

Hi all,

So I've grown fed-up with our add-hoc (and pretty much always buggy) return value tracking for testcases with subtests. Furthermore sprinkling testcases with tons of if (kernel_has_some_optional_feature) return 77; isn't really helping test case readability.

So I've gone ahead and implement some magic stuff using setjmp/longjmp and a few macros. On top of that a few exemplary conversions of existing testcases.

Comments highly welcome.

Cheers, Daniel

Daniel Vetter (7):
tests: s/cacheing/caching
lib/drmtest: Add drmtest_subtest_block macro lib/drmtest: skip/fail handling
tests/gem_caching: convert to use drmtest retval infrastructure lib/drmtest: make signal process cleanup more robust
tests: use drmtest_skip() in caching ioctl helpers
tests: use drmtest_skip to check for rings

 demos/intel_sprite_on.c                |   2 -
 lib/drmtest.c                          | 134 ++++++++++++---
 lib/drmtest.h                          |  46 ++++-
 tests/.gitignore                       |   2 +-
 tests/Makefile.am                      |   6 +-
 tests/gem_bad_length.c                 |   2 -
 tests/gem_basic.c                      |   6 +-
 tests/gem_cacheing.c                   | 303 --------------------------------
 tests/gem_caching.c                    | 305 +++++++++++++++++++++++++++++++++
 tests/gem_cpu_concurrent_blit.c        |  12 +-
 tests/gem_cs_tlb.c                     |  20 +--
 tests/gem_ctx_bad_exec.c               |   1 -
 tests/gem_dummy_reloc_loop.c           |  18 +-
 tests/gem_exec_bad_domains.c           |  10 +-
 tests/gem_exec_big.c                   |   1 -
 tests/gem_exec_faulting_reloc.c        |   4 +-
 tests/gem_exec_lut_handle.c            |   1 -
 tests/gem_exec_nop.c                   |  19 +-
 tests/gem_fence_thrash.c               |  14 +-
 tests/gem_flink.c                      |  10 +-
 tests/gem_flink_race.c                 |   4 +-
 tests/gem_gtt_concurrent_blit.c        |  12 +-
 tests/gem_linear_blits.c               |   4 +-
 tests/gem_lut_handle.c                 |   1 -
 tests/gem_mmap_gtt.c                   |  14 +-
 tests/gem_partial_pwrite_pread.c       |  21 +--
 tests/gem_pread.c                      |  50 +++---
 tests/gem_pread_after_blit.c           |  25 +--
 tests/gem_prw_concurrent_blit.c        |  12 +-
 tests/gem_pwrite.c                     |  49 +++---
 tests/gem_pwrite_pread.c               | 194 ++++++++++-----------
 tests/gem_ringfill.c                   |   8 +-
 tests/gem_set_tiling_vs_blt.c          |   6 +-
 tests/gem_suspend.c                    |   4 +-
 tests/gem_tiled_blits.c                |   4 +-
 tests/gem_tiled_partial_pwrite_pread.c |   6 +-
 tests/gem_write_read_ring_switch.c     |  15 +-
 tests/kms_flip.c                       |   4 +-
 tests/kms_render.c                     |   2 +-
 tests/prime_nv_api.c                   |   2 +-
 tests/prime_nv_pcopy.c                 |  17 +-
 tests/prime_nv_test.c                  |   2 +-
 tests/prime_self_import.c              |   4 +-
 tests/testdisplay.c                    |   2 -
 44 files changed, 749 insertions(+), 629 deletions(-)
 delete mode 100644 tests/gem_cacheing.c
 create mode 100644 tests/gem_caching.c
Signature · 1 line
1.8.3.2
#1 lore raw

PATCH 1/7 tests: s/cacheing/caching

---
 lib/drmtest.c                    |  28 ++--
 lib/drmtest.h                    |   6 +-
 tests/.gitignore                 |   2 +-
 tests/Makefile.am                |   2 +-
 tests/gem_cacheing.c             | 303 ---------------------------------------
 tests/gem_caching.c              | 303 +++++++++++++++++++++++++++++++++++++++
 tests/gem_partial_pwrite_pread.c |   2 +-
 tests/gem_pread.c                |   2 +-
 tests/gem_pread_after_blit.c     |   4 +-
 tests/gem_pwrite.c               |   2 +-
 tests/gem_pwrite_pread.c         |  12 +-
 11 files changed, 333 insertions(+), 333 deletions(-)
 delete mode 100644 tests/gem_cacheing.c
 create mode 100644 tests/gem_caching.c
lib/drmtest.c +14 -14
index f546784..cae07a2 100644
@@ -380,56 +380,56 @@ skip:
 	return num_rings;
 }
 
-struct local_drm_i915_gem_cacheing {
+struct local_drm_i915_gem_caching {
 	uint32_t handle;
-	uint32_t cacheing;
+	uint32_t caching;
 };
 
 #define LOCAL_DRM_I915_GEM_SET_CACHEING    0x2f
 #define LOCAL_DRM_I915_GEM_GET_CACHEING    0x30
 #define LOCAL_DRM_IOCTL_I915_GEM_SET_CACHEING \
-	DRM_IOW(DRM_COMMAND_BASE + LOCAL_DRM_I915_GEM_SET_CACHEING, struct local_drm_i915_gem_cacheing)
+	DRM_IOW(DRM_COMMAND_BASE + LOCAL_DRM_I915_GEM_SET_CACHEING, struct local_drm_i915_gem_caching)
 #define LOCAL_DRM_IOCTL_I915_GEM_GET_CACHEING \
-	DRM_IOWR(DRM_COMMAND_BASE + LOCAL_DRM_I915_GEM_GET_CACHEING, struct local_drm_i915_gem_cacheing)
+	DRM_IOWR(DRM_COMMAND_BASE + LOCAL_DRM_I915_GEM_GET_CACHEING, struct local_drm_i915_gem_caching)
 
-int gem_has_cacheing(int fd)
+int gem_has_caching(int fd)
 {
-	struct local_drm_i915_gem_cacheing arg;
+	struct local_drm_i915_gem_caching arg;
 	int ret;
 
 	arg.handle = gem_create(fd, 4096);
 	if (arg.handle == 0)
 		return 0;
 
-	arg.cacheing = 0;
+	arg.caching = 0;
 	ret = ioctl(fd, LOCAL_DRM_IOCTL_I915_GEM_SET_CACHEING, &arg);
 	gem_close(fd, arg.handle);
 
 	return ret == 0;
 }
 
-int gem_set_cacheing(int fd, uint32_t handle, int cacheing)
+int gem_set_caching(int fd, uint32_t handle, int caching)
 {
-	struct local_drm_i915_gem_cacheing arg;
+	struct local_drm_i915_gem_caching arg;
 	int ret;
 
 	arg.handle = handle;
-	arg.cacheing = cacheing;
+	arg.caching = caching;
 	ret = ioctl(fd, LOCAL_DRM_IOCTL_I915_GEM_SET_CACHEING, &arg);
 	return ret == 0 ? 0 : -errno;
 }
 
-int gem_get_cacheing(int fd, uint32_t handle)
+uint32_t gem_get_caching(int fd, uint32_t handle)
 {
-	struct local_drm_i915_gem_cacheing arg;
+	struct local_drm_i915_gem_caching arg;
 	int ret;
 
 	arg.handle = handle;
-	arg.cacheing = 0;
+	arg.caching = 0;
 	ret = ioctl(fd, LOCAL_DRM_IOCTL_I915_GEM_GET_CACHEING, &arg);
 	assert(ret == 0);
 
-	return arg.cacheing;
+	return arg.caching;
 }
 
 uint32_t gem_open(int fd, uint32_t name)
lib/drmtest.h +3 -3
index 8320dbe..773beaa 100644
@@ -53,9 +53,9 @@ bool gem_has_bsd(int fd);
 bool gem_has_blt(int fd);
 bool gem_has_vebox(int fd);
 int gem_get_num_rings(int fd);
-int gem_has_cacheing(int fd);
-int gem_set_cacheing(int fd, uint32_t handle, int cacheing);
-int gem_get_cacheing(int fd, uint32_t handle);
+int gem_has_caching(int fd);
+int gem_set_caching(int fd, uint32_t handle, int caching);
+uint32_t gem_get_caching(int fd, uint32_t handle);
 uint32_t gem_flink(int fd, uint32_t handle);
 uint32_t gem_open(int fd, uint32_t name);
 void gem_close(int fd, uint32_t handle);
tests/.gitignore +1 -1
index 8d0b6e5..6395c73 100644
@@ -9,7 +9,7 @@ gem_bad_batch
 gem_bad_blit
 gem_bad_length
 gem_basic
-gem_cacheing
+gem_caching
 gem_cpu_concurrent_blit
 gem_cpu_reloc
 gem_cs_prefetch
tests/Makefile.am +1 -1
index 5d0ed3e..8fff22c 100644
@@ -17,7 +17,7 @@ endif
 
 TESTS_progs_M = \
 	gem_basic \
-	gem_cacheing \
+	gem_caching \
 	gem_cpu_concurrent_blit \
 	gem_cs_tlb \
 	gem_dummy_reloc_loop \
tests/gem_cacheing.c deleted +0 -303

303 lines not on this page · raw message

tests/gem_caching.c new file +303 -0

303 lines not on this page · raw message

tests/gem_partial_pwrite_pread.c +1 -1
index ee176b1..0330216 100644
@@ -258,7 +258,7 @@ static void do_tests(int cache_level, const char *suffix)
 	char name[80];
 
 	if (cache_level != -1) {
-		switch (gem_set_cacheing(fd, scratch_bo->handle, cache_level)) {
+		switch (gem_set_caching(fd, scratch_bo->handle, cache_level)) {
 		case 0: break;
 		case -EINVAL:
 		case -ENOTTY:
tests/gem_pread.c +1 -1
index 7037221..7c2f18f 100644
@@ -120,7 +120,7 @@ int main(int argc, char **argv)
 	}
 
 	for (c = cache; c->level != -1; c++) {
-		if (gem_set_cacheing(fd, dst, c->level))
+		if (gem_set_caching(fd, dst, c->level))
 			continue;
 
 		for (count = 1; count <= 1<<17; count <<= 1) {
tests/gem_pread_after_blit.c +2 -2
index dce8241..55caa98 100644
@@ -131,8 +131,8 @@ static void do_test(int fd, int cache_level,
 		    int loop)
 {
 	if (cache_level != -1) {
-		if (gem_set_cacheing(fd, tmp[0]->handle, cache_level) ||
-		    gem_set_cacheing(fd, tmp[1]->handle, cache_level))
+		if (gem_set_caching(fd, tmp[0]->handle, cache_level) ||
+		    gem_set_caching(fd, tmp[1]->handle, cache_level))
 			return;
 	}
 
tests/gem_pwrite.c +1 -1
index 447a200..f939b9f 100644
@@ -127,7 +127,7 @@ int main(int argc, char **argv)
 	}
 
 	for (c = cache; c->level != -1; c++) {
-		if (gem_set_cacheing(fd, dst, c->level))
+		if (gem_set_caching(fd, dst, c->level))
 			continue;
 
 		for (count = 1; count <= 1<<17; count <<= 1) {
tests/gem_pwrite_pread.c +6 -6
index 1f9187f..65427c3 100644
@@ -398,8 +398,8 @@ int main(int argc, char **argv)
 	src = gem_create(fd, object_size);
 	tmp = malloc(object_size);
 
-	if (gem_set_cacheing(fd, src, 0) == 0 &&
-	    gem_set_cacheing(fd, dst, 0) == 0) {
+	if (gem_set_caching(fd, src, 0) == 0 &&
+	    gem_set_caching(fd, dst, 0) == 0) {
 		if (drmtest_run_subtest("uncached-copy-correctness"))
 			test_copy(fd, src, dst, tmp, object_size);
 		if (drmtest_run_subtest("uncached-copy-performance")) {
@@ -435,8 +435,8 @@ int main(int argc, char **argv)
 		}
 	}
 
-	if (gem_set_cacheing(fd, src, 1) == 0 &&
-	    gem_set_cacheing(fd, dst, 1) == 0) {
+	if (gem_set_caching(fd, src, 1) == 0 &&
+	    gem_set_caching(fd, dst, 1) == 0) {
 		if (drmtest_run_subtest("snooped-copy-correctness"))
 			test_copy(fd, src, dst, tmp, object_size);
 		if (drmtest_run_subtest("snooped-copy-performance")) {
@@ -472,8 +472,8 @@ int main(int argc, char **argv)
 		}
 	}
 
-	if (gem_set_cacheing(fd, src, 2) == 0 &&
-	    gem_set_cacheing(fd, dst, 2) == 0) {
+	if (gem_set_caching(fd, src, 2) == 0 &&
+	    gem_set_caching(fd, dst, 2) == 0) {
 		if (drmtest_run_subtest("display-copy-correctness"))
 			test_copy(fd, src, dst, tmp, object_size);
 		if (drmtest_run_subtest("display-copy-performance")) {
Signature · 6 lines
1.8.3.2

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw

PATCH 2/7 lib/drmtest: Add drmtest_subtest_block macro

In reply to Daniel Vetter

Doesn't do more than an if (drmtest_run_test(name)) right now, but as soon as we get a bit of infrastructure to handle test failures and skipping, this will get more interesting.

---
 lib/drmtest.h                          |  1 +
 tests/gem_basic.c                      |  6 +++---
 tests/gem_cpu_concurrent_blit.c        | 12 ++++++------
 tests/gem_cs_tlb.c                     |  8 ++++----
 tests/gem_dummy_reloc_loop.c           | 10 +++++-----
 tests/gem_exec_bad_domains.c           | 10 +++++-----
 tests/gem_exec_faulting_reloc.c        |  4 ++--
 tests/gem_exec_nop.c                   |  8 ++++----
 tests/gem_fence_thrash.c               | 14 +++++++-------
 tests/gem_flink.c                      | 10 +++++-----
 tests/gem_flink_race.c                 |  4 ++--
 tests/gem_gtt_concurrent_blit.c        | 12 ++++++------
 tests/gem_linear_blits.c               |  4 ++--
 tests/gem_mmap_gtt.c                   | 14 +++++++-------
 tests/gem_partial_pwrite_pread.c       |  6 +++---
 tests/gem_pread_after_blit.c           | 16 ++++++++--------
 tests/gem_prw_concurrent_blit.c        | 12 ++++++------
 tests/gem_pwrite_pread.c               | 24 ++++++++++++------------
 tests/gem_ringfill.c                   |  8 +++++---
 tests/gem_set_tiling_vs_blt.c          |  6 +++---
 tests/gem_suspend.c                    |  4 ++--
 tests/gem_tiled_blits.c                |  4 ++--
 tests/gem_tiled_partial_pwrite_pread.c |  6 +++---
 tests/gem_write_read_ring_switch.c     |  9 +++++----
 tests/kms_flip.c                       |  4 ++--
 tests/kms_render.c                     |  2 +-
 tests/prime_nv_api.c                   |  2 +-
 tests/prime_nv_pcopy.c                 | 17 +++++++++--------
 tests/prime_nv_test.c                  |  2 +-
 tests/prime_self_import.c              |  2 +-
 30 files changed, 123 insertions(+), 118 deletions(-)
lib/drmtest.h +1 -0
index 773beaa..ada8e81 100644
@@ -95,6 +95,7 @@ void drmtest_progress(const char *header, uint64_t i, uint64_t total);
 /* subtest infrastructure */
 void drmtest_subtest_init(int argc, char **argv);
 bool drmtest_run_subtest(const char *subtest_name);
+#define drmtest_subtest_block(name) if (drmtest_run_subtest((name)))
 bool drmtest_only_list_subtests(void);
 
 /* helpers to automatically reduce test runtime in simulation */
tests/gem_basic.c +3 -3
index 5cc8684..900194d 100644
@@ -84,11 +84,11 @@ int main(int argc, char **argv)
 
 	fd = drm_open_any();
 
-	if (drmtest_run_subtest("bad-close"))
+	drmtest_subtest_block("bad-close")
 		test_bad_close(fd);
-	if (drmtest_run_subtest("create-close"))
+	drmtest_subtest_block("create-close")
 		test_create_close(fd);
-	if (drmtest_run_subtest("create-fd-close"))
+	drmtest_subtest_block("create-fd-close")
 		test_create_fd_close(fd);
 
 	return 0;
tests/gem_cpu_concurrent_blit.c +6 -6
index e6cc50b..7bcfcd8 100644
@@ -117,7 +117,7 @@ main(int argc, char **argv)
 	}
 
 	/* try to overwrite the source values */
-	if (drmtest_run_subtest("overwrite-source")) {
+	drmtest_subtest_block("overwrite-source") {
 		for (i = 0; i < num_buffers; i++) {
 			set_bo(src[i], i, width, height);
 			set_bo(dst[i], i, width, height);
@@ -131,7 +131,7 @@ main(int argc, char **argv)
 	}
 
 	/* try to read the results before the copy completes */
-	if (drmtest_run_subtest("early-read")) {
+	drmtest_subtest_block("early-read") {
 		for (i = num_buffers; i--; )
 			set_bo(src[i], 0xdeadbeef, width, height);
 		for (i = 0; i < num_buffers; i++)
@@ -141,7 +141,7 @@ main(int argc, char **argv)
 	}
 
 	/* and finally try to trick the kernel into loosing the pending write */
-	if (drmtest_run_subtest("gpu-read-after-write")) {
+	drmtest_subtest_block("gpu-read-after-write") {
 		for (i = num_buffers; i--; )
 			set_bo(src[i], 0xabcdabcd, width, height);
 		for (i = 0; i < num_buffers; i++)
@@ -155,7 +155,7 @@ main(int argc, char **argv)
 	drmtest_fork_signal_helper();
 
 	/* try to overwrite the source values */
-	if (drmtest_run_subtest("overwrite-source-interruptible")) {
+	drmtest_subtest_block("overwrite-source-interruptible") {
 		for (loop = 0; loop < 10; loop++) {
 			gem_quiescent_gpu(fd);
 			for (i = 0; i < num_buffers; i++) {
@@ -172,7 +172,7 @@ main(int argc, char **argv)
 	}
 
 	/* try to read the results before the copy completes */
-	if (drmtest_run_subtest("early-read-interruptible")) {
+	drmtest_subtest_block("early-read-interruptible") {
 		for (loop = 0; loop < 10; loop++) {
 			gem_quiescent_gpu(fd);
 			for (i = num_buffers; i--; )
@@ -185,7 +185,7 @@ main(int argc, char **argv)
 	}
 
 	/* and finally try to trick the kernel into loosing the pending write */
-	if (drmtest_run_subtest("gpu-read-after-write-interruptible")) {
+	drmtest_subtest_block("gpu-read-after-write-interruptible") {
 		for (loop = 0; loop < 10; loop++) {
 			gem_quiescent_gpu(fd);
 			for (i = num_buffers; i--; )
tests/gem_cs_tlb.c +4 -4
index 05e78c2..081b6f2 100644
@@ -164,18 +164,18 @@ int main(int argc, char **argv)
 		sleep(5); /* needs more serious ducttape */
 	}
 
-	if (drmtest_run_subtest("render"))
+	drmtest_subtest_block("render")
 		run_on_ring(fd, I915_EXEC_RENDER, "render");
 
-	if (drmtest_run_subtest("bsd"))
+	drmtest_subtest_block("bsd")
 		if (HAS_BSD_RING(devid))
 			run_on_ring(fd, I915_EXEC_BSD, "bsd");
 
-	if (drmtest_run_subtest("blt"))
+	drmtest_subtest_block("blt")
 		if (HAS_BLT_RING(devid))
 			run_on_ring(fd, I915_EXEC_BLT, "blt");
 
-	if (drmtest_run_subtest("vebox"))
+	drmtest_subtest_block("vebox")
 		if (gem_has_vebox(fd))
 			run_on_ring(fd, LOCAL_I915_EXEC_VEBOX, "vebox");
 
tests/gem_dummy_reloc_loop.c +5 -5
index b889f83..7cffbbe 100644
@@ -160,13 +160,13 @@ int main(int argc, char **argv)
 		exit(-1);
 	}
 
-	if (drmtest_run_subtest("render")) {
+	drmtest_subtest_block("render") {
 		printf("running dummy loop on render\n");
 		dummy_reloc_loop(I915_EXEC_RENDER);
 		printf("dummy loop run on render completed\n");
 	}
 
-	if (drmtest_run_subtest("bsd")) {
+	drmtest_subtest_block("bsd") {
 		if (HAS_BSD_RING(devid)) {
 			sleep(2);
 			printf("running dummy loop on bsd\n");
@@ -175,7 +175,7 @@ int main(int argc, char **argv)
 		}
 	}
 
-	if (drmtest_run_subtest("blt")) {
+	drmtest_subtest_block("blt") {
 		if (HAS_BLT_RING(devid)) {
 			sleep(2);
 			printf("running dummy loop on blt\n");
@@ -184,7 +184,7 @@ int main(int argc, char **argv)
 		}
 	}
 
-	if (drmtest_run_subtest("vebox")) {
+	drmtest_subtest_block("vebox") {
 		if (gem_has_vebox(fd)) {
 			sleep(2);
 			printf("running dummy loop on vebox\n");
@@ -193,7 +193,7 @@ int main(int argc, char **argv)
 		}
 	}
 
-	if (drmtest_run_subtest("mixed")) {
+	drmtest_subtest_block("mixed") {
 		if (num_rings > 1) {
 			sleep(2);
 			printf("running dummy loop on random rings\n");
tests/gem_exec_bad_domains.c +5 -5
index d174349..53c33fd 100644
@@ -166,7 +166,7 @@ int main(int argc, char **argv)
 
 	tmp = drm_intel_bo_alloc(bufmgr, "tmp", 128 * 128, 4096);
 
-	if (drmtest_run_subtest("cpu-domain")) {
+	drmtest_subtest_block("cpu-domain") {
 		BEGIN_BATCH(2);
 		OUT_BATCH(0);
 		OUT_RELOC(tmp, I915_GEM_DOMAIN_CPU, 0, 0);
@@ -188,7 +188,7 @@ int main(int argc, char **argv)
 		}
 	}
 
-	if (drmtest_run_subtest("gtt-domain")) {
+	drmtest_subtest_block("gtt-domain") {
 		BEGIN_BATCH(2);
 		OUT_BATCH(0);
 		OUT_RELOC(tmp, I915_GEM_DOMAIN_GTT, 0, 0);
@@ -212,7 +212,7 @@ int main(int argc, char **argv)
 
 #if 0 /* kernel checks have been eased, doesn't reject conflicting write domains
 	 any more */
-	if (drmtest_run_subtest("conflicting-write-domain")) {
+	drmtest_subtest_block("conflicting-write-domain") {
 		BEGIN_BATCH(4);
 		OUT_BATCH(0);
 		OUT_RELOC(tmp, I915_GEM_DOMAIN_RENDER,
@@ -229,10 +229,10 @@ int main(int argc, char **argv)
 	}
 #endif
 
-	if (drmtest_run_subtest("double-write-domain"))
+	drmtest_subtest_block("double-write-domain")
 		multi_write_domain(fd);
 
-	if (drmtest_run_subtest("invalid-gpu-domain")) {
+	drmtest_subtest_block("invalid-gpu-domain") {
 		BEGIN_BATCH(2);
 		OUT_BATCH(0);
 		OUT_RELOC(tmp, ~(I915_GEM_GPU_DOMAINS | I915_GEM_DOMAIN_GTT | I915_GEM_DOMAIN_CPU),
tests/gem_exec_faulting_reloc.c +2 -2
index c7f7b6b..d9c9db3 100644
@@ -222,9 +222,9 @@ int main(int argc, char **argv)
 {
 	drmtest_subtest_init(argc, argv);
 
-	if (drmtest_run_subtest("normal"))
+	drmtest_subtest_block("normal")
 		run(OBJECT_SIZE);
-	if (drmtest_run_subtest("no-prefault")) {
+	drmtest_subtest_block("no-prefault") {
 		drmtest_disable_prefault();
 		run(OBJECT_SIZE);
 		drmtest_enable_prefault();
tests/gem_exec_nop.c +4 -4
index 35cb23d..ca1f580 100644
@@ -124,18 +124,18 @@ int main(int argc, char **argv)
 	handle = gem_create(fd, 4096);
 	gem_write(fd, handle, 0, batch, sizeof(batch));
 
-	if (drmtest_run_subtest("render"))
+	drmtest_subtest_block("render")
 		loop(fd, handle, I915_EXEC_RENDER, "render");
 
-	if (drmtest_run_subtest("bsd"))
+	drmtest_subtest_block("bsd")
 		if (HAS_BSD_RING(devid))
 			loop(fd, handle, I915_EXEC_BSD, "bsd");
 
-	if (drmtest_run_subtest("blt"))
+	drmtest_subtest_block("blt")
 		if (HAS_BLT_RING(devid))
 			loop(fd, handle, I915_EXEC_BLT, "blt");
 
-	if (drmtest_run_subtest("vebox"))
+	drmtest_subtest_block("vebox")
 		if (gem_has_vebox(fd))
 			loop(fd, handle, LOCAL_I915_EXEC_VEBOX, "vebox");
 
tests/gem_fence_thrash.c +7 -7
index a28c127..a6cd6ee 100644
@@ -210,33 +210,33 @@ main(int argc, char **argv)
 	drmtest_subtest_init(argc, argv);
 	drmtest_skip_on_simulation();
 
-	if (drmtest_run_subtest("bo-write-verify-none"))
+	drmtest_subtest_block("bo-write-verify-none")
 		assert (run_test(0, bo_write_verify, I915_TILING_NONE, 80) == 0);
 
-	if (drmtest_run_subtest("bo-write-verify-x"))
+	drmtest_subtest_block("bo-write-verify-x")
 		assert (run_test(0, bo_write_verify, I915_TILING_X, 80) == 0);
 
-	if (drmtest_run_subtest("bo-write-verify-y"))
+	drmtest_subtest_block("bo-write-verify-y")
 		assert (run_test(0, bo_write_verify, I915_TILING_Y, 80) == 0);
 
-	if (drmtest_run_subtest("bo-write-verify-threaded-none"))
+	drmtest_subtest_block("bo-write-verify-threaded-none")
 		assert (run_test(5, bo_write_verify, I915_TILING_NONE, 2) == 0);
 
-	if (drmtest_run_subtest("bo-write-verify-threaded-x")) {
+	drmtest_subtest_block("bo-write-verify-threaded-x") {
 		assert (run_test(2, bo_write_verify, I915_TILING_X, 2) == 0);
 		assert (run_test(5, bo_write_verify, I915_TILING_X, 2) == 0);
 		assert (run_test(10, bo_write_verify, I915_TILING_X, 2) == 0);
 		assert (run_test(20, bo_write_verify, I915_TILING_X, 2) == 0);
 	}
 
-	if (drmtest_run_subtest("bo-write-verify-threaded-y")) {
+	drmtest_subtest_block("bo-write-verify-threaded-y") {
 		assert (run_test(2, bo_write_verify, I915_TILING_Y, 2) == 0);
 		assert (run_test(5, bo_write_verify, I915_TILING_Y, 2) == 0);
 		assert (run_test(10, bo_write_verify, I915_TILING_Y, 2) == 0);
 		assert (run_test(20, bo_write_verify, I915_TILING_Y, 2) == 0);
 	}
 
-	if (drmtest_run_subtest("bo-copy"))
+	drmtest_subtest_block("bo-copy")
 		assert(run_test(1, bo_copy, I915_TILING_X, 1) == 0);
 
 	return 0;
tests/gem_flink.c +5 -5
index cc4f0e5..abdbfca 100644
@@ -158,15 +158,15 @@ int main(int argc, char **argv)
 
 	fd = drm_open_any();
 
-	if (drmtest_run_subtest("basic"))
+	drmtest_subtest_block("basic")
 		test_flink(fd);
-	if (drmtest_run_subtest("double-flink"))
+	drmtest_subtest_block("double-flink")
 		test_double_flink(fd);
-	if (drmtest_run_subtest("bad-flink"))
+	drmtest_subtest_block("bad-flink")
 		test_bad_flink(fd);
-	if (drmtest_run_subtest("bad-open"))
+	drmtest_subtest_block("bad-open")
 		test_bad_open(fd);
-	if (drmtest_run_subtest("flink-lifetime"))
+	drmtest_subtest_block("flink-lifetime")
 		test_flink_lifetime(fd);
 
 	return 0;
tests/gem_flink_race.c +2 -2
index ce6f302..4c846e0 100644
@@ -197,10 +197,10 @@ int main(int argc, char **argv)
 
 	drmtest_subtest_init(argc, argv);
 
-	if (drmtest_run_subtest("flink_name"))
+	drmtest_subtest_block("flink_name")
 		test_flink_name();
 
-	if (drmtest_run_subtest("flink_close"))
+	drmtest_subtest_block("flink_close")
 		test_flink_close();
 
 	return 0;
tests/gem_gtt_concurrent_blit.c +6 -6
index b3ac0b4..63fbcc2 100644
@@ -120,7 +120,7 @@ main(int argc, char **argv)
 	}
 
 	/* try to overwrite the source values */
-	if (drmtest_run_subtest("overwrite-source")) {
+	drmtest_subtest_block("overwrite-source") {
 		for (i = 0; i < num_buffers; i++) {
 			set_bo(src[i], i, width, height);
 			set_bo(dst[i], i, width, height);
@@ -134,7 +134,7 @@ main(int argc, char **argv)
 	}
 
 	/* try to read the results before the copy completes */
-	if (drmtest_run_subtest("early-read")) {
+	drmtest_subtest_block("early-read") {
 		for (i = num_buffers; i--; )
 			set_bo(src[i], 0xdeadbeef, width, height);
 		for (i = 0; i < num_buffers; i++)
@@ -144,7 +144,7 @@ main(int argc, char **argv)
 	}
 
 	/* and finally try to trick the kernel into loosing the pending write */
-	if (drmtest_run_subtest("gpu-read-after-write")) {
+	drmtest_subtest_block("gpu-read-after-write") {
 		for (i = num_buffers; i--; )
 			set_bo(src[i], 0xabcdabcd, width, height);
 		for (i = 0; i < num_buffers; i++)
@@ -158,7 +158,7 @@ main(int argc, char **argv)
 	drmtest_fork_signal_helper();
 
 	/* try to read the results before the copy completes */
-	if (drmtest_run_subtest("overwrite-source-interruptible")) {
+	drmtest_subtest_block("overwrite-source-interruptible") {
 		for (loop = 0; loop < 10; loop++) {
 			gem_quiescent_gpu(fd);
 			for (i = 0; i < num_buffers; i++) {
@@ -175,7 +175,7 @@ main(int argc, char **argv)
 	}
 
 	/* try to read the results before the copy completes */
-	if (drmtest_run_subtest("early-read-interruptible")) {
+	drmtest_subtest_block("early-read-interruptible") {
 		for (loop = 0; loop < 10; loop++) {
 			gem_quiescent_gpu(fd);
 			for (i = num_buffers; i--; )
@@ -188,7 +188,7 @@ main(int argc, char **argv)
 	}
 
 	/* and finally try to trick the kernel into loosing the pending write */
-	if (drmtest_run_subtest("gpu-read-after-write-interruptible")) {
+	drmtest_subtest_block("gpu-read-after-write-interruptible") {
 		for (loop = 0; loop < 10; loop++) {
 			gem_quiescent_gpu(fd);
 			for (i = num_buffers; i--; )
tests/gem_linear_blits.c +2 -2
index 0956fd0..661baa8 100644
@@ -264,10 +264,10 @@ int main(int argc, char **argv)
 		printf("Using %d 1MiB buffers\n", count);
 	}
 
-	if (drmtest_run_subtest("normal"))
+	drmtest_subtest_block("normal")
 		run_test(fd, count);
 
-	if (drmtest_run_subtest("interruptible")) {
+	drmtest_subtest_block("interruptible") {
 		drmtest_fork_signal_helper();
 		run_test(fd, count);
 		drmtest_stop_signal_helper();
tests/gem_mmap_gtt.c +7 -7
index 5151ea3..198dd59 100644
@@ -164,19 +164,19 @@ int main(int argc, char **argv)
 
 	fd = drm_open_any();
 
-	if (drmtest_run_subtest("copy"))
+	drmtest_subtest_block("copy")
 		test_copy(fd);
-	if (drmtest_run_subtest("read"))
+	drmtest_subtest_block("read")
 		test_read(fd);
-	if (drmtest_run_subtest("write"))
+	drmtest_subtest_block("write")
 		test_write(fd);
-	if (drmtest_run_subtest("write-gtt"))
+	drmtest_subtest_block("write-gtt")
 		test_write_gtt(fd);
-	if (drmtest_run_subtest("read-no-prefault"))
+	drmtest_subtest_block("read-no-prefault")
 		run_without_prefault(fd, test_read);
-	if (drmtest_run_subtest("write-no-prefault"))
+	drmtest_subtest_block("write-no-prefault")
 		run_without_prefault(fd, test_write);
-	if (drmtest_run_subtest("write-gtt-no-prefault"))
+	drmtest_subtest_block("write-gtt-no-prefault")
 		run_without_prefault(fd, test_write_gtt);
 
 	close(fd);
tests/gem_partial_pwrite_pread.c +3 -3
index 0330216..a27e584 100644
@@ -270,15 +270,15 @@ static void do_tests(int cache_level, const char *suffix)
 	}
 
 	snprintf(name, sizeof(name), "reads%s", suffix);
-	if (drmtest_run_subtest(name))
+	drmtest_subtest_block(name)
 		test_partial_reads();
 
 	snprintf(name, sizeof(name), "writes%s", suffix);
-	if (drmtest_run_subtest(name))
+	drmtest_subtest_block(name)
 		test_partial_writes();
 
 	snprintf(name, sizeof(name), "writes-after-reads%s", suffix);
-	if (drmtest_run_subtest(name))
+	drmtest_subtest_block(name)
 		test_partial_read_writes();
 }
 
tests/gem_pread_after_blit.c +8 -8
index 55caa98..7375000 100644
@@ -190,37 +190,37 @@ main(int argc, char **argv)
 	dst[0] = drm_intel_bo_alloc(bufmgr, "dst bo", size, 4096);
 	dst[1] = drm_intel_bo_alloc(bufmgr, "dst bo", size, 4096);
 
-	if (drmtest_run_subtest("normal"))
+	drmtest_subtest_block("normal")
 		do_test(fd, -1, src, start, dst, 1);
 
-	if (drmtest_run_subtest("interruptible")) {
+	drmtest_subtest_block("interruptible") {
 		drmtest_fork_signal_helper();
 		do_test(fd, -1, src, start, dst, 100);
 		drmtest_stop_signal_helper();
 	}
 
-	if (drmtest_run_subtest("normal-uncached"))
+	drmtest_subtest_block("normal-uncached")
 		do_test(fd, 0, src, start, dst, 1);
 
-	if (drmtest_run_subtest("interruptible-uncached")) {
+	drmtest_subtest_block("interruptible-uncached") {
 		drmtest_fork_signal_helper();
 		do_test(fd, 0, src, start, dst, 100);
 		drmtest_stop_signal_helper();
 	}
 
-	if (drmtest_run_subtest("normal-snoop"))
+	drmtest_subtest_block("normal-snoop")
 		do_test(fd, 1, src, start, dst, 1);
 
-	if (drmtest_run_subtest("interruptible-snoop")) {
+	drmtest_subtest_block("interruptible-snoop") {
 		drmtest_fork_signal_helper();
 		do_test(fd, 1, src, start, dst, 100);
 		drmtest_stop_signal_helper();
 	}
 
-	if (drmtest_run_subtest("normal-display"))
+	drmtest_subtest_block("normal-display")
 		do_test(fd, 2, src, start, dst, 1);
 
-	if (drmtest_run_subtest("interruptible-display")) {
+	drmtest_subtest_block("interruptible-display") {
 		drmtest_fork_signal_helper();
 		do_test(fd, 2, src, start, dst, 100);
 		drmtest_stop_signal_helper();
tests/gem_prw_concurrent_blit.c +6 -6
index 1765f09..2e0d36f 100644
@@ -120,7 +120,7 @@ main(int argc, char **argv)
 	}
 
 	/* try to overwrite the source values */
-	if (drmtest_run_subtest("overwrite-source")) {
+	drmtest_subtest_block("overwrite-source") {
 		for (i = 0; i < num_buffers; i++) {
 			set_bo(src[i], i, width, height);
 			set_bo(dst[i], i, width, height);
@@ -134,7 +134,7 @@ main(int argc, char **argv)
 	}
 
 	/* try to read the results before the copy completes */
-	if (drmtest_run_subtest("early-read")) {
+	drmtest_subtest_block("early-read") {
 		for (i = num_buffers; i--; )
 			set_bo(src[i], 0xdeadbeef, width, height);
 		for (i = 0; i < num_buffers; i++)
@@ -144,7 +144,7 @@ main(int argc, char **argv)
 	}
 
 	/* and finally try to trick the kernel into loosing the pending write */
-	if (drmtest_run_subtest("gpu-read-after-write")) {
+	drmtest_subtest_block("gpu-read-after-write") {
 		for (i = num_buffers; i--; )
 			set_bo(src[i], 0xabcdabcd, width, height);
 		for (i = 0; i < num_buffers; i++)
@@ -158,7 +158,7 @@ main(int argc, char **argv)
 	drmtest_fork_signal_helper();
 
 	/* try to read the results before the copy completes */
-	if (drmtest_run_subtest("overwrite-source-interruptible")) {
+	drmtest_subtest_block("overwrite-source-interruptible") {
 		for (loop = 0; loop < 10; loop++) {
 			gem_quiescent_gpu(fd);
 			for (i = 0; i < num_buffers; i++) {
@@ -175,7 +175,7 @@ main(int argc, char **argv)
 	}
 
 	/* try to read the results before the copy completes */
-	if (drmtest_run_subtest("early-read-interruptible")) {
+	drmtest_subtest_block("early-read-interruptible") {
 		for (loop = 0; loop < 10; loop++) {
 			gem_quiescent_gpu(fd);
 			for (i = num_buffers; i--; )
@@ -188,7 +188,7 @@ main(int argc, char **argv)
 	}
 
 	/* and finally try to trick the kernel into loosing the pending write */
-	if (drmtest_run_subtest("gpu-read-after-write-interruptible")) {
+	drmtest_subtest_block("gpu-read-after-write-interruptible") {
 		for (loop = 0; loop < 10; loop++) {
 			gem_quiescent_gpu(fd);
 			for (i = num_buffers; i--; )
tests/gem_pwrite_pread.c +12 -12
index 65427c3..d29c531 100644
@@ -400,9 +400,9 @@ int main(int argc, char **argv)
 
 	if (gem_set_caching(fd, src, 0) == 0 &&
 	    gem_set_caching(fd, dst, 0) == 0) {
-		if (drmtest_run_subtest("uncached-copy-correctness"))
+		drmtest_subtest_block("uncached-copy-correctness")
 			test_copy(fd, src, dst, tmp, object_size);
-		if (drmtest_run_subtest("uncached-copy-performance")) {
+		drmtest_subtest_block("uncached-copy-performance") {
 			for (count = 1; count <= 1<<17; count <<= 1) {
 				struct timeval start, end;
 
@@ -417,9 +417,9 @@ int main(int argc, char **argv)
 			}
 		}
 
-		if (drmtest_run_subtest("uncached-pwrite-blt-gtt_mmap-correctness"))
+		drmtest_subtest_block("uncached-pwrite-blt-gtt_mmap-correctness")
 			test_as_gtt_mmap(fd, src, dst, object_size);
-		if (drmtest_run_subtest("uncached-pwrite-blt-gtt_mmap-performance")) {
+		drmtest_subtest_block("uncached-pwrite-blt-gtt_mmap-performance") {
 			for (count = 1; count <= 1<<17; count <<= 1) {
 				struct timeval start, end;
 
@@ -437,9 +437,9 @@ int main(int argc, char **argv)
 
 	if (gem_set_caching(fd, src, 1) == 0 &&
 	    gem_set_caching(fd, dst, 1) == 0) {
-		if (drmtest_run_subtest("snooped-copy-correctness"))
+		drmtest_subtest_block("snooped-copy-correctness")
 			test_copy(fd, src, dst, tmp, object_size);
-		if (drmtest_run_subtest("snooped-copy-performance")) {
+		drmtest_subtest_block("snooped-copy-performance") {
 			for (count = 1; count <= 1<<17; count <<= 1) {
 				struct timeval start, end;
 
@@ -454,9 +454,9 @@ int main(int argc, char **argv)
 			}
 		}
 
-		if (drmtest_run_subtest("snooped-pwrite-blt-cpu_mmap-correctness"))
+		drmtest_subtest_block("snooped-pwrite-blt-cpu_mmap-correctness")
 			test_as_cpu_mmap(fd, src, dst, object_size);
-		if (drmtest_run_subtest("snooped-pwrite-blt-cpu_mmap-performance")) {
+		drmtest_subtest_block("snooped-pwrite-blt-cpu_mmap-performance") {
 			for (count = 1; count <= 1<<17; count <<= 1) {
 				struct timeval start, end;
 
@@ -474,9 +474,9 @@ int main(int argc, char **argv)
 
 	if (gem_set_caching(fd, src, 2) == 0 &&
 	    gem_set_caching(fd, dst, 2) == 0) {
-		if (drmtest_run_subtest("display-copy-correctness"))
+		drmtest_subtest_block("display-copy-correctness")
 			test_copy(fd, src, dst, tmp, object_size);
-		if (drmtest_run_subtest("display-copy-performance")) {
+		drmtest_subtest_block("display-copy-performance") {
 			for (count = 1; count <= 1<<17; count <<= 1) {
 				struct timeval start, end;
 
@@ -491,9 +491,9 @@ int main(int argc, char **argv)
 			}
 		}
 
-		if (drmtest_run_subtest("display-pwrite-blt-gtt_mmap-correctness"))
+		drmtest_subtest_block("display-pwrite-blt-gtt_mmap-correctness")
 			test_as_gtt_mmap(fd, src, dst, object_size);
-		if (drmtest_run_subtest("display-pwrite-blt-gtt_mmap-performance")) {
+		drmtest_subtest_block("display-pwrite-blt-gtt_mmap-performance") {
 			for (count = 1; count <= 1<<17; count <<= 1) {
 				struct timeval start, end;
 
tests/gem_ringfill.c +5 -3
index db842fe..1f5faf3 100644
@@ -214,7 +214,7 @@ int main(int argc, char **argv)
 	drm_intel_bufmgr_gem_enable_reuse(bufmgr);
 	batch = intel_batchbuffer_alloc(bufmgr, intel_get_drm_devid(fd));
 
-	if (drmtest_run_subtest("blitter"))
+	drmtest_subtest_block("blitter")
 		fails += check_ring(bufmgr, batch, "blt", blt_copy);
 
 	/* Strictly only required on architectures with a separate BLT ring,
@@ -222,8 +222,10 @@ int main(int argc, char **argv)
 	 */
 	copy = get_render_copyfunc(batch->devid);
 
-	if (drmtest_run_subtest("render") && copy)
-		fails += check_ring(bufmgr, batch, "render", copy);
+	drmtest_subtest_block("render") {
+		if (copy)
+			fails += check_ring(bufmgr, batch, "render", copy);
+	}
 
 	intel_batchbuffer_free(batch);
 	drm_intel_bufmgr_destroy(bufmgr);
tests/gem_set_tiling_vs_blt.c +3 -3
index 398a227..56a8203 100644
@@ -246,7 +246,7 @@ int main(int argc, char **argv)
 	devid = intel_get_drm_devid(fd);
 	batch = intel_batchbuffer_alloc(bufmgr, devid);
 
-	if (drmtest_run_subtest("untiled-to-tiled")) {
+	drmtest_subtest_block("untiled-to-tiled") {
 		printf("testing untiled->tiled transisition:\n");
 		tiling = I915_TILING_NONE;
 		tiling_after = I915_TILING_X;
@@ -255,7 +255,7 @@ int main(int argc, char **argv)
 		assert(tiling_after == I915_TILING_X);
 	}
 
-	if (drmtest_run_subtest("tiled-to-untiled")) {
+	drmtest_subtest_block("tiled-to-untiled") {
 		printf("testing tiled->untiled transisition:\n");
 		tiling = I915_TILING_X;
 		tiling_after = I915_TILING_NONE;
@@ -264,7 +264,7 @@ int main(int argc, char **argv)
 		assert(tiling_after == I915_TILING_NONE);
 	}
 
-	if (drmtest_run_subtest("tiled-to-tiled")) {
+	drmtest_subtest_block("tiled-to-tiled") {
 		printf("testing tiled->tiled transisition:\n");
 		tiling = I915_TILING_X;
 		tiling_after = I915_TILING_X;
tests/gem_suspend.c +2 -2
index a31161d..e252d14 100644
@@ -105,10 +105,10 @@ int main(int argc, char **argv)
 
 	fd = drm_open_any();
 
-	if (drmtest_run_subtest("fence-restore-tiled2untiled"))
+	drmtest_subtest_block("fence-restore-tiled2untiled")
 		test_fence_restore(fd, true);
 
-	if (drmtest_run_subtest("fence-restore-untiled"))
+	drmtest_subtest_block("fence-restore-untiled")
 		test_fence_restore(fd, false);
 
 	close(fd);
tests/gem_tiled_blits.c +2 -2
index b879b1c..ddb5b79 100644
@@ -220,10 +220,10 @@ int main(int argc, char **argv)
 	drm_intel_bufmgr_gem_set_vma_cache_size(bufmgr, 32);
 	batch = intel_batchbuffer_alloc(bufmgr, intel_get_drm_devid(fd));
 
-	if (drmtest_run_subtest("normal"))
+	drmtest_subtest_block("normal")
 		run_test(count);
 
-	if (drmtest_run_subtest("interruptible")) {
+	drmtest_subtest_block("interruptible") {
 		drmtest_fork_signal_helper();
 		run_test(count);
 		drmtest_stop_signal_helper();
tests/gem_tiled_partial_pwrite_pread.c +3 -3
index 48fd506..8e68406 100644
@@ -303,13 +303,13 @@ int main(int argc, char **argv)
 	drmtest_init_aperture_trashers(bufmgr);
 	mappable_gtt_limit = gem_mappable_aperture_size();
 
-	if (drmtest_run_subtest("reads"))
+	drmtest_subtest_block("reads")
 		test_partial_reads();
 
-	if (drmtest_run_subtest("writes"))
+	drmtest_subtest_block("writes")
 		test_partial_writes();
 
-	if (drmtest_run_subtest("writes-after-reads"))
+	drmtest_subtest_block("writes-after-reads")
 		test_partial_read_writes();
 
 	drmtest_cleanup_aperture_trashers();
tests/gem_write_read_ring_switch.c +5 -4
index 162c059..211b530 100644
@@ -206,16 +206,17 @@ int main(int argc, char **argv)
 	}
 
 	for (i = 0; i < ARRAY_SIZE(tests); i++) {
-		if (has_ring(tests[i].ring) &&
-		    drmtest_run_subtest(tests[i].name))
-			run_test(tests[i].ring, tests[i].name);
+		drmtest_subtest_block(tests[i].name) {
+			if (has_ring(tests[i].ring))
+				run_test(tests[i].ring, tests[i].name);
+		}
 	}
 
 	drmtest_fork_signal_helper();
 	for (i = 0; i < ARRAY_SIZE(tests); i++) {
 		char name[180];
 		snprintf(name, sizeof(name), "%s-interruptible", tests[i].name);
-		if (has_ring(tests[i].ring) && drmtest_run_subtest(name))
+		drmtest_subtest_block(name)
 			run_test(tests[i].ring, name);
 	}
 	drmtest_stop_signal_helper();
tests/kms_flip.c +2 -2
index 9e0d235..1998bd9 100644
@@ -1186,7 +1186,7 @@ int main(int argc, char **argv)
 	batch = intel_batchbuffer_alloc(bufmgr, devid);
 
 	for (i = 0; i < sizeof(tests) / sizeof (tests[0]); i++) {
-		if (drmtest_run_subtest(tests[i].name)) {
+		drmtest_subtest_block(tests[i].name) {
 			printf("running testcase: %s\n", tests[i].name);
 			run_test(tests[i].duration, tests[i].flags, tests[i].name);
 		}
@@ -1203,7 +1203,7 @@ int main(int argc, char **argv)
 		    !(tests[i].flags & TEST_VBLANK_ABSOLUTE))
 			continue;
 
-		if (drmtest_run_subtest(name)) {
+		drmtest_subtest_block(name) {
 			printf("running testcase: %s\n", name);
 			run_test(tests[i].duration, tests[i].flags, name);
 		}
tests/kms_render.c +1 -1
index e6d3e93..5670d1b 100644
@@ -247,7 +247,7 @@ int main(int argc, char **argv)
 	}
 
 	for (i = 0; i < ARRAY_SIZE(tests); i++) {
-		if (drmtest_run_subtest(tests[i].name))
+		drmtest_subtest_block(tests[i].name)
 			run_test(tests[i].name, tests[i].flags);
 	}
 
tests/prime_nv_api.c +1 -1
index f470fd7..ad030b0 100644
@@ -569,7 +569,7 @@ int main(int argc, char **argv)
 	intel_batch = intel_batchbuffer_alloc(bufmgr, devid);
 
 #define xtest(name) \
-	if (drmtest_run_subtest(#name)) \
+	drmtest_subtest_block(#name) \
 		if (test_##name()) \
 			exit(2);
 
tests/prime_nv_pcopy.c +9 -8
index 88b14e5..52f5e7b 100644
@@ -1295,14 +1295,15 @@ int main(int argc, char **argv)
 	devid = intel_get_drm_devid(intel_fd);
 	batch = intel_batchbuffer_alloc(bufmgr, devid);
 
-#define xtest(x, args...) do { \
-	if (!drmtest_run_subtest( #x )) break; \
-	ret = ((x)(args)); \
-	++run; \
-	if (ret) { \
-		++failed; \
-		fprintf(stderr, "prime_pcopy: failed " #x "\n"); } \
-	} while (0)
+#define xtest(x, args...) \
+	drmtest_subtest_block( #x ) { \
+		ret = ((x)(args)); \
+		++run; \
+		if (ret) { \
+			++failed; \
+			fprintf(stderr, "prime_pcopy: failed " #x "\n"); \
+		} \
+	}
 
 	xtest(test1_macro);
 	xtest(test1_micro);
tests/prime_nv_test.c +1 -1
index c641095..c850eeb 100644
@@ -504,7 +504,7 @@ int main(int argc, char **argv)
 	intel_batch = intel_batchbuffer_alloc(bufmgr, devid);
 
 #define xtest(name) \
-	if (drmtest_run_subtest(#name)) \
+	drmtest_subtest_block(#name) \
 		if (test_##name()) \
 			exit(2);
 
tests/prime_self_import.c +1 -1
index ed3ff95..1bd0bb5 100644
@@ -386,7 +386,7 @@ int main(int argc, char **argv)
 	drmtest_subtest_init(argc, argv);
 
 	for (i = 0; i < ARRAY_SIZE(tests); i++) {
-		if (drmtest_run_subtest(tests[i].name))
+		drmtest_subtest_block(tests[i].name)
 			tests[i].fn();
 	}
 
Signature · 1 line
1.8.3.2
#3 lore raw

Re: [PATCH 2/7] lib/drmtest: Add drmtest_subtest_block macro

Quoted 3 lines · Daniel Vetter

Doesn't do more than an if (drmtest_run_test(name)) right now, but as soon as we get a bit of infrastructure to handle test failures and skipping, this will get more interesting.

Just use drm_subtest("name") { }

drm_subtest_block() reads like a function and so one expects "block" to be a verb.
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
#4 lore raw

Re: [PATCH 2/7] lib/drmtest: Add drmtest_subtest_block macro

Quoted 9 lines · Chris Wilson
Quoted 3 lines · Daniel Vetter

Doesn't do more than an if (drmtest_run_test(name)) right now, but as soon as we get a bit of infrastructure to handle test failures and skipping, this will get more interesting.

Just use drm_subtest("name") { }

drm_subtest_block() reads like a function and so one expects "block" to be a verb.

The intention was to make clear that the macro expects a C code block afterwards. See the later patches for some of the fun I add ... I see that the _block suffix can be misread, but tbh I don't have any other ideas that might properly convey what this thing is. The 2nd best I could think of is do_subtest("name") similar to do {} while (). But that's not great either.
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#5 lore raw

Re: [PATCH 2/7] lib/drmtest: Add drmtest_subtest_block macro

Quoted 11 lines · Daniel Vetter
Quoted 9 lines · Chris Wilson
Quoted 3 lines · Daniel Vetter

Doesn't do more than an if (drmtest_run_test(name)) right now, but as soon as we get a bit of infrastructure to handle test failures and skipping, this will get more interesting.

Just use drm_subtest("name") { }

drm_subtest_block() reads like a function and so one expects "block" to be a verb.

Quoted 6 lines

The intention was to make clear that the macro expects a C code block afterwards. See the later patches for some of the fun I add ... I see that the _block suffix can be misread, but tbh I don't have any other ideas that might properly convey what this thing is. The 2nd best I could think of is do_subtest("name") similar to do {} while (). But that's not great either.

Ok, I've applied the following three bikesheds onto my tree:
- s/drmtest_run_subtest/__drmtest_run_subtest/ since that fuction is now internal to drmtest.c (but needs to be in the header due to the fancy macro).
- s/drmtest_subtest_block/drmtest/subtest/ ... see above.
- s/drmtest_/igt_/ just because (suggested by Chris on irc).

-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#6 lore raw

Re: [PATCH 2/7] lib/drmtest: Add drmtest_subtest_block macro

Quoted 19 lines · Daniel Vetter
Quoted 11 lines · Daniel Vetter
Quoted 9 lines · Chris Wilson
Quoted 3 lines · Daniel Vetter

Doesn't do more than an if (drmtest_run_test(name)) right now, but as soon as we get a bit of infrastructure to handle test failures and skipping, this will get more interesting.

Just use drm_subtest("name") { }

drm_subtest_block() reads like a function and so one expects "block" to be a verb.

Quoted 6 lines

The intention was to make clear that the macro expects a C code block afterwards. See the later patches for some of the fun I add ... I see that the _block suffix can be misread, but tbh I don't have any other ideas that might properly convey what this thing is. The 2nd best I could think of is do_subtest("name") similar to do {} while (). But that's not great either.

Quoted 6 lines

Ok, I've applied the following three bikesheds onto my tree:
- s/drmtest_run_subtest/__drmtest_run_subtest/ since that fuction is now internal to drmtest.c (but needs to be in the header due to the fancy macro).
- s/drmtest_subtest_block/drmtest/subtest/ ... see above.
- s/drmtest_/igt_/ just because (suggested by Chris on irc).

One more on top:
- s/return igt_retval()/igt_exit()/

I'll push this one the US has woken up an had a chance to comment. There's too much tree-wide sed and sed-like stuff in this series now. Latest patches pushed to my private repo.
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#7 lore raw

PATCH 3/7 lib/drmtest: skip/fail handling

In reply to Daniel Vetter

Exitcode handling in igt testcases has too ugly facets in combination with subtests:

- When individual subtest needed to be skipped for different reasons we need to painstakingly thread this information through the test to make sure that we still succeed if just one testcase worked (for running it with the simple automake test runner in igt). But it also needs to correctly report the skip exit value if only this one skipped testcase has been run (e.g. when run with piglit or in QA's test infrastructure).

- We'd prefer to easily skip (and also fail) subtests without hampering other subtests. Again threading the return value of each subtest through the code is cumbersome.

To simplify test case writing use longjmps to be able to get out of subcases easily. But since longjmps are funny things thug it all away into the newly added drmtest_subtest_block macro.

Note that if drmtest_skip is called outside of a subtest, but in a testcase with subtests all subsequent subtests will be automatically skipped.

---
 lib/drmtest.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 lib/drmtest.h | 10 +++++++-
 2 files changed, 84 insertions(+), 3 deletions(-)
lib/drmtest.c +75 -2
index cae07a2..767c8dc 100644
@@ -657,6 +657,9 @@ void drmtest_stop_signal_helper(void)
 /* subtests helpers */
 static bool list_subtests = false;
 static char *run_single_subtest = NULL;
+static bool in_subtest = false;
+static bool test_with_subtests = false;
+static bool skip_subtests_henceforth = false;
 
 void drmtest_subtest_init(int argc, char **argv)
 {
@@ -667,6 +670,8 @@ void drmtest_subtest_init(int argc, char **argv)
 		{NULL, 0, 0, 0,}
 	};
 
+	test_with_subtests = true;
+
 	/* supress getopt errors about unknown options */
 	opterr = 0;
 	/* restrict the option parsing to long option names to avoid collisions
@@ -695,16 +700,21 @@ out:
  */
 bool drmtest_run_subtest(const char *subtest_name)
 {
+	assert(in_subtest == false);
+
 	if (list_subtests) {
 		printf("%s\n", subtest_name);
 		return false;
 	}
 
+	if (skip_subtests_henceforth)
+		return false;
+
 	if (!run_single_subtest) {
-		return true;
+		return in_subtest = true;
 	} else {
 		if (strcmp(subtest_name, run_single_subtest) == 0)
-			return true;
+			return in_subtest = true;
 
 		return false;
 	}
@@ -715,6 +725,69 @@ bool drmtest_only_list_subtests(void)
 	return list_subtests;
 }
 
+static bool skipped_one = false;
+static bool succeeded_one = false;
+static bool failed_one = false;
+static int drmtest_exitcode;
+
+static void exit_subtest(void) __attribute__((noreturn));
+static void exit_subtest(void)
+{
+	in_subtest = false;
+	longjmp(drmtest_subtest_jmpbuf, 1);
+}
+
+void drmtest_skip(void)
+{
+	skipped_one = true;
+	if (in_subtest)
+		exit_subtest();
+	else if (test_with_subtests)
+		skip_subtests_henceforth = true;
+	else
+		exit(77);
+}
+
+void drmtest_success(void)
+{
+	succeeded_one = true;
+	if (in_subtest)
+		exit_subtest();
+}
+
+void drmtest_fail(int exitcode)
+{
+	assert(exitcode != 0 && exitcode != 77);
+
+	if (!failed_one)
+		drmtest_exitcode = exitcode;
+
+	failed_one = true;
+
+	if (in_subtest)
+		exit_subtest();
+	else {
+		assert(!test_with_subtests);
+		exit(exitcode);
+	}
+}
+
+int drmtest_retval(void)
+{
+	if (drmtest_only_list_subtests())
+		return 0;
+
+	/* Calling this without calling one of the above is a failure */
+	assert(skipped_one || succeeded_one || failed_one);
+
+	if (failed_one)
+		return drmtest_exitcode;
+	else if (succeeded_one)
+		return 0;
+	else
+		return 77;
+}
+
 static bool env_set(const char *env_var, bool default_value)
 {
 	char *val;
lib/drmtest.h +9 -1
index ada8e81..13e25bb 100644
@@ -32,6 +32,7 @@
 #include <errno.h>
 #include <stdbool.h>
 #include <cairo.h>
+#include <setjmp.h>
 
 #include "xf86drm.h"
 #include "xf86drmMode.h"
@@ -93,10 +94,17 @@ void drmtest_permute_array(void *array, unsigned size,
 void drmtest_progress(const char *header, uint64_t i, uint64_t total);
 
 /* subtest infrastructure */
+jmp_buf drmtest_subtest_jmpbuf;
 void drmtest_subtest_init(int argc, char **argv);
 bool drmtest_run_subtest(const char *subtest_name);
-#define drmtest_subtest_block(name) if (drmtest_run_subtest((name)))
+#define drmtest_subtest_block(name) for (; drmtest_run_subtest((name)) && \
+					 (setjmp(drmtest_subtest_jmpbuf) == 0); \
+					 drmtest_success())
 bool drmtest_only_list_subtests(void);
+void drmtest_skip(void);
+void drmtest_success(void);
+void drmtest_fail(int exitcode) __attribute__((noreturn));
+int drmtest_retval(void);
 
 /* helpers to automatically reduce test runtime in simulation */
 bool drmtest_run_in_simulation(void);
Signature · 1 line
1.8.3.2
#8 lore raw

PATCH 4/7 tests/gem_caching: convert to use drmtest retval infrastructure

In reply to Daniel Vetter
---
 tests/gem_caching.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)
tests/gem_caching.c +13 -8
index d67bbf6..259662f 100644
@@ -110,7 +110,6 @@ int main(int argc, char **argv)
 	int i, j;
 	uint8_t *cpu_ptr;
 	uint8_t *gtt_ptr;
-	bool skipped_all = true;
 
 	drmtest_subtest_init(argc, argv);
 	drmtest_skip_on_simulation();
@@ -145,9 +144,11 @@ int main(int argc, char **argv)
 	drmtest_init_aperture_trashers(bufmgr);
 	mappable_gtt_limit = gem_mappable_aperture_size();
 
-	if (drmtest_run_subtest("reads") && (flags & TEST_READ)) {
+	drmtest_subtest_block("reads") {
+		if (!(flags & TEST_READ))
+			drmtest_skip();
+
 		printf("checking partial reads\n");
-		skipped_all = false;
 
 		for (i = 0; i < ROUNDS; i++) {
 			uint8_t val0 = i;
@@ -173,9 +174,11 @@ int main(int argc, char **argv)
 		}
 	}
 
-	if (drmtest_run_subtest("writes") && (flags & TEST_WRITE)) {
+	drmtest_subtest_block("writes") {
+		if (!(flags & TEST_WRITE))
+			drmtest_skip();
+
 		printf("checking partial writes\n");
-		skipped_all = false;
 
 		for (i = 0; i < ROUNDS; i++) {
 			uint8_t val0 = i, val1;
@@ -223,9 +226,11 @@ int main(int argc, char **argv)
 		}
 	}
 
-	if (drmtest_run_subtest("read-writes") && (flags & TEST_BOTH) == TEST_BOTH) {
+	drmtest_subtest_block("read-writes") {
+		if (!((flags & TEST_BOTH) == TEST_BOTH))
+			drmtest_skip();
+
 		printf("checking partial writes after partial reads\n");
-		skipped_all = false;
 
 		for (i = 0; i < ROUNDS; i++) {
 			uint8_t val0 = i, val1, val2;
@@ -299,5 +304,5 @@ int main(int argc, char **argv)
 
 	close(fd);
 
-	return skipped_all ? 77 : 0;
+	return drmtest_retval();
 }
Signature · 1 line
1.8.3.2
#9 lore raw

PATCH 5/7 lib/drmtest: make signal process cleanup more robust

In reply to Daniel Vetter

If we skip a test and and fail somewhere the parent might die before the child. So add some cleanup to handle this case. Also make sure that the parent indeed waits for the child to die.

This is required to make the latest version of the piglit runner happy, it tends to wait for all zombies to disappear.

---
 lib/drmtest.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
lib/drmtest.c +12 -1
index 767c8dc..77e8002 100644
@@ -625,11 +625,18 @@ static void sig_handler(int i)
 	sig_stat++;
 }
 
+static void signal_helper_exit_handler(int sig)
+{
+	drmtest_stop_signal_helper();
+}
+
 void drmtest_fork_signal_helper(void)
 {
 	pid_t pid;
 	sighandler_t oldsig;
 
+	drmtest_install_exit_handler(signal_helper_exit_handler);
+
 	signal(SIGUSR1, sig_handler);
 	oldsig = signal(SIGQUIT, SIG_DFL);
 	pid = fork();
@@ -644,8 +651,12 @@ void drmtest_fork_signal_helper(void)
 
 void drmtest_stop_signal_helper(void)
 {
-	if (signal_helper != -1)
+	int exitcode;
+
+	if (signal_helper != -1) {
 		kill(signal_helper, SIGQUIT);
+		wait(&exitcode);
+	}
 
 	if (sig_stat)
 		fprintf(stdout, "signal handler called %llu times\n", sig_stat);
Signature · 1 line
1.8.3.2
#10 lore raw

PATCH 6/7 tests: use drmtest_skip() in caching ioctl helpers

In reply to Daniel Vetter

This way we can rip out all the skip handling from the test control flow, and additionally (by using drmtest_retval()) even get correct exit codes.

The only tricky part is that when we only want ot skip parts of a test (like for gem_pread and gem_pwrite) we need to split out those parts as subtests. But no addition of control-flow is required, the set/longjmp magic in the helpers all makes it happen.

Also we make extensive use of the behaviour of drmtest_skip to skip all subsequent subtests if it is called outside of a subtest. This allows us to re-flatten the control flow a lot.

---
 lib/drmtest.c                    |  20 ++--
 lib/drmtest.h                    |   4 +-
 tests/Makefile.am                |   4 +-
 tests/gem_caching.c              |   5 +-
 tests/gem_partial_pwrite_pread.c |  15 +--
 tests/gem_pread.c                |  50 +++++-----
 tests/gem_pread_after_blit.c     |   9 +-
 tests/gem_pwrite.c               |  48 +++++-----
 tests/gem_pwrite_pread.c         | 194 +++++++++++++++++++--------------------
 9 files changed, 178 insertions(+), 171 deletions(-)
lib/drmtest.c +14 -6
index 77e8002..7e3c1d8 100644
@@ -40,6 +40,7 @@
 #include <stdlib.h>
 #include <linux/kd.h>
 #include <unistd.h>
+#include <sys/wait.h>
 #include "drm_fourcc.h"
 
 #include "drmtest.h"
@@ -392,23 +393,26 @@ struct local_drm_i915_gem_caching {
 #define LOCAL_DRM_IOCTL_I915_GEM_GET_CACHEING \
 	DRM_IOWR(DRM_COMMAND_BASE + LOCAL_DRM_I915_GEM_GET_CACHEING, struct local_drm_i915_gem_caching)
 
-int gem_has_caching(int fd)
+void gem_check_caching(int fd)
 {
 	struct local_drm_i915_gem_caching arg;
 	int ret;
 
 	arg.handle = gem_create(fd, 4096);
-	if (arg.handle == 0)
-		return 0;
+	assert(arg.handle != 0);
 
 	arg.caching = 0;
 	ret = ioctl(fd, LOCAL_DRM_IOCTL_I915_GEM_SET_CACHEING, &arg);
 	gem_close(fd, arg.handle);
 
-	return ret == 0;
+	if (ret != 0) {
+		if (!drmtest_only_list_subtests())
+			printf("no set_caching support detected\n");
+		drmtest_skip();
+	}
 }
 
-int gem_set_caching(int fd, uint32_t handle, int caching)
+void gem_set_caching(int fd, uint32_t handle, int caching)
 {
 	struct local_drm_i915_gem_caching arg;
 	int ret;
@@ -416,7 +420,11 @@ int gem_set_caching(int fd, uint32_t handle, int caching)
 	arg.handle = handle;
 	arg.caching = caching;
 	ret = ioctl(fd, LOCAL_DRM_IOCTL_I915_GEM_SET_CACHEING, &arg);
-	return ret == 0 ? 0 : -errno;
+
+	if (ret != 0 && (errno == ENOTTY || errno == EINVAL))
+		drmtest_skip();
+	else
+		assert(ret == 0);
 }
 
 uint32_t gem_get_caching(int fd, uint32_t handle)
lib/drmtest.h +2 -2
index 13e25bb..624abb2 100644
@@ -54,8 +54,8 @@ bool gem_has_bsd(int fd);
 bool gem_has_blt(int fd);
 bool gem_has_vebox(int fd);
 int gem_get_num_rings(int fd);
-int gem_has_caching(int fd);
-int gem_set_caching(int fd, uint32_t handle, int caching);
+void gem_check_caching(int fd);
+void gem_set_caching(int fd, uint32_t handle, int caching);
 uint32_t gem_get_caching(int fd, uint32_t handle);
 uint32_t gem_flink(int fd, uint32_t handle);
 uint32_t gem_open(int fd, uint32_t name);
tests/Makefile.am +2 -2
index 8fff22c..f3475ad 100644
@@ -30,8 +30,10 @@ TESTS_progs_M = \
 	gem_linear_blits \
 	gem_mmap_gtt \
 	gem_partial_pwrite_pread \
+	gem_pread \
 	gem_pread_after_blit \
 	gem_prw_concurrent_blit \
+	gem_pwrite \
 	gem_pwrite_pread \
 	gem_ringfill \
 	gem_set_tiling_vs_blt \
@@ -73,8 +75,6 @@ TESTS_progs = \
 	gem_mmap_offset_exhaustion \
 	gem_pin \
 	gem_pipe_control_store_loop \
-	gem_pread \
-	gem_pwrite \
 	gem_readwrite \
 	gem_reg_read \
 	gem_reloc_overflow \
tests/gem_caching.c +1 -4
index 259662f..ed58c28 100644
@@ -118,10 +118,7 @@ int main(int argc, char **argv)
 
 	fd = drm_open_any();
 
-	if (!gem_has_caching(fd)) {
-		printf("no set_caching support detected\n");
-		return 77;
-	}
+	gem_check_caching(fd);
 
 	devid = intel_get_drm_devid(fd);
 	if (IS_GEN2(devid)) /* chipset only handles cached -> uncached */
tests/gem_partial_pwrite_pread.c +3 -12
index a27e584..f6e6e32 100644
@@ -257,17 +257,8 @@ static void do_tests(int cache_level, const char *suffix)
 {
 	char name[80];
 
-	if (cache_level != -1) {
-		switch (gem_set_caching(fd, scratch_bo->handle, cache_level)) {
-		case 0: break;
-		case -EINVAL:
-		case -ENOTTY:
-			return;
-		default:
-			assert(0);
-			return;
-		}
-	}
+	if (cache_level != -1)
+		gem_set_caching(fd, scratch_bo->handle, cache_level);
 
 	snprintf(name, sizeof(name), "reads%s", suffix);
 	drmtest_subtest_block(name)
@@ -315,5 +306,5 @@ int main(int argc, char **argv)
 
 	close(fd);
 
-	return 0;
+	return drmtest_retval();
 }
tests/gem_pread.c +27 -23

77 lines not on this page · raw message

tests/gem_pread_after_blit.c +5 -4
index 7375000..71dab34 100644
@@ -131,11 +131,12 @@ static void do_test(int fd, int cache_level,
 		    int loop)
 {
 	if (cache_level != -1) {
-		if (gem_set_caching(fd, tmp[0]->handle, cache_level) ||
-		    gem_set_caching(fd, tmp[1]->handle, cache_level))
-			return;
+		gem_set_caching(fd, tmp[0]->handle, cache_level);
+		gem_set_caching(fd, tmp[1]->handle, cache_level);
 	}
 
+	printf("meh");
+
 	do {
 		/* First, do a full-buffer read after blitting */
 		intel_copy_bo(batch, tmp[0], src[0], width, height);
@@ -235,5 +236,5 @@ main(int argc, char **argv)
 
 	close(fd);
 
-	return 0;
+	return drmtest_retval();
 }
tests/gem_pwrite.c +27 -21

74 lines not on this page · raw message

tests/gem_pwrite_pread.c +97 -97

216 lines not on this page · raw message

Signature · 6 lines
1.8.3.2

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
#11 lore raw

PATCH 7/7 tests: use drmtest_skip to check for rings

In reply to Daniel Vetter

To simplify things add a set of gem_check_<ring> functions which take care of this. Since I've opted for static inlines drmtest.h grew a few more header includes which was a neat opportunity to dump a few redundant #defines.

This kills all the skipped_all hand-rolled logic we have.

---
 demos/intel_sprite_on.c            |  2 --
 lib/drmtest.h                      | 33 ++++++++++++++++++++++++++++++++-
 tests/gem_bad_length.c             |  2 --
 tests/gem_cs_tlb.c                 | 12 ++++--------
 tests/gem_ctx_bad_exec.c           |  1 -
 tests/gem_dummy_reloc_loop.c       |  8 ++++----
 tests/gem_exec_big.c               |  1 -
 tests/gem_exec_lut_handle.c        |  1 -
 tests/gem_exec_nop.c               | 11 ++++-------
 tests/gem_lut_handle.c             |  1 -
 tests/gem_pwrite.c                 |  1 -
 tests/gem_write_read_ring_switch.c |  6 +++---
 tests/prime_self_import.c          |  2 --
 tests/testdisplay.c                |  2 --
 14 files changed, 47 insertions(+), 36 deletions(-)
demos/intel_sprite_on.c +0 -2
index 783f9af..5c380c1 100644
@@ -51,8 +51,6 @@
 #include "drm_fourcc.h"
 #endif
 
-#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
-
 /*
  * Mode setting with the kernel interfaces is a bit of a chore.
  * First you have to find the connector in question and make sure the
lib/drmtest.h +32 -1
index 624abb2..b687411 100644
@@ -37,6 +37,8 @@
 #include "xf86drm.h"
 #include "xf86drmMode.h"
 #include "intel_batchbuffer.h"
+#include "intel_chipset.h"
+#include "intel_gpu_tools.h"
 
 drm_intel_bo * gem_handle_to_libdrm_bo(drm_intel_bufmgr *bufmgr, int fd,
 				       const char *name, uint32_t handle);
@@ -54,7 +56,7 @@ bool gem_has_bsd(int fd);
 bool gem_has_blt(int fd);
 bool gem_has_vebox(int fd);
 int gem_get_num_rings(int fd);
-void gem_check_caching(int fd);
+
 void gem_set_caching(int fd, uint32_t handle, int caching);
 uint32_t gem_get_caching(int fd, uint32_t handle);
 uint32_t gem_flink(int fd, uint32_t handle);
@@ -106,6 +108,35 @@ void drmtest_success(void);
 void drmtest_fail(int exitcode) __attribute__((noreturn));
 int drmtest_retval(void);
 
+/* check functions which auto-skip tests by calling drmtest_skip() */
+void gem_check_caching(int fd);
+static inline bool gem_check_vebox(int fd)
+{
+	if (gem_has_vebox(fd))
+		return true;
+
+	drmtest_skip();
+	return false;
+}
+
+static inline bool gem_check_bsd(int fd)
+{
+	if (HAS_BSD_RING(intel_get_drm_devid(fd)))
+		return true;
+
+	drmtest_skip();
+	return false;
+}
+
+static inline bool gem_check_blt(int fd)
+{
+	if (HAS_BLT_RING(intel_get_drm_devid(fd)))
+		return true;
+
+	drmtest_skip();
+	return false;
+}
+
 /* helpers to automatically reduce test runtime in simulation */
 bool drmtest_run_in_simulation(void);
 #define SLOW_QUICK(slow,quick) (drmtest_run_in_simulation() ? (quick) : (slow))
tests/gem_bad_length.c +0 -2
index bb8b6b8..2d5f977 100644
@@ -40,8 +40,6 @@
 #include "i915_drm.h"
 #include "drmtest.h"
 
-#define MI_BATCH_BUFFER_END	(0xA<<23)
-
 /*
  * Testcase: Minmal bo_create and batchbuffer exec
  *
tests/gem_cs_tlb.c +4 -8
index 081b6f2..0378fdb 100644
@@ -55,7 +55,6 @@
 
 #define LOCAL_I915_EXEC_VEBOX (4<<0)
 #define BATCH_SIZE (1024*1024)
-bool skipped_all = true;
 
 static int exec(int fd, uint32_t handle, int split,
 		uint64_t *gtt_ofs, unsigned ring_id)
@@ -104,7 +103,6 @@ static void run_on_ring(int fd, unsigned ring_id, const char *ring_name)
 	int i;
 
 	sprintf(buf, "testing %s cs tlb coherency: ", ring_name);
-	skipped_all = false;
 
 	/* Shut up gcc, too stupid. */
 	batch_ptr_old = NULL;
@@ -149,13 +147,11 @@ static void run_on_ring(int fd, unsigned ring_id, const char *ring_name)
 int main(int argc, char **argv)
 {
 	int fd;
-	uint32_t devid;
 
 	drmtest_subtest_init(argc, argv);
 	drmtest_skip_on_simulation();
 
 	fd = drm_open_any();
-	devid = intel_get_drm_devid(fd);
 
 	if (!drmtest_only_list_subtests()) {
 		/* This test is very sensitive to residual gtt_mm noise from previous
@@ -168,18 +164,18 @@ int main(int argc, char **argv)
 		run_on_ring(fd, I915_EXEC_RENDER, "render");
 
 	drmtest_subtest_block("bsd")
-		if (HAS_BSD_RING(devid))
+		if (gem_check_bsd(fd))
 			run_on_ring(fd, I915_EXEC_BSD, "bsd");
 
 	drmtest_subtest_block("blt")
-		if (HAS_BLT_RING(devid))
+		if (gem_check_blt(fd))
 			run_on_ring(fd, I915_EXEC_BLT, "blt");
 
 	drmtest_subtest_block("vebox")
-		if (gem_has_vebox(fd))
+		if (gem_check_vebox(fd))
 			run_on_ring(fd, LOCAL_I915_EXEC_VEBOX, "vebox");
 
 	close(fd);
 
-	return skipped_all ? 77 : 0;
+	return drmtest_retval();
 }
tests/gem_ctx_bad_exec.c +0 -1
index f6463ac..b7e5db0 100644
@@ -104,7 +104,6 @@ static int exec(int fd, uint32_t handle, int ring, int ctx_id)
 	return ret;
 }
 
-#define MI_BATCH_BUFFER_END	(0xA<<23)
 int main(int argc, char *argv[])
 {
 	uint32_t handle;
tests/gem_dummy_reloc_loop.c +4 -4
index 7cffbbe..2d0a245 100644
@@ -167,7 +167,7 @@ int main(int argc, char **argv)
 	}
 
 	drmtest_subtest_block("bsd") {
-		if (HAS_BSD_RING(devid)) {
+		if (gem_check_bsd(fd)) {
 			sleep(2);
 			printf("running dummy loop on bsd\n");
 			dummy_reloc_loop(I915_EXEC_BSD);
@@ -176,7 +176,7 @@ int main(int argc, char **argv)
 	}
 
 	drmtest_subtest_block("blt") {
-		if (HAS_BLT_RING(devid)) {
+		if (gem_check_blt(fd)) {
 			sleep(2);
 			printf("running dummy loop on blt\n");
 			dummy_reloc_loop(I915_EXEC_BLT);
@@ -185,7 +185,7 @@ int main(int argc, char **argv)
 	}
 
 	drmtest_subtest_block("vebox") {
-		if (gem_has_vebox(fd)) {
+		if (gem_check_vebox(fd)) {
 			sleep(2);
 			printf("running dummy loop on vebox\n");
 			dummy_reloc_loop(LOCAL_I915_EXEC_VEBOX);
@@ -208,5 +208,5 @@ int main(int argc, char **argv)
 
 	close(fd);
 
-	return 0;
+	return drmtest_retval();
 }
tests/gem_exec_big.c +0 -1
index 9dddfac..b67aba1 100644
@@ -49,7 +49,6 @@
 #include "i915_drm.h"
 #include "drmtest.h"
 
-#define MI_BATCH_BUFFER_END	(0xA<<23)
 #define BATCH_SIZE		(1024*1024)
 
 static int exec(int fd, uint32_t handle, uint32_t reloc_ofs)
tests/gem_exec_lut_handle.c +0 -1
index 54ed3dd..8ea889a 100644
@@ -40,7 +40,6 @@
 #include "i915_drm.h"
 #include "drmtest.h"
 
-#define MI_BATCH_BUFFER_END	(0xA<<23)
 #define BATCH_SIZE		(1024*1024)
 
 #define LOCAL_I915_EXEC_NO_RELOC (1<<11)
tests/gem_exec_nop.c +4 -7
index ca1f580..a821440 100644
@@ -44,7 +44,6 @@
 #include "intel_gpu_tools.h"
 
 #define LOCAL_I915_EXEC_VEBOX (4<<0)
-bool skipped_all = true;
 
 static double elapsed(const struct timeval *start,
 		      const struct timeval *end,
@@ -94,8 +93,6 @@ static void loop(int fd, uint32_t handle, unsigned ring_id, const char *ring_nam
 {
 	int count;
 
-	skipped_all = false;
-
 	for (count = 1; count <= SLOW_QUICK(1<<17, 1<<4); count <<= 1) {
 		struct timeval start, end;
 
@@ -128,20 +125,20 @@ int main(int argc, char **argv)
 		loop(fd, handle, I915_EXEC_RENDER, "render");
 
 	drmtest_subtest_block("bsd")
-		if (HAS_BSD_RING(devid))
+		if (gem_check_blt(fd))
 			loop(fd, handle, I915_EXEC_BSD, "bsd");
 
 	drmtest_subtest_block("blt")
-		if (HAS_BLT_RING(devid))
+		if (gem_check_blt(fd))
 			loop(fd, handle, I915_EXEC_BLT, "blt");
 
 	drmtest_subtest_block("vebox")
-		if (gem_has_vebox(fd))
+		if (gem_check_vebox(fd))
 			loop(fd, handle, LOCAL_I915_EXEC_VEBOX, "vebox");
 
 	gem_close(fd, handle);
 
 	close(fd);
 
-	return skipped_all ? 77 : 0;
+	return drmtest_retval();
 }
tests/gem_lut_handle.c +0 -1
index f3e5734..1b7974b 100644
@@ -40,7 +40,6 @@
 #include "i915_drm.h"
 #include "drmtest.h"
 
-#define MI_BATCH_BUFFER_END	(0xA<<23)
 #define BATCH_SIZE		(1024*1024)
 
 #define LOCAL_I915_EXEC_HANDLE_LUT (1<<12)
tests/gem_pwrite.c +0 -1
index bd9d9cd..f6a0ffc 100644
@@ -49,7 +49,6 @@
 #define BLT_WRITE_RGB		(1<<20)
 #define BLT_SRC_TILED		(1<<15)
 #define BLT_DST_TILED		(1<<11)
-#define MI_BATCH_BUFFER_END	(0xA<<23)
 
 static void do_gem_write(int fd, uint32_t handle, void *buf, int len, int loops)
 {
tests/gem_write_read_ring_switch.c +3 -3
index 211b530..bd50520 100644
@@ -151,11 +151,11 @@ static int has_ring(int ring)
 {
 	switch (ring) {
 	case I915_EXEC_RENDER: /* test only makes sense with separate blitter */
-		return HAS_BLT_RING(intel_get_drm_devid(fd));
+		return gem_check_blt(fd);
 	case I915_EXEC_BSD:
-		return HAS_BSD_RING(intel_get_drm_devid(fd));
+		return gem_check_bsd(fd);
 	case LOCAL_I915_EXEC_VEBOX:
-		return gem_has_vebox(fd);
+		return gem_check_vebox(fd);
 	default:
 		return 0;
 	}
tests/prime_self_import.c +0 -2
index 1bd0bb5..8b0a198 100644
@@ -51,8 +51,6 @@
 
 #define BO_SIZE (16*1024)
 
-#define ARRAY_SIZE(x)	(sizeof(x) / sizeof((x)[0]))
-
 static char counter;
 volatile int pls_die = 0;
 
tests/testdisplay.c +0 -2
index 3781612..06dd0e3 100644
@@ -86,8 +86,6 @@ int plane_width, plane_height;
 static const uint32_t SPRITE_COLOR_KEY = 0x00aaaaaa;
 uint32_t *fb_ptr;
 
-#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
-
 /*
  * Mode setting with the kernel interfaces is a bit of a chore.
  * First you have to find the connector in question and make sure the
Signature · 1 line
1.8.3.2
#12 lore raw
In reply to Daniel Vetter
Quoted 7 lines · Daniel Vetter

Hi all,

So I've grown fed-up with our add-hoc (and pretty much always buggy) return value tracking for testcases with subtests. Furthermore sprinkling testcases with tons of if (kernel_has_some_optional_feature) return 77; isn't really helping test case readability.

Quoted 6 lines

So I've gone ahead and implement some magic stuff using setjmp/longjmp and a few macros. On top of that a few exemplary conversions of existing testcases.

Comments highly welcome.

Cheers, Daniel

Just noticed that this already doesn't apply, so I've pushed a rebased version to

http://cgit.freedesktop.org/~danvet/intel-gpu-tools/log/?h=retval-infrastructure

That one also contains one hunk I've failed to git add.

Cheers, Daniel

Quoted 61 lines

Daniel Vetter (7):
tests: s/cacheing/caching
lib/drmtest: Add drmtest_subtest_block macro lib/drmtest: skip/fail handling
tests/gem_caching: convert to use drmtest retval infrastructure lib/drmtest: make signal process cleanup more robust
tests: use drmtest_skip() in caching ioctl helpers
tests: use drmtest_skip to check for rings

 demos/intel_sprite_on.c                |   2 -
 lib/drmtest.c                          | 134 ++++++++++++---
 lib/drmtest.h                          |  46 ++++-
 tests/.gitignore                       |   2 +-
 tests/Makefile.am                      |   6 +-
 tests/gem_bad_length.c                 |   2 -
 tests/gem_basic.c                      |   6 +-
 tests/gem_cacheing.c                   | 303 --------------------------------
 tests/gem_caching.c                    | 305 +++++++++++++++++++++++++++++++++
 tests/gem_cpu_concurrent_blit.c        |  12 +-
 tests/gem_cs_tlb.c                     |  20 +--
 tests/gem_ctx_bad_exec.c               |   1 -
 tests/gem_dummy_reloc_loop.c           |  18 +-
 tests/gem_exec_bad_domains.c           |  10 +-
 tests/gem_exec_big.c                   |   1 -
 tests/gem_exec_faulting_reloc.c        |   4 +-
 tests/gem_exec_lut_handle.c            |   1 -
 tests/gem_exec_nop.c                   |  19 +-
 tests/gem_fence_thrash.c               |  14 +-
 tests/gem_flink.c                      |  10 +-
 tests/gem_flink_race.c                 |   4 +-
 tests/gem_gtt_concurrent_blit.c        |  12 +-
 tests/gem_linear_blits.c               |   4 +-
 tests/gem_lut_handle.c                 |   1 -
 tests/gem_mmap_gtt.c                   |  14 +-
 tests/gem_partial_pwrite_pread.c       |  21 +--
 tests/gem_pread.c                      |  50 +++---
 tests/gem_pread_after_blit.c           |  25 +--
 tests/gem_prw_concurrent_blit.c        |  12 +-
 tests/gem_pwrite.c                     |  49 +++---
 tests/gem_pwrite_pread.c               | 194 ++++++++++-----------
 tests/gem_ringfill.c                   |   8 +-
 tests/gem_set_tiling_vs_blt.c          |   6 +-
 tests/gem_suspend.c                    |   4 +-
 tests/gem_tiled_blits.c                |   4 +-
 tests/gem_tiled_partial_pwrite_pread.c |   6 +-
 tests/gem_write_read_ring_switch.c     |  15 +-
 tests/kms_flip.c                       |   4 +-
 tests/kms_render.c                     |   2 +-
 tests/prime_nv_api.c                   |   2 +-
 tests/prime_nv_pcopy.c                 |  17 +-
 tests/prime_nv_test.c                  |   2 +-
 tests/prime_self_import.c              |   4 +-
 tests/testdisplay.c                    |   2 -
 44 files changed, 749 insertions(+), 629 deletions(-)
 delete mode 100644 tests/gem_cacheing.c
 create mode 100644 tests/gem_caching.c
Signature · 1 line
1.8.3.2
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#13 lore raw
Quoted 13 lines · Daniel Vetter
Quoted 12 lines · Daniel Vetter

Hi all,

So I've grown fed-up with our add-hoc (and pretty much always buggy) return value tracking for testcases with subtests. Furthermore sprinkling testcases with tons of if (kernel_has_some_optional_feature) return 77; isn't really helping test case readability.

So I've gone ahead and implement some magic stuff using setjmp/longjmp and a few macros. On top of that a few exemplary conversions of existing testcases.

Comments highly welcome.

Quoted 8 lines
Quoted 1 line

Cheers, Daniel

Just noticed that this already doesn't apply, so I've pushed a rebased version to

http://cgit.freedesktop.org/~danvet/intel-gpu-tools/log/?h=retval-infrastructure

That one also contains one hunk I've failed to git add.

One more thing I've forgotten to mention is that I want to add a drmtest_assert macro on top of this which would replace allmost all usage of assert in lib/drmtest and tests/*. With a few useful printks sprinkled over drmtest_run_subtest and the drmtest_(skip|success|fail) functions we could dump per-subtest results even when running with the legacy igt automake testrunner. And with that we could also make sure that we run all subtests and don't just fall over after the first one completed.

Cheers, Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch