blob: e326e9f500c28d85aa2ba1b329043cf02d0592cb [file] [log] [blame]
Adrian Villin688ac5a2024-05-10 04:19:35 -04001export HS_ROOT=$(CURDIR)
Filip Tehlar229f5fc2022-08-09 14:44:47 +00002
Adrian Villin56387402024-06-11 10:32:08 +02003# sets WS_ROOT if called from extras/hs-test
4ifeq ($(WS_ROOT),)
5export WS_ROOT=$(HS_ROOT)/../..
6endif
7
Filip Tehlar671cf512023-01-31 10:34:18 +01008ifeq ($(VERBOSE),)
9VERBOSE=false
10endif
Maros Ondrejicka2ddb2fd2023-02-15 17:44:46 +010011
Filip Tehlar671cf512023-01-31 10:34:18 +010012ifeq ($(PERSIST),)
13PERSIST=false
14endif
15
Maros Ondrejickaaf004dd2023-02-27 16:52:57 +010016ifeq ($(UNCONFIGURE),)
17UNCONFIGURE=false
18endif
19
Filip Tehlar671cf512023-01-31 10:34:18 +010020ifeq ($(TEST),)
21TEST=all
22endif
23
adrianvillin85121452024-01-11 11:59:47 +010024ifeq ($(TEST-HS),)
25TEST-HS=all
26endif
27
Filip Tehlarec5c40b2023-02-28 18:59:15 +010028ifeq ($(DEBUG),)
29DEBUG=false
30endif
31
Filip Tehlar608d0062023-04-28 10:29:47 +020032ifeq ($(CPUS),)
33CPUS=1
34endif
35
Adrian Villincee15aa2024-03-14 11:42:55 -040036ifeq ($(PARALLEL),)
37PARALLEL=1
38endif
39
Matus Fabianbbee45c2024-04-22 19:47:27 +020040ifeq ($(REPEAT),)
41REPEAT=0
42endif
43
Adrian Villin5d171eb2024-06-17 08:51:27 +020044ifeq ($(CPU0),)
45CPU0=false
46endif
47
Filip Tehlar109f3ce2023-09-05 15:36:28 +020048ifeq ($(VPPSRC),)
49VPPSRC=$(shell pwd)/../..
50endif
51
Dave Wallace05120fb2023-03-07 22:09:20 -050052ifeq ($(UBUNTU_CODENAME),)
53UBUNTU_CODENAME=$(shell grep '^UBUNTU_CODENAME=' /etc/os-release | cut -f2- -d=)
54endif
55
56ifeq ($(ARCH),)
57ARCH=$(shell dpkg --print-architecture)
58endif
59
Filip Tehlar671cf512023-01-31 10:34:18 +010060.PHONY: help
61help:
62 @echo "Make targets:"
Adrian Villin4677d922024-06-14 09:32:39 +020063 @echo " test - run tests"
64 @echo " test-debug - run tests (vpp debug image)"
65 @echo " build - build test infra"
66 @echo " build-cov - coverage build of VPP and Docker images"
67 @echo " build-debug - build test infra (vpp debug image)"
68 @echo " build-go - just build golang files"
69 @echo " checkstyle-go - check style of .go source files"
70 @echo " fixstyle-go - format .go source files"
71 @echo " cleanup-hst - stops and removes all docker contaiers and namespaces"
72 @echo " list-tests - list all tests"
Filip Tehlar671cf512023-01-31 10:34:18 +010073 @echo
Adrian Villin4677d922024-06-14 09:32:39 +020074 @echo "'make build' arguments:"
Filip Tehlar671cf512023-01-31 10:34:18 +010075 @echo " UBUNTU_VERSION - ubuntu version for docker image"
Adrian Villin4677d922024-06-14 09:32:39 +020076 @echo " HST_EXTENDED_TESTS - build extended tests"
Filip Tehlar31eaea92023-06-15 10:06:57 +020077 @echo
Adrian Villin4677d922024-06-14 09:32:39 +020078 @echo "'make test' arguments:"
Filip Tehlar671cf512023-01-31 10:34:18 +010079 @echo " PERSIST=[true|false] - whether clean up topology and dockers after test"
80 @echo " VERBOSE=[true|false] - verbose output"
Florin Corase2415f72023-02-28 14:51:03 -080081 @echo " UNCONFIGURE=[true|false] - unconfigure selected test"
Filip Tehlarec5c40b2023-02-28 18:59:15 +010082 @echo " DEBUG=[true|false] - attach VPP to GDB"
Filip Tehlar671cf512023-01-31 10:34:18 +010083 @echo " TEST=[test-name] - specific test to run"
Adrian Villinb9464cd2024-05-27 09:52:59 -040084 @echo " CPUS=[n-cpus] - number of cpus to allocate to VPP and containers"
Filip Tehlar109f3ce2023-09-05 15:36:28 +020085 @echo " VPPSRC=[path-to-vpp-src] - path to vpp source files (for gdb)"
Matus Fabianbbee45c2024-04-22 19:47:27 +020086 @echo " PARALLEL=[n-cpus] - number of test processes to spawn to run in parallel"
87 @echo " REPEAT=[n] - repeat tests up to N times or until a failure occurs"
Adrian Villin5d171eb2024-06-17 08:51:27 +020088 @echo " CPU0=[true|false] - use cpu0"
Filip Tehlar671cf512023-01-31 10:34:18 +010089 @echo
90 @echo "List of all tests:"
Adrian Villin4677d922024-06-14 09:32:39 +020091 @$(MAKE) list-tests
Filip Tehlar671cf512023-01-31 10:34:18 +010092
93.PHONY: list-tests
94list-tests:
Adrian Villin4677d922024-06-14 09:32:39 +020095 @go run github.com/onsi/ginkgo/v2/ginkgo --dry-run -v --no-color --seed=2 | head -n -1 | grep 'Test' | \
96 sed 's/^/* /; s/\(Suite\) /\1\//g'
Filip Tehlar671cf512023-01-31 10:34:18 +010097
Dave Wallace83b12bf2024-04-25 16:21:37 -040098.PHONY: build-vpp-release
Filip Tehlar671cf512023-01-31 10:34:18 +010099build-vpp-release:
Renato Botelho do Couto893daca2024-06-05 18:11:46 +0000100 @$(MAKE) -C ../.. build-release
Filip Tehlar671cf512023-01-31 10:34:18 +0100101
Dave Wallace83b12bf2024-04-25 16:21:37 -0400102.PHONY: build-vpp-debug
Filip Tehlar671cf512023-01-31 10:34:18 +0100103build-vpp-debug:
Renato Botelho do Couto893daca2024-06-05 18:11:46 +0000104 @$(MAKE) -C ../.. build
Filip Tehlar671cf512023-01-31 10:34:18 +0100105
adrianvillin85121452024-01-11 11:59:47 +0100106.PHONY: build-vpp-gcov
107build-vpp-gcov:
Renato Botelho do Couto893daca2024-06-05 18:11:46 +0000108 @$(MAKE) -C ../.. build-vpp-gcov
adrianvillin85121452024-01-11 11:59:47 +0100109
Dave Wallace83b12bf2024-04-25 16:21:37 -0400110.build.ok: build
111 @touch .build.ok
112
Adrian Villinf4972f92024-06-04 08:59:58 -0400113.build.cov.ok: build-vpp-gcov
114 @touch .build.cov.ok
115
Matus Fabian2d1bc4c2024-05-09 10:46:58 +0200116.build_debug.ok: build-debug
117 @touch .build.ok
118
Filip Tehlar671cf512023-01-31 10:34:18 +0100119.PHONY: test
Dave Wallace83b12bf2024-04-25 16:21:37 -0400120test: .deps.ok .build.ok
Adrian Villin7d1e4a42024-06-13 08:59:58 +0200121 @# '-' ignores the exit status, it is set in compress.sh
122 @# necessary so gmake won't skip executing the bash script
Dave Wallacebee28af2024-06-14 14:59:38 -0400123 @-bash ./hs_test.sh --persist=$(PERSIST) --verbose=$(VERBOSE) \
Filip Tehlar109f3ce2023-09-05 15:36:28 +0200124 --unconfigure=$(UNCONFIGURE) --debug=$(DEBUG) --test=$(TEST) --cpus=$(CPUS) \
Adrian Villin5d171eb2024-06-17 08:51:27 +0200125 --vppsrc=$(VPPSRC) --parallel=$(PARALLEL) --repeat=$(REPEAT) --cpu0=$(CPU0)
Adrian Villin637edda2024-05-06 06:55:34 -0400126 @bash ./script/compress.sh
Filip Tehlar671cf512023-01-31 10:34:18 +0100127
Matus Fabian2d1bc4c2024-05-09 10:46:58 +0200128.PHONY: test-debug
129test-debug: .deps.ok .build_debug.ok
Adrian Villin7d1e4a42024-06-13 08:59:58 +0200130 @# '-' ignores the exit status, it is set in compress.sh
131 @# necessary so gmake won't skip executing the bash script
Dave Wallacebee28af2024-06-14 14:59:38 -0400132 @-bash ./hs_test.sh --persist=$(PERSIST) --verbose=$(VERBOSE) \
Matus Fabian2d1bc4c2024-05-09 10:46:58 +0200133 --unconfigure=$(UNCONFIGURE) --debug=$(DEBUG) --test=$(TEST) --cpus=$(CPUS) \
Adrian Villin5d171eb2024-06-17 08:51:27 +0200134 --vppsrc=$(VPPSRC) --parallel=$(PARALLEL) --repeat=$(REPEAT) --debug_build=true \
135 --cpu0=$(CPU0)
Adrian Villin688ac5a2024-05-10 04:19:35 -0400136 @bash ./script/compress.sh
Matus Fabian2d1bc4c2024-05-09 10:46:58 +0200137
adrianvillin85121452024-01-11 11:59:47 +0100138.PHONY: test-cov
Adrian Villinf4972f92024-06-04 08:59:58 -0400139test-cov: .deps.ok .build.cov.ok
Dave Wallacebee28af2024-06-14 14:59:38 -0400140 @-bash ./hs_test.sh --persist=$(PERSIST) --verbose=$(VERBOSE) \
adrianvillin85121452024-01-11 11:59:47 +0100141 --unconfigure=$(UNCONFIGURE) --debug=$(DEBUG) --test=$(TEST-HS) --cpus=$(CPUS) \
Adrian Villin5d171eb2024-06-17 08:51:27 +0200142 --vppsrc=$(VPPSRC) --cpu0=$(CPU0)
Renato Botelho do Couto893daca2024-06-05 18:11:46 +0000143 @$(MAKE) -C ../.. test-cov-post HS_TEST=1
adrianvillin85121452024-01-11 11:59:47 +0100144 @bash ./script/compress.sh
145
Dave Wallace83b12bf2024-04-25 16:21:37 -0400146.PHONY: build-go
Filip Tehlar671cf512023-01-31 10:34:18 +0100147build-go:
Filip Tehlar229f5fc2022-08-09 14:44:47 +0000148 go build ./tools/http_server
Filip Tehlar229f5fc2022-08-09 14:44:47 +0000149
Dave Wallace83b12bf2024-04-25 16:21:37 -0400150.PHONY: build
Filip Tehlar671cf512023-01-31 10:34:18 +0100151build: .deps.ok build-vpp-release build-go
Dave Wallace83b12bf2024-04-25 16:21:37 -0400152 @rm -f .build.ok
Filip Tehlar31eaea92023-06-15 10:06:57 +0200153 bash ./script/build_hst.sh release
Dave Wallace83b12bf2024-04-25 16:21:37 -0400154 @touch .build.ok
Filip Tehlar229f5fc2022-08-09 14:44:47 +0000155
adrianvillin85121452024-01-11 11:59:47 +0100156.PHONY: build-cov
157build-cov: .deps.ok build-vpp-gcov build-go
Adrian Villinf4972f92024-06-04 08:59:58 -0400158 @rm -f .build.cov.ok
adrianvillin85121452024-01-11 11:59:47 +0100159 bash ./script/build_hst.sh gcov
Adrian Villinf4972f92024-06-04 08:59:58 -0400160 @touch .build.cov.ok
adrianvillin85121452024-01-11 11:59:47 +0100161
Dave Wallace83b12bf2024-04-25 16:21:37 -0400162.PHONY: build-debug
Filip Tehlar671cf512023-01-31 10:34:18 +0100163build-debug: .deps.ok build-vpp-debug build-go
Dave Wallace83b12bf2024-04-25 16:21:37 -0400164 @rm -f .build.ok
Filip Tehlar31eaea92023-06-15 10:06:57 +0200165 bash ./script/build_hst.sh debug
Dave Wallace83b12bf2024-04-25 16:21:37 -0400166 @touch .build.ok
Filip Tehlar671cf512023-01-31 10:34:18 +0100167
Dave Wallaced0df24d2023-04-26 18:03:03 -0400168.deps.ok:
Renato Botelho do Couto893daca2024-06-05 18:11:46 +0000169 @sudo $(MAKE) install-deps
Dave Wallaced0df24d2023-04-26 18:03:03 -0400170
Filip Tehlar671cf512023-01-31 10:34:18 +0100171.PHONY: install-deps
172install-deps:
Dave Wallace05120fb2023-03-07 22:09:20 -0500173 @rm -f .deps.ok
Dave Wallacef72bb6f2023-03-08 13:53:32 -0500174 @apt-get update \
175 && apt-get install -y apt-transport-https ca-certificates curl software-properties-common \
Dave Wallace83b12bf2024-04-25 16:21:37 -0400176 apache2-utils wrk bridge-utils
Dave Wallacef72bb6f2023-03-08 13:53:32 -0500177 @if [ ! -f /usr/share/keyrings/docker-archive-keyring.gpg ] ; then \
178 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg; \
179 echo "deb [arch=$(ARCH) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(UBUNTU_CODENAME) stable" \
180 | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null ; \
181 apt-get update; \
182 fi
Filip Tehlar671cf512023-01-31 10:34:18 +0100183 @touch .deps.ok
184
Adrian Villin56387402024-06-11 10:32:08 +0200185.PHONY: checkstyle-go
186checkstyle-go:
187 @output=$$(gofmt -d $${WS_ROOT}); \
188 if [ -z "$$output" ]; then \
189 echo "*******************************************************************"; \
190 echo "Checkstyle OK."; \
191 echo "*******************************************************************"; \
192 else \
193 echo "$$output"; \
194 echo "*******************************************************************"; \
195 echo "Checkstyle failed. Use 'make fixstyle-go' or fix errors manually."; \
196 echo "*******************************************************************"; \
197 exit 1; \
198 fi
199
200.PHONY: fixstyle-go
201fixstyle-go:
202 @echo "Modified files:"
203 @gofmt -w -l $(WS_ROOT)
Maros Ondrejicka7d7ab102023-02-14 12:56:49 +0100204 @go mod tidy
Adrian Villin56387402024-06-11 10:32:08 +0200205 @echo "*******************************************************************"
206 @echo "Fixstyle done."
207 @echo "*******************************************************************"
Adrian Villin7d1e4a42024-06-13 08:59:58 +0200208
209.PHONY: cleanup-hst
210cleanup-hst:
211 @if [ ! -f ".last_hst_ppid" ]; then \
212 echo "'.last_hst_ppid' file does not exist."; \
213 exit 1; \
214 fi
215 @echo "****************************"
216 @echo "Removing docker containers:"
217 @# "-" ignores errors
218 @-sudo docker rm $$(sudo docker stop $$(sudo docker ps -a -q --filter "name=$$(cat .last_hst_ppid)") -t 0)
219 @echo "****************************"
220 @echo "Removing IP address files:"
221 @find . -type f -regextype egrep -regex '.*[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' -exec sudo rm -v {} \;
222 @echo "****************************"
223 @echo "Removing network namespaces:"
224 @for ns in $$(ip netns list | grep $$(cat .last_hst_ppid) | awk '{print $$1}'); do \
225 echo $$ns; \
226 sudo ip netns delete $$ns; \
227 done
228 @echo "****************************"
229 @echo "Done."
230 @echo "****************************"