The barebox test suite is invoked by running pytest, but for many
projects running make check is what is usually expected.

Add a make check target that calls pytest to accommodate that.
In future, we may add extra checks to test that pytest is correctly
installed to make it easier to use.

Signed-off-by: Ahmad Fatoum <[email protected]>
---
 Makefile | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/Makefile b/Makefile
index 9af028cbc6a0..018a206ee8ca 100644
--- a/Makefile
+++ b/Makefile
@@ -463,6 +463,7 @@ KLZOP               = lzop
 LZMA           = lzma
 LZ4            = lz4
 XZ             = xz
+PYTEST         = $(if $(shell command -v labgrid-pytest 
2>/dev/null),labgrid-pytest,pytest)
 
 CHECKFLAGS     := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise 
$(CF)
 CFLAGS_KERNEL  =
@@ -1054,7 +1055,32 @@ endif
 
 PHONY += install
 
+# Testing barebox
+# ---------------------------------------------------------------------------
+# This target has pytest select the YAML env matching CONFIG_NAME if available.
+# Use pytest --lg-env $labgrid_env_yaml directly if you need more than that.
+
+labgrid-env := $(srctree)/test/$(SRCARCH)/$(CONFIG_NAME).yaml
+
+check:
+ifeq ($(CONFIG_NAME),"")
+       @echo "error: can't autoload labgrid env with CONFIG_NAME unset!" >&2
+       @exit 1
+endif
+       @if [ ! -r "$(labgrid-env)" ]; then \
+               echo "error: No Labgrid environment at $(labgrid-env)!" >&2; \
+               echo "Choose a different config (or change CONFIG_NAME)" >&2; \
+               echo "that can be automatically tested" >&2; \
+               exit 1; \
+       fi
+       @echo
+       @# This is intentionally not @suppressed, to make it easier to reproduce
+       (cd $(srctree); $(PYTEST))
+
+PHONY += check
+
 # barebox image
+# ---------------------------------------------------------------------------
 barebox: $(BAREBOX_LDS) $(BAREBOX_OBJS) $(kallsyms.o) FORCE
        $(call if_changed_rule,barebox__)
        $(Q)rm -f .old_version
-- 
2.47.3


Reply via email to