blob: 596acb1b57d72ecc9db231b9de5b63ab43c0c8cf [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
Filip Tehlar109f3ce2023-09-05 15:36:28 +020044ifeq ($(VPPSRC),)
45VPPSRC=$(shell pwd)/../..
46endif
47
Dave Wallace05120fb2023-03-07 22:09:20 -050048ifeq ($(UBUNTU_CODENAME),)
49UBUNTU_CODENAME=$(shell grep '^UBUNTU_CODENAME=' /etc/os-release | cut -f2- -d=)
50endif
51
52ifeq ($(ARCH),)
53ARCH=$(shell dpkg --print-architecture)
54endif
55
Filip Tehlar671cf512023-01-31 10:34:18 +010056.PHONY: help
57help:
58 @echo "Make targets:"
Adrian Villin4677d922024-06-14 09:32:39 +020059 @echo " test - run tests"
60 @echo " test-debug - run tests (vpp debug image)"
61 @echo " build - build test infra"
62 @echo " build-cov - coverage build of VPP and Docker images"
63 @echo " build-debug - build test infra (vpp debug image)"
64 @echo " build-go - just build golang files"
65 @echo " checkstyle-go - check style of .go source files"
66 @echo " fixstyle-go - format .go source files"
67 @echo " cleanup-hst - stops and removes all docker contaiers and namespaces"
68 @echo " list-tests - list all tests"
Filip Tehlar671cf512023-01-31 10:34:18 +010069 @echo
Adrian Villin4677d922024-06-14 09:32:39 +020070 @echo "'make build' arguments:"
Filip Tehlar671cf512023-01-31 10:34:18 +010071 @echo " UBUNTU_VERSION - ubuntu version for docker image"
Adrian Villin4677d922024-06-14 09:32:39 +020072 @echo " HST_EXTENDED_TESTS - build extended tests"
Filip Tehlar31eaea92023-06-15 10:06:57 +020073 @echo
Adrian Villin4677d922024-06-14 09:32:39 +020074 @echo "'make test' arguments:"
Filip Tehlar671cf512023-01-31 10:34:18 +010075 @echo " PERSIST=[true|false] - whether clean up topology and dockers after test"
76 @echo " VERBOSE=[true|false] - verbose output"
Florin Corase2415f72023-02-28 14:51:03 -080077 @echo " UNCONFIGURE=[true|false] - unconfigure selected test"
Filip Tehlarec5c40b2023-02-28 18:59:15 +010078 @echo " DEBUG=[true|false] - attach VPP to GDB"
Filip Tehlar671cf512023-01-31 10:34:18 +010079 @echo " TEST=[test-name] - specific test to run"
Adrian Villinb9464cd2024-05-27 09:52:59 -040080 @echo " CPUS=[n-cpus] - number of cpus to allocate to VPP and containers"
Filip Tehlar109f3ce2023-09-05 15:36:28 +020081 @echo " VPPSRC=[path-to-vpp-src] - path to vpp source files (for gdb)"
Matus Fabianbbee45c2024-04-22 19:47:27 +020082 @echo " PARALLEL=[n-cpus] - number of test processes to spawn to run in parallel"
83 @echo " REPEAT=[n] - repeat tests up to N times or until a failure occurs"
Filip Tehlar671cf512023-01-31 10:34:18 +010084 @echo
85 @echo "List of all tests:"
Adrian Villin4677d922024-06-14 09:32:39 +020086 @$(MAKE) list-tests
Filip Tehlar671cf512023-01-31 10:34:18 +010087
88.PHONY: list-tests
89list-tests:
Adrian Villin4677d922024-06-14 09:32:39 +020090 @go run github.com/onsi/ginkgo/v2/ginkgo --dry-run -v --no-color --seed=2 | head -n -1 | grep 'Test' | \
91 sed 's/^/* /; s/\(Suite\) /\1\//g'
Filip Tehlar671cf512023-01-31 10:34:18 +010092
Dave Wallace83b12bf2024-04-25 16:21:37 -040093.PHONY: build-vpp-release
Filip Tehlar671cf512023-01-31 10:34:18 +010094build-vpp-release:
Renato Botelho do Couto893daca2024-06-05 18:11:46 +000095 @$(MAKE) -C ../.. build-release
Filip Tehlar671cf512023-01-31 10:34:18 +010096
Dave Wallace83b12bf2024-04-25 16:21:37 -040097.PHONY: build-vpp-debug
Filip Tehlar671cf512023-01-31 10:34:18 +010098build-vpp-debug:
Renato Botelho do Couto893daca2024-06-05 18:11:46 +000099 @$(MAKE) -C ../.. build
Filip Tehlar671cf512023-01-31 10:34:18 +0100100
adrianvillin85121452024-01-11 11:59:47 +0100101.PHONY: build-vpp-gcov
102build-vpp-gcov:
Renato Botelho do Couto893daca2024-06-05 18:11:46 +0000103 @$(MAKE) -C ../.. build-vpp-gcov
adrianvillin85121452024-01-11 11:59:47 +0100104
Dave Wallace83b12bf2024-04-25 16:21:37 -0400105.build.ok: build
106 @touch .build.ok
107
Adrian Villinf4972f92024-06-04 08:59:58 -0400108.build.cov.ok: build-vpp-gcov
109 @touch .build.cov.ok
110
Matus Fabian2d1bc4c2024-05-09 10:46:58 +0200111.build_debug.ok: build-debug
112 @touch .build.ok
113
Filip Tehlar671cf512023-01-31 10:34:18 +0100114.PHONY: test
Dave Wallace83b12bf2024-04-25 16:21:37 -0400115test: .deps.ok .build.ok
Adrian Villin7d1e4a42024-06-13 08:59:58 +0200116 @# '-' ignores the exit status, it is set in compress.sh
117 @# necessary so gmake won't skip executing the bash script
Dave Wallacebee28af2024-06-14 14:59:38 -0400118 @-bash ./hs_test.sh --persist=$(PERSIST) --verbose=$(VERBOSE) \
Filip Tehlar109f3ce2023-09-05 15:36:28 +0200119 --unconfigure=$(UNCONFIGURE) --debug=$(DEBUG) --test=$(TEST) --cpus=$(CPUS) \
Matus Fabianbbee45c2024-04-22 19:47:27 +0200120 --vppsrc=$(VPPSRC) --parallel=$(PARALLEL) --repeat=$(REPEAT)
Adrian Villin637edda2024-05-06 06:55:34 -0400121 @bash ./script/compress.sh
Filip Tehlar671cf512023-01-31 10:34:18 +0100122
Matus Fabian2d1bc4c2024-05-09 10:46:58 +0200123.PHONY: test-debug
124test-debug: .deps.ok .build_debug.ok
Adrian Villin7d1e4a42024-06-13 08:59:58 +0200125 @# '-' ignores the exit status, it is set in compress.sh
126 @# necessary so gmake won't skip executing the bash script
Dave Wallacebee28af2024-06-14 14:59:38 -0400127 @-bash ./hs_test.sh --persist=$(PERSIST) --verbose=$(VERBOSE) \
Matus Fabian2d1bc4c2024-05-09 10:46:58 +0200128 --unconfigure=$(UNCONFIGURE) --debug=$(DEBUG) --test=$(TEST) --cpus=$(CPUS) \
Adrian Villinb4516bb2024-06-19 06:20:00 -0400129 --vppsrc=$(VPPSRC) --parallel=$(PARALLEL) --repeat=$(REPEAT) --debug_build=true
Adrian Villin688ac5a2024-05-10 04:19:35 -0400130 @bash ./script/compress.sh
Matus Fabian2d1bc4c2024-05-09 10:46:58 +0200131
adrianvillin85121452024-01-11 11:59:47 +0100132.PHONY: test-cov
Adrian Villinf4972f92024-06-04 08:59:58 -0400133test-cov: .deps.ok .build.cov.ok
Dave Wallacebee28af2024-06-14 14:59:38 -0400134 @-bash ./hs_test.sh --persist=$(PERSIST) --verbose=$(VERBOSE) \
adrianvillin85121452024-01-11 11:59:47 +0100135 --unconfigure=$(UNCONFIGURE) --debug=$(DEBUG) --test=$(TEST-HS) --cpus=$(CPUS) \
136 --vppsrc=$(VPPSRC)
Renato Botelho do Couto893daca2024-06-05 18:11:46 +0000137 @$(MAKE) -C ../.. test-cov-post HS_TEST=1
adrianvillin85121452024-01-11 11:59:47 +0100138 @bash ./script/compress.sh
139
Dave Wallace83b12bf2024-04-25 16:21:37 -0400140.PHONY: build-go
Filip Tehlar671cf512023-01-31 10:34:18 +0100141build-go:
Filip Tehlar229f5fc2022-08-09 14:44:47 +0000142 go build ./tools/http_server
Filip Tehlar229f5fc2022-08-09 14:44:47 +0000143
Dave Wallace83b12bf2024-04-25 16:21:37 -0400144.PHONY: build
Filip Tehlar671cf512023-01-31 10:34:18 +0100145build: .deps.ok build-vpp-release build-go
Dave Wallace83b12bf2024-04-25 16:21:37 -0400146 @rm -f .build.ok
Filip Tehlar31eaea92023-06-15 10:06:57 +0200147 bash ./script/build_hst.sh release
Dave Wallace83b12bf2024-04-25 16:21:37 -0400148 @touch .build.ok
Filip Tehlar229f5fc2022-08-09 14:44:47 +0000149
adrianvillin85121452024-01-11 11:59:47 +0100150.PHONY: build-cov
151build-cov: .deps.ok build-vpp-gcov build-go
Adrian Villinf4972f92024-06-04 08:59:58 -0400152 @rm -f .build.cov.ok
adrianvillin85121452024-01-11 11:59:47 +0100153 bash ./script/build_hst.sh gcov
Adrian Villinf4972f92024-06-04 08:59:58 -0400154 @touch .build.cov.ok
adrianvillin85121452024-01-11 11:59:47 +0100155
Dave Wallace83b12bf2024-04-25 16:21:37 -0400156.PHONY: build-debug
Filip Tehlar671cf512023-01-31 10:34:18 +0100157build-debug: .deps.ok build-vpp-debug build-go
Dave Wallace83b12bf2024-04-25 16:21:37 -0400158 @rm -f .build.ok
Filip Tehlar31eaea92023-06-15 10:06:57 +0200159 bash ./script/build_hst.sh debug
Dave Wallace83b12bf2024-04-25 16:21:37 -0400160 @touch .build.ok
Filip Tehlar671cf512023-01-31 10:34:18 +0100161
Dave Wallaced0df24d2023-04-26 18:03:03 -0400162.deps.ok:
Renato Botelho do Couto893daca2024-06-05 18:11:46 +0000163 @sudo $(MAKE) install-deps
Dave Wallaced0df24d2023-04-26 18:03:03 -0400164
Filip Tehlar671cf512023-01-31 10:34:18 +0100165.PHONY: install-deps
166install-deps:
Dave Wallace05120fb2023-03-07 22:09:20 -0500167 @rm -f .deps.ok
Dave Wallacef72bb6f2023-03-08 13:53:32 -0500168 @apt-get update \
169 && apt-get install -y apt-transport-https ca-certificates curl software-properties-common \
Dave Wallace83b12bf2024-04-25 16:21:37 -0400170 apache2-utils wrk bridge-utils
Dave Wallacef72bb6f2023-03-08 13:53:32 -0500171 @if [ ! -f /usr/share/keyrings/docker-archive-keyring.gpg ] ; then \
172 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg; \
173 echo "deb [arch=$(ARCH) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(UBUNTU_CODENAME) stable" \
174 | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null ; \
175 apt-get update; \
176 fi
Filip Tehlar671cf512023-01-31 10:34:18 +0100177 @touch .deps.ok
178
Adrian Villin56387402024-06-11 10:32:08 +0200179.PHONY: checkstyle-go
180checkstyle-go:
181 @output=$$(gofmt -d $${WS_ROOT}); \
182 if [ -z "$$output" ]; then \
183 echo "*******************************************************************"; \
184 echo "Checkstyle OK."; \
185 echo "*******************************************************************"; \
186 else \
187 echo "$$output"; \
188 echo "*******************************************************************"; \
189 echo "Checkstyle failed. Use 'make fixstyle-go' or fix errors manually."; \
190 echo "*******************************************************************"; \
191 exit 1; \
192 fi
193
194.PHONY: fixstyle-go
195fixstyle-go:
196 @echo "Modified files:"
197 @gofmt -w -l $(WS_ROOT)
Maros Ondrejicka7d7ab102023-02-14 12:56:49 +0100198 @go mod tidy
Adrian Villin56387402024-06-11 10:32:08 +0200199 @echo "*******************************************************************"
200 @echo "Fixstyle done."
201 @echo "*******************************************************************"
Adrian Villin7d1e4a42024-06-13 08:59:58 +0200202
203.PHONY: cleanup-hst
204cleanup-hst:
205 @if [ ! -f ".last_hst_ppid" ]; then \
206 echo "'.last_hst_ppid' file does not exist."; \
207 exit 1; \
208 fi
209 @echo "****************************"
210 @echo "Removing docker containers:"
211 @# "-" ignores errors
212 @-sudo docker rm $$(sudo docker stop $$(sudo docker ps -a -q --filter "name=$$(cat .last_hst_ppid)") -t 0)
213 @echo "****************************"
214 @echo "Removing IP address files:"
215 @find . -type f -regextype egrep -regex '.*[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' -exec sudo rm -v {} \;
216 @echo "****************************"
217 @echo "Removing network namespaces:"
218 @for ns in $$(ip netns list | grep $$(cat .last_hst_ppid) | awk '{print $$1}'); do \
219 echo $$ns; \
220 sudo ip netns delete $$ns; \
221 done
222 @echo "****************************"
223 @echo "Done."
224 @echo "****************************"