summaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 46e04ec4c11ebb20ed1f7b3a6066814e6cb4f30e (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
SHELL := /usr/bin/env bash -o pipefail

PROJECT := govpp

VERSION      ?= $(shell git describe --always --tags --dirty)
COMMIT       ?= $(shell git rev-parse HEAD)
BUILD_STAMP  ?= $(shell git log -1 --format='%ct')
BUILD_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)

BUILD_HOST ?= $(shell hostname)
BUILD_USER ?= $(shell id -un)

GOVPP_PKG := git.fd.io/govpp.git

VERSION_PKG := $(GOVPP_PKG)/internal/version
LDFLAGS = \
	-X $(VERSION_PKG).version=$(VERSION) \
	-X $(VERSION_PKG).commitHash=$(COMMIT) \
	-X $(VERSION_PKG).buildStamp=$(BUILD_STAMP) \
	-X $(VERSION_PKG).buildBranch=$(BUILD_BRANCH) \
	-X $(VERSION_PKG).buildUser=$(BUILD_USER) \
	-X $(VERSION_PKG).buildHost=$(BUILD_HOST)

ifeq ($(NOSTRIP),)
LDFLAGS += -w -s
endif

GO_BUILD_TAGS ?= novpp

GO_BUILD_ARGS = -ldflags "$(LDFLAGS)"
ifneq ($(GO_BUILD_TAGS),)
GO_BUILD_ARGS += -tags="${GO_BUILD_TAGS}"
endif
ifneq ($(GO_NOTRIM),0)
GO_BUILD_ARGS += -trimpath
endif
ifeq ($(V),1)
GO_BUILD_ARGS += -v
endif

# VPP Docker image to use for api generation (gen-binapi-docker)
VPP_IMG 	      ?= ligato/vpp-base:latest
# Local VPP directory used for binary api generation (gen-binapi-from-code)
VPP_DIR           ?=
# Target directory for generated go api bindings
BINAPI_DIR	      ?= ./binapi
# Binapi generator path
BINAPI_GENERATOR  = ./bin/binapi-generator

.DEFAULT_GOAL = help

bin:
	mkdir -p bin

build: ## Build all
	@echo "# building ${VERSION}"
	go build ${GO_BUILD_ARGS} ./...

cmd: bin ## Build commands
	go build ${GO_BUILD_ARGS} -o bin ./cmd/...

examples: bin ## Build examples
	go build ${GO_BUILD_ARGS} -o bin ./examples/...

test: ## Run unit tests
	@echo "# running tests"
	go test -tags="${GO_BUILD_TAGS}" ./...

test-integration: ## Run integration tests
	@echo "# running integration tests"
	go test -tags="integration ${GO_BUILD_TAGS}" ./test/integration

lint: ## Run code linter
	@echo "# running linter"
	@golint ./...

install: install-generator install-proxy ## Install all

install-generator: ## Install binapi-generator
	@echo "# installing binapi-generator ${VERSION}"
	@go install ${GO_BUILD_ARGS} ./cmd/binapi-generator

install-proxy: ## Install vpp-proxy
	@echo "# installing vpp-proxy ${VERSION}"
	go install ${GO_BUILD_ARGS} ./cmd/vpp-proxy

generate: generate-binapi ## Generate all

generate-binapi: install-generator ## Generate binapi code
	@echo "# generating binapi"
	go generate -x "$(BINAPI_DIR)"

gen-binapi-from-code: cmd-binapi-generator
	$(eval VPP_API_DIR := ${VPP_DIR}/build-root/install-vpp-native/vpp/share/vpp/api/)
	@echo "Generating vpp API.json and go bindings"
	@echo "Vpp Directory ${VPP_DIR}"
	@echo "Vpp API files ${VPP_API_DIR}"
	@echo "Go bindings   ${BINAPI_DIR}"
	@cd ${VPP_DIR} && make json-api-files
	@${BINAPI_GENERATOR} \
		--input-dir=${VPP_API_DIR} \
	    --output-dir=${BINAPI_DIR} \
	    --gen rpc,rest \
	    --no-source-path-info

