quiet-command = $(if $(V),$1,$(if $(2),@printf "  %-7s %s\n" $2 $3 && $1, @$1))
 
+# $1 = test name, $2 = cmd, $3 = desc
+run-test = $(call quiet-command, timeout $(TIMEOUT) $2 > $1.out,"TEST",$3)
+
+# $1 = test name, $2 = reference
+diff-out = $(call quiet-command, diff -u $1.out $2 | head -n 10,"DIFF","$1.out with $2")
+
+# $1 = test name, $2 = reason
+skip-test = @printf "  SKIPPED %s on $(TARGET_NAME) because %s\n" $1 $2
+
 # Tests we are building
 TESTS=
 
 RUN_TESTS+=$(EXTRA_RUNS)
 
 run-%: %
-       $(call quiet-command, \
-               timeout $(TIMEOUT) $(QEMU) $< > $<.out, \
-               "TEST", "$< on $(TARGET_NAME)")
+       $(call run-test, $<, $(QEMU) $<, "$< on $(TARGET_NAME)")
 
 .PHONY: run
 run: $(RUN_TESTS)
 
 fcvt: LDFLAGS+=-lm
 
 run-fcvt: fcvt
-       $(call quiet-command, \
-               $(QEMU) $< > fcvt.out && \
-               diff -u $(AARCH64_SRC)/fcvt.ref fcvt.out, \
-               "TEST", "$< (default) on $(TARGET_NAME)")
+       $(call run-test,$<,$(QEMU) $<, "$< on $(TARGET_NAME)")
+       $(call diff-out,$<,$(AARCH64_SRC)/fcvt.ref)
 
 # fcvt: CFLAGS+=-march=armv8.2-a+fp16 -mfpu=neon-fp-armv8
 
 run-fcvt: fcvt
-       $(call quiet-command, \
-               $(QEMU) $< > fcvt.out && \
-               diff -u $(ARM_SRC)/fcvt.ref fcvt.out, \
-               "TEST", "$< (default) on $(TARGET_NAME)")
+       $(call run-test,fcvt,$(QEMU) $<,"$< on $(TARGET_NAME)")
+       $(call diff-out,fcvt,$(ARM_SRC)/fcvt.ref)
 endif
 
 # On ARM Linux only supports 4k pages
 
 
 # Specialist test runners
 run-runcom: runcom pi_10.com
-       $(call quiet-command, $(QEMU) ./runcom $(I386_SRC)/pi_10.com > runcom.out, "TEST", "$< on $(TARGET_NAME)")
+       $(call run-test,$<,$(QEMU) ./runcom $(I386_SRC)/pi_10.com,"$< on $(TARGET_NAME)")
 
 ifeq ($(SPEED), slow)
 
 
 run-test-i386-fprem: TIMEOUT=60
 run-test-i386-fprem: test-i386-fprem
-       $(call quiet-command, \
-               $(QEMU) $< > $<.out && \
-               diff -u $(I386_SRC)/$<.ref $<.out, \
-               "TEST", "$< (default) on $(TARGET_NAME)")
+       $(call run-test,test-i386-fprem, $(QEMU) $<,"$< on $(TARGET_NAME)")
+       $(call diff-out,test-i386-fprem, $(I386_SRC)/$<.ref)
 else
 run-test-i386-fprem: test-i386-fprem
-       $(call quiet-command, /bin/true, "SLOW TEST", "$< SKIPPED on $(TARGET_NAME)")
+       $(call skip-test, $<, "SLOW")
 endif
 
 # On i386 and x86_64 Linux only supports 4k pages (large pages are a different hack)
 
 
 # default case (host page size)
 run-test-mmap: test-mmap
-       $(call quiet-command, $(QEMU) $< > test-mmap.out, "TEST", \
+       $(call run-test, test-mmap, $(QEMU) $<, \
                "$< (default) on $(TARGET_NAME)")
 
 # additional page sizes (defined by each architecture adding to EXTRA_RUNS)
 run-test-mmap-%: test-mmap
-       $(call quiet-command, $(QEMU) -p $* $< > test-mmap-$*.out, "TEST", \
+       $(call run-test, test-mmap-$*, $(QEMU) -p $* $<,\
                "$< ($* byte pages) on $(TARGET_NAME)")