summaryrefslogtreecommitdiffstats
path: root/extras/hs-test/Makefile
blob: 118afefa543b92b26ab620fbacd4c87d389094a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
export HS_ROOT=$(CURDIR)

# sets WS_ROOT if called from extras/hs-test
ifeq ($(WS_ROOT),)
export WS_ROOT=$(HS_ROOT)/../..
endif

ifeq ($(VERBOSE),)
VERBOSE=false
endif

ifeq ($(PERSIST),)
PERSIST=false
endif

ifeq ($(UNCONFIGURE),)
UNCONFIGURE=false
endif

ifeq ($(TEST),)
TEST=all
endif

ifeq ($(TEST-HS),)
TEST-HS=all
endif

ifeq ($(DEBUG),)
DEBUG=false
endif

ifeq ($(CPUS),)
CPUS=1
endif

ifeq ($(PARALLEL),)
PARALLEL=1
endif

ifeq ($(REPEAT),)
REPEAT=0
endif

ifeq ($(VPPSRC),)
VPPSRC=$(shell pwd)/../..
endif

ifeq ($(UBUNTU_CODENAME),)
UBUNTU_CODENAME=$(shell grep '^UBUNTU_CODENAME=' /etc/os-release | cut -f2- -d=)
endif

ifeq ($(ARCH),)
ARCH=$(shell dpkg --print-architecture)
endif

list_tests = @go run github.com/onsi/ginkgo/v2/ginkgo --dry-run -v --no-color --seed=2 | head -n -1 | grep 'Test' | \
		sed 's/^/* /; s/\(Suite\) /\1\//g'

.PHONY: help
help:
	@echo "Make targets:"
	@echo " test                 - run tests"
	@echo " test-debug           - run tests (vpp debug image)"
	@echo " build                - build test infra"
	@echo " build-cov			 - coverage build of VPP and Docker images"
	@echo " build-debug          - build test infra (vpp debug image)"
	@echo " build-go             - just build golang files"
	@echo " checkstyle-go        - check style of .go source files"
	@echo " fixstyle-go          - format .go source files"
	@echo " list-tests           - list all tests"
	@echo
	@echo "make build arguments:"
	@echo " UBUNTU_VERSION           - ubuntu version for docker image"
	@echo " HST_EXTENDED_TESTS	 - build extended tests"
	@echo
	@echo "make test arguments:"
	@echo " PERSIST=[true|false]     - whether clean up topology and dockers after test"
	@echo " VERBOSE=[true|false]     - verbose output"
	@echo " UNCONFIGURE=[true|false] - unconfigure selected test"
	@echo " DEBUG=[true|false]       - attach VPP to GDB"
	@echo " TEST=[test-name]         - specific test to run"
	@echo " CPUS=[n-cpus]            - number of cpus to allocate to VPP and containers"
	@echo " VPPSRC=[path-to-vpp-src] - path to vpp source files (for gdb)"
	@echo " PARALLEL=[n-cpus]        - number of test processes to spawn to run in parallel"
	@echo " REPEAT=[n]               - repeat tests up to N times or until a failure occurs"
	@echo
	@echo "List of all tests:"
	$(call list_tests)

.PHONY: list-tests
list-tests:
	$(call list_tests)

.PHONY: build-vpp-release
build-vpp-release:
	@$(MAKE) -C ../.. build-release

.PHONY: build-vpp-debug
build-vpp-debug:
	@$(MAKE) -C ../.. build

.PHONY: build-vpp-gcov
build-vpp-gcov:
	@$(MAKE) -C ../.. build-vpp-gcov

.build.ok: build
	@touch .build.ok

.build.cov.ok: build-vpp-gcov
	@touch .build.cov.ok

.build_debug.ok: build-debug
	@touch .build.ok

.PHONY: test
test: .deps.ok .build.ok
	# '-' ignores the exit status, it is set in compress.sh
	# necessary so gmake won't skip executing the bash script
	-bash ./test --persist=$(PERSIST) --verbose=$(VERBOSE) \
		--unconfigure=$(UNCONFIGURE) --debug=$(DEBUG) --test=$(TEST) --cpus=$(CPUS) \
		--vppsrc=$(VPPSRC) --parallel=$(PARALLEL) --repeat=$(REPEAT)
	@bash ./script/compress.sh

.PHONY: test-debug
test-debug: .deps.ok .build_debug.ok
	# '-' ignores the exit status, it is set in compress.sh
	# necessary so gmake won't skip executing the bash script
	-bash ./test --persist=$(PERSIST) --verbose=$(VERBOSE) \
		--unconfigure=$(UNCONFIGURE) --debug=$(DEBUG) --test=$(TEST) --cpus=$(CPUS) \
		--vppsrc=$(VPPSRC) --parallel=$(PARALLEL) --repeat=$(REPEAT)
	@bash ./script/compress.sh

.PHONY: test-cov
test-cov: .deps.ok .build.cov.ok
	-bash ./test --persist=$(PERSIST) --verbose=$(VERBOSE) \
		--unconfigure=$(UNCONFIGURE) --debug=$(DEBUG) --test=$(TEST-HS) --cpus=$(CPUS) \
		--vppsrc=$(VPPSRC)
	@$(MAKE) -C ../.. test-cov-post HS_TEST=1
	@bash ./script/compress.sh

.PHONY: build-go
build-go:
	go build ./tools/http_server

.PHONY: build
build: .deps.ok build-vpp-release build-go
	@rm -f .build.ok
	bash ./script/build_hst.sh release
	@touch .build.ok

.PHONY: build-cov
build-cov: .deps.ok build-vpp-gcov build-go
	@rm -f .build.cov.ok
	bash ./script/build_hst.sh gcov
	@touch .build.cov.ok

.PHONY: build-debug
build-debug: .deps.ok build-vpp-debug build-go
	@rm -f .build.ok
	bash ./script/build_hst.sh debug
	@touch .build.ok

.deps.ok:
	@sudo $(MAKE) install-deps

.PHONY: install-deps
install-deps:
	@rm -f .deps.ok
	@apt-get update \
		&& apt-get install -y apt-transport-https ca-certificates curl software-properties-common \
		apache2-utils wrk bridge-utils
	@if [ ! -f /usr/share/keyrings/docker-archive-keyring.gpg ] ; then \
		curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg; \
		echo "deb [arch=$(ARCH) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(UBUNTU_CODENAME) stable" \
			| sudo tee /etc/apt/sources.list.d/docker.list > /dev/null ; \
		apt-get update; \
	fi
	@touch .deps.ok

.PHONY: checkstyle-go
checkstyle-go:
	@output=$$(gofmt -d $${WS_ROOT}); \
    if [ -z "$$output" ]; then \
        echo "*******************************************************************"; \
        echo "Checkstyle OK."; \
        echo "*******************************************************************"; \
    else \
        echo "$$output"; \
        echo "*******************************************************************"; \
        echo "Checkstyle failed. Use 'make fixstyle-go' or fix errors manually."; \
        echo "*******************************************************************"; \
        exit 1; \
    fi

.PHONY: fixstyle-go
fixstyle-go:
	@echo "Modified files:"
	@gofmt -w -l $(WS_ROOT)
	@go mod tidy
	@echo "*******************************************************************"
	@echo "Fixstyle done."
	@echo "*******************************************************************"