blob: 2a501580e53decbe479f643ced067117a2f69046 [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 Villin399d4402024-08-22 10:35:19 +0200122 @bash ./hs_test.sh --persist=$(PERSIST) --verbose=$(VERBOSE) \
Filip Tehlar109f3ce2023-09-05 15:36:28 +0200123 --unconfigure=$(UNCONFIGURE) --debug=$(DEBUG) --test=$(TEST) --cpus=$(CPUS) \
Adrian Villin399d4402024-08-22 10:35:19 +0200124 --vppsrc=$(VPPSRC) --parallel=$(PARALLEL) --repeat=$(REPEAT) --cpu0=$(CPU0); \
125 ./script/compress.sh $$?
126
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 Villin399d4402024-08-22 10:35:19 +0200130 @bash ./hs_test.sh --persist=$(PERSIST) --verbose=$(VERBOSE) \
Matus Fabian2d1bc4c2024-05-09 10:46:58 +0200131 --unconfigure=$(UNCONFIGURE) --debug=$(DEBUG) --test=$(TEST) --cpus=$(CPUS) \
Adrian Villin5d171eb2024-06-17 08:51:27 +0200132 --vppsrc=$(VPPSRC) --parallel=$(PARALLEL) --repeat=$(REPEAT) --debug_build=true \
Adrian Villin399d4402024-08-22 10:35:19 +0200133 --cpu0=$(CPU0); \
134 ./script/compress.sh $$?
Matus Fabian2d1bc4c2024-05-09 10:46:58 +0200135
adrianvillin85121452024-01-11 11:59:47 +0100136.PHONY: test-cov
Adrian Villinf4972f92024-06-04 08:59:58 -0400137test-cov: .deps.ok .build.cov.ok
Adrian Villin399d4402024-08-22 10:35:19 +0200138 @bash ./hs_test.sh --persist=$(PERSIST) --verbose=$(VERBOSE) \
adrianvillin85121452024-01-11 11:59:47 +0100139 --unconfigure=$(UNCONFIGURE) --debug=$(DEBUG) --test=$(TEST-HS) --cpus=$(CPUS) \
Adrian Villin399d4402024-08-22 10:35:19 +0200140 --vppsrc=$(VPPSRC) --cpu0=$(CPU0); \
141 ./script/compress.sh $$?
adrianvillin85121452024-01-11 11:59:47 +0100142
Matus Fabiane99d2662024-07-19 16:04:09 +0200143.PHONY: test-leak
144test-leak: .deps.ok .build_debug.ok
145 @bash ./hs_test.sh --test=$(TEST) --debug_build=true --leak_check=true --vppsrc=$(VPPSRC)
146
Dave Wallace83b12bf2024-04-25 16:21:37 -0400147.PHONY: build-go
Filip Tehlar671cf512023-01-31 10:34:18 +0100148build-go:
Filip Tehlar229f5fc2022-08-09 14:44:47 +0000149 go build ./tools/http_server
Filip Tehlar229f5fc2022-08-09 14:44:47 +0000150
Dave Wallace83b12bf2024-04-25 16:21:37 -0400151.PHONY: build
Filip Tehlar671cf512023-01-31 10:34:18 +0100152build: .deps.ok build-vpp-release build-go
Dave Wallace83b12bf2024-04-25 16:21:37 -0400153 @rm -f .build.ok
Filip Tehlar31eaea92023-06-15 10:06:57 +0200154 bash ./script/build_hst.sh release
Dave Wallace83b12bf2024-04-25 16:21:37 -0400155 @touch .build.ok
Filip Tehlar229f5fc2022-08-09 14:44:47 +0000156
adrianvillin85121452024-01-11 11:59:47 +0100157.PHONY: build-cov
158build-cov: .deps.ok build-vpp-gcov build-go
Adrian Villinf4972f92024-06-04 08:59:58 -0400159 @rm -f .build.cov.ok
adrianvillin85121452024-01-11 11:59:47 +0100160 bash ./script/build_hst.sh gcov
Adrian Villinf4972f92024-06-04 08:59:58 -0400161 @touch .build.cov.ok
adrianvillin85121452024-01-11 11:59:47 +0100162
Dave Wallace83b12bf2024-04-25 16:21:37 -0400163.PHONY: build-debug
Filip Tehlar671cf512023-01-31 10:34:18 +0100164build-debug: .deps.ok build-vpp-debug build-go
Dave Wallace83b12bf2024-04-25 16:21:37 -0400165 @rm -f .build.ok
Filip Tehlar31eaea92023-06-15 10:06:57 +0200166 bash ./script/build_hst.sh debug
Dave Wallace83b12bf2024-04-25 16:21:37 -0400167 @touch .build.ok
Filip Tehlar671cf512023-01-31 10:34:18 +0100168
Dave Wallaced0df24d2023-04-26 18:03:03 -0400169.deps.ok:
Renato Botelho do Couto893daca2024-06-05 18:11:46 +0000170 @sudo $(MAKE) install-deps
Dave Wallaced0df24d2023-04-26 18:03:03 -0400171
Filip Tehlar671cf512023-01-31 10:34:18 +0100172.PHONY: install-deps
173install-deps:
Dave Wallace05120fb2023-03-07 22:09:20 -0500174 @rm -f .deps.ok
Dave Wallacef72bb6f2023-03-08 13:53:32 -0500175 @apt-get update \
176 && apt-get install -y apt-transport-https ca-certificates curl software-properties-common \
Dave Wallace5874dd02024-06-25 20:17:47 -0400177 apache2-utils wrk bridge-utils gpg
Dave Wallacef72bb6f2023-03-08 13:53:32 -0500178 @if [ ! -f /usr/share/keyrings/docker-archive-keyring.gpg ] ; then \
179 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg; \
180 echo "deb [arch=$(ARCH) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(UBUNTU_CODENAME) stable" \
181 | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null ; \
182 apt-get update; \
183 fi
Dave Wallace5874dd02024-06-25 20:17:47 -0400184 @apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Filip Tehlar671cf512023-01-31 10:34:18 +0100185 @touch .deps.ok
186
Adrian Villin56387402024-06-11 10:32:08 +0200187.PHONY: checkstyle-go
188checkstyle-go:
189 @output=$$(gofmt -d $${WS_ROOT}); \
190 if [ -z "$$output" ]; then \
191 echo "*******************************************************************"; \
192 echo "Checkstyle OK."; \
193 echo "*******************************************************************"; \
194 else \
195 echo "$$output"; \
196 echo "*******************************************************************"; \
197 echo "Checkstyle failed. Use 'make fixstyle-go' or fix errors manually."; \
198 echo "*******************************************************************"; \
199 exit 1; \
200 fi
201
202.PHONY: fixstyle-go
203fixstyle-go:
204 @echo "Modified files:"
205 @gofmt -w -l $(WS_ROOT)
Maros Ondrejicka7d7ab102023-02-14 12:56:49 +0100206 @go mod tidy
Adrian Villin56387402024-06-11 10:32:08 +0200207 @echo "*******************************************************************"
208 @echo "Fixstyle done."
209 @echo "*******************************************************************"
Adrian Villin7d1e4a42024-06-13 08:59:58 +0200210
211.PHONY: cleanup-hst
212cleanup-hst:
213 @if [ ! -f ".last_hst_ppid" ]; then \
214 echo "'.last_hst_ppid' file does not exist."; \
215 exit 1; \
216 fi
217 @echo "****************************"
218 @echo "Removing docker containers:"
219 @# "-" ignores errors
220 @-sudo docker rm $$(sudo docker stop $$(sudo docker ps -a -q --filter "name=$$(cat .last_hst_ppid)") -t 0)
221 @echo "****************************"
222 @echo "Removing IP address files:"
223 @find . -type f -regextype egrep -regex '.*[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' -exec sudo rm -v {} \;
224 @echo "****************************"
225 @echo "Removing network namespaces:"
226 @for ns in $$(ip netns list | grep $$(cat .last_hst_ppid) | awk '{print $$1}'); do \
227 echo $$ns; \
228 sudo ip netns delete $$ns; \
229 done
230 @echo "****************************"
231 @echo "Done."
232 @echo "****************************"