all: $(TEST_GEN_PROGS) $(TEST_GEN_PROGS_EXTENDED) $(TEST_GEN_FILES)
 
 .ONESHELL:
+define RUN_TEST_PRINT_RESULT
+       echo "selftests: $$BASENAME_TEST";      \
+       echo "========================================";        \
+       if [ ! -x $$TEST ]; then        \
+               echo "selftests: Warning: file $$BASENAME_TEST is not executable, correct this.";\
+               echo "not ok 1..$$test_num selftests: $$BASENAME_TEST [FAIL]"; \
+       else                                    \
+               cd `dirname $$TEST` > /dev/null; \
+               if [ "X$(summary)" != "X" ]; then       \
+                       (./$$BASENAME_TEST > /tmp/$$BASENAME_TEST 2>&1 && \
+                       echo "ok 1..$$test_num selftests: $$BASENAME_TEST [PASS]") || \
+                       (if [ $$? -eq $$skip ]; then    \
+                               echo "not ok 1..$$test_num selftests:  $$BASENAME_TEST [SKIP]";                         \
+                       else echo "not ok 1..$$test_num selftests:  $$BASENAME_TEST [FAIL]";                                    \
+                       fi;)                    \
+               else                            \
+                       (./$$BASENAME_TEST &&   \
+                       echo "ok 1..$$test_num selftests: $$BASENAME_TEST [PASS]") ||                                           \
+                       (if [ $$? -eq $$skip ]; then \
+                               echo "not ok 1..$$test_num selftests:  $$BASENAME_TEST [SKIP]"; \
+                       else echo "not ok 1..$$test_num selftests:  $$BASENAME_TEST [FAIL]";                            \
+                       fi;)            \
+               fi;                             \
+               cd - > /dev/null;               \
+       fi;
+endef
+
 define RUN_TESTS
        @export KSFT_TAP_LEVEL=`echo 1`;                \
        test_num=`echo 0`;                              \
        for TEST in $(1); do                            \
                BASENAME_TEST=`basename $$TEST`;        \
                test_num=`echo $$test_num+1 | bc`;      \
-               echo "selftests: $$BASENAME_TEST";      \
-               echo "========================================";        \
-               if [ ! -x $$TEST ]; then        \
-                       echo "selftests: Warning: file $$BASENAME_TEST is not executable, correct this.";\
-                       echo "not ok 1..$$test_num selftests: $$BASENAME_TEST [FAIL]"; \
-               else                                    \
-                       cd `dirname $$TEST` > /dev/null; \
-                       if [ "X$(summary)" != "X" ]; then       \
-                               (./$$BASENAME_TEST > /tmp/$$BASENAME_TEST 2>&1 && \
-                               echo "ok 1..$$test_num selftests: $$BASENAME_TEST [PASS]") || \
-                               (if [ $$? -eq $$skip ]; then    \
-                                       echo "not ok 1..$$test_num selftests:  $$BASENAME_TEST [SKIP]";                         \
-                               else echo "not ok 1..$$test_num selftests:  $$BASENAME_TEST [FAIL]";                                    \
-                               fi;)                    \
-                       else                            \
-                               (./$$BASENAME_TEST &&   \
-                               echo "ok 1..$$test_num selftests: $$BASENAME_TEST [PASS]") ||                                           \
-                               (if [ $$? -eq $$skip ]; then \
-                                       echo "not ok 1..$$test_num selftests:  $$BASENAME_TEST [SKIP]"; \
-                               else echo "not ok 1..$$test_num selftests:  $$BASENAME_TEST [FAIL]";                            \
-                               fi;)            \
-                       fi;                             \
-                       cd - > /dev/null;               \
-               fi;                                     \
+               $(call RUN_TEST_PRINT_RESULT,$(TEST),$(BASENAME_TEST),$(test_num),$(skip))                                              \
        done;
 endef