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