hs-test: always build when running 'make build'

- running 'make build' will now always build docker images,
  'make test' will try to skip building them unless FORCE_BUILD=true
- now also checking ubuntu version

Type: make

Change-Id: Ie16e8dc4712963de19e2450e058b867c1cede7ee
Signed-off-by: Adrian Villin <avillin@cisco.com>
diff --git a/extras/hs-test/Makefile b/extras/hs-test/Makefile
index 8d7d641..ccccf4f 100644
--- a/extras/hs-test/Makefile
+++ b/extras/hs-test/Makefile
@@ -57,6 +57,8 @@
 ARCH=$(shell dpkg --print-architecture)
 endif
 
+FORCE_BUILD?=true
+
 .PHONY: help
 help:
 	@echo "Make targets:"
@@ -74,6 +76,7 @@
 	@echo
 	@echo "'make build' and 'make test' arguments:"
 	@echo " UBUNTU_VERSION           - ubuntu version for docker image"
+	@echo " FORCE_BUILD=[true|false] - force docker image building"
 	@echo
 	@echo "'make test' specific arguments:"
 	@echo " PERSIST=[true|false]     - whether clean up topology and dockers after test"
@@ -115,6 +118,7 @@
 	@touch .build.ok
 
 .PHONY: test
+test: FORCE_BUILD=false
 test: .deps.ok .build.ok
 	@bash ./hs_test.sh --persist=$(PERSIST) --verbose=$(VERBOSE) \
 		--unconfigure=$(UNCONFIGURE) --debug=$(DEBUG) --test=$(TEST) --cpus=$(CPUS) \
@@ -122,8 +126,8 @@
 		--dryrun=$(DRYRUN); \
 		./script/compress.sh $$?
 
-
 .PHONY: test-debug
+test-debug: FORCE_BUILD=false
 test-debug: .deps.ok .build_debug.ok
 	@bash ./hs_test.sh --persist=$(PERSIST) --verbose=$(VERBOSE) \
 		--unconfigure=$(UNCONFIGURE) --debug=$(DEBUG) --test=$(TEST) --cpus=$(CPUS) \
@@ -132,6 +136,7 @@
 		./script/compress.sh $$?
 
 .PHONY: test-cov
+test-leak: FORCE_BUILD=false
 test-cov: .deps.ok .build.cov.ok
 	@bash ./hs_test.sh --persist=$(PERSIST) --verbose=$(VERBOSE) \
 		--unconfigure=$(UNCONFIGURE) --debug=$(DEBUG) --test=$(TEST-HS) --cpus=$(CPUS) \
@@ -149,19 +154,19 @@
 .PHONY: build
 build: .deps.ok build-vpp-release build-go
 	@rm -f .build.ok
-	bash ./script/build_hst.sh release
+	bash ./script/build_hst.sh release $(FORCE_BUILD)
 	@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
+	bash ./script/build_hst.sh gcov $(FORCE_BUILD)
 	@touch .build.cov.ok
 
 .PHONY: build-debug
 build-debug: .deps.ok build-vpp-debug build-go
 	@rm -f .build.ok
-	bash ./script/build_hst.sh debug
+	bash ./script/build_hst.sh debug $(FORCE_BUILD)
 	@touch .build.ok
 
 .deps.ok:
diff --git a/extras/hs-test/script/build_hst.sh b/extras/hs-test/script/build_hst.sh
index 96a7214..523398c 100755
--- a/extras/hs-test/script/build_hst.sh
+++ b/extras/hs-test/script/build_hst.sh
@@ -5,10 +5,14 @@
 	exit 1
 fi
 
+export UBUNTU_VERSION=${UBUNTU_VERSION:-"$(lsb_release -rs)"}
+echo "Ubuntu version is set to ${UBUNTU_VERSION}"
+
 LAST_STATE_FILE=".last_state_hash"
 
-# get current state hash
+# get current state hash and ubuntu version
 current_state_hash=$(git status --porcelain | grep -vE '(/\.|/10|\.go$|\.sum$|\.mod$|\.txt$|\.test$)' | sha1sum | awk '{print $1}')
+current_state_hash=$current_state_hash$UBUNTU_VERSION
 
 if [ -f "$LAST_STATE_FILE" ]; then
     last_state_hash=$(cat "$LAST_STATE_FILE")
@@ -16,8 +20,8 @@
     last_state_hash=""
 fi
 
-# compare current state with last state
-if [ "$current_state_hash" = "$last_state_hash" ]; then
+# compare current state with last state and check FORCE_BUILD
+if [ "$current_state_hash" = "$last_state_hash" ] && [ "$2" = "false" ]; then
     echo "*** Skipping docker build - no new changes \
 (excluding .go, .txt, .sum, .mod, dotfiles, IP address files) ***"
     exit 0
@@ -48,9 +52,6 @@
 fi
 echo "Taking build objects from ${VPP_BUILD_ROOT}"
 
-export UBUNTU_VERSION=${UBUNTU_VERSION:-"$(lsb_release -rs)"}
-echo "Ubuntu version is set to ${UBUNTU_VERSION}"
-
 export HST_LDPRELOAD=${VPP_BUILD_ROOT}/lib/${OS_ARCH}-linux-gnu/libvcl_ldpreload.so
 echo "HST_LDPRELOAD is set to ${HST_LDPRELOAD}"