gen-binapi-docker: install-generator ## Generate binapi code (using Docker)
	@echo "# generating binapi in docker image ${VPP_IMG}"
	$(eval cmds := $(shell go generate -n $(BINAPI_DIR) 2>&1 | tr "\n" ";"))
	docker run -t --rm \
		-e DEBUG_GOVPP \
		-v "$(shell which binapi-generator):/usr/local/bin/binapi-generator:ro" \
		-v "$(shell pwd):/govpp" \
		-w /govpp \
		-u "$(shell id -u):$(shell id -g)" \
		"${VPP_IMG}" \
	  sh -ec "cd $(BINAPI_DIR) && $(cmds)"

help:
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.PHONY: help \
    build cmd examples clean \
	lint test integration \
	install install-generator install-proxy \
	generate generate-binapi gen-binapi-docker \
	extras
st shell: make test-shell\" &&\ echo \"* 2. execute debugger: gdb python -ex 'run sanity_import_vpp_papi.py'\" &&\ echo \"*******************************************************************\" &&\ false)" @bash -c "source $(PYTHON_VENV_PATH)/bin/activate && python sanity_run_vpp.py ||\ (echo \"*******************************************************************\" &&\ echo \"* Sanity check failed, cannot run vpp\" &&\ echo \"*******************************************************************\" &&\ false)" test: verify-python-path $(PAPI_INSTALL_DONE) sanity reset $(call retest-func) retest: verify-python-path sanity reset $(call retest-func) shell: verify-python-path $(PAPI_INSTALL_DONE) @echo "source $(PYTHON_VENV_PATH)/bin/activate;\ echo '***';\ echo VPP_TEST_BUILD_DIR=$(VPP_TEST_BUILD_DIR);\ echo VPP_TEST_BIN=$(VPP_TEST_BIN);\ echo VPP_TEST_PLUGIN_PATH=$(VPP_TEST_PLUGIN_PATH);\ echo VPP_TEST_INSTALL_PATH=$(VPP_TEST_INSTALL_PATH);\ echo EXTERN_TESTS=$(EXTERN_TESTS);\ echo EXTERN_PLUGINS=$(EXTERN_PLUGINS);\ echo EXTERN_COV_DIR=$(EXTERN_COV_DIR);\ echo LD_LIBRARY_PATH=$(LD_LIBRARY_PATH);\ echo '***';\ exec </dev/tty" | bash -i .PHONY: wipe doc reset: @rm -f /dev/shm/vpp-unittest-* @rm -rf /tmp/vpp-unittest-* wipe: reset @rm -rf $(PYTHON_VENV_PATH) @rm -f $(PAPI_INSTALL_FLAGS) doc: verify-python-path $(PIP_PATCH_DONE) @virtualenv $(PYTHON_VENV_PATH) -p $(PYTHON_INTERP) @bash -c "source $(PYTHON_VENV_PATH)/bin/activate && pip install sphinx sphinx-rtd-theme" @bash -c "source $(PYTHON_VENV_PATH)/bin/activate && make -C doc WS_ROOT=$(WS_ROOT) BR=$(BR) NO_VPP_PAPI=1 html" .PHONY: wipe-doc wipe-doc: @make -C doc wipe BR=$(BR) cov: wipe-cov reset verify-python-path $(PAPI_INSTALL_DONE) @lcov --zerocounters --directory $(VPP_TEST_BUILD_DIR) @test -z "$(EXTERN_COV_DIR)" || lcov --zerocounters --directory $(EXTERN_COV_DIR) $(call retest-func) @mkdir $(BUILD_COV_DIR) @lcov --capture --directory $(VPP_TEST_BUILD_DIR) --output-file $(BUILD_COV_DIR)/coverage.info @test -z "$(EXTERN_COV_DIR)" || lcov --capture --directory $(EXTERN_COV_DIR) --output-file $(BUILD_COV_DIR)/extern-coverage.info @genhtml $(BUILD_COV_DIR)/coverage.info --output-directory $(BUILD_COV_DIR)/html @test -z "$(EXTERN_COV_DIR)" || genhtml $(BUILD_COV_DIR)/extern-coverage.info --output-directory $(BUILD_COV_DIR)/extern-html @echo @echo "Build finished. Code coverage report is in $(BUILD_COV_DIR)/html/index.html" @test -z "$(EXTERN_COV_DIR)" || echo "Code coverage report for out-of-tree objects is in $(BUILD_COV_DIR)/extern-html/index.html" .PHONY: wipe-cov wipe-cov: wipe @rm -rf $(BUILD_COV_DIR) .PHONY: checkstyle checkstyle: verify-python-path @virtualenv $(PYTHON_VENV_PATH) -p $(PYTHON_INTERP) @bash -c "source $(PYTHON_VENV_PATH)/bin/activate && pip install pep8" @bash -c "source $(PYTHON_VENV_PATH)/bin/activate &&\ pep8 --show-source -v $(WS_ROOT)/test/*.py ||\ (echo \"*******************************************************************\" &&\ echo \"* Test framework PEP8 compliance check FAILED \" &&\ echo \"*******************************************************************\" &&\ false)" @echo "*******************************************************************" @echo "* Test framework PEP8 compliance check passed" @echo "*******************************************************************" help: @echo "Running tests:" @echo "" @echo " test - build and run (basic) functional tests" @echo " test-debug - build and run (basic) functional tests (debug build)" @echo " test-all - build and run (all) functional tests" @echo " test-all-debug - build and run (all) functional tests (debug build)" @echo " retest - run functional tests" @echo " retest-debug - run functional tests (debug build)" @echo " test-wipe - wipe (temporary) files generated by unit tests" @echo " test-shell - enter shell with test environment" @echo " test-shell-debug - enter shell with test environment (debug build)" @echo "" @echo "Arguments controlling test runs:" @echo " V=[0|1|2] - set test verbosity level" @echo " FAILFAST=[0|1] - fail fast if 1, complete all tests if 0" @echo " DEBUG=<type> - set VPP debugging kind" @echo " DEBUG=core - detect coredump and load it in gdb on crash" @echo " DEBUG=gdb - allow easy debugging by printing VPP PID " @echo " and waiting for user input before running " @echo " and tearing down a testcase" @echo " DEBUG=gdbserver - run gdb inside a gdb server, otherwise " @echo " same as above" @echo " STEP=[yes|no] - ease debugging by stepping through a testcase " @echo " TEST=<filter> - filter the set of tests:" @echo " by file-name - only run tests from specified file, e.g. TEST=test_bfd selects all tests from test_bfd.py" @echo " by file-suffix - same as file-name, but 'test_' is omitted e.g. TEST=bfd selects all tests from test_bfd.py" @echo " by wildcard - wildcard filter is <file>.<class>.<test function>, each can be replaced by '*'" @echo " e.g. TEST='test_bfd.*.*' is equivalent to above example of filter by file-name" @echo " TEST='bfd.*.*' is equivalent to above example of filter by file-suffix" @echo " TEST='bfd.BFDAPITestCase.*' selects all tests from test_bfd.py which are part of BFDAPITestCase class" @echo " TEST='bfd.BFDAPITestCase.test_add_bfd' selects a single test named test_add_bfd from test_bfd.py/BFDAPITestCase" @echo " TEST='*.*.test_add_bfd' selects all test functions named test_add_bfd from all files/classes" @echo "" @echo " VPP_ZOMBIE_NOCHECK=1 - skip checking for vpp (zombie) processes (CAUTION)" @echo " COREDUMP_SIZE=<size> - pass <size> as unix { coredump-size <size> } argument to vpp" @echo " e.g. COREDUMP_SIZE=4g" @echo " COREDUMP_SIZE=unlimited" @echo " EXTERN_TESTS=<path> - path to out-of-tree test_<name>.py files containing test cases" @echo " EXTERN_PLUGINS=<path>- path to out-of-tree plugins to be loaded by vpp under test" @echo " EXTERN_COV_DIR=<path>- path to out-of-tree prefix, where source, object and .gcda files can be found for coverage report" @echo "" @echo "Creating test documentation" @echo " test-doc - generate documentation for test framework" @echo " test-wipe-doc - wipe documentation for test framework" @echo "" @echo "Creating test code coverage report" @echo " test-cov - generate code coverage report for test framework" @echo " test-wipe-cov - wipe code coverage report for test framework" @echo "" @echo "Verifying code-style" @echo " test-checkstyle - check PEP8 compliance" @echo ""