mc | cd7e950 | 2019-12-16 22:04:13 +0000 | [diff] [blame] | 1 | # Copyright 2018-present Open Networking Foundation |
| 2 | # |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | # you may not use this file except in compliance with the License. |
| 5 | # You may obtain a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | # See the License for the specific language governing permissions and |
| 13 | # limitations under the License. |
| 14 | |
| 15 | SHELL = /bin/bash |
| 16 | DEMOTESTDIR = .. |
Ubuntu | f45d1aa | 2020-02-06 07:01:44 +0000 | [diff] [blame] | 17 | DEMOTESTLOG = demotest.log |
mc | cd7e950 | 2019-12-16 22:04:13 +0000 | [diff] [blame] | 18 | TESTSDIR = tests |
| 19 | TESTTAG = tc |
| 20 | TESTS := $(wildcard ${TESTSDIR}/*.$(TESTTAG)) |
| 21 | |
| 22 | .PHONY : check-arg test demotest $(TESTS) clean |
| 23 | |
| 24 | .DEFAULT_GOAL := dm |
| 25 | |
| 26 | check-arg: |
| 27 | ifeq ($(strip $(TESTS)),) |
| 28 | $(error no test found) |
| 29 | endif |
Ubuntu | f45d1aa | 2020-02-06 07:01:44 +0000 | [diff] [blame] | 30 | ifeq "$(and $(IP1),$(PORT1),$(IP2),$(PORT2))" "" |
mc | cd7e950 | 2019-12-16 22:04:13 +0000 | [diff] [blame] | 31 | $(error IP1, PORT1, IP2, and PORT2 are not all defined) |
| 32 | endif |
Ubuntu | f45d1aa | 2020-02-06 07:01:44 +0000 | [diff] [blame] | 33 | ADDR1 := $(shell printf '${IP1}:${PORT1}\n${IP2}:${PORT2}' | sort | sed -n '1 p') |
| 34 | ADDR2 := $(shell printf '${IP1}:${PORT1}\n${IP2}:${PORT2}' | sort | sed -n '2 p') |
| 35 | I1 := $(shell echo ${ADDR1} | cut -d ':' -f 1) |
| 36 | P1 := $(shell echo ${ADDR1} | cut -d ':' -f 2) |
| 37 | I2 := $(shell echo ${ADDR2} | cut -d ':' -f 1) |
| 38 | P2 := $(shell echo ${ADDR2} | cut -d ':' -f 2) |
mc | cd7e950 | 2019-12-16 22:04:13 +0000 | [diff] [blame] | 39 | |
| 40 | demotest: |
Ubuntu | f45d1aa | 2020-02-06 07:01:44 +0000 | [diff] [blame] | 41 | @cd ${DEMOTESTDIR}; make demotest || exit 1; ./demotest > ${DEMOTESTLOG} 2>&1 & \ |
mc | cd7e950 | 2019-12-16 22:04:13 +0000 | [diff] [blame] | 42 | sleep 2 |
| 43 | |
| 44 | dm: test_cli.go |
| 45 | go build -i -v -o $@ |
| 46 | |
| 47 | test: check-arg dm demotest $(TESTS) clean |
Ubuntu | f45d1aa | 2020-02-06 07:01:44 +0000 | [diff] [blame] | 48 | @echo "All tests passed!" |
mc | cd7e950 | 2019-12-16 22:04:13 +0000 | [diff] [blame] | 49 | |
| 50 | $(TESTS): ${TESTSDIR}/%.${TESTTAG}: |
Ubuntu | f45d1aa | 2020-02-06 07:01:44 +0000 | [diff] [blame] | 51 | @sed -e '/^\/\//d' -e 's/ip1/${I1}/g; s/port1/${P1}/g; s/ip2/${I2}/g; s/port2/${P2}/g' ${TESTSDIR}/$*.expected > ${TESTSDIR}/$*.e |
mc | cd7e950 | 2019-12-16 22:04:13 +0000 | [diff] [blame] | 52 | # @sed -i '/^\/\//d' ${TESTSDIR}/$*.e |
| 53 | @echo "===== Running test $@" |
Ubuntu | f45d1aa | 2020-02-06 07:01:44 +0000 | [diff] [blame] | 54 | @./$@ $(I1) $(P1) $(I2) $(P2) > /dev/null > ${TESTSDIR}/$*.out |
mc | cd7e950 | 2019-12-16 22:04:13 +0000 | [diff] [blame] | 55 | @diff -q ${TESTSDIR}/$*.out ${TESTSDIR}/$*.e || (pkill demotest; exit 1) |
| 56 | @rm ${TESTSDIR}/*.out ${TESTSDIR}/*.e |
| 57 | |
| 58 | clean: |
| 59 | @pkill demotest |
Ubuntu | f45d1aa | 2020-02-06 07:01:44 +0000 | [diff] [blame] | 60 | @rm ${DEMOTESTDIR}/${DEMOTESTLOG} |