#!/bin/bash

# run test script
# @version 1.0
# @date Jun 2010
# @author Javier Fresno Bausela

# hit v1.0
# (c) 2010, Javier Fresno Bausela


function runtest1
{
	# Names of the test and test solution
	testprogram=$1
	testsolution=$1.out

	# Create a temporal file
	output=$(tempfile) || exit

	$testprogram > $output 2>/dev/null

	result=$(diff -q  "$testsolution" "$output") 

	if [ "$result" ]
	then
		echo -e "$testprogram:\tError"
	else
		echo -e "$testprogram:\tOK"
	fi

	# Delete the temporal file
	rm -f "$outpput"
}


function createtest
{

	# Names of the test and test solution
	testprogram=$1
	testsolution=$1.out

	$testprogram > $testsolution
	echo -e "$testprogram:\tOK"

}

function show_help
{
	echo "$1 [create]"
	echo " - Without options: Execute the tests"
	echo " - Create: Create the test ouput"
}


TESTS=" testLayoutBlocksL testActiveRanks testGroupLayout testShapeUtils testTopologyArrayDims "
#TESTSMPI= " testAlltoAll testBroadCastDim "
#TESTSOTHER= " testPattern "

if [ "$1" = "" ]; then
	echo "Executing the test"
	for i in $TESTS
	do
		runtest1 $i
	done
	exit
fi

if [ "$1" = "create" ]; then
	echo "Creating the test output"
	for i in $TESTS
	do
		createtest $i
	done

	exit
fi

show_help $0




