iproute2/testsuite/Makefile
<<
>>
Prefs
   1# SPDX-License-Identifier: GPL-2.0
   2## -- Config --
   3DEV := lo
   4PREFIX := sudo -E unshare -n
   5RESULTS_DIR := results
   6## -- End Config --
   7
   8HAVE_UNSHARED_UTIL := $(shell unshare --version 2> /dev/null)
   9
  10rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
  11
  12TESTS := $(patsubst tests/%,%,$(call rwildcard,tests/,*.t))
  13TESTS_DIR := $(dir $(TESTS))
  14
  15IPVERS := $(filter-out iproute2/Makefile,$(wildcard iproute2/*))
  16
  17KENVFN := $(shell mktemp /tmp/tc_testkenv.XXXXXX)
  18ifneq (,$(wildcard /proc/config.gz))
  19        KCPATH := /proc/config.gz
  20else
  21        KVER := $(shell uname -r)
  22        KCPATHS := /lib/modules/$(KVER)/config /boot/config-$(KVER)
  23        KCPATH := $(firstword $(wildcard $(KCPATHS)))
  24endif
  25
  26.PHONY: compile listtests alltests configure $(TESTS)
  27
  28configure:
  29        $(MAKE) -C iproute2 configure
  30
  31compile: configure generate_nlmsg
  32        $(MAKE) -C iproute2
  33
  34listtests:
  35        @for t in $(TESTS); do \
  36                echo "$$t"; \
  37        done
  38
  39generate_nlmsg:
  40        $(MAKE) -C tools
  41
  42alltests: generate_nlmsg $(TESTS)
  43
  44testclean:
  45        @echo "Removing $(RESULTS_DIR) dir ..."
  46        @rm -rf $(RESULTS_DIR)
  47
  48clean: testclean
  49        @rm -f iproute2/iproute2-this
  50        @rm -f tests/ip/link/dev_wo_vf_rate.nl
  51        $(MAKE) -C tools clean
  52
  53distclean: clean
  54        $(MAKE) -C iproute2 distclean
  55
  56$(TESTS): generate_nlmsg testclean
  57ifeq (,$(IPVERS))
  58        $(error Please run make first)
  59endif
  60ifeq (,$(HAVE_UNSHARED_UTIL))
  61        $(error Please install util-linux tools to run tests in separated network namespace)
  62endif
  63        @./tools/generate_nlmsg
  64
  65        @mkdir -p $(RESULTS_DIR)
  66
  67        @for d in $(TESTS_DIR); do \
  68            mkdir -p $(RESULTS_DIR)/$$d; \
  69        done
  70
  71        @if [ "$(KCPATH)" = "/proc/config.gz" ]; then \
  72                gunzip -c $(KCPATH) >$(KENVFN); \
  73        elif [ "$(KCPATH)" != "" ]; then \
  74               cat $(KCPATH) >$(KENVFN); \
  75        fi
  76        @sed -i -e 's/^CONFIG_/export CONFIG_/' $(KENVFN)
  77
  78        @for i in $(IPVERS); do \
  79                o=`echo $$i | sed -e 's/iproute2\///'`; \
  80                echo -n "Running $@ [$$o/`uname -r`]: "; \
  81                TMP_ERR=`mktemp /tmp/tc_testsuite.XXXXXX`; \
  82                TMP_OUT=`mktemp /tmp/tc_testsuite.XXXXXX`; \
  83                . $(KENVFN); \
  84                STD_ERR="$$TMP_ERR" STD_OUT="$$TMP_OUT" \
  85                TC="$$i/tc/tc" IP="$$i/ip/ip" SS=$$i/misc/ss BRIDGE="$$i/bridge/bridge" \
  86                DEV="$(DEV)" IPVER="$@" SNAME="$$i" \
  87                ERRF="$(RESULTS_DIR)/$@.$$o.err" $(PREFIX) tests/$@ > $(RESULTS_DIR)/$@.$$o.out; \
  88                if [ "$$?" = "127" ]; then \
  89                        printf "\033[1;35mSKIPPED\033[0m\n"; \
  90                elif [ -e "$(RESULTS_DIR)/$@.$$o.err" ]; then \
  91                        printf "\033[0;31mFAILED\033[0m\n"; \
  92                else \
  93                        printf "\033[0;32mPASS\033[0m\n"; \
  94                fi; \
  95                rm "$$TMP_ERR" "$$TMP_OUT"; \
  96                sudo dmesg > $(RESULTS_DIR)/$@.$$o.dmesg; \
  97        done
  98