Slightly improved the tests

This commit is contained in:
Pierre Pronchery 2013-10-25 22:24:38 +02:00
parent 745654a94e
commit f392915040
3 changed files with 73 additions and 33 deletions

View File

@ -18,7 +18,7 @@ INSTALL = install
all: $(TARGETS) all: $(TARGETS)
tests.log: transport ../src/transport/tcp.c ../src/transport/udp.c tests.log: tests.sh transport ../src/transport/tcp.c ../src/transport/udp.c
./tests.sh -P "$(PREFIX)" -- "tests.log" ./tests.sh -P "$(PREFIX)" -- "tests.log"
transport_OBJS = transport.o transport_OBJS = transport.o

View File

@ -9,7 +9,7 @@ dist=Makefile,tests.sh
[tests.log] [tests.log]
type=script type=script
script=./tests.sh script=./tests.sh
depends=transport,../src/transport/tcp.c,../src/transport/udp.c depends=tests.sh,transport,../src/transport/tcp.c,../src/transport/udp.c
[transport] [transport]
type=binary type=binary

View File

@ -15,23 +15,63 @@
#along with this program. If not, see <http://www.gnu.org/licenses/>. #along with this program. If not, see <http://www.gnu.org/licenses/>.
#functions #variables
#transport #executables
_transport() DATE="date"
{
[ $# -eq 2 ] || return 1
transport="$1"
name="$2"
echo "transport: Testing $transport ($name)" 1<&2
./transport -p "$transport" "$name" #functions
#fail
_fail()
{
test="$1"
#XXX
protocol="$3"
name="$4"
shift
echo -n "$test:" 1>&2
(echo ""
echo "Testing: ./$test" "$@"
"./$test" "$@") >> "$target" 2>&1
res=$?
if [ $res -ne 0 ]; then
echo " FAILED ($protocol $name, error $res)" 1>&2
else
echo " PASS" 1>&2
fi
}
#test
_test()
{
test="$1"
#XXX
protocol="$3"
name="$4"
shift
echo -n "$test:" 1>&2
(echo ""
echo "Testing: ./$test" "$@"
"./$test" "$@") >> "$target" 2>&1
res=$?
if [ $res -ne 0 ]; then
echo " FAILED" 1>&2
FAILED="$FAILED $test($protocol $name, error $res)"
return 2
else
echo " PASS" 1>&2
return 0
fi
} }
#usage #usage
_usage() _usage()
{ {
echo "Usage: tests.sh target" 1>&2 echo "Usage: tests.sh [-c][-P prefix] target" 1>&2
return 1 return 1
} }
@ -61,25 +101,25 @@ target="$1"
[ "$clean" -ne 0 ] && exit 0 [ "$clean" -ne 0 ] && exit 0
> "$target" $DATE > "$target"
FAILED= FAILED=
_transport tcp4 127.0.0.1:4242 >> "$target" || FAILED="$FAILED tcp4(error $?)" echo "Performing tests:" 1>&2
_transport tcp6 ::1.4242 >> "$target" || FAILED="$FAILED tcp6(error $?)" _test "transport" -p tcp4 127.0.0.1:4242
_transport tcp6 ::1:4242 >> "$target" _test "transport" -p tcp6 ::1.4242
[ $? -eq 2 ] || FAILED="$FAILED tcp6(error $?)" _test "transport" -p tcp 127.0.0.1:4242
_transport tcp 127.0.0.1:4242 >> "$target" || FAILED="$FAILED tcp(error $?)" _test "transport" -p tcp ::1.4242
_transport tcp ::1.4242 >> "$target" || FAILED="$FAILED tcp(error $?)" echo "Expected failures:" 1>&2
_transport tcp ::1:4242 >> "$target" #XXX next four should pass instead
[ $? -eq 2 ] || FAILED="$FAILED tcp(error $?)" _fail "transport" -p udp4 127.0.0.1:4242
_transport udp4 127.0.0.1:4242 >> "$target" || FAILED="$FAILED udp4(error $?)" _fail "transport" -p udp6 ::1.4242
_transport udp6 ::1.4242 >> "$target" || FAILED="$FAILED udp6(error $?)" _fail "transport" -p udp 127.0.0.1:4242
_transport udp6 ::1:4242 >> "$target" _fail "transport" -p udp ::1.4242
[ $? -eq 2 ] || FAILED="$FAILED udp6(error $?)" _fail "transport" -p tcp6 ::1:4242
_transport udp 127.0.0.1:4242 >> "$target" || FAILED="$FAILED udp(error $?)" _fail "transport" -p tcp ::1:4242
_transport udp ::1.4242 >> "$target" || FAILED="$FAILED udp(error $?)" _fail "transport" -p udp6 ::1:4242
_transport udp ::1:4242 >> "$target" _fail "transport" -p udp ::1:4242
[ $? -eq 2 ] || FAILED="$FAILED udp(error $?)" if [ -n "$FAILED" ]; then
[ -z "$FAILED" ] && exit 0
echo "Failed tests:$FAILED" 1>&2 echo "Failed tests:$FAILED" 1>&2
#XXX ignore errors for now exit 2
#exit 2 fi
echo "All tests completed" 1>&2