blob: 5d94ea88ede2c125c67c72ddde36aa8d5982f722 [file] [log] [blame]
Filip Tehlar229f5fc2022-08-09 14:44:47 +00001#!/usr/bin/env bash
2
3source vars
Maros Ondrejicka87531802022-12-19 20:35:27 +01004
Filip Tehlar671cf512023-01-31 10:34:18 +01005args=
6single_test=0
7persist_set=0
Maros Ondrejickaaf004dd2023-02-27 16:52:57 +01008unconfigure_set=0
Filip Tehlarec5c40b2023-02-28 18:59:15 +01009debug_set=0
Matus Fabiane99d2662024-07-19 16:04:09 +020010leak_check_set=0
Adrian Villinb4516bb2024-06-19 06:20:00 -040011debug_build=
Adrian Villincee15aa2024-03-14 11:42:55 -040012ginkgo_args=
Matus Fabiane99d2662024-07-19 16:04:09 +020013tc_name=
Filip Tehlar671cf512023-01-31 10:34:18 +010014
15for i in "$@"
Maros Ondrejicka87531802022-12-19 20:35:27 +010016do
Filip Tehlar671cf512023-01-31 10:34:18 +010017case "${i}" in
18 --persist=*)
19 persist="${i#*=}"
Dave Wallacebee28af2024-06-14 14:59:38 -040020 if [ "$persist" = "true" ]; then
Filip Tehlar671cf512023-01-31 10:34:18 +010021 args="$args -persist"
22 persist_set=1
23 fi
24 ;;
Filip Tehlarec5c40b2023-02-28 18:59:15 +010025 --debug=*)
26 debug="${i#*=}"
Dave Wallacebee28af2024-06-14 14:59:38 -040027 if [ "$debug" = "true" ]; then
Filip Tehlarec5c40b2023-02-28 18:59:15 +010028 args="$args -debug"
29 debug_set=1
30 fi
31 ;;
Adrian Villinb4516bb2024-06-19 06:20:00 -040032 --debug_build=*)
33 debug_build="${i#*=}"
34 if [ "$debug_build" = "true" ]; then
35 args="$args -debug_build"
36 fi
37 ;;
Filip Tehlar671cf512023-01-31 10:34:18 +010038 --verbose=*)
39 verbose="${i#*=}"
Dave Wallacebee28af2024-06-14 14:59:38 -040040 if [ "$verbose" = "true" ]; then
Filip Tehlar671cf512023-01-31 10:34:18 +010041 args="$args -verbose"
42 fi
43 ;;
Maros Ondrejickaaf004dd2023-02-27 16:52:57 +010044 --unconfigure=*)
45 unconfigure="${i#*=}"
Dave Wallacebee28af2024-06-14 14:59:38 -040046 if [ "$unconfigure" = "true" ]; then
Maros Ondrejickaaf004dd2023-02-27 16:52:57 +010047 args="$args -unconfigure"
48 unconfigure_set=1
49 fi
50 ;;
Filip Tehlar608d0062023-04-28 10:29:47 +020051 --cpus=*)
52 args="$args -cpus ${i#*=}"
53 ;;
Filip Tehlar109f3ce2023-09-05 15:36:28 +020054 --vppsrc=*)
55 args="$args -vppsrc ${i#*=}"
56 ;;
Filip Tehlar671cf512023-01-31 10:34:18 +010057 --test=*)
58 tc_name="${i#*=}"
Dave Wallacebee28af2024-06-14 14:59:38 -040059 if [ "$tc_name" != "all" ]; then
Filip Tehlar671cf512023-01-31 10:34:18 +010060 single_test=1
Adrian Villincee15aa2024-03-14 11:42:55 -040061 ginkgo_args="$ginkgo_args --focus $tc_name -vv"
62 args="$args -verbose"
63 else
64 ginkgo_args="$ginkgo_args -v"
Filip Tehlar671cf512023-01-31 10:34:18 +010065 fi
Adrian Villincee15aa2024-03-14 11:42:55 -040066 ;;
67 --parallel=*)
68 ginkgo_args="$ginkgo_args -procs=${i#*=}"
Matus Fabianbbee45c2024-04-22 19:47:27 +020069 ;;
70 --repeat=*)
71 ginkgo_args="$ginkgo_args --repeat=${i#*=}"
72 ;;
Adrian Villin5d171eb2024-06-17 08:51:27 +020073 --cpu0=*)
74 cpu0="${i#*=}"
75 if [ "$cpu0" = "true" ]; then
76 args="$args -cpu0"
77 fi
78 ;;
Matus Fabiane99d2662024-07-19 16:04:09 +020079 --leak_check=*)
80 leak_check="${i#*=}"
81 if [ "$leak_check" = "true" ]; then
82 args="$args -leak_check"
83 leak_check_set=1
84 fi
85 ;;
Filip Tehlar671cf512023-01-31 10:34:18 +010086esac
Maros Ondrejicka87531802022-12-19 20:35:27 +010087done
88
Filip Tehlar671cf512023-01-31 10:34:18 +010089if [ $single_test -eq 0 ] && [ $persist_set -eq 1 ]; then
Maros Ondrejickaaf004dd2023-02-27 16:52:57 +010090 echo "persist flag is not supported while running all tests!"
91 exit 1
92fi
93
94if [ $unconfigure_set -eq 1 ] && [ $single_test -eq 0 ]; then
95 echo "a single test has to be specified when unconfigure is set"
96 exit 1
97fi
98
99if [ $persist_set -eq 1 ] && [ $unconfigure_set -eq 1 ]; then
100 echo "setting persist flag and unconfigure flag is not allowed"
Filip Tehlar671cf512023-01-31 10:34:18 +0100101 exit 1
102fi
103
Filip Tehlarec5c40b2023-02-28 18:59:15 +0100104if [ $single_test -eq 0 ] && [ $debug_set -eq 1 ]; then
Adrian Villinb4516bb2024-06-19 06:20:00 -0400105 echo "VPP debug flag is not supported while running all tests!"
Filip Tehlarec5c40b2023-02-28 18:59:15 +0100106 exit 1
107fi
108
Matus Fabiane99d2662024-07-19 16:04:09 +0200109if [ $leak_check_set -eq 1 ]; then
110 if [ $single_test -eq 0 ]; then
111 echo "a single test has to be specified when leak_check is set"
112 exit 1
113 fi
114 ginkgo_args="--focus $tc_name"
115 sudo -E go run github.com/onsi/ginkgo/v2/ginkgo $ginkgo_args -- $args
116 exit 0
117fi
118
Matus Fabiana3308562024-07-29 13:51:51 +0200119if [ -n "${BUILD_NUMBER}" ]; then
120 ginkgo_args="$ginkgo_args --no-color"
121fi
122
Adrian Villin637edda2024-05-06 06:55:34 -0400123mkdir -p summary
Dave Wallacebee28af2024-06-14 14:59:38 -0400124# shellcheck disable=SC2086
Adrian Villin58cb6ba2024-08-20 14:36:12 +0200125sudo -E go run github.com/onsi/ginkgo/v2/ginkgo --json-report=summary/report.json $ginkgo_args -- $args
Adrian Villin688ac5a2024-05-10 04:19:35 -0400126
Adrian Villin399d4402024-08-22 10:35:19 +0200127if [ $? != 0 ]; then
128 jq -r '.[0] | .SpecReports[] | select((.State == "failed") or (.State == "timedout") or (.State == "panicked")) | select(.Failure != null) |
129"TestName:
130 \(.LeafNodeText)
131Suite:
132 \(.Failure.FailureNodeLocation.FileName)
Matus Fabian4306a3e2024-08-23 15:52:54 +0200133Message:\n"
134+(if .ReportEntries? then .ReportEntries[] | select(.Name == "VPP Backtrace") |
135"\tVPP crashed
136Full Back Trace:
137\(.Value.Representation | ltrimstr("{{red}}") | rtrimstr("{{/}}"))" else
138 "\(.Failure.Message)"
Adrian Villin399d4402024-08-22 10:35:19 +0200139 + (if .Failure.Message == "A spec timeout occurred" then "\n" else
140"\nFull Stack Trace:
Matus Fabian4306a3e2024-08-23 15:52:54 +0200141\(.Failure.Location.FullStackTrace)\n" end) end)' summary/report.json > summary/failed-summary.log \
Dave Wallacebee28af2024-06-14 14:59:38 -0400142 && echo "Summary generated -> summary/failed-summary.log"
Adrian Villin399d4402024-08-22 10:35:19 +0200143fi