blob: 5cd57f7208cb3373eb423d9cf561ab6f8d68bd6d [file] [log] [blame]
mccd7e9502019-12-16 22:04:13 +00001# Copyright 2018-present Open Networking Foundation
Dinesh Belwalkar6c0bc752020-04-24 23:47:53 +00002# Copyright 2018-present Edgecore Networks Corporation
mccd7e9502019-12-16 22:04:13 +00003#
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
16SHELL = /bin/bash
17DEMOTESTDIR = ..
Ubuntuf45d1aa2020-02-06 07:01:44 +000018DEMOTESTLOG = demotest.log
mccd7e9502019-12-16 22:04:13 +000019TESTSDIR = tests
20TESTTAG = tc
21TESTS := $(wildcard ${TESTSDIR}/*.$(TESTTAG))
22
23.PHONY : check-arg test demotest $(TESTS) clean
24
25.DEFAULT_GOAL := dm
26
27check-arg:
28ifeq ($(strip $(TESTS)),)
29 $(error no test found)
30endif
Ubuntuf45d1aa2020-02-06 07:01:44 +000031ifeq "$(and $(IP1),$(PORT1),$(IP2),$(PORT2))" ""
mccd7e9502019-12-16 22:04:13 +000032 $(error IP1, PORT1, IP2, and PORT2 are not all defined)
33endif
Ubuntuf45d1aa2020-02-06 07:01:44 +000034ADDR1 := $(shell printf '${IP1}:${PORT1}\n${IP2}:${PORT2}' | sort | sed -n '1 p')
35ADDR2 := $(shell printf '${IP1}:${PORT1}\n${IP2}:${PORT2}' | sort | sed -n '2 p')
36I1 := $(shell echo ${ADDR1} | cut -d ':' -f 1)
37P1 := $(shell echo ${ADDR1} | cut -d ':' -f 2)
38I2 := $(shell echo ${ADDR2} | cut -d ':' -f 1)
39P2 := $(shell echo ${ADDR2} | cut -d ':' -f 2)
mccd7e9502019-12-16 22:04:13 +000040
41demotest:
Ubuntuf45d1aa2020-02-06 07:01:44 +000042 @cd ${DEMOTESTDIR}; make demotest || exit 1; ./demotest > ${DEMOTESTLOG} 2>&1 & \
mccd7e9502019-12-16 22:04:13 +000043 sleep 2
44
45dm: test_cli.go
46 go build -i -v -o $@
47
48test: check-arg dm demotest $(TESTS) clean
Ubuntuf45d1aa2020-02-06 07:01:44 +000049 @echo "All tests passed!"
mccd7e9502019-12-16 22:04:13 +000050
51$(TESTS): ${TESTSDIR}/%.${TESTTAG}:
Ubuntuf45d1aa2020-02-06 07:01:44 +000052 @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 +000053# @sed -i '/^\/\//d' ${TESTSDIR}/$*.e
54 @echo "===== Running test $@"
Ubuntuf45d1aa2020-02-06 07:01:44 +000055 @./$@ $(I1) $(P1) $(I2) $(P2) > /dev/null > ${TESTSDIR}/$*.out
mccd7e9502019-12-16 22:04:13 +000056 @diff -q ${TESTSDIR}/$*.out ${TESTSDIR}/$*.e || (pkill demotest; exit 1)
57 @rm ${TESTSDIR}/*.out ${TESTSDIR}/*.e
58
59clean:
60 @pkill demotest
Ubuntuf45d1aa2020-02-06 07:01:44 +000061 @rm ${DEMOTESTDIR}/${DEMOTESTLOG}