tests: add igt_subtest_f for snprintf'ing testnames
authorDaniel Vetter <daniel.vetter@ffwll.ch>
Wed, 14 Aug 2013 11:47:47 +0000 (13:47 +0200)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Wed, 14 Aug 2013 11:47:47 +0000 (13:47 +0200)
Useful when stitching together combinatorial testnames.

v2:
- ## rules are just fun. We need 2 indirections to actually get
  __LINE__ to properly expand.
- Kill stray ; which botched the logic.

Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
lib/drmtest.h
tests/gem_partial_pwrite_pread.c
tests/gem_write_read_ring_switch.c

index d9a11e1..440e27e 100644 (file)
@@ -100,6 +100,17 @@ void igt_progress(const char *header, uint64_t i, uint64_t total);
 jmp_buf igt_subtest_jmpbuf;
 void igt_subtest_init(int argc, char **argv);
 bool __igt_run_subtest(const char *subtest_name);
+#define igt_tokencat2(x, y) x ## y
+#define igt_tokencat(x, y) igt_tokencat2(x, y)
+#define __igt_subtest_f(tmp, format, args...) \
+       for (char tmp [256]; \
+            snprintf( tmp , sizeof( tmp ), \
+                     format, args), \
+            __igt_run_subtest( tmp ) && \
+            (setjmp(igt_subtest_jmpbuf) == 0); \
+            igt_success())
+#define igt_subtest_f(f, a...) \
+       __igt_subtest_f(igt_tokencat(__tmpchar, __LINE__), f, a)
 #define igt_subtest(name) for (; __igt_run_subtest((name)) && \
                                   (setjmp(igt_subtest_jmpbuf) == 0); \
                                   igt_success())
index ce2f1c8..814c552 100644 (file)
@@ -254,21 +254,16 @@ static void test_partial_read_writes(void)
 
 static void do_tests(int cache_level, const char *suffix)
 {
-       char name[80];
-
        if (cache_level != -1)
                gem_set_caching(fd, scratch_bo->handle, cache_level);
 
-       snprintf(name, sizeof(name), "reads%s", suffix);
-       igt_subtest(name)
+       igt_subtest_f("reads%s", suffix)
                test_partial_reads();
 
-       snprintf(name, sizeof(name), "writes%s", suffix);
-       igt_subtest(name)
+       igt_subtest_f("write%s", suffix)
                test_partial_writes();
 
-       snprintf(name, sizeof(name), "writes-after-reads%s", suffix);
-       igt_subtest(name)
+       igt_subtest_f("writes-after-reads%s", suffix)
                test_partial_read_writes();
 }
 
index 21eef64..b7efac3 100644 (file)
@@ -56,7 +56,7 @@ int fd;
  */
 
 #define COLOR 0xffffffff
-static void run_test(int ring, const char *testname)
+static void run_test(int ring)
 {
        uint32_t *ptr;
        int i;
@@ -66,8 +66,6 @@ static void run_test(int ring, const char *testname)
        if (ring == I915_EXEC_RENDER)
                gem_require_ring(fd, I915_EXEC_BLT);
 
-       printf("running subtest %s\n", testname);
-
        target_bo = drm_intel_bo_alloc(bufmgr, "target bo", 4096, 4096);
        if (!target_bo) {
                fprintf(stderr, "failed to alloc target buffer\n");
@@ -194,15 +192,13 @@ int main(int argc, char **argv)
 
        for (i = 0; i < ARRAY_SIZE(tests); i++) {
                igt_subtest(tests[i].name)
-                       run_test(tests[i].ring, tests[i].name);
+                       run_test(tests[i].ring);
        }
 
        igt_fork_signal_helper();
        for (i = 0; i < ARRAY_SIZE(tests); i++) {
-               char name[180];
-               snprintf(name, sizeof(name), "%s-interruptible", tests[i].name);
-               igt_subtest(name)
-                       run_test(tests[i].ring, name);
+               igt_subtest_f("%s-interruptible", tests[i].name)
+                       run_test(tests[i].ring);
        }
        igt_stop_signal_helper();