xref: /freebsd/contrib/libucl/tests/run_tests.sh (revision 6cec9cad762b6476313fb1f8e931a1647822db6b)
1#!/bin/sh
2
3if [ $# -lt 1 ] ; then
4	echo 'Specify binary to run as the first argument'
5	exit 1
6fi
7
8
9for _tin in ${TEST_DIR}/*.in ; do
10	_t=`echo $_tin | sed -e 's/.in$//'`
11	$1 $_t.in $_t.out
12	if [ $? -ne 0 ] ; then
13		echo "Test: $_t failed, output:"
14		cat $_t.out
15		rm $_t.out
16		exit 1
17	fi
18	if [ -f $_t.res ] ; then
19	diff -s $_t.out $_t.res -u 2>/dev/null
20		if [ $? -ne 0 ] ; then
21			rm $_t.out
22			echo "Test: $_t output missmatch"
23			exit 1
24		fi
25	fi
26	rm $_t.out
27done
28
29if [ $# -gt 2 ] ; then
30	$3 ${TEST_DIR}/generate.out
31	diff -s ${TEST_DIR}/generate.out ${TEST_DIR}/generate.res -u 2>/dev/null
32	if [ $? -ne 0 ] ; then
33		rm ${TEST_DIR}/generate.out
34		echo "Test: generate.res output missmatch"
35    	exit 1
36	fi
37	rm ${TEST_DIR}/generate.out
38fi
39
40if [ $# -gt 3 ] ; then
41	rm /tmp/_ucl_test_schema.out ||true
42	for i in ${TEST_DIR}/schema/*.json ; do
43		_name=`basename $i`
44		printf "running schema test suite $_name... "
45		cat $i | $4 >> /tmp/_ucl_test_schema.out && ( echo "OK" ) || ( echo "Fail" )
46	done
47fi
48
49sh -c "xz -c < /dev/null > /dev/null"
50if [ $? -eq 0 -a $# -gt 1 ] ; then
51	echo 'Running speed tests'
52	for _tin in ${TEST_DIR}/*.xz ; do
53		echo "Unpacking $_tin..."
54		xz -cd < $_tin > ${TEST_DIR}/test_file
55		# Preread file to cheat benchmark!
56		cat ${TEST_DIR}/test_file > /dev/null
57		echo "Starting benchmarking for $_tin..."
58		$2 ${TEST_DIR}/test_file
59		if [ $? -ne 0 ] ; then
60			echo "Test: $_tin failed"
61			rm ${TEST_DIR}/test_file
62			exit 1
63		fi
64		rm ${TEST_DIR}/test_file
65	done
66fi
67
68