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 = .. |
| 17 | TESTSDIR = tests |
| 18 | TESTTAG = tc |
| 19 | TESTS := $(wildcard ${TESTSDIR}/*.$(TESTTAG)) |
| 20 | |
| 21 | .PHONY : check-arg test demotest $(TESTS) clean |
| 22 | |
| 23 | .DEFAULT_GOAL := dm |
| 24 | |
| 25 | check-arg: |
| 26 | ifeq ($(strip $(TESTS)),) |
| 27 | $(error no test found) |
| 28 | endif |
| 29 | ifeq "$(and $(IP1),$(PORT1),$(IP2),$(PORT2))" "" |
| 30 | $(error IP1, PORT1, IP2, and PORT2 are not all defined) |
| 31 | endif |
| 32 | |
| 33 | demotest: |
| 34 | @cd ${DEMOTESTDIR}; make demotest || exit 1; ./demotest & \ |
| 35 | sleep 2 |
| 36 | |
| 37 | dm: test_cli.go |
| 38 | go build -i -v -o $@ |
| 39 | |
| 40 | test: check-arg dm demotest $(TESTS) clean |
| 41 | @echo "Alll tests passed!" |
| 42 | |
| 43 | $(TESTS): ${TESTSDIR}/%.${TESTTAG}: |
| 44 | @sed -e '/^\/\//d' -e 's/ip1/${IP1}/g; s/port1/${PORT1}/g; s/ip2/${IP2}/g; s/port2/${PORT2}/g' ${TESTSDIR}/$*.expected > ${TESTSDIR}/$*.e |
| 45 | # @sed -i '/^\/\//d' ${TESTSDIR}/$*.e |
| 46 | @echo "===== Running test $@" |
| 47 | @./$@ $(IP1) $(PORT1) $(IP2) $(PORT2) > /dev/null > ${TESTSDIR}/$*.out |
| 48 | @diff -q ${TESTSDIR}/$*.out ${TESTSDIR}/$*.e || (pkill demotest; exit 1) |
| 49 | @rm ${TESTSDIR}/*.out ${TESTSDIR}/*.e |
| 50 | |
| 51 | clean: |
| 52 | @pkill demotest |