blob: 07755468de0dd15717ed9745ff67c8298741fa8e [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 = ..
17TESTSDIR = tests
18TESTTAG = tc
19TESTS := $(wildcard ${TESTSDIR}/*.$(TESTTAG))
20
21.PHONY : check-arg test demotest $(TESTS) clean
22
23.DEFAULT_GOAL := dm
24
25check-arg:
26ifeq ($(strip $(TESTS)),)
27 $(error no test found)
28endif
29ifeq "$(and $(IP1),$(PORT1),$(IP2),$(PORT2))" ""
30 $(error IP1, PORT1, IP2, and PORT2 are not all defined)
31endif
32
33demotest:
34 @cd ${DEMOTESTDIR}; make demotest || exit 1; ./demotest & \
35 sleep 2
36
37dm: test_cli.go
38 go build -i -v -o $@
39
40test: 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
51clean:
52 @pkill demotest