hs-test: output docker build command for ci console log
[vpp.git] / extras / hs-test / Makefile
index 0db3958..c51f70b 100644 (file)
@@ -1,5 +1,10 @@
 export HS_ROOT=$(CURDIR)
 
+# sets WS_ROOT if called from extras/hs-test
+ifeq ($(WS_ROOT),)
+export WS_ROOT=$(HS_ROOT)/../..
+endif
+
 ifeq ($(VERBOSE),)
 VERBOSE=false
 endif
@@ -16,6 +21,10 @@ ifeq ($(TEST),)
 TEST=all
 endif
 
+ifeq ($(TEST-HS),)
+TEST-HS=all
+endif
+
 ifeq ($(DEBUG),)
 DEBUG=false
 endif
@@ -44,25 +53,25 @@ ifeq ($(ARCH),)
 ARCH=$(shell dpkg --print-architecture)
 endif
 
-list_tests = @go run github.com/onsi/ginkgo/v2/ginkgo --dry-run -v --no-color --seed=2 | head -n -1 | grep 'Test' | \
-               sed 's/^/* /; s/\(Suite\) /\1\//g'
-
 .PHONY: help
 help:
        @echo "Make targets:"
-       @echo " test                 - run tests"
-       @echo " test-debug           - run tests (vpp debug image)"
-       @echo " build                - build test infra"
-       @echo " build-debug          - build test infra (vpp debug image)"
-       @echo " build-go             - just build golang files"
-       @echo " fixstyle             - format .go source files"
-       @echo " list-tests           - list all tests"
+       @echo " test                     - run tests"
+       @echo " test-debug               - run tests (vpp debug image)"
+       @echo " build                    - build test infra"
+       @echo " build-cov                - coverage build of VPP and Docker images"
+       @echo " build-debug              - build test infra (vpp debug image)"
+       @echo " build-go                 - just build golang files"
+       @echo " checkstyle-go            - check style of .go source files"
+       @echo " fixstyle-go              - format .go source files"
+       @echo " cleanup-hst              - stops and removes all docker contaiers and namespaces"
+       @echo " list-tests               - list all tests"
        @echo
-       @echo "make build arguments:"
+       @echo "'make build' arguments:"
        @echo " UBUNTU_VERSION           - ubuntu version for docker image"
-       @echo " HST_EXTENDED_TESTS       - build extended tests"
+       @echo " HST_EXTENDED_TESTS       - build extended tests"
        @echo
-       @echo "make test arguments:"
+       @echo "'make test' arguments:"
        @echo " PERSIST=[true|false]     - whether clean up topology and dockers after test"
        @echo " VERBOSE=[true|false]     - verbose output"
        @echo " UNCONFIGURE=[true|false] - unconfigure selected test"
@@ -74,44 +83,60 @@ help:
        @echo " REPEAT=[n]               - repeat tests up to N times or until a failure occurs"
        @echo
        @echo "List of all tests:"
-       $(call list_tests)
+       @$(MAKE) list-tests
 
 .PHONY: list-tests
 list-tests:
-       $(call list_tests)
+       @go run github.com/onsi/ginkgo/v2/ginkgo --dry-run -v --no-color --seed=2 | head -n -1 | grep 'Test' | \
+               sed 's/^/* /; s/\(Suite\) /\1\//g'
 
 .PHONY: build-vpp-release
 build-vpp-release:
-       @make -C ../.. build-release
+       @$(MAKE) -C ../.. build-release
 
 .PHONY: build-vpp-debug
 build-vpp-debug:
-       @make -C ../.. build
+       @$(MAKE) -C ../.. build
+
+.PHONY: build-vpp-gcov
+build-vpp-gcov:
+       @$(MAKE) -C ../.. build-vpp-gcov
 
 .build.ok: build
        @touch .build.ok
 
+.build.cov.ok: build-vpp-gcov
+       @touch .build.cov.ok
+
 .build_debug.ok: build-debug
        @touch .build.ok
 
 .PHONY: test
 test: .deps.ok .build.ok
-       # '-' ignores the exit status, it is set in compress.sh
-       # necessary so gmake won't skip executing the bash script
-       -bash ./test --persist=$(PERSIST) --verbose=$(VERBOSE) \
+       @# '-' ignores the exit status, it is set in compress.sh
+       @# necessary so gmake won't skip executing the bash script
+       @-bash ./hs_test.sh --persist=$(PERSIST) --verbose=$(VERBOSE) \
                --unconfigure=$(UNCONFIGURE) --debug=$(DEBUG) --test=$(TEST) --cpus=$(CPUS) \
                --vppsrc=$(VPPSRC) --parallel=$(PARALLEL) --repeat=$(REPEAT)
        @bash ./script/compress.sh
 
 .PHONY: test-debug
 test-debug: .deps.ok .build_debug.ok
