From 45e1b47b26afd356f6caca839704f6e97666e059 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Sat, 23 Mar 2019 18:02:26 +0100 Subject: [PATCH 1/3] Makefile.include: declare 'test' PHONY --- Makefile.include | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile.include b/Makefile.include index 9b5fe11cc3..74cd9dd089 100644 --- a/Makefile.include +++ b/Makefile.include @@ -569,6 +569,7 @@ reset: $(call check_cmd,$(RESET),Reset program) $(RESET) $(RESET_FLAGS) +.PHONY: test TESTS ?= $(foreach file,$(wildcard $(APPDIR)/tests/*),\ $(shell test -f $(file) -a -x $(file) && echo $(file))) test: $(TEST_DEPS) From ec4d83727a8aa68eb83a8ac7a600e75fdb48a778 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Sat, 23 Mar 2019 18:03:44 +0100 Subject: [PATCH 2/3] Makefile.include: add a 'test/available' target This allows querying the build system if there are test available. Before, one should rely on 'info-debug-variable-TESTS' to print the list of test files. But was not reliable as sometime the build system printed messages anyway. BOARD=esp32-wroom-32 make --silent --no-print-directory \ -C examples/hello-world/ info-debug-variable-TESTS ESP32_SDK_DIR should be defined as /path/to/esp-idf directory ESP32_SDK_DIR is set by default to /opt/esp/esp-idf # empty line here Now the return code can be trusted. --- Makefile.include | 6 +++++- tests/README.md | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Makefile.include b/Makefile.include index 74cd9dd089..59ccb38dc6 100644 --- a/Makefile.include +++ b/Makefile.include @@ -569,7 +569,7 @@ reset: $(call check_cmd,$(RESET),Reset program) $(RESET) $(RESET_FLAGS) -.PHONY: test +.PHONY: test test/available TESTS ?= $(foreach file,$(wildcard $(APPDIR)/tests/*),\ $(shell test -f $(file) -a -x $(file) && echo $(file))) test: $(TEST_DEPS) @@ -577,6 +577,10 @@ test: $(TEST_DEPS) $$t || exit 1; \ done +test/available: + $(Q)test -n "$(strip $(TESTS))" + + # Default OBJDUMPFLAGS for platforms which do not specify it: OBJDUMPFLAGS ?= -S -D -h diff --git a/tests/README.md b/tests/README.md index a760cd1769..e0e3b1f5f9 100644 --- a/tests/README.md +++ b/tests/README.md @@ -20,3 +20,10 @@ testing. From the test application directory run: BOARD= make flash test + + +An automated way of knowing if a test is available is to execute the +'test/available' target from the test application directory. +It executes without error if tests run by 'make test' are present. + + make test/available From 87a1d086029c67eb9c9c14028f28d0b756f5f8db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Harter?= Date: Sat, 23 Mar 2019 18:05:18 +0100 Subject: [PATCH 3/3] compile_and_test_for_board: use 'test/available' to detect test Use the new 'test/available' target to detect if there are tests. This prevents issues where calling make would print unrelated debug messages that would be taken as an output. The targets executed to check if there are tests can be set with '--test-available-targets'. --- .../compile_and_test_for_board.py | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/dist/tools/compile_and_test_for_board/compile_and_test_for_board.py b/dist/tools/compile_and_test_for_board/compile_and_test_for_board.py index 1a48160a29..a22d799de9 100755 --- a/dist/tools/compile_and_test_for_board/compile_and_test_for_board.py +++ b/dist/tools/compile_and_test_for_board/compile_and_test_for_board.py @@ -39,6 +39,7 @@ usage: compile_and_test_for_board.py [-h] [--applications APPLICATIONS] [--incremental] [--clean-after] [--compile-targets COMPILE_TARGETS] [--test-targets TEST_TARGETS] + [--test-available-targets TEST_AVAILABLE_TARGETS] [--jobs JOBS] riot_directory board [result_directory] @@ -67,6 +68,9 @@ optional arguments: List of make targets to compile (default: clean all) --test-targets TEST_TARGETS List of make targets to run test (default: test) + --test-available-targets TEST_AVAILABLE_TARGETS + List of make targets to know if a test is present + (default: test/available) --jobs JOBS, -j JOBS Parallel building (0 means not limit, like '--jobs') (default: None) ``` @@ -201,6 +205,7 @@ class RIOTApplication(): COMPILE_TARGETS = ('clean', 'all',) TEST_TARGETS = ('test',) + TEST_AVAILABLE_TARGETS = ('test/available',) def __init__(self, board, riotdir, appdir, resultdir): self.board = board @@ -220,13 +225,14 @@ class RIOTApplication(): def has_test(self): """Detect if the application has tests. - Use '--silent' to disable the message from packages: - - make[1]: Nothing to be done for 'Makefile.include' + Check TEST_AVAILABLE_TARGETS execute without error. """ - tests = self.make(['--silent', 'info-debug-variable-TESTS'], - log_error=True).strip() - return bool(tests) + try: + self.make(self.TEST_AVAILABLE_TARGETS) + except subprocess.CalledProcessError: + return False + else: + return True def board_is_supported(self): """Return if current board is supported.""" @@ -573,6 +579,9 @@ PARSER.add_argument('--compile-targets', type=list_from_string, PARSER.add_argument('--test-targets', type=list_from_string, default=' '.join(RIOTApplication.TEST_TARGETS), help='List of make targets to run test') +PARSER.add_argument('--test-available-targets', type=list_from_string, + default=' '.join(RIOTApplication.TEST_AVAILABLE_TARGETS), + help='List of make targets to know if a test is present') PARSER.add_argument( '--jobs', '-j', type=int, default=None, @@ -607,6 +616,7 @@ def main(): # Overwrite the compile/test targets from command line arguments RIOTApplication.COMPILE_TARGETS = args.compile_targets RIOTApplication.TEST_TARGETS = args.test_targets + RIOTApplication.TEST_AVAILABLE_TARGETS = args.test_available_targets # List of applications for board applications = [RIOTApplication(board, args.riot_directory, app_dir,