Adrian Villin | 688ac5a | 2024-05-10 04:19:35 -0400 | [diff] [blame] | 1 | export HS_ROOT=$(CURDIR) |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 2 | |
Adrian Villin | 5638740 | 2024-06-11 10:32:08 +0200 | [diff] [blame] | 3 | # sets WS_ROOT if called from extras/hs-test |
| 4 | ifeq ($(WS_ROOT),) |
| 5 | export WS_ROOT=$(HS_ROOT)/../.. |
| 6 | endif |
| 7 | |
Filip Tehlar | 671cf51 | 2023-01-31 10:34:18 +0100 | [diff] [blame] | 8 | ifeq ($(VERBOSE),) |
| 9 | VERBOSE=false |
| 10 | endif |
Maros Ondrejicka | 2ddb2fd | 2023-02-15 17:44:46 +0100 | [diff] [blame] | 11 | |
Filip Tehlar | 671cf51 | 2023-01-31 10:34:18 +0100 | [diff] [blame] | 12 | ifeq ($(PERSIST),) |
| 13 | PERSIST=false |
| 14 | endif |
| 15 | |
Maros Ondrejicka | af004dd | 2023-02-27 16:52:57 +0100 | [diff] [blame] | 16 | ifeq ($(UNCONFIGURE),) |
| 17 | UNCONFIGURE=false |
| 18 | endif |
| 19 | |
Filip Tehlar | 671cf51 | 2023-01-31 10:34:18 +0100 | [diff] [blame] | 20 | ifeq ($(TEST),) |
| 21 | TEST=all |
| 22 | endif |
| 23 | |
adrianvillin | 8512145 | 2024-01-11 11:59:47 +0100 | [diff] [blame] | 24 | ifeq ($(TEST-HS),) |
| 25 | TEST-HS=all |
| 26 | endif |
| 27 | |
Filip Tehlar | ec5c40b | 2023-02-28 18:59:15 +0100 | [diff] [blame] | 28 | ifeq ($(DEBUG),) |
| 29 | DEBUG=false |
| 30 | endif |
| 31 | |
Filip Tehlar | 608d006 | 2023-04-28 10:29:47 +0200 | [diff] [blame] | 32 | ifeq ($(CPUS),) |
| 33 | CPUS=1 |
| 34 | endif |
| 35 | |
Adrian Villin | cee15aa | 2024-03-14 11:42:55 -0400 | [diff] [blame] | 36 | ifeq ($(PARALLEL),) |
| 37 | PARALLEL=1 |
| 38 | endif |
| 39 | |
Matus Fabian | bbee45c | 2024-04-22 19:47:27 +0200 | [diff] [blame] | 40 | ifeq ($(REPEAT),) |
| 41 | REPEAT=0 |
| 42 | endif |
| 43 | |
Adrian Villin | 5d171eb | 2024-06-17 08:51:27 +0200 | [diff] [blame] | 44 | ifeq ($(CPU0),) |
| 45 | CPU0=false |
| 46 | endif |
| 47 | |
Filip Tehlar | 109f3ce | 2023-09-05 15:36:28 +0200 | [diff] [blame] | 48 | ifeq ($(VPPSRC),) |
| 49 | VPPSRC=$(shell pwd)/../.. |
| 50 | endif |
| 51 | |
Dave Wallace | 05120fb | 2023-03-07 22:09:20 -0500 | [diff] [blame] | 52 | ifeq ($(UBUNTU_CODENAME),) |
| 53 | UBUNTU_CODENAME=$(shell grep '^UBUNTU_CODENAME=' /etc/os-release | cut -f2- -d=) |
| 54 | endif |
| 55 | |
| 56 | ifeq ($(ARCH),) |
| 57 | ARCH=$(shell dpkg --print-architecture) |
| 58 | endif |
| 59 | |
Filip Tehlar | 671cf51 | 2023-01-31 10:34:18 +0100 | [diff] [blame] | 60 | .PHONY: help |
| 61 | help: |
| 62 | @echo "Make targets:" |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 63 | @echo " test - run tests" |
| 64 | @echo " test-debug - run tests (vpp debug image)" |
Matus Fabian | e99d266 | 2024-07-19 16:04:09 +0200 | [diff] [blame] | 65 | @echo " test-leak - run memory leak tests (vpp debug image)" |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 66 | @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 Tehlar | 671cf51 | 2023-01-31 10:34:18 +0100 | [diff] [blame] | 74 | @echo |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 75 | @echo "'make build' arguments:" |
Filip Tehlar | 671cf51 | 2023-01-31 10:34:18 +0100 | [diff] [blame] | 76 | @echo " UBUNTU_VERSION - ubuntu version for docker image" |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 77 | @echo " HST_EXTENDED_TESTS - build extended tests" |
Filip Tehlar | 31eaea9 | 2023-06-15 10:06:57 +0200 | [diff] [blame] | 78 | @echo |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 79 | @echo "'make test' arguments:" |
Filip Tehlar | 671cf51 | 2023-01-31 10:34:18 +0100 | [diff] [blame] | 80 | @echo " PERSIST=[true|false] - whether clean up topology and dockers after test" |
| 81 | @echo " VERBOSE=[true|false] - verbose output" |
Florin Coras | e2415f7 | 2023-02-28 14:51:03 -0800 | [diff] [blame] | 82 | @echo " UNCONFIGURE=[true|false] - unconfigure selected test" |
Filip Tehlar | ec5c40b | 2023-02-28 18:59:15 +0100 | [diff] [blame] | 83 | @echo " DEBUG=[true|false] - attach VPP to GDB" |
Filip Tehlar | 671cf51 | 2023-01-31 10:34:18 +0100 | [diff] [blame] | 84 | @echo " TEST=[test-name] - specific test to run" |
Adrian Villin | b9464cd | 2024-05-27 09:52:59 -0400 | [diff] [blame] | 85 | @echo " CPUS=[n-cpus] - number of cpus to allocate to VPP and containers" |
Filip Tehlar | 109f3ce | 2023-09-05 15:36:28 +0200 | [diff] [blame] | 86 | @echo " VPPSRC=[path-to-vpp-src] - path to vpp source files (for gdb)" |
Matus Fabian | bbee45c | 2024-04-22 19:47:27 +0200 | [diff] [blame] | 87 | @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 Villin | 5d171eb | 2024-06-17 08:51:27 +0200 | [diff] [blame] | 89 | @echo " CPU0=[true|false] - use cpu0" |
Filip Tehlar | 671cf51 | 2023-01-31 10:34:18 +0100 | [diff] [blame] | 90 | @echo |
| 91 | @echo "List of all tests:" |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 92 | @$(MAKE) list-tests |
Filip Tehlar | 671cf51 | 2023-01-31 10:34:18 +0100 | [diff] [blame] | 93 | |
| 94 | .PHONY: list-tests |
| 95 | list-tests: |
Adrian Villin | 4677d92 | 2024-06-14 09:32:39 +0200 | [diff] [blame] | 96 | @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 Tehlar | 671cf51 | 2023-01-31 10:34:18 +0100 | [diff] [blame] | 98 | |
Dave Wallace | 83b12bf | 2024-04-25 16:21:37 -0400 | [diff] [blame] | 99 | .PHONY: build-vpp-release |
Filip Tehlar | 671cf51 | 2023-01-31 10:34:18 +0100 | [diff] [blame] | 100 | build-vpp-release: |
Renato Botelho do Couto | 893daca | 2024-06-05 18:11:46 +0000 | [diff] [blame] | 101 | @$(MAKE) -C ../.. build-release |
Filip Tehlar | 671cf51 | 2023-01-31 10:34:18 +0100 | [diff] [blame] | 102 | |
Dave Wallace | 83b12bf | 2024-04-25 16:21:37 -0400 | [diff] [blame] | 103 | .PHONY: build-vpp-debug |
Filip Tehlar | 671cf51 | 2023-01-31 10:34:18 +0100 | [diff] [blame] | 104 | build-vpp-debug: |
Renato Botelho do Couto | 893daca | 2024-06-05 18:11:46 +0000 | [diff] [blame] | 105 | @$(MAKE) -C ../.. build |
Filip Tehlar | 671cf51 | 2023-01-31 10:34:18 +0100 | [diff] [blame] | 106 | |
adrianvillin | 8512145 | 2024-01-11 11:59:47 +0100 | [diff] [blame] | 107 | .PHONY: build-vpp-gcov |
| 108 | build-vpp-gcov: |
Renato Botelho do Couto | 893daca | 2024-06-05 18:11:46 +0000 | [diff] [blame] | 109 | @$(MAKE) -C ../.. build-vpp-gcov |
adrianvillin | 8512145 | 2024-01-11 11:59:47 +0100 | [diff] [blame] | 110 | |
Dave Wallace | 83b12bf | 2024-04-25 16:21:37 -0400 | [diff] [blame] | 111 | .build.ok: build |
| 112 | @touch .build.ok |
| 113 | |
Adrian Villin | f4972f9 | 2024-06-04 08:59:58 -0400 | [diff] [blame] | 114 | .build.cov.ok: build-vpp-gcov |
| 115 | @touch .build.cov.ok |
| 116 | |
Matus Fabian | 2d1bc4c | 2024-05-09 10:46:58 +0200 | [diff] [blame] | 117 | .build_debug.ok: build-debug |
| 118 | @touch .build.ok |
| 119 | |
Filip Tehlar | 671cf51 | 2023-01-31 10:34:18 +0100 | [diff] [blame] | 120 | .PHONY: test |
Dave Wallace | 83b12bf | 2024-04-25 16:21:37 -0400 | [diff] [blame] | 121 | test: .deps.ok .build.ok |
Adrian Villin | 7d1e4a4 | 2024-06-13 08:59:58 +0200 | [diff] [blame] | 122 | @# '-' ignores the exit status, it is set in compress.sh |
| 123 | @# necessary so gmake won't skip executing the bash script |
Dave Wallace | bee28af | 2024-06-14 14:59:38 -0400 | [diff] [blame] | 124 | @-bash ./hs_test.sh --persist=$(PERSIST) --verbose=$(VERBOSE) \ |
Filip Tehlar | 109f3ce | 2023-09-05 15:36:28 +0200 | [diff] [blame] | 125 | --unconfigure=$(UNCONFIGURE) --debug=$(DEBUG) --test=$(TEST) --cpus=$(CPUS) \ |
Adrian Villin | 5d171eb | 2024-06-17 08:51:27 +0200 | [diff] [blame] | 126 | --vppsrc=$(VPPSRC) --parallel=$(PARALLEL) --repeat=$(REPEAT) --cpu0=$(CPU0) |
Adrian Villin | 637edda | 2024-05-06 06:55:34 -0400 | [diff] [blame] | 127 | @bash ./script/compress.sh |
Filip Tehlar | 671cf51 | 2023-01-31 10:34:18 +0100 | [diff] [blame] | 128 | |
Matus Fabian | 2d1bc4c | 2024-05-09 10:46:58 +0200 | [diff] [blame] | 129 | .PHONY: test-debug |
| 130 | test-debug: .deps.ok .build_debug.ok |
Adrian Villin | 7d1e4a4 | 2024-06-13 08:59:58 +0200 | [diff] [blame] | 131 | @# '-' ignores the exit status, it is set in compress.sh |
| 132 | @# necessary so gmake won't skip executing the bash script |
Dave Wallace | bee28af | 2024-06-14 14:59:38 -0400 | [diff] [blame] | 133 | @-bash ./hs_test.sh --persist=$(PERSIST) --verbose=$(VERBOSE) \ |
Matus Fabian | 2d1bc4c | 2024-05-09 10:46:58 +0200 | [diff] [blame] | 134 | --unconfigure=$(UNCONFIGURE) --debug=$(DEBUG) --test=$(TEST) --cpus=$(CPUS) \ |
Adrian Villin | 5d171eb | 2024-06-17 08:51:27 +0200 | [diff] [blame] | 135 | --vppsrc=$(VPPSRC) --parallel=$(PARALLEL) --repeat=$(REPEAT) --debug_build=true \ |
| 136 | --cpu0=$(CPU0) |
Adrian Villin | 688ac5a | 2024-05-10 04:19:35 -0400 | [diff] [blame] | 137 | @bash ./script/compress.sh |
Matus Fabian | 2d1bc4c | 2024-05-09 10:46:58 +0200 | [diff] [blame] | 138 | |
adrianvillin | 8512145 | 2024-01-11 11:59:47 +0100 | [diff] [blame] | 139 | .PHONY: test-cov |
Adrian Villin | f4972f9 | 2024-06-04 08:59:58 -0400 | [diff] [blame] | 140 | test-cov: .deps.ok .build.cov.ok |
Dave Wallace | bee28af | 2024-06-14 14:59:38 -0400 | [diff] [blame] | 141 | @-bash ./hs_test.sh --persist=$(PERSIST) --verbose=$(VERBOSE) \ |
adrianvillin | 8512145 | 2024-01-11 11:59:47 +0100 | [diff] [blame] | 142 | --unconfigure=$(UNCONFIGURE) --debug=$(DEBUG) --test=$(TEST-HS) --cpus=$(CPUS) \ |
Adrian Villin | 5d171eb | 2024-06-17 08:51:27 +0200 | [diff] [blame] | 143 | --vppsrc=$(VPPSRC) --cpu0=$(CPU0) |
Renato Botelho do Couto | 893daca | 2024-06-05 18:11:46 +0000 | [diff] [blame] | 144 | @$(MAKE) -C ../.. test-cov-post HS_TEST=1 |
adrianvillin | 8512145 | 2024-01-11 11:59:47 +0100 | [diff] [blame] | 145 | @bash ./script/compress.sh |
| 146 | |
Matus Fabian | e99d266 | 2024-07-19 16:04:09 +0200 | [diff] [blame] | 147 | .PHONY: test-leak |
| 148 | test-leak: .deps.ok .build_debug.ok |
| 149 | @bash ./hs_test.sh --test=$(TEST) --debug_build=true --leak_check=true --vppsrc=$(VPPSRC) |
| 150 | |
Dave Wallace | 83b12bf | 2024-04-25 16:21:37 -0400 | [diff] [blame] | 151 | .PHONY: build-go |
Filip Tehlar | 671cf51 | 2023-01-31 10:34:18 +0100 | [diff] [blame] | 152 | build-go: |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 153 | go build ./tools/http_server |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 154 | |
Dave Wallace | 83b12bf | 2024-04-25 16:21:37 -0400 | [diff] [blame] | 155 | .PHONY: build |
Filip Tehlar | 671cf51 | 2023-01-31 10:34:18 +0100 | [diff] [blame] | 156 | build: .deps.ok build-vpp-release build-go |
Dave Wallace | 83b12bf | 2024-04-25 16:21:37 -0400 | [diff] [blame] | 157 | @rm -f .build.ok |
Filip Tehlar | 31eaea9 | 2023-06-15 10:06:57 +0200 | [diff] [blame] | 158 | bash ./script/build_hst.sh release |
Dave Wallace | 83b12bf | 2024-04-25 16:21:37 -0400 | [diff] [blame] | 159 | @touch .build.ok |
Filip Tehlar | 229f5fc | 2022-08-09 14:44:47 +0000 | [diff] [blame] | 160 | |
adrianvillin | 8512145 | 2024-01-11 11:59:47 +0100 | [diff] [blame] | 161 | .PHONY: build-cov |
| 162 | build-cov: .deps.ok build-vpp-gcov build-go |
Adrian Villin | f4972f9 | 2024-06-04 08:59:58 -0400 | [diff] [blame] | 163 | @rm -f .build.cov.ok |
adrianvillin | 8512145 | 2024-01-11 11:59:47 +0100 | [diff] [blame] | 164 | bash ./script/build_hst.sh gcov |
Adrian Villin | f4972f9 | 2024-06-04 08:59:58 -0400 | [diff] [blame] | 165 | @touch .build.cov.ok |
adrianvillin | 8512145 | 2024-01-11 11:59:47 +0100 | [diff] [blame] | 166 | |
Dave Wallace | 83b12bf | 2024-04-25 16:21:37 -0400 | [diff] [blame] | 167 | .PHONY: build-debug |
Filip Tehlar | 671cf51 | 2023-01-31 10:34:18 +0100 | [diff] [blame] | 168 | build-debug: .deps.ok build-vpp-debug build-go |
Dave Wallace | 83b12bf | 2024-04-25 16:21:37 -0400 | [diff] [blame] | 169 | @rm -f .build.ok |
Filip Tehlar | 31eaea9 | 2023-06-15 10:06:57 +0200 | [diff] [blame] | 170 | bash ./script/build_hst.sh debug |
Dave Wallace | 83b12bf | 2024-04-25 16:21:37 -0400 | [diff] [blame] | 171 | @touch .build.ok |
Filip Tehlar | 671cf51 | 2023-01-31 10:34:18 +0100 | [diff] [blame] | 172 | |
Dave Wallace | d0df24d | 2023-04-26 18:03:03 -0400 | [diff] [blame] | 173 | .deps.ok: |
Renato Botelho do Couto | 893daca | 2024-06-05 18:11:46 +0000 | [diff] [blame] | 174 | @sudo $(MAKE) install-deps |
Dave Wallace | d0df24d | 2023-04-26 18:03:03 -0400 | [diff] [blame] | 175 | |
Filip Tehlar | 671cf51 | 2023-01-31 10:34:18 +0100 | [diff] [blame] | 176 | .PHONY: install-deps |
| 177 | install-deps: |
Dave Wallace | 05120fb | 2023-03-07 22:09:20 -0500 | [diff] [blame] | 178 | @rm -f .deps.ok |
Dave Wallace | f72bb6f | 2023-03-08 13:53:32 -0500 | [diff] [blame] | 179 | @apt-get update \ |
| 180 | && apt-get install -y apt-transport-https ca-certificates curl software-properties-common \ |
Dave Wallace | 5874dd0 | 2024-06-25 20:17:47 -0400 | [diff] [blame] | 181 | apache2-utils wrk bridge-utils gpg |
Dave Wallace | f72bb6f | 2023-03-08 13:53:32 -0500 | [diff] [blame] | 182 | @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 Wallace | 5874dd0 | 2024-06-25 20:17:47 -0400 | [diff] [blame] | 188 | @apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin |
Filip Tehlar | 671cf51 | 2023-01-31 10:34:18 +0100 | [diff] [blame] | 189 | @touch .deps.ok |
| 190 | |
Adrian Villin | 5638740 | 2024-06-11 10:32:08 +0200 | [diff] [blame] | 191 | .PHONY: checkstyle-go |
| 192 | checkstyle-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 |
| 207 | fixstyle-go: |
| 208 | @echo "Modified files:" |
| 209 | @gofmt -w -l $(WS_ROOT) |
Maros Ondrejicka | 7d7ab10 | 2023-02-14 12:56:49 +0100 | [diff] [blame] | 210 | @go mod tidy |
Adrian Villin | 5638740 | 2024-06-11 10:32:08 +0200 | [diff] [blame] | 211 | @echo "*******************************************************************" |
| 212 | @echo "Fixstyle done." |
| 213 | @echo "*******************************************************************" |
Adrian Villin | 7d1e4a4 | 2024-06-13 08:59:58 +0200 | [diff] [blame] | 214 | |
| 215 | .PHONY: cleanup-hst |
| 216 | cleanup-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 "****************************" |