blob: 83a42c846290eee9f6185370f1ecefc1dcb2c178 [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)"
Matus Fabiane99d2662024-07-19 16:04:09 +020065 @echo " test-leak - run memory leak tests (vpp debug image)"
Adrian Villin4677d922024-06-14 09:32:39 +020066 @echo " build - build test infra"
67 @echo " build-cov - coverage build of VPP and Docker images"
68 @echo " build-debug - build test infra (vpp debug image)"
69 @echo " build-go - just build golang files"
70 @echo " checkstyle-go - check style of .go source files"
71 @echo " fixstyle-go - format .go source files"
72 @echo " cleanup-hst - stops and removes all docker contaiers and namespaces"
73 @echo " list-tests - list all tests"
Filip Tehlar671cf512023-01-31 10:34:18 +010074 @echo
Adrian Villin4677d922024-06-14 09:32:39 +020075 @echo "'make build' arguments:"
Filip Tehlar671cf512023-01-31 10:34:18 +010076 @echo " UBUNTU_VERSION - ubuntu version for docker image"
Adrian Villin4677d922024-06-14 09:32:39 +020077 @echo " HST_EXTENDED_TESTS - build extended tests"
Filip Tehlar31eaea92023-06-15 10:06:57 +020078 @echo
Adrian Villin4677d922024-06-14 09:32:39 +020079 @echo "'make test' arguments:"
Filip Tehlar671cf512023-01-31 10:34:18 +010080 @echo " PERSIST=[true|false] - whether clean up topology and dockers after test"
81 @echo " VERBOSE=[true|false] - verbose output"
Florin Corase2415f72023-02-28 14:51:03 -080082 @echo " UNCONFIGURE=[true|false] - unconfigure selected test"
Filip Tehlarec5c40b2023-02-28 18:59:15 +010083 @echo " DEBUG=[true|false] - attach VPP to GDB"
Filip Tehlar671cf512023-01-31 10:34:18 +010084 @echo " TEST=[test-name] - specific test to run"
Adrian Villinb9464cd2024-05-27 09:52:59 -040085 @echo " CPUS=[n-cpus] - number of cpus to allocate to VPP and containers"
Filip Tehlar109f3ce2023-09-05 15:36:28 +020086 @echo " VPPSRC=[path-to-vpp-src] - path to vpp source files (for gdb)"
Matus Fabianbbee45c2024-04-22 19:47:27 +020087 @echo " PARALLEL=[n-cpus] - number of test processes to spawn to run in parallel"
88 @echo " REPEAT=[n] - repeat tests up to N times or until a failure occurs"
Adrian Villin5d171eb2024-06-17 08:51:27 +020089 @echo " CPU0=[true|false] - use cpu0"
Filip Tehlar671cf512023-01-31 10:34:18 +010090 @echo
91 @echo "List of all tests:"
Adrian Villin4677d922024-06-14 09:32:39 +020092 @$(MAKE) list-tests
Filip Tehlar671cf512023-01-31 10:34:18 +010093
94.PHONY: list-tests
95list-tests:
Adrian Villin4677d922024-06-14 09:32:39 +020096 @go run github.com/onsi/ginkgo/v2/ginkgo --dry-run -v --no-color --seed=2 | head -n -1 | grep 'Test' | \
97 sed 's/^/* /; s/\(Suite\) /\1\//g'
Filip Tehlar671cf512023-01-31 10:34:18 +010098
Dave Wallace83b12bf2024-04-25 16:21:37 -040099.PHONY: build-vpp-release
Filip Tehlar671cf512023-01-31 10:34:18 +0100100build-vpp-release:
Renato Botelho do Couto893daca2024-06-05 18:11:46 +0000101 @$(MAKE) -C ../.. build-release
Filip Tehlar671cf512023-01-31 10:34:18 +0100102
Dave Wallace83b12bf2024-04-25 16:21:37 -0400103.PHONY: build-vpp-debug
Filip Tehlar671cf512023-01-31 10:34:18 +0100104build-vpp-debug:
Renato Botelho do Couto893daca2024-06-05 18:11:46 +0000105 @$(MAKE) -C ../.. build
Filip Tehlar671cf512023-01-31 10:34:18 +0100106
adrianvillin85121452024-01-11 11:59:47 +0100107.PHONY: build-vpp-gcov
108build-vpp-gcov:
Renato Botelho do Couto893daca2024-06-05 18:11:46 +0000109 @$(MAKE) -C ../.. build-vpp-gcov
adrianvillin85121452024-01-11 11:59:47 +0100110
Dave Wallace83b12bf2024-04-25 16:21:37 -0400111.build.ok: build
112 @touch .build.ok
113
Adrian Villinf4972f92024-06-04 08:59:58 -0400114.build.cov.ok: build-vpp-gcov
115 @touch .build.cov.ok
116
Matus Fabian2d1bc4c2024-05-09 10:46:58 +0200117.build_debug.ok: build-debug
118 @touch .build.ok
119
Filip Tehlar671cf512023-01-31 10:34:18 +0100120.PHONY: test
Dave Wallace83b12bf2024-04-25 16:21:37 -0400121test: .deps.ok .build.ok
Adrian Villin7d1e4a42024-06-13 08:59:58 +0200122 @# '-' ignores the exit status, it is set in compress.sh
123 @# necessary so gmake won't skip executing the bash script
Dave Wallacebee28af2024-06-14 14:59:38 -0400124 @-bash ./hs_test.sh --persist=$(PERSIST) --verbose=$(VERBOSE) \
Filip Tehlar109f3ce2023-09-05 15:36:28 +0200125 --unconfigure=$(UNCONFIGURE) --debug=$(DEBUG) --test=$(TEST) --cpus=$(CPUS) \
Adrian Villin5d171eb2024-06-17 08:51:27 +0200126 --vppsrc=$(VPPSRC) --parallel=$(PARALLEL) --repeat=$(REPEAT) --cpu0=$(CPU0)
Adrian Villin637edda2024-05-06 06:55:34 -0400127 @bash ./script/compress.sh
Filip Tehlar671cf512023-01-31 10:34:18 +0100128
Matus Fabian2d1bc4c2024-05-09 10:46:58 +0200129.PHONY: test-debug
130test-debug: .deps.ok .build_debug.ok
Adrian Villin7d1e4a42024-06-13 08:59:58 +0200131 @# '-' ignores the exit status, it is set in compress.sh
132 @# necessary so gmake won't skip executing the bash script
Dave Wallacebee28af2024-06-14 14:59:38 -0400133 @-bash ./hs_test.sh --persist=$(PERSIST) --verbose=$(VERBOSE) \
Matus Fabian2d1bc4c2024-05-09 10:46:58 +0200134 --unconfigure=$(UNCONFIGURE) --debug=$(DEBUG) --test=$(TEST) --cpus=$(CPUS) \
Adrian Villin5d171eb2024-06-17 08:51:27 +0200135 --vppsrc=$(VPPSRC) --parallel=$(PARALLEL) --repeat=$(REPEAT) --debug_build=true \
136 --cpu0=$(CPU0)
Adrian Villin688ac5a2024-05-10 04:19:35 -0400137 @bash ./script/compress.sh
Matus Fabian2d1bc4c2024-05-09 10:46:58 +0200138
adrianvillin85121452024-01-11 11:59:47 +0100139.PHONY: test-cov
Adrian Villinf4972f92024-06-04 08:59:58 -0400140test-cov: .deps.ok .build.cov.ok
Dave Wallacebee28af2024-06-14 14:59:38 -0400141 @-bash ./hs_test.sh --persist=$(PERSIST) --verbose=$(VERBOSE) \
adrianvillin85121452024-01-11 11:59:47 +0100142 --unconfigure=$(UNCONFIGURE) --debug=$(DEBUG) --test=$(TEST-HS) --cpus=$(CPUS) \
Adrian Villin5d171eb2024-06-17 08:51:27 +0200143 --vppsrc=$(VPPSRC) --cpu0=$(CPU0)
Renato Botelho do Couto893daca2024-06-05 18:11:46 +0000144 @$(MAKE) -C ../.. test-cov-post HS_TEST=1
adrianvillin85121452024-01-11 11:59:47 +0100145 @bash ./script/compress.sh
146
Matus Fabiane99d2662024-07-19 16:04:09 +0200147.PHONY: test-leak
148test-leak: .deps.ok .build_debug.ok
149 @bash ./hs_test.sh --test=$(TEST) --debug_build=true --leak_check=true --vppsrc=$(VPPSRC)
150
Dave Wallace83b12bf2024-04-25 16:21:37 -0400151.PHONY: build-go
Filip Tehlar671cf512023-01-31 10:34:18 +0100152build-go:
Filip Tehlar229f5fc2022-08-09 14:44:47 +0000153 go build ./tools/http_server
Filip Tehlar229f5fc2022-08-09 14:44:47 +0000154
Dave Wallace83b12bf2024-04-25 16:21:37 -0400155.PHONY: build
Filip Tehlar671cf512023-01-31 10:34:18 +0100156build: .deps.ok build-vpp-release build-go
Dave Wallace83b12bf2024-04-25 16:21:37 -0400157 @rm -f .build.ok
Filip Tehlar31eaea92023-06-15 10:06:57 +0200158 bash ./script/build_hst.sh release
Dave Wallace83b12bf2024-04-25 16:21:37 -0400159 @touch .build.ok
Filip Tehlar229f5fc2022-08-09 14:44:47 +0000160
adrianvillin85121452024-01-11 11:59:47 +0100161.PHONY: build-cov
162build-cov: .deps.ok build-vpp-gcov build-go
Adrian Villinf4972f92024-06-04 08:59:58 -0400163 @rm -f .build.cov.ok
adrianvillin85121452024-01-11 11:59:47 +0100164 bash ./script/build_hst.sh gcov
Adrian Villinf4972f92024-06-04 08:59:58 -0400165 @touch .build.cov.ok
adrianvillin85121452024-01-11 11:59:47 +0100166
Dave Wallace83b12bf2024-04-25 16:21:37 -0400167.PHONY: build-debug
Filip Tehlar671cf512023-01-31 10:34:18 +0100168build-debug: .deps.ok build-vpp-debug build-go
Dave Wallace83b12bf2024-04-25 16:21:37 -0400169 @rm -f .build.ok
Filip Tehlar31eaea92023-06-15 10:06:57 +0200170 bash ./script/build_hst.sh debug
Dave Wallace83b12bf2024-04-25 16:21:37 -0400171 @touch .build.ok
Filip Tehlar671cf512023-01-31 10:34:18 +0100172
Dave Wallaced0df24d2023-04-26 18:03:03 -0400173.deps.ok:
Renato Botelho do Couto893daca2024-06-05 18:11:46 +0000174 @sudo $(MAKE) install-deps
Dave Wallaced0df24d2023-04-26 18:03:03 -0400175
Filip Tehlar671cf512023-01-31 10:34:18 +0100176.PHONY: install-deps
177install-deps:
Dave Wallace05120fb2023-03-07 22:09:20 -0500178 @rm -f .deps.ok
Dave Wallacef72bb6f2023-03-08 13:53:32 -0500179 @apt-get update \
180 && apt-get install -y apt-transport-https ca-certificates curl software-properties-common \
Dave Wallace5874dd02024-06-25 20:17:47 -0400181 apache2-utils wrk bridge-utils gpg
Dave Wallacef72bb6f2023-03-08 13:53:32 -0500182 @if [ ! -f /usr/share/keyrings/docker-archive-keyring.gpg ] ; then \
183 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg; \
184 echo "deb [arch=$(ARCH) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(UBUNTU_CODENAME) stable" \
185 | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null ; \
186 apt-get update; \
187 fi
Dave Wallace5874dd02024-06-25 20:17:47 -0400188 @apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Filip Tehlar671cf512023-01-31 10:34:18 +0100189 @touch .deps.ok
190
Adrian Villin56387402024-06-11 10:32:08 +0200191.PHONY: checkstyle-go
192checkstyle-go:
193 @output=$$(gofmt -d $${WS_ROOT}); \
194 if [ -z "$$output" ]; then \
195 echo "*******************************************************************"; \
196 echo "Checkstyle OK."; \
197 echo "*******************************************************************"; \
198 else \
199 echo "$$output"; \
200 echo "*******************************************************************"; \
201 echo "Checkstyle failed. Use 'make fixstyle-go' or fix errors manually."; \
202 echo "*******************************************************************"; \
203 exit 1; \
204 fi
205
206.PHONY: fixstyle-go
207fixstyle-go:
208 @echo "Modified files:"
209 @gofmt -w -l $(WS_ROOT)
Maros Ondrejicka7d7ab102023-02-14 12:56:49 +0100210 @go mod tidy
Adrian Villin56387402024-06-11 10:32:08 +0200211 @echo "*******************************************************************"
212 @echo "Fixstyle done."
213 @echo "*******************************************************************"
Adrian Villin7d1e4a42024-06-13 08:59:58 +0200214
215.PHONY: cleanup-hst
216cleanup-hst:
217 @if [ ! -f ".last_hst_ppid" ]; then \
218 echo "'.last_hst_ppid' file does not exist."; \
219 exit 1; \
220 fi
221 @echo "****************************"
222 @echo "Removing docker containers:"
223 @# "-" ignores errors
224 @-sudo docker rm $$(sudo docker stop $$(sudo docker ps -a -q --filter "name=$$(cat .last_hst_ppid)") -t 0)
225 @echo "****************************"
226 @echo "Removing IP address files:"
227 @find . -type f -regextype egrep -regex '.*[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' -exec sudo rm -v {} \;
228 @echo "****************************"
229 @echo "Removing network namespaces:"
230 @for ns in $$(ip netns list | grep $$(cat .last_hst_ppid) | awk '{print $$1}'); do \
231 echo $$ns; \
232 sudo ip netns delete $$ns; \
233 done
234 @echo "****************************"
235 @echo "Done."
236 @echo "****************************"