Blame testsuite/Makefile

Packit Service 3880ab
# SPDX-License-Identifier: GPL-2.0
Packit Service 3880ab
## -- Config --
Packit Service 3880ab
DEV := lo
Packit Service 3880ab
PREFIX := sudo -E unshare -n
Packit Service 3880ab
RESULTS_DIR := results
Packit Service 3880ab
## -- End Config --
Packit Service 3880ab
Packit Service 3880ab
HAVE_UNSHARED_UTIL := $(shell unshare --version 2> /dev/null)
Packit Service 3880ab
Packit Service 3880ab
rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
Packit Service 3880ab
Packit Service 3880ab
TESTS := $(patsubst tests/%,%,$(call rwildcard,tests/,*.t))
Packit Service 3880ab
TESTS_DIR := $(dir $(TESTS))
Packit Service 3880ab
Packit Service 3880ab
IPVERS := $(filter-out iproute2/Makefile,$(wildcard iproute2/*))
Packit Service 3880ab
Packit Service 3880ab
KENVFN := $(shell mktemp /tmp/tc_testkenv.XXXXXX)
Packit Service 3880ab
ifneq (,$(wildcard /proc/config.gz))
Packit Service 3880ab
	KCPATH := /proc/config.gz
Packit Service 3880ab
else
Packit Service 3880ab
	KVER := $(shell uname -r)
Packit Service 3880ab
	KCPATHS := /lib/modules/$(KVER)/config /boot/config-$(KVER)
Packit Service 3880ab
	KCPATH := $(firstword $(wildcard $(KCPATHS)))
Packit Service 3880ab
endif
Packit Service 3880ab
Packit Service 3880ab
.PHONY: compile listtests alltests configure $(TESTS)
Packit Service 3880ab
Packit Service 3880ab
configure:
Packit Service 3880ab
	$(MAKE) -C iproute2 configure
Packit Service 3880ab
Packit Service 3880ab
compile: configure generate_nlmsg
Packit Service 3880ab
	$(MAKE) -C iproute2
Packit Service 3880ab
Packit Service 3880ab
listtests:
Packit Service 3880ab
	@for t in $(TESTS); do \
Packit Service 3880ab
		echo "$$t"; \
Packit Service 3880ab
	done
Packit Service 3880ab
Packit Service 3880ab
generate_nlmsg:
Packit Service 3880ab
	$(MAKE) -C tools
Packit Service 3880ab
Packit Service 3880ab
alltests: generate_nlmsg $(TESTS)
Packit Service 3880ab
Packit Service 3880ab
testclean:
Packit Service 3880ab
	@echo "Removing $(RESULTS_DIR) dir ..."
Packit Service 3880ab
	@rm -rf $(RESULTS_DIR)
Packit Service 3880ab
Packit Service 3880ab
clean: testclean
Packit Service 3880ab
	@rm -f iproute2/iproute2-this
Packit Service 3880ab
	@rm -f tests/ip/link/dev_wo_vf_rate.nl
Packit Service 3880ab
	$(MAKE) -C tools clean
Packit Service 3880ab
Packit Service 3880ab
distclean: clean
Packit Service 3880ab
	$(MAKE) -C iproute2 distclean
Packit Service 3880ab
Packit Service 3880ab
$(TESTS): generate_nlmsg testclean
Packit Service 3880ab
ifeq (,$(IPVERS))
Packit Service 3880ab
	$(error Please run make first)
Packit Service 3880ab
endif
Packit Service 3880ab
ifeq (,$(HAVE_UNSHARED_UTIL))
Packit Service 3880ab
	$(error Please install util-linux tools to run tests in separated network namespace)
Packit Service 3880ab
endif
Packit Service 3880ab
	@./tools/generate_nlmsg
Packit Service 3880ab
Packit Service 3880ab
	@mkdir -p $(RESULTS_DIR)
Packit Service 3880ab
Packit Service 3880ab
	@for d in $(TESTS_DIR); do \
Packit Service 3880ab
	    mkdir -p $(RESULTS_DIR)/$$d; \
Packit Service 3880ab
	done
Packit Service 3880ab
Packit Service 3880ab
	@if [ "$(KCPATH)" = "/proc/config.gz" ]; then \
Packit Service 3880ab
		gunzip -c $(KCPATH) >$(KENVFN); \
Packit Service 3880ab
	elif [ "$(KCPATH)" != "" ]; then \
Packit Service 3880ab
               cat $(KCPATH) >$(KENVFN); \
Packit Service 3880ab
	fi
Packit Service 3880ab
	@sed -i -e 's/^CONFIG_/export CONFIG_/' $(KENVFN)
Packit Service 3880ab
Packit Service 3880ab
	@for i in $(IPVERS); do \
Packit Service 3880ab
		o=`echo $$i | sed -e 's/iproute2\///'`; \
Packit Service 3880ab
		echo -n "Running $@ [$$o/`uname -r`]: "; \
Packit Service 3880ab
		TMP_ERR=`mktemp /tmp/tc_testsuite.XXXXXX`; \
Packit Service 3880ab
		TMP_OUT=`mktemp /tmp/tc_testsuite.XXXXXX`; \
Packit Service 3880ab
		. $(KENVFN); \
Packit Service 3880ab
		STD_ERR="$$TMP_ERR" STD_OUT="$$TMP_OUT" \
Packit Service 3880ab
		TC="$$i/tc/tc" IP="$$i/ip/ip" SS=$$i/misc/ss BRIDGE="$$i/bridge/bridge" \
Packit Service 3880ab
		DEV="$(DEV)" IPVER="$@" SNAME="$$i" \
Packit Service 3880ab
		ERRF="$(RESULTS_DIR)/$@.$$o.err" $(PREFIX) tests/$@ > $(RESULTS_DIR)/$@.$$o.out; \
Packit Service 3880ab
		if [ "$$?" = "127" ]; then \
Packit Service 3880ab
			printf "\033[1;35mSKIPPED\033[0m\n"; \
Packit Service 3880ab
		elif [ -e "$(RESULTS_DIR)/$@.$$o.err" ]; then \
Packit Service 3880ab
			printf "\033[0;31mFAILED\033[0m\n"; \
Packit Service 3880ab
		else \
Packit Service 3880ab
			printf "\033[0;32mPASS\033[0m\n"; \
Packit Service 3880ab
		fi; \
Packit Service 3880ab
		rm "$$TMP_ERR" "$$TMP_OUT"; \
Packit Service 3880ab
		sudo dmesg > $(RESULTS_DIR)/$@.$$o.dmesg; \
Packit Service 3880ab
	done