-       # '-' ignores the exit status, it is set in compress.sh
-       # necessary so gmake won't skip executing the bash script
-       -bash ./test --persist=$(PERSIST) --verbose=$(VERBOSE) \
+       @# '-' ignores the exit status, it is set in compress.sh
+       @# necessary so gmake won't skip executing the bash script
+       @-bash ./hs_test.sh --persist=$(PERSIST) --verbose=$(VERBOSE) \
                --unconfigure=$(UNCONFIGURE) --debug=$(DEBUG) --test=$(TEST) --cpus=$(CPUS) \
                --vppsrc=$(VPPSRC) --parallel=$(PARALLEL) --repeat=$(REPEAT)
        @bash ./script/compress.sh
 
+.PHONY: test-cov
+test-cov: .deps.ok .build.cov.ok
+       @-bash ./hs_test.sh --persist=$(PERSIST) --verbose=$(VERBOSE) \
+               --unconfigure=$(UNCONFIGURE) --debug=$(DEBUG) --test=$(TEST-HS) --cpus=$(CPUS) \
+               --vppsrc=$(VPPSRC)
+       @$(MAKE) -C ../.. test-cov-post HS_TEST=1
+       @bash ./script/compress.sh
+
 .PHONY: build-go
 build-go:
        go build ./tools/http_server
@@ -122,6 +147,12 @@ build: .deps.ok build-vpp-release build-go
        bash ./script/build_hst.sh release
        @touch .build.ok
 
+.PHONY: build-cov
+build-cov: .deps.ok build-vpp-gcov build-go
+       @rm -f .build.cov.ok
+       bash ./script/build_hst.sh gcov
+       @touch .build.cov.ok
+
 .PHONY: build-debug
 build-debug: .deps.ok build-vpp-debug build-go
        @rm -f .build.ok
@@ -129,7 +160,7 @@ build-debug: .deps.ok build-vpp-debug build-go
        @touch .build.ok
 
 .deps.ok:
-       @sudo make install-deps
+       @sudo $(MAKE) install-deps
 
 .PHONY: install-deps
 install-deps:
@@ -145,7 +176,49 @@ install-deps:
        fi
        @touch .deps.ok
 
-.PHONY: fixstyle
-fixstyle:
-       @gofmt -w .
+.PHONY: checkstyle-go
+checkstyle-go:
+       @output=$$(gofmt -d $${WS_ROOT}); \
+    if [ -z "$$output" ]; then \
+        echo "*******************************************************************"; \
+        echo "Checkstyle OK."; \
+        echo "*******************************************************************"; \
+    else \
+        echo "$$output"; \
+        echo "*******************************************************************"; \
+        echo "Checkstyle failed. Use 'make fixstyle-go' or fix errors manually."; \
+        echo "*******************************************************************"; \
+        exit 1; \
+    fi
+
+.PHONY: fixstyle-go
+fixstyle-go:
+       @echo "Modified files:"
+       @gofmt -w -l $(WS_ROOT)
        @go mod tidy
+       @echo "*******************************************************************"
+       @echo "Fixstyle done."
+       @echo "*******************************************************************"
+
+.PHONY: cleanup-hst
+cleanup-hst:
+       @if [ ! -f ".last_hst_ppid" ]; then \
+               echo "'.last_hst_ppid' file does not exist."; \
+               exit 1; \
+       fi
+       @echo "****************************"
+       @echo "Removing docker containers:"
+       @# "-" ignores errors
+       @-sudo docker rm $$(sudo docker stop $$(sudo docker ps -a -q --filter "name=$$(cat .last_hst_ppid)") -t 0)
+       @echo "****************************"
+       @echo "Removing IP address files:"
+       @find . -type f -regextype egrep -regex '.*[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' -exec sudo rm -v {} \;
+       @echo "****************************"
+       @echo "Removing network namespaces:"
+       @for ns in $$(ip netns list | grep $$(cat .last_hst_ppid) | awk '{print $$1}'); do \
+               echo $$ns; \
+       sudo ip netns delete $$ns; \
+       done
+       @echo "****************************"
+       @echo "Done."
+       @echo "****************************"