tests: organize test coverage report generation
[vpp.git] / Makefile
1 # Copyright (c) 2021 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13
14 export WS_ROOT=$(CURDIR)
15 export BR=$(WS_ROOT)/build-root
16 CCACHE_DIR?=$(BR)/.ccache
17 SHELL:=$(shell which bash)
18 GDB?=gdb
19 PLATFORM?=vpp
20 SAMPLE_PLUGIN?=no
21 STARTUP_DIR?=$(PWD)
22 MACHINE=$(shell uname -m)
23 SUDO?=sudo -E
24 DPDK_CONFIG?=no-pci
25
26 ifeq ($(strip $(SHELL)),)
27 $(error "bash not found, VPP requires bash to build")
28 endif
29
30 ,:=,
31 define disable_plugins
32 $(if $(1), \
33   "plugins {" \
34   $(patsubst %,"plugin %_plugin.so { disable }",$(subst $(,), ,$(1))) \
35   " }" \
36   ,)
37 endef
38
39 MINIMAL_STARTUP_CONF="                                                  \
40 unix {                                                                  \
41         interactive                                                     \
42         cli-listen /run/vpp/cli.sock                                    \
43         gid $(shell id -g)                                              \
44         $(if $(wildcard startup.vpp),"exec startup.vpp",)               \
45 }                                                                       \
46 $(if $(DPDK_CONFIG), "dpdk { $(DPDK_CONFIG) }",)                        \
47 $(if $(EXTRA_VPP_CONFIG), "$(EXTRA_VPP_CONFIG)",)                       \
48 $(call disable_plugins,$(DISABLED_PLUGINS))                             \
49 "
50
51 GDB_ARGS= -ex "handle SIGUSR1 noprint nostop"
52
53 #
54 # OS Detection
55 #
56 # We allow Darwin (MacOS) for docs generation; VPP build will still fail.
57 ifneq ($(shell uname),Darwin)
58 OS_ID        = $(shell grep '^ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g')
59 OS_VERSION_ID= $(shell grep '^VERSION_ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g')
60 endif
61
62 ifeq ($(filter ubuntu debian linuxmint,$(OS_ID)),$(OS_ID))
63 PKG=deb
64 else ifeq ($(filter rhel centos fedora opensuse-leap rocky almalinux,$(OS_ID)),$(OS_ID))
65 PKG=rpm
66 endif
67
68 # +libganglia1-dev if building the gmond plugin
69
70 DEB_DEPENDS  = curl build-essential autoconf automake ccache
71 DEB_DEPENDS += debhelper dkms git libtool libapr1-dev dh-python
72 DEB_DEPENDS += libconfuse-dev git-review exuberant-ctags cscope pkg-config
73 DEB_DEPENDS += gcovr lcov chrpath autoconf libnuma-dev
74 DEB_DEPENDS += python3-all python3-setuptools check
75 DEB_DEPENDS += libffi-dev python3-ply libunwind-dev
76 DEB_DEPENDS += cmake ninja-build python3-jsonschema python3-yaml
77 DEB_DEPENDS += python3-venv  # ensurepip
78 DEB_DEPENDS += python3-dev python3-pip
79 DEB_DEPENDS += libnl-3-dev libnl-route-3-dev libmnl-dev
80 # DEB_DEPENDS += enchant  # for docs
81 DEB_DEPENDS += python3-virtualenv
82 DEB_DEPENDS += libssl-dev
83 DEB_DEPENDS += libelf-dev libpcap-dev # for libxdp (af_xdp)
84 DEB_DEPENDS += iperf3 # for 'make test TEST=vcl'
85 DEB_DEPENDS += nasm
86 DEB_DEPENDS += iperf ethtool  # for 'make test TEST=vm_vpp_interfaces'
87 DEB_DEPENDS += libpcap-dev
88 DEB_DEPENDS += tshark
89 DEB_DEPENDS += jq # for extracting test summary from .json report (hs-test)
90
91 LIBFFI=libffi6 # works on all but 20.04 and debian-testing
92
93 ifeq ($(OS_VERSION_ID),22.04)
94         DEB_DEPENDS += python3-virtualenv
95         DEB_DEPENDS += libssl-dev
96         DEB_DEPENDS += clang clang-format-11
97         LIBFFI=libffi7
98         DEB_DEPENDS += enchant-2  # for docs
99 else ifeq ($(OS_VERSION_ID),20.04)
100         DEB_DEPENDS += python3-virtualenv
101         DEB_DEPENDS += libssl-dev
102         DEB_DEPENDS += clang clang-format-11
103         LIBFFI=libffi7
104         DEB_DEPENDS += enchant-2  # for docs
105 else ifeq ($(OS_VERSION_ID),20.10)
106         DEB_DEPENDS += clang clang-format-11
107         LIBFFI=libffi8ubuntu1
108 else ifeq ($(OS_ID)-$(OS_VERSION_ID),debian-10)
109         DEB_DEPENDS += virtualenv
110 else ifeq ($(OS_ID)-$(OS_VERSION_ID),debian-11)
111         DEB_DEPENDS += virtualenv
112         DEB_DEPENDS += clang clang-format-11
113         LIBFFI=libffi7
114 else ifeq ($(OS_ID)-$(OS_VERSION_ID),debian-12)
115         DEB_DEPENDS += virtualenv
116         DEB_DEPENDS += clang-14 clang-format-14
117         # for extras/scripts/checkstyle.sh
118         export CLANG_FORMAT_VER=14
119         LIBFFI=libffi8
120 else
121         DEB_DEPENDS += clang-11 clang-format-11
122         LIBFFI=libffi7
123         DEB_DEPENDS += enchant-2  # for docs
124 endif
125
126 DEB_DEPENDS += $(LIBFFI)
127
128 RPM_DEPENDS  = glibc-static
129 RPM_DEPENDS += apr-devel
130 RPM_DEPENDS += numactl-devel
131 RPM_DEPENDS += check check-devel
132 RPM_DEPENDS += selinux-policy selinux-policy-devel
133 RPM_DEPENDS += ninja-build
134 RPM_DEPENDS += ccache
135 RPM_DEPENDS += xmlto
136 RPM_DEPENDS += elfutils-libelf-devel libpcap-devel
137 RPM_DEPENDS += libnl3-devel libmnl-devel
138 RPM_DEPENDS += nasm
139
140 ifeq ($(OS_ID),fedora)
141         RPM_DEPENDS += dnf-utils
142         RPM_DEPENDS += subunit subunit-devel
143         RPM_DEPENDS += compat-openssl10-devel
144         RPM_DEPENDS += python3-devel  # needed for python3 -m pip install psutil
145         RPM_DEPENDS += python3-ply  # for vppapigen
146         RPM_DEPENDS += python3-virtualenv python3-jsonschema
147         RPM_DEPENDS += cmake
148         RPM_DEPENDS_GROUPS = 'C Development Tools and Libraries'
149 else ifeq ($(OS_ID),rocky)
150         RPM_DEPENDS += yum-utils
151         RPM_DEPENDS += subunit subunit-devel
152         RPM_DEPENDS += openssl-devel
153         RPM_DEPENDS += python3-devel  # needed for python3 -m pip install psutil
154         RPM_DEPENDS += python3-ply  # for vppapigen
155         RPM_DEPENDS += python3-virtualenv python3-jsonschema
156         RPM_DEPENDS += infiniband-diags llvm clang cmake
157         RPM_DEPENDS_GROUPS = 'Development Tools'
158 else ifeq ($(OS_ID),almalinux)
159         RPM_DEPENDS += yum-utils
160         RPM_DEPENDS += subunit subunit-devel
161         RPM_DEPENDS += openssl-devel
162         RPM_DEPENDS += python3-devel  # needed for python3 -m pip install psutil
163         RPM_DEPENDS += python3-ply  # for vppapigen
164         RPM_DEPENDS += python3-virtualenv python3-jsonschema
165         RPM_DEPENDS += infiniband-diags llvm clang cmake
166         RPM_DEPENDS_GROUPS = 'Development Tools'
167 else ifeq ($(OS_ID)-$(OS_VERSION_ID),centos-8)
168         RPM_DEPENDS += yum-utils
169         RPM_DEPENDS += compat-openssl10 openssl-devel
170         RPM_DEPENDS += python2-devel python36-devel python3-ply
171         RPM_DEPENDS += python3-virtualenv python3-jsonschema
172         RPM_DEPENDS += libarchive cmake
173         RPM_DEPENDS += infiniband-diags libibumad
174         RPM_DEPENDS += libpcap-devel llvm-toolset
175         RPM_DEPENDS_GROUPS = 'Development Tools'
176 else
177         RPM_DEPENDS += yum-utils
178         RPM_DEPENDS += openssl-devel
179         RPM_DEPENDS += python36-ply  # for vppapigen
180         RPM_DEPENDS += python3-devel python3-pip
181         RPM_DEPENDS += python-virtualenv python36-jsonschema
182         RPM_DEPENDS += devtoolset-9 devtoolset-9-libasan-devel
183         RPM_DEPENDS += cmake3
184         RPM_DEPENDS_GROUPS = 'Development Tools'
185 endif
186
187 # +ganglia-devel if building the ganglia plugin
188
189 RPM_DEPENDS += chrpath libffi-devel rpm-build
190
191 RPM_DEPENDS_DEBUG  = glibc-debuginfo e2fsprogs-debuginfo
192 RPM_DEPENDS_DEBUG += krb5-debuginfo openssl-debuginfo
193 RPM_DEPENDS_DEBUG += zlib-debuginfo nss-softokn-debuginfo
194 RPM_DEPENDS_DEBUG += yum-plugin-auto-update-debug-info
195
196 RPM_SUSE_BUILDTOOLS_DEPS = autoconf automake ccache check-devel chrpath
197 RPM_SUSE_BUILDTOOLS_DEPS += clang cmake indent libtool make ninja python3-ply
198
199 RPM_SUSE_DEVEL_DEPS = glibc-devel-static libnuma-devel libelf-devel
200 RPM_SUSE_DEVEL_DEPS += libopenssl-devel lsb-release
201 RPM_SUSE_DEVEL_DEPS += libpcap-devel llvm-devel
202 RPM_SUSE_DEVEL_DEPS += curl libstdc++-devel bison gcc-c++ zlib-devel
203
204 RPM_SUSE_PYTHON_DEPS = python3-devel python3-pip python3-rpm-macros
205
206 RPM_SUSE_PLATFORM_DEPS = shadow rpm-build
207
208 ifeq ($(OS_ID),opensuse-leap)
209         RPM_SUSE_DEVEL_DEPS += xmlto openssl-devel asciidoc git nasm
210         RPM_SUSE_PYTHON_DEPS += python3 python3-ply python3-virtualenv
211         RPM_SUSE_PLATFORM_DEPS += distribution-release
212 endif
213
214 RPM_SUSE_DEPENDS += $(RPM_SUSE_BUILDTOOLS_DEPS) $(RPM_SUSE_DEVEL_DEPS) $(RPM_SUSE_PYTHON_DEPS) $(RPM_SUSE_PLATFORM_DEPS)
215
216 ifneq ($(wildcard $(STARTUP_DIR)/startup.conf),)
217         STARTUP_CONF ?= $(STARTUP_DIR)/startup.conf
218 endif
219
220 ifeq ($(findstring y,$(UNATTENDED)),y)
221 DEBIAN_FRONTEND=noninteractive
222 CONFIRM=-y
223 FORCE=--allow-downgrades --allow-remove-essential --allow-change-held-packages
224 endif
225
226 TARGETS = vpp
227
228 ifneq ($(SAMPLE_PLUGIN),no)
229 TARGETS += sample-plugin
230 endif
231
232 define banner
233         @echo "========================================================================"
234         @echo " $(1)"
235         @echo "========================================================================"
236         @echo " "
237 endef
238
239 .PHONY: help
240 help:
241         @echo "Make Targets:"
242         @echo " install-dep[s]       - install software dependencies"
243         @echo " wipe                 - wipe all products of debug build "
244         @echo " wipe-release         - wipe all products of release build "
245         @echo " build                - build debug binaries"
246         @echo " build-release        - build release binaries"
247         @echo " build-coverity       - build coverity artifacts"
248         @echo " build-vpp-gcov           - build gcov vpp only"
249         @echo " rebuild              - wipe and build debug binaries"
250         @echo " rebuild-release      - wipe and build release binaries"
251         @echo " run                  - run debug binary"
252         @echo " run-release          - run release binary"
253         @echo " debug                - run debug binary with debugger"
254         @echo " debug-release        - run release binary with debugger"
255         @echo " test                 - build and run tests"
256         @echo " test-cov-hs              - build and run host stack tests with coverage"
257         @echo " test-cov-both            - build and run python and host stack tests, merge coverage data"
258         @echo " test-help            - show help on test framework"
259         @echo " run-vat              - run vpp-api-test tool"
260         @echo " pkg-deb              - build DEB packages"
261         @echo " pkg-deb-debug        - build DEB debug packages"
262         @echo " pkg-snap             - build SNAP package"
263         @echo " snap-clean           - clean up snap build environment"
264         @echo " pkg-rpm              - build RPM packages"
265         @echo " install-ext-dep[s]   - install external development dependencies"
266         @echo " ctags                - (re)generate ctags database"
267         @echo " gtags                - (re)generate gtags database"
268         @echo " cscope               - (re)generate cscope database"
269         @echo " compdb               - (re)generate compile_commands.json"
270         @echo " checkstyle           - check coding style"
271         @echo " checkstyle-commit    - check commit message format"
272         @echo " checkstyle-python    - check python coding style using 'black' formatter"
273         @echo " checkstyle-api       - check api for incompatible changes"
274         @echo " fixstyle             - fix coding style"
275         @echo " fixstyle-python      - fix python coding style using 'black' formatter"
276         @echo " doxygen              - DEPRECATED - use 'make docs'"
277         @echo " bootstrap-doxygen    - DEPRECATED"
278         @echo " wipe-doxygen         - DEPRECATED"
279         @echo " checkfeaturelist     - check FEATURE.yaml according to schema"
280         @echo " featurelist          - dump feature list in markdown"
281         @echo " json-api-files       - (re)-generate json api files"
282         @echo " json-api-files-debug - (re)-generate json api files for debug target"
283         @echo " go-api-files         - (re)-generate golang api files"
284         @echo " docs                 - Build the Sphinx documentation"
285         @echo " docs-venv            - Build the virtual environment for the Sphinx docs"
286         @echo " docs-clean           - Remove the generated files from the Sphinx docs"
287         @echo " docs-rebuild         - Rebuild all of the Sphinx documentation"
288         @echo ""
289         @echo "Make Arguments:"
290         @echo " V=[0|1]                  - set build verbosity level"
291         @echo " STARTUP_CONF=<path>      - startup configuration file"
292         @echo "                            (e.g. /etc/vpp/startup.conf)"
293         @echo " STARTUP_DIR=<path>       - startup directory (e.g. /etc/vpp)"
294         @echo "                            It also sets STARTUP_CONF if"
295         @echo "                            startup.conf file is present"
296         @echo " GDB=<path>               - gdb binary to use for debugging"
297         @echo " PLATFORM=<name>          - target platform. default is vpp"
298         @echo " DPDK_CONFIG=<conf>       - add specified dpdk config commands to"
299         @echo "                            autogenerated startup.conf"
300         @echo "                            (e.g. \"no-pci\" )"
301         @echo " SAMPLE_PLUGIN=yes        - in addition build/run/debug sample plugin"
302         @echo " DISABLED_PLUGINS=<list>  - comma separated list of plugins which"
303         @echo "                            should not be loaded"
304         @echo ""
305         @echo "Current Argument Values:"
306         @echo " V                 = $(V)"
307         @echo " STARTUP_CONF      = $(STARTUP_CONF)"
308         @echo " STARTUP_DIR       = $(STARTUP_DIR)"
309         @echo " GDB               = $(GDB)"
310         @echo " PLATFORM          = $(PLATFORM)"
311         @echo " DPDK_VERSION      = $(DPDK_VERSION)"
312         @echo " DPDK_CONFIG       = $(DPDK_CONFIG)"
313         @echo " SAMPLE_PLUGIN     = $(SAMPLE_PLUGIN)"
314         @echo " DISABLED_PLUGINS  = $(DISABLED_PLUGINS)"
315
316 $(BR)/.deps.ok:
317 ifeq ($(findstring y,$(UNATTENDED)),y)
318         $(MAKE) install-dep
319 endif
320 ifeq ($(filter ubuntu debian linuxmint,$(OS_ID)),$(OS_ID))
321         @MISSING=$$(apt-get install -y -qq -s $(DEB_DEPENDS) | grep "^Inst ") ; \
322         if [ -n "$$MISSING" ] ; then \
323           echo "\nPlease install missing packages: \n$$MISSING\n" ; \
324           echo "by executing \"make install-dep\"\n" ; \
325           exit 1 ; \
326         fi ; \
327         exit 0
328 else ifneq ("$(wildcard /etc/redhat-release)","")
329         @for i in $(RPM_DEPENDS) ; do \
330             RPM=$$(basename -s .rpm "$${i##*/}" | cut -d- -f1,2,3,4)  ; \
331             MISSING+=$$(rpm -q $$RPM | grep "^package")    ;    \
332         done                                                       ;    \
333         if [ -n "$$MISSING" ] ; then \
334           echo "Please install missing RPMs: \n$$MISSING\n" ; \
335           echo "by executing \"make install-dep\"\n" ; \
336           exit 1 ; \
337         fi ; \
338         exit 0
339 endif
340         @touch $@
341
342 .PHONY: bootstrap
343 bootstrap:
344         @echo "'make bootstrap' is not needed anymore"
345
346 .PHONY: install-dep
347 install-dep:
348 ifeq ($(filter ubuntu debian linuxmint,$(OS_ID)),$(OS_ID))
349         @sudo -E apt-get update
350         @sudo -E apt-get $(APT_ARGS) $(CONFIRM) $(FORCE) install $(DEB_DEPENDS)
351 else ifneq ("$(wildcard /etc/redhat-release)","")
352 ifeq ($(OS_ID),rhel)
353         @sudo -E yum-config-manager --enable rhel-server-rhscl-7-rpms
354         @sudo -E yum groupinstall $(CONFIRM) $(RPM_DEPENDS_GROUPS)
355         @sudo -E yum install $(CONFIRM) $(RPM_DEPENDS)
356         @sudo -E debuginfo-install $(CONFIRM) glibc openssl-libs zlib
357 else ifeq ($(OS_ID),rocky)
358         @sudo -E dnf install $(CONFIRM) dnf-plugins-core epel-release
359         @sudo -E dnf config-manager --set-enabled \
360           $(shell dnf repolist all 2>/dev/null|grep -i crb|cut -d' ' -f1|grep -v source)
361         @sudo -E dnf groupinstall $(CONFIRM) $(RPM_DEPENDS_GROUPS)
362         @sudo -E dnf install $(CONFIRM) $(RPM_DEPENDS)
363 else ifeq ($(OS_ID)-$(OS_VERSION_ID),centos-8)
364         @sudo -E dnf install $(CONFIRM) dnf-plugins-core epel-release
365         @sudo -E dnf config-manager --set-enabled \
366           $(shell dnf repolist all 2>/dev/null|grep -i powertools|cut -d' ' -f1|grep -v source)
367         @sudo -E dnf groupinstall $(CONFIRM) $(RPM_DEPENDS_GROUPS)
368         @sudo -E dnf install --skip-broken $(CONFIRM) $(RPM_DEPENDS)
369 else ifeq ($(OS_ID),centos)
370         @sudo -E yum install $(CONFIRM) centos-release-scl-rh epel-release
371         @sudo -E yum groupinstall $(CONFIRM) $(RPM_DEPENDS_GROUPS)
372         @sudo -E yum install $(CONFIRM) $(RPM_DEPENDS)
373         @sudo -E yum install $(CONFIRM) --enablerepo=base-debuginfo $(RPM_DEPENDS_DEBUG)
374 else ifeq ($(OS_ID),fedora)
375         @sudo -E dnf groupinstall $(CONFIRM) $(RPM_DEPENDS_GROUPS)
376         @sudo -E dnf install $(CONFIRM) $(RPM_DEPENDS)
377         @sudo -E debuginfo-install $(CONFIRM) glibc openssl-libs zlib
378 endif
379 else ifeq ($(filter opensuse-leap-15.3 opensuse-leap-15.4 ,$(OS_ID)-$(OS_VERSION_ID)),$(OS_ID)-$(OS_VERSION_ID))
380         @sudo -E zypper refresh
381         @sudo -E zypper install  -y $(RPM_SUSE_DEPENDS)
382 else
383         $(error "This option currently works only on Ubuntu, Debian, RHEL, CentOS or openSUSE-leap systems")
384 endif
385         git config commit.template .git_commit_template.txt
386
387 .PHONY: install-deps
388 install-deps: install-dep
389
390 define make
391         @$(MAKE) -C $(BR) PLATFORM=$(PLATFORM) TAG=$(1) $(2)
392 endef
393
394 $(BR)/scripts/.version:
395 ifneq ("$(wildcard /etc/redhat-release)","")
396         $(shell $(BR)/scripts/version rpm-string > $(BR)/scripts/.version)
397 else
398         $(shell $(BR)/scripts/version > $(BR)/scripts/.version)
399 endif
400
401 DIST_FILE = $(BR)/vpp-$(shell src/scripts/version).tar
402 DIST_SUBDIR = vpp-$(shell src/scripts/version|cut -f1 -d-)
403
404 .PHONY: dist
405 dist:
406         @if git rev-parse 2> /dev/null ; then \
407             git archive \
408               --prefix=$(DIST_SUBDIR)/ \
409               --format=tar \
410               -o $(DIST_FILE) \
411             HEAD ; \
412             git describe --long > $(BR)/.version ; \
413         else \
414             (cd .. ; tar -cf $(DIST_FILE) $(DIST_SUBDIR) --exclude=*.tar) ; \
415             src/scripts/version > $(BR)/.version ; \
416         fi
417         @tar --append \
418           --file $(DIST_FILE) \
419           --transform='s,.*/.version,$(DIST_SUBDIR)/src/scripts/.version,' \
420           $(BR)/.version
421         @$(RM) $(BR)/.version $(DIST_FILE).xz
422         @xz -v --threads=0 $(DIST_FILE)
423         @$(RM) $(BR)/vpp-latest.tar.xz
424         @ln -rs $(DIST_FILE).xz $(BR)/vpp-latest.tar.xz
425
426 .PHONY: build
427 build: $(BR)/.deps.ok
428         $(call make,$(PLATFORM)_debug,$(addsuffix -install,$(TARGETS)))
429
430 .PHONY: wipedist
431 wipedist:
432         @$(RM) $(BR)/*.tar.xz
433
434 .PHONY: wipe
435 wipe: wipedist test-wipe $(BR)/.deps.ok
436         $(call make,$(PLATFORM)_debug,$(addsuffix -wipe,$(TARGETS)))
437         @find . -type f -name "*.api.json" ! -path "./src/*" -exec rm {} \;
438
439 .PHONY: rebuild
440 rebuild: wipe build
441
442 .PHONY: build-release
443 build-release: $(BR)/.deps.ok
444         $(call make,$(PLATFORM),$(addsuffix -install,$(TARGETS)))
445
446 .PHONY: build-vpp-gcov
447 build-vpp-gcov:
448         $(call test,vpp_gcov)
449
450 .PHONY: wipe-release
451 wipe-release: test-wipe $(BR)/.deps.ok
452         $(call make,$(PLATFORM),$(addsuffix -wipe,$(TARGETS)))
453
454 .PHONY: rebuild-release
455 rebuild-release: wipe-release build-release
456
457 export TEST_DIR ?= $(WS_ROOT)/test
458
459 define test
460         $(if $(filter-out $(2),retest),$(MAKE) -C $(BR) PLATFORM=vpp TAG=$(1) CC=$(CC) vpp-install,)
461         $(eval libs:=lib lib64)
462         $(MAKE) -C test \
463           VPP_BUILD_DIR=$(BR)/build-$(1)-native/vpp \
464           VPP_BIN=$(BR)/install-$(1)-native/vpp/bin/vpp \
465           VPP_INSTALL_PATH=$(BR)/install-$(1)-native/ \
466           EXTENDED_TESTS=$(EXTENDED_TESTS) \
467           TEST_GCOV=$(TEST_GCOV) \
468           PYTHON=$(PYTHON) \
469           OS_ID=$(OS_ID) \
470           RND_SEED=$(RND_SEED) \
471           CACHE_OUTPUT=$(CACHE_OUTPUT) \
472           TAG=$(1) \
473           $(2)
474 endef
475
476 .PHONY: test
477 test:
478 ifeq ($(CC),cc)
479         $(eval CC=clang)
480 endif
481         $(call test,vpp,test)
482
483 .PHONY: test-debug
484 test-debug:
485 ifeq ($(CC),cc)
486         $(eval CC=clang)
487 endif
488         $(call test,vpp_debug,test)
489
490 .PHONY: test-cov
491 test-cov:
492         $(eval CC=gcc)
493         $(eval TEST_GCOV=1)
494         $(call test,vpp_gcov,cov)
495
496 .PHONY: test-cov-hs
497 test-cov-hs:
498         @make -C extras/hs-test build-cov
499         @make -C extras/hs-test test-cov
500
501 .PHONY: test-cov-both
502 test-cov-both:
503         @echo "Running Python, Golang tests and merging coverage reports."
504         find $(BR) -name '*.gcda' -delete
505         @make test-cov
506         find $(BR) -name '*.gcda' -delete
507         @make test-cov-hs
508         @make cov-merge
509
510 .PHONY: test-cov-build
511 test-cov-build:
512         $(eval CC=gcc)
513         $(eval TEST_GCOV=1)
514         $(call test,vpp_gcov,test)
515
516 .PHONY: test-cov-prep
517 test-cov-prep:
518         $(eval CC=gcc)
519         $(call test,vpp_gcov,cov-prep)
520
521 .PHONY: test-cov-post
522 test-cov-post:
523         $(eval CC=gcc)
524         $(call test,vpp_gcov,cov-post)
525
526 .PHONY: cov-merge
527 cov-merge:
528         @lcov --add-tracefile $(BR)/test-coverage-merged/coverage-filtered.info \
529                 -a $(BR)/test-coverage-merged/coverage-filtered1.info -o $(BR)/test-coverage-merged/coverage-merged.info
530         @genhtml $(BR)/test-coverage-merged/coverage-merged.info \
531                 --output-directory $(BR)/test-coverage-merged/html
532         @echo "Code coverage report is in $(BR)/test-coverage-merged/html/index.html"
533
534 .PHONY: test-all
535 test-all:
536         $(eval EXTENDED_TESTS=1)
537         $(call test,vpp,test)
538
539 .PHONY: test-all-debug
540 test-all-debug:
541         $(eval EXTENDED_TESTS=1)
542         $(call test,vpp_debug,test)
543
544 .PHONY: test-all-cov
545 test-all-cov:
546         $(eval CC=gcc)
547         $(eval TEST_GCOV=1)
548         $(eval EXTENDED_TESTS=1)
549         $(call test,vpp_gcov,test)
550
551 .PHONY: papi-wipe
552 papi-wipe: test-wipe-papi
553         $(call banner,"This command is deprecated. Please use 'test-wipe-papi'")
554
555 .PHONY: test-wipe-papi
556 test-wipe-papi:
557         @$(MAKE) -C test wipe-papi
558
559 .PHONY: test-help
560 test-help:
561         @$(MAKE) -C test help
562
563 .PHONY: test-wipe
564 test-wipe:
565         @$(MAKE) -C test wipe
566
567 .PHONY: test-shell
568 test-shell:
569         $(call test,vpp,shell)
570
571 .PHONY: test-shell-debug
572 test-shell-debug:
573         $(call test,vpp_debug,shell)
574
575 .PHONY: test-shell-cov
576 test-shell-cov:
577         $(eval CC=gcc)
578         $(eval TEST_GCOV=1)
579         $(call test,vpp_gcov,shell)
580
581 .PHONY: test-dep
582 test-dep:
583         @make -C test test-dep
584
585 .PHONY: test-doc
586 test-doc:
587         @echo "make test-doc is DEPRECATED: use 'make docs'"
588         sleep 300
589
590 .PHONY: test-wipe-doc
591 test-wipe-doc:
592         @echo "make test-wipe-doc is DEPRECATED"
593         sleep 300
594
595 .PHONY: test-wipe-cov
596 test-wipe-cov:
597         $(call make,$(PLATFORM)_gcov,$(addsuffix -wipe,$(TARGETS)))
598         @$(MAKE) -C test wipe-cov
599
600 .PHONY: test-wipe-all
601 test-wipe-all:
602         @$(MAKE) -C test wipe-all
603
604 # Note: All python venv consolidated in test/Makefile, test/requirements*.txt
605 .PHONY: test-checkstyle
606 test-checkstyle:
607         $(warning test-checkstyle is deprecated. Running checkstyle-python.")
608         @$(MAKE) -C test checkstyle-python-all
609
610 # Note: All python venv consolidated in test/Makefile, test/requirements*.txt
611 .PHONY: test-checkstyle-diff
612 test-checkstyle-diff:
613         $(warning test-checkstyle-diff is deprecated. Running checkstyle-python.")
614         @$(MAKE) -C test checkstyle-python-all
615
616 .PHONY: test-refresh-deps
617 test-refresh-deps:
618         @$(MAKE) -C test refresh-deps
619
620 .PHONY: retest
621 retest:
622         $(call test,vpp,retest)
623
624 .PHONY: retest-debug
625 retest-debug:
626         $(call test,vpp_debug,retest)
627
628 .PHONY: retest-all
629 retest-all:
630         $(eval EXTENDED_TESTS=1)
631         $(call test,vpp,retest)
632
633 .PHONY: retest-all-debug
634 retest-all-debug:
635         $(eval EXTENDED_TESTS=1)
636         $(call test,vpp_debug,retest)
637
638 .PHONY: test-start-vpp-in-gdb
639 test-start-vpp-in-gdb:
640         $(call test,vpp,start-gdb)
641
642 .PHONY: test-start-vpp-debug-in-gdb
643 test-start-vpp-debug-in-gdb:
644         $(call test,vpp_debug,start-gdb)
645
646 ifeq ("$(wildcard $(STARTUP_CONF))","")
647 define run
648         @echo "WARNING: STARTUP_CONF not defined or file doesn't exist."
649         @echo "         Running with minimal startup config: $(MINIMAL_STARTUP_CONF)\n"
650         @cd $(STARTUP_DIR) && \
651           $(SUDO) $(2) $(1)/vpp/bin/vpp $(MINIMAL_STARTUP_CONF)
652 endef
653 else
654 define run
655         @cd $(STARTUP_DIR) && \
656           $(SUDO) $(2) $(1)/vpp/bin/vpp $(shell cat $(STARTUP_CONF) | sed -e 's/#.*//')
657 endef
658 endif
659
660 %.files: .FORCE
661         @find src -name '*.[chS]' > $@
662
663 .FORCE:
664
665 .PHONY: run
666 run:
667         $(call run, $(BR)/install-$(PLATFORM)_debug-native)
668
669 .PHONY: run-release
670 run-release:
671         $(call run, $(BR)/install-$(PLATFORM)-native)
672
673 .PHONY: debug
674 debug:
675         $(call run, $(BR)/install-$(PLATFORM)_debug-native,$(GDB) $(GDB_ARGS) --args)
676
677 .PHONY: build-coverity
678 build-coverity:
679         $(call make,$(PLATFORM)_coverity,install-packages)
680         @$(MAKE) -C build-root PLATFORM=vpp TAG=vpp_coverity libmemif-install
681
682 .PHONY: debug-release
683 debug-release:
684         $(call run, $(BR)/install-$(PLATFORM)-native,$(GDB) $(GDB_ARGS) --args)
685
686 .PHONY: build-vat
687 build-vat:
688         $(call make,$(PLATFORM)_debug,vpp-api-test-install)
689
690 .PHONY: run-vat
691 run-vat:
692         @$(SUDO) $(BR)/install-$(PLATFORM)_debug-native/vpp/bin/vpp_api_test
693
694 .PHONY: pkg-deb
695 pkg-deb:
696         $(call make,$(PLATFORM),vpp-package-deb)
697
698 .PHONY: pkg-snap
699 pkg-snap:
700         cd extras/snap ;                        \
701         ./prep ;                                \
702         SNAPCRAFT_BUILD_ENVIRONMENT_MEMORY=8G   \
703         SNAPCRAFT_BUILD_ENVIRONMENT_CPU=6       \
704         snapcraft --debug
705
706 .PHONY: snap-clean
707 snap-clean:
708         cd extras/snap ;                        \
709         snapcraft clean ;                       \
710         rm -f *.snap *.tgz
711
712 .PHONY: pkg-deb-debug
713 pkg-deb-debug:
714         $(call make,$(PLATFORM)_debug,vpp-package-deb)
715
716 .PHONY: pkg-rpm
717 pkg-rpm: dist
718         $(MAKE) -C extras/rpm
719
720 .PHONY: pkg-srpm
721 pkg-srpm: dist
722         $(MAKE) -C extras/rpm srpm
723
724 .PHONY: install-ext-deps
725 install-ext-deps:
726         $(MAKE) -C build/external install-$(PKG)
727
728 .PHONY: install-ext-dep
729 install-ext-dep: install-ext-deps
730
731 .PHONY: json-api-files
732 json-api-files:
733         $(WS_ROOT)/src/tools/vppapigen/generate_json.py
734
735 .PHONY: json-api-files-debug
736 json-api-files-debug:
737         $(WS_ROOT)/src/tools/vppapigen/generate_json.py --debug-target
738
739 .PHONY: go-api-files
740 go-api-files: json-api-files
741         $(WS_ROOT)/src/tools/vppapigen/generate_go.py $(ARGS)
742
743 .PHONY: ctags
744 ctags: ctags.files
745         @ctags --totals --tag-relative=yes -L $<
746         @rm $<
747
748 .PHONY: gtags
749 gtags: ctags
750         @gtags --gtagslabel=ctags
751
752 .PHONY: cscope
753 cscope: cscope.files
754         @cscope -b -q -v
755
756 .PHONY: compdb
757 compdb:
758         @ninja -C build-root/build-vpp_debug-native/vpp build.ninja
759         @ninja -C build-root/build-vpp_debug-native/vpp -t compdb | \
760           src/scripts/compdb_cleanup.py > compile_commands.json
761
762 .PHONY: checkstyle
763 checkstyle: checkfeaturelist
764         @extras/scripts/checkstyle.sh
765
766 .PHONY: checkstyle-commit
767 checkstyle-commit:
768         @extras/scripts/check_commit_msg.sh
769
770 .PHONY: checkstyle-test
771 checkstyle-test:
772         $(warning test-checkstyle is deprecated. Running checkstyle-python.")
773         @$(MAKE) -C test checkstyle-python-all
774
775 # Note: All python venv consolidated in test/Makefile, test/requirements*.txt
776 .PHONY: checkstyle-python
777 checkstyle-python:
778         @$(MAKE) -C test checkstyle-python-all
779
780 .PHONY: checkstyle-all
781 checkstyle-all: checkstyle-commit checkstyle checkstyle-python docs-spell
782
783 .PHONY: fixstyle
784 fixstyle:
785         @extras/scripts/checkstyle.sh --fix
786
787 # Note: All python venv consolidated in test/Makefile, test/requirements*.txt
788 .PHONY: fixstyle-python
789 fixstyle-python:
790         @$(MAKE) -C test fixstyle-python-all
791
792 .PHONY: checkstyle-api
793 checkstyle-api:
794         @extras/scripts/crcchecker.py --check-patchset
795
796 # necessary because Bug 1696324 - Update to python3.6 breaks PyYAML dependencies
797 # Status:       CLOSED CANTFIX
798 # https://bugzilla.redhat.com/show_bug.cgi?id=1696324
799 .PHONY: centos-pyyaml
800 centos-pyyaml:
801 ifeq ($(OS_ID)-$(OS_VERSION_ID),centos-8)
802         @sudo -E yum install $(CONFIRM) python3-pyyaml
803 endif
804
805 .PHONY: featurelist
806 featurelist: centos-pyyaml
807         @extras/scripts/fts.py --all --markdown
808
809 .PHONY: checkfeaturelist
810 checkfeaturelist: centos-pyyaml
811         @extras/scripts/fts.py --validate --all
812
813 #
814 # Build the documentation
815 #
816
817 .PHONY: bootstrap-doxygen
818 bootstrap-doxygen:
819         @echo "make bootstrap-doxygen is DEPRECATED"
820         sleep 300
821
822 .PHONY: doxygen
823 doxygen: docs
824         @echo "make doxygen is DEPRECATED: use 'make docs'"
825         sleep 300
826
827 .PHONY: wipe-doxygen
828 wipe-doxygen:
829         @echo "make wipe-doxygen is DEPRECATED"
830         sleep 300
831
832 .PHONY: docs-%
833 docs-%:
834         @$(MAKE) -C $(WS_ROOT)/docs $*
835
836 .PHONY: docs
837 docs:
838         @$(MAKE) -C $(WS_ROOT)/docs docs
839
840 .PHONY: pkg-verify
841 pkg-verify: install-dep $(BR)/.deps.ok install-ext-deps
842         $(call banner,"Building for PLATFORM=vpp")
843         @$(MAKE) -C build-root PLATFORM=vpp TAG=vpp wipe-all install-packages
844         $(call banner,"Building sample-plugin")
845         @$(MAKE) -C build-root PLATFORM=vpp TAG=vpp sample-plugin-install
846         $(call banner,"Building libmemif")
847         @$(MAKE) -C build-root PLATFORM=vpp TAG=vpp libmemif-install
848         $(call banner,"Building $(PKG) packages")
849         @$(MAKE) pkg-$(PKG)
850
851 # Note: 'make verify' target is not used by ci-management scripts
852 MAKE_VERIFY_GATE_OS ?= ubuntu-22.04
853 .PHONY: verify
854 verify: pkg-verify
855 ifeq ($(OS_ID)-$(OS_VERSION_ID),$(MAKE_VERIFY_GATE_OS))
856         $(call banner,"Testing vppapigen")
857         @src/tools/vppapigen/test_vppapigen.py
858         $(call banner,"Running tests")
859         @$(MAKE) COMPRESS_FAILED_TEST_LOGS=yes RETRIES=3 test
860 else
861         $(call banner,"Skipping tests. Tests under 'make verify' supported on $(MAKE_VERIFY_GATE_OS)")
862 endif
863
864 .PHONY: check-dpdk-mlx
865 check-dpdk-mlx:
866         @[ $$($(MAKE) -sC build/external dpdk-show-DPDK_MLX_DEFAULT) = y ]