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