From 58f62d01caf186a2ffdca4dd244e258deba9e064 Mon Sep 17 00:00:00 2001 From: Martin Kalcok Date: Wed, 6 Mar 2024 18:10:30 +0100 Subject: [PATCH 1/3] Make: generate test targets dynamically By generating test targets dynamically from the list of `.bats` files in the `tests/` directory, we can more easily invoke individual test suites via Make. We can also leverage parallel execution of multiple test targets via Make's `-j` option. Individual test suite can be invoked with `make tests/.bats` Behavior of `check-system` target remains unchanged, with additional benefit of supporting parallel execution too. Signed-off-by: Martin Kalcok --- Makefile | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index f28e5111..7450d72a 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,8 @@ ifndef MICROOVN_SNAP_CHANNEL export MICROOVN_SNAP_CHANNEL="22.03/stable" endif +ALL_TESTS := $(wildcard tests/*.bats) + check: check-lint check-system check-tabs: @@ -17,9 +19,11 @@ check-lint: check-tabs -not -name \*.swp \ | xargs shellcheck --severity=warning && echo Success! -check-system: $(MICROOVN_SNAP) - echo "Running functional tests"; \ - $(CURDIR)/.bats/bats-core/bin/bats tests/ +$(ALL_TESTS): $(MICROOVN_SNAP) + echo "Running functional test $@"; \ + $(CURDIR)/.bats/bats-core/bin/bats $@ + +check-system: $(ALL_TESTS) $(MICROOVN_SNAP): echo "Building the snap"; \ @@ -28,3 +32,5 @@ $(MICROOVN_SNAP): clean: rm -f $(MICROOVN_SNAP_PATH); \ snapcraft clean + +.PHONY: $(ALL_TESTS) clean check-system check-lint check-tabs From 153ad9528933194fed856cf645b50c462641439b Mon Sep 17 00:00:00 2001 From: Martin Kalcok Date: Wed, 6 Mar 2024 18:14:54 +0100 Subject: [PATCH 2/3] Make: Rebuild snap file when sources change. Adding prerequisites to `$(MICROOVN_SNAP)` target ensures that whenever files in `microovn/`, `snap/` or `snapcraft/` change, it will trigger rebuild of a snap by Make. Signed-off-by: Martin Kalcok --- Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 7450d72a..c8db3913 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,9 @@ ifndef MICROOVN_SNAP_CHANNEL endif ALL_TESTS := $(wildcard tests/*.bats) +MICROOVN_SOURCES := $(shell find microovn/ -type f) +COMMAND_WRAPPERS := $(shell find snapcraft/ -type f) +SNAP_SOURCES := $(shell find snap/ -type f) check: check-lint check-system @@ -25,7 +28,7 @@ $(ALL_TESTS): $(MICROOVN_SNAP) check-system: $(ALL_TESTS) -$(MICROOVN_SNAP): +$(MICROOVN_SNAP): $(MICROOVN_SOURCES) $(SNAP_SOURCES) $(COMMAND_WRAPPERS) echo "Building the snap"; \ snapcraft pack -v -o $(MICROOVN_SNAP) From 976a20e530b65e4971e3da3a90f73fc869d593bd Mon Sep 17 00:00:00 2001 From: Martin Kalcok Date: Thu, 7 Mar 2024 13:51:14 +0100 Subject: [PATCH 3/3] Make: Set default target By setting .DEFAULT_GOAL variable we ensure that when `make` is executed without any arguments, it will build the snap without running functional tests. Signed-off-by: Martin Kalcok --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index c8db3913..13a9c6fd 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,8 @@ ifndef MICROOVN_SNAP_CHANNEL export MICROOVN_SNAP_CHANNEL="22.03/stable" endif +.DEFAULT_GOAL := $(MICROOVN_SNAP) + ALL_TESTS := $(wildcard tests/*.bats) MICROOVN_SOURCES := $(shell find microovn/ -type f) COMMAND_WRAPPERS := $(shell find snapcraft/ -type f)