Fixed up indentation and some general style.

This commit is contained in:
Tom Hacohen 2013-04-26 10:25:57 +01:00
parent 802baf489f
commit bf5f589310
1 changed files with 210 additions and 211 deletions

View File

@ -75,151 +75,150 @@ echo "$0 -v -p [-b BaseDir] [-d DestDir] TestsFile"
} }
get_test_params () { get_test_params () {
# This function analyze input line and sets test-file-name, rec-file-name # This function analyze input line and sets test-file-name, rec-file-name
# reset globals # reset globals
_test_name= _test_name=
_test_cmd= _test_cmd=
local line="$1" local line="$1"
local c=${line:0:1} local c=${line:0:1}
if [ "$c" = "#" ] if [ "$c" = "#" ]
then then
# This line is a comment
return 1 return 1
fi fi
local p=\`expr index "$line" \\ \` local p=\`expr index "$line" \\ \`
if [ $p -ne 0 ] if [ $p -ne 0 ]
then then
(( p-- )) (( p-- ))
fi fi
_test_name=${line:0:p} _test_name=${line:0:p}
(( p++ )) (( p++ ))
_test_cmd=${line:p} _test_cmd=${line:p}
# Test that input is valid # Test that input is valid
if [ -z "$_test_name" ] if [ -z "$_test_name" ]
then then
_test_name= _test_name=
_test_cmd= _test_cmd=
return 1 return 1
fi fi
if [ -z "$_test_cmd" ] if [ -z "$_test_cmd" ]
then then
_test_name= _test_name=
_test_cmd= _test_cmd=
return 1 return 1
fi fi
DEBUG echo test name=\""$_test_name"\" DEBUG echo test name=\""$_test_name"\"
DEBUG echo test cmd=\""$_test_cmd"\" DEBUG echo test cmd=\""$_test_cmd"\"
return 0 return 0
} }
do_record () { do_record () {
DEBUG printf "do_record()\n" DEBUG printf "do_record()\n"
# This will run record for all test if no specific test specified # This will run record for all test if no specific test specified
# or run recording of specified tests (names passed as parameter). # or run recording of specified tests (names passed as parameter).
# run ALL tests to record # run ALL tests to record
DEBUG echo do_record "$*" DEBUG echo do_record "$*"
get_test_params "$1" get_test_params "$1"
if [ $? -ne 0 ] if [ $? -ne 0 ]
then then
return 0 return 0
fi fi
if [ "$_verbose" -ne 0 ] if [ "$_verbose" -ne 0 ]
then then
echo "do_record: $_test_name" echo "do_record: $_test_name"
fi fi
TSUITE_RECORDING='rec' TSUITE_BASE_DIR=${_base_dir} TSUITE_DEST_DIR=${_dest_dir} TSUITE_FILE_NAME=${_base_dir}/${_test_name}.rec TSUITE_TEST_NAME=${_test_name} LD_PRELOAD=${OUR_LIBPATH}/libexactness.so eval ${_test_cmd} TSUITE_RECORDING='rec' TSUITE_BASE_DIR=${_base_dir} TSUITE_DEST_DIR=${_dest_dir} TSUITE_FILE_NAME=${_base_dir}/${_test_name}.rec TSUITE_TEST_NAME=${_test_name} LD_PRELOAD=${OUR_LIBPATH}/libexactness.so eval ${_test_cmd}
} }
do_simulation () { do_simulation () {
# This will play simulation # This will play simulation
# this will NOT produce screenshots # this will NOT produce screenshots
DEBUG echo do_simulation "$*" DEBUG echo do_simulation "$*"
get_test_params "$1" get_test_params "$1"
if [ $? -ne 0 ] if [ $? -ne 0 ]
then then
return 0 return 0
fi fi
local file_name=${_base_dir}/${_test_name}.rec local file_name=${_base_dir}/${_test_name}.rec
if [ ! -e "$file_name" ] if [ ! -e "$file_name" ]
then then
echo Rec file "$file_name" not found. echo Rec file "$file_name" not found.
return 1 return 1
fi fi
if [ "$_verbose" -ne 0 ] if [ "$_verbose" -ne 0 ]
then then
echo "do_simulation: $_test_name" echo "do_simulation: $_test_name"
fi fi
TSUITE_BASE_DIR=${_base_dir} TSUITE_DEST_DIR=${_dest_dir} TSUITE_FILE_NAME=${file_name} TSUITE_TEST_NAME=${_test_name} LD_PRELOAD=${OUR_LIBPATH}/libexactness.so eval ${_test_cmd} TSUITE_BASE_DIR=${_base_dir} TSUITE_DEST_DIR=${_dest_dir} TSUITE_FILE_NAME=${file_name} TSUITE_TEST_NAME=${_test_name} LD_PRELOAD=${OUR_LIBPATH}/libexactness.so eval ${_test_cmd}
} }
do_play () { do_play () {
# This will play record for all test if '-a' specified. # This will play record for all test if '-a' specified.
# or play record of tests specified as parameter. # or play record of tests specified as parameter.
# run ALL tests to record # run ALL tests to record
DEBUG echo base dir: "$_base_dir" DEBUG echo base dir: "$_base_dir"
DEBUG echo dest dir: "$_dest_dir" DEBUG echo dest dir: "$_dest_dir"
DEBUG echo do_play "$_dest_dir" "$*" DEBUG echo do_play "$_dest_dir" "$*"
# Play recorded tests and produce PNG files. # Play recorded tests and produce PNG files.
# this will produce screenshots in "_dest_dir" folder # this will produce screenshots in "_dest_dir" folder
get_test_params "$1" get_test_params "$1"
if [ $? -ne 0 ] if [ $? -ne 0 ]
then then
return 0 return 0
fi fi
local file_name=${_base_dir}/${_test_name}.rec local file_name=${_base_dir}/${_test_name}.rec
if [ ! -e "$file_name" ] if [ ! -e "$file_name" ]
then then
echo Rec file "$file_name" not found. echo Rec file "$file_name" not found.
return 1 return 1
fi fi
if [ -e "$_dest_dir" ] if [ -e "$_dest_dir" ]
then then
# Remove PNG files according to tests played # Remove PNG files according to tests played
rm "$_dest_dir"/${_test_name}_[0-9]*.png &> /dev/null rm "$_dest_dir"/${_test_name}_[0-9]*.png &> /dev/null
else else
# Create dest dir # Create dest dir
mkdir -p "$_dest_dir" &> /dev/null mkdir -p "$_dest_dir" &> /dev/null
fi fi
if [ "$_verbose" -ne 0 ] if [ "$_verbose" -ne 0 ]
then then
echo "do_play: $_test_name" echo "do_play: $_test_name"
fi fi
ELM_ENGINE="buffer" TSUITE_BASE_DIR=${_base_dir} TSUITE_DEST_DIR=${_dest_dir} TSUITE_FILE_NAME=${file_name} TSUITE_TEST_NAME=${_test_name} LD_PRELOAD=${OUR_LIBPATH}/libexactness.so eval ${_test_cmd} ELM_ENGINE="buffer" TSUITE_BASE_DIR=${_base_dir} TSUITE_DEST_DIR=${_dest_dir} TSUITE_FILE_NAME=${file_name} TSUITE_TEST_NAME=${_test_name} LD_PRELOAD=${OUR_LIBPATH}/libexactness.so eval ${_test_cmd}
} }
compare_files () { compare_files () {
if [ "$_verbose" -ne 0 ] if [ "$_verbose" -ne 0 ]
then then
echo "compare_files: <$1> and <$2>" echo "compare_files: <$1> and <$2>"
fi fi
if [ -e "$1" ] if [ -e "$1" ]
# First file exists # First file exists
then then
local md_file1=\`md5sum $1\` local md_file1=\`md5sum $1\`
if [ -e "$2" ] if [ -e "$2" ]
then then
# Second file exists # Second file exists
local md_file2=\`md5sum $2\` local md_file2=\`md5sum $2\`
# Get md5 of both files # Get md5 of both files
local md1=\`echo "$md_file1" | cut -d ' ' -f1\` local md1=\`echo "$md_file1" | cut -d ' ' -f1\`
local md2=\`echo "$md_file2" | cut -d ' ' -f1\` local md2=\`echo "$md_file2" | cut -d ' ' -f1\`
# Increase counter of comparisons # Increase counter of comparisons
(( ncomp++ )) (( ncomp++ ))
# Compare md5 of both files # Compare md5 of both files
@ -233,19 +232,19 @@ then
else else
echo "$name does not match." echo "$name does not match."
fi fi
# Increment counter of files not identical. # Increment counter of files not identical.
(( nfail++ )) (( nfail++ ))
fi fi
else else
# Failed to find second file # Failed to find second file
echo "Test file was not found $2" echo "Test file was not found $2"
(( nerr++ )) (( nerr++ ))
fi fi
else else
# Failed to find first file # Failed to find first file
echo "Test file was not found $1" echo "Test file was not found $1"
(( nerr++ )) (( nerr++ ))
fi fi
} }
process_compare () { process_compare () {
@ -260,85 +259,85 @@ process_compare () {
} }
do_compare () { do_compare () {
DEBUG printf "do_compare()\n" DEBUG printf "do_compare()\n"
DEBUG echo orig dir: "$_orig_dir" DEBUG echo orig dir: "$_orig_dir"
DEBUG echo dest dir: "$_dest_dir" DEBUG echo dest dir: "$_dest_dir"
# This will compare files in 'orig' folder with files in _dest_dir # This will compare files in 'orig' folder with files in _dest_dir
if [ $comp_unavail -ne 0 ] if [ $comp_unavail -ne 0 ]
then then
if [ $# -eq 1 ] if [ $# -eq 1 ]
then then
echo "Compare software missing." echo "Compare software missing."
echo "Install \"ImageMagick\" if you like to procduce \"comp\" files." echo "Install \"ImageMagick\" if you like to procduce \"comp\" files."
echo "Printing diffs to output" echo "Printing diffs to output"
fi fi
fi fi
if [ -z "$_dest_dir" ] if [ -z "$_dest_dir" ]
then then
printf "For comparing, Usage: %s -c -a -d DirName\nor\n%s -c -d DirName TestName1, TestName2,...\n" $(basename $0) $(basename $0) >&2 printf "For comparing, Usage: %s -c -a -d DirName\nor\n%s -c -d DirName TestName1, TestName2,...\n" $(basename $0) $(basename $0) >&2
fi fi
if [ "$_dest_dir" = "$_orig_dir" ] if [ "$_dest_dir" = "$_orig_dir" ]
then then
printf "Dest-Dir is $_dest_dir, exiting.\n" printf "Dest-Dir is $_dest_dir, exiting.\n"
return 0 return 0
fi fi
local files_list= local files_list=
for test_name in $* for test_name in $*
do do
rm "$_dest_dir"/comp_"$test_name"_[0-9]*.png &> /dev/null rm "$_dest_dir"/comp_"$test_name"_[0-9]*.png &> /dev/null
files_list=( \`ls "$_dest_dir"/"$test_name"_[0-9]*.png\` ) files_list=( \`ls "$_dest_dir"/"$test_name"_[0-9]*.png\` )
process_compare "${files_list[@]}" process_compare "${files_list[@]}"
done done
if [ "$ncomp" -ne 0 ] if [ "$ncomp" -ne 0 ]
then then
echo "Processed $ncomp comparisons" echo "Processed $ncomp comparisons"
fi fi
if [ "$nfail" -ne 0 ] if [ "$nfail" -ne 0 ]
then then
echo "with $nfail diff errors" echo "with $nfail diff errors"
fi fi
if [ "$nerr" -ne 0 ] if [ "$nerr" -ne 0 ]
then then
echo "$nerr PNG-files were not found" echo "$nerr PNG-files were not found"
fi fi
return 0 return 0
} }
name_in_args () { name_in_args () {
# This function gets curline as first arg # This function gets curline as first arg
# Then list of args to find if test name is first field of curline # Then list of args to find if test name is first field of curline
get_test_params "$1" get_test_params "$1"
if [ $? -ne 0 ] if [ $? -ne 0 ]
then then
return 0 return 0
fi fi
if [ -z "$_test_name" ] if [ -z "$_test_name" ]
then then
return 0 return 0
fi fi
shift shift
while (( "$#" )); while (( "$#" ));
do do
if [ "$_test_name" = "$1" ] if [ "$_test_name" = "$1" ]
# found test name in list of args # found test name in list of args
then then
return 1 return 1
fi fi
shift shift
done done
# Not found # Not found
return 0 return 0
} }
# Script Entry Point # Script Entry Point
@ -423,7 +422,7 @@ DEBUG echo _dest_dir="$_dest_dir"
if [ "$_simulation" ] if [ "$_simulation" ]
then then
# When in simulation mode, we will just commit play (ignore other options) # When in simulation mode, we will just commit play (ignore other options)
_init= _init=
_record= _record=
_compare= _compare=
@ -442,7 +441,7 @@ then
fi fi
fi fi
done < "$_test_file_name" done < "$_test_file_name"
# This will cause render simulation # This will cause render simulation
fi fi
if [ ! -e "$_base_dir" ] if [ ! -e "$_base_dir" ]