blob: 1b5ea3be456ae7c7d9baec11b426a5e4c09f11b5 [file] [log] [blame]
mccd7e9502019-12-16 22:04:13 +00001# 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
15SHELL = /bin/bash
16DEMOTESTDIR = ..
Ubuntuf45d1aa2020-02-06 07:01:44 +000017DEMOTESTLOG = demotest.log
mccd7e9502019-12-16 22:04:13 +000018TESTSDIR = tests
19TESTTAG = tc
20TESTS := $(wildcard ${TESTSDIR}/*.$(TESTTAG))
21
22.PHONY : check-arg test demotest $(TESTS) clean
23
24.DEFAULT_GOAL := dm
25
26check-arg:
27ifeq ($(strip $(TESTS)),)
28 $(error no test found)
29endif
Ubuntuf45d1aa2020-02-06 07:01:44 +000030ifeq "$(and $(IP1),$(PORT1),$(IP2),$(PORT2))" ""
mccd7e9502019-12-16 22:04:13 +000031 $(error IP1, PORT1, IP2, and PORT2 are not all defined)
32endif
Ubuntuf45d1aa2020-02-06 07:01:44 +000033ADDR1 := $(shell printf '${IP1}:${PORT1}\n${IP2}:${PORT2}' | sort | sed -n '1 p')
34ADDR2 := $(shell printf '${IP1}:${PORT1}\n${IP2}:${PORT2}' | sort | sed -n '2 p')
35I1 := $(shell echo ${ADDR1} | cut -d ':' -f 1)
36P1 := $(shell echo ${ADDR1} | cut -d ':' -f 2)
37I2 := $(shell echo ${ADDR2} | cut -d ':' -f 1)
38P2 := $(shell echo ${ADDR2} | cut -d ':' -f 2)
mccd7e9502019-12-16 22:04:13 +000039
40demotest:
Ubuntuf45d1aa2020-02-06 07:01:44 +000041 @cd ${DEMOTESTDIR}; make demotest || exit 1; ./demotest > ${DEMOTESTLOG} 2>&1 & \
mccd7e9502019-12-16 22:04:13 +000042 sleep 2
43
44dm: test_cli.go
45 go build -i -v -o $@
46
47test: check-arg dm demotest $(TESTS) clean
Ubuntuf45d1aa2020-02-06 07:01:44 +000048 @echo "All tests passed!"
mccd7e9502019-12-16 22:04:13 +000049
50$(TESTS): ${TESTSDIR}/%.${TESTTAG}:
Ubuntuf45d1aa2020-02-06 07:01:44 +000051 @sed -e '/^\/\//d' -e 's/ip1/${I1}/g; s/port1/${P1}/g; s/ip2/${I2}/g; s/port2/${P2}/g' ${TESTSDIR}/$*.expected > ${TESTSDIR}/$*.e
mccd7e9502019-12-16 22:04:13 +000052# @sed -i '/^\/\//d' ${TESTSDIR}/$*.e
53 @echo "===== Running test $@"
Ubuntuf45d1aa2020-02-06 07:01:44 +000054 @./$@ $(I1) $(P1) $(I2) $(P2) > /dev/null > ${TESTSDIR}/$*.out
mccd7e9502019-12-16 22:04:13 +000055 @diff -q ${TESTSDIR}/$*.out ${TESTSDIR}/$*.e || (pkill demotest; exit 1)
56 @rm ${TESTSDIR}/*.out ${TESTSDIR}/*.e
57
58clean:
59 @pkill demotest
Ubuntuf45d1aa2020-02-06 07:01:44 +000060 @rm ${DEMOTESTDIR}/${DEMOTESTLOG}