hs-test: fixed timed out tests passing in the CI

Type: test

Change-Id: Id05ea56bc5dfd80d42b8600cf11e763e25420bd0
Signed-off-by: Adrian Villin <avillin@cisco.com>
diff --git a/extras/hs-test/Makefile b/extras/hs-test/Makefile
index 6ee89bc..e247bf4 100644
--- a/extras/hs-test/Makefile
+++ b/extras/hs-test/Makefile
@@ -1,3 +1,4 @@
+export HS_ROOT=$(CURDIR)
 
 ifeq ($(VERBOSE),)
 VERBOSE=false
@@ -95,17 +96,21 @@
 
 .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) \
 		--unconfigure=$(UNCONFIGURE) --debug=$(DEBUG) --test=$(TEST) --cpus=$(CPUS) \
 		--vppsrc=$(VPPSRC) --parallel=$(PARALLEL) --repeat=$(REPEAT)
-	$(call jq-summary)
 	@bash ./script/compress.sh
 
 .PHONY: test-debug
 test-debug: .deps.ok .build_debug.ok
-	@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 ./test --persist=$(PERSIST) --verbose=$(VERBOSE) \
 		--unconfigure=$(UNCONFIGURE) --debug=$(DEBUG) --test=$(TEST) --cpus=$(CPUS) \
 		--vppsrc=$(VPPSRC) --parallel=$(PARALLEL) --repeat=$(REPEAT)
+	@bash ./script/compress.sh
 
 .PHONY: build-go
 build-go:
@@ -144,7 +149,3 @@
 fixstyle:
 	@gofmt -w .
 	@go mod tidy
-
-# splitting this into multiple lines breaks the command
-jq-summary = @jq -r '.[0] | .SpecReports[] | select(.State == "failed") | select(.Failure != null) | "TestName: \(.LeafNodeText)\nMessage:\n\(.Failure.Message)\n Full Stack Trace:\n\(.Failure.Location.FullStackTrace)\n"' summary/report.json > summary/failed-summary.log \
-	&& echo "Summary generated -> failed-summary.log"
diff --git a/extras/hs-test/script/compress.sh b/extras/hs-test/script/compress.sh
index 92a2fbd..1f0205c 100644
--- a/extras/hs-test/script/compress.sh
+++ b/extras/hs-test/script/compress.sh
@@ -1,34 +1,33 @@
 #!/usr/bin/env bash
 
-if [ "${COMPRESS_FAILED_TEST_LOGS}" == "yes" -a -s "${HS_SUMMARY}/failed-summary.log" ]
+# if failed-summary.log is not empty, exit status = 1
+if [ -s "${HS_ROOT}/summary/failed-summary.log" ]
 then
-    echo -n "Copying docker logs..."
-    dirs=$(jq -r '.[0] | .SpecReports[] | select(.State == "failed") | .LeafNodeText' ${HS_SUMMARY}/report.json)
-    for dirName in $dirs; do
-        logDir=/tmp/hs-test/$dirName
-        if [ -d "$logDir" ]; then
-            mkdir -p $WORKSPACE/archives/summary
-            cp -r $logDir $WORKSPACE/archives/summary/
-        fi
-    done
-    echo "Done."
-
-    if [ -n "$WORKSPACE" ]
+    if [ -n "${WORKSPACE}" ]
     then
-        echo -n "Copying failed test logs into build log archive directory ($WORKSPACE/archives)... "
-        mkdir -p $WORKSPACE/archives/summary
-        cp -a ${HS_SUMMARY}/* $WORKSPACE/archives/summary
-    echo "Done."
+        echo -n "Copying docker logs..."
+        dirs=$(jq -r '.[0] | .SpecReports[] | select(.State == "failed") | .LeafNodeText' ${HS_ROOT}/summary/report.json)
+        for dirName in $dirs; do
+            logDir=/tmp/hs-test/$dirName
+            if [ -d "$logDir" ]; then
+                mkdir -p ${WORKSPACE}/archives/summary
+                cp -r $logDir ${WORKSPACE}/archives/summary/
+            fi
+        done
+        echo "Done."
+
+        echo -n "Copying failed test logs into build log archive directory (${WORKSPACE}/archives)... "
+        mkdir -p ${WORKSPACE}/archives/summary
+        cp -a ${HS_ROOT}/summary/* ${WORKSPACE}/archives/summary
+        echo "Done."
+
+        echo -n "Compressing files in ${WORKSPACE}/archives from test runs... "
+        cd ${WORKSPACE}/archives
+        find . -type f \( -name "*.json" -o -name "*.log" \) -exec gzip {} \;
+        echo "Done."
+
+    else
+        echo "Not compressing files in temporary directories from test runs."
     fi
-
-    echo -n "Compressing files in $WORKSPACE/archives from test runs... "
-    cd $WORKSPACE/archives
-    find . -type f \( -name "*.json" -o -name "*.log" \) -exec gzip {} \;
-    echo "Done."
-
-else
-    echo "Not compressing files in temporary directories from test runs."
-    exit 0
+    exit 1
 fi
-
-exit 1
\ No newline at end of file
diff --git a/extras/hs-test/test b/extras/hs-test/test
old mode 100755
new mode 100644
index fd17feb..398e2b3
--- a/extras/hs-test/test
+++ b/extras/hs-test/test
@@ -89,3 +89,6 @@
 mkdir -p summary
 
 sudo -E go run github.com/onsi/ginkgo/v2/ginkgo --no-color --trace --json-report=summary/report.json $ginkgo_args -- $args
+
+jq -r '.[0] | .SpecReports[] | select((.State == "failed") or (.State == "timedout") or (.State == "panicked")) | select(.Failure != null) | "TestName: \(.LeafNodeText)\nSuite:\n\(.Failure.Location.FileName)\nMessage:\n\(.Failure.Message)\n Full Stack Trace:\n\(.Failure.Location.FullStackTrace)\n"' summary/report.json > summary/failed-summary.log \
+	&& echo "Summary generated -> summary/failed-summary.log"
\ No newline at end of file