Major rework started on unit tests (ppss-test.sh)

This commit is contained in:
Louwrentius 2010-06-06 20:45:56 +00:00
parent 708803688f
commit 4b9df537a0
3 changed files with 75 additions and 177 deletions

11
ppss
View File

@ -24,7 +24,6 @@
# Handling control-c for a clean shutdown. # Handling control-c for a clean shutdown.
# #
trap 'kill_process' SIGINT trap 'kill_process' SIGINT
SCRIPT_NAME="Distributed Parallel Processing Shell Script" SCRIPT_NAME="Distributed Parallel Processing Shell Script"
SCRIPT_VERSION="2.70" SCRIPT_VERSION="2.70"
@ -760,12 +759,10 @@ expand_str () {
are_we_sourced () { are_we_sourced () {
if [ "$SOURCED" == "-bash" ] || [ "$SOURCED" == "bash" ] || [ "$SOURCED" = "dash" ] if [ ! "$SOURCED" == "./ppss" ]
then then
log DEBUG "This script is sourced."
return 0 return 0
else else
log DEBUG "This script is not sourced."
return 1 return 1
fi fi
} }
@ -1574,7 +1571,7 @@ get_all_items () {
else else
log DEBUG "Recursion is disabled." log DEBUG "Recursion is disabled."
#ITEMS=`exec_cmd "ls -1 $SRC_DIR"` #ITEMS=`exec_cmd "ls -1 $SRC_DIR"`
`exec_cmd "ls -1 $SRC_DIR" > "$LOCAL_INPUT_FILE"` `exec_cmd "find $SRC_DIR/ -d 1 ! -type d" > "$LOCAL_INPUT_FILE"`
check_status "$?" "$FUNCNAME" "Could not list files within remote source directory." check_status "$?" "$FUNCNAME" "Could not list files within remote source directory."
fi fi
else else
@ -1589,7 +1586,7 @@ get_all_items () {
else else
log DEBUG "Recursion is disabled." log DEBUG "Recursion is disabled."
#ITEMS=`ls -1 "$SRC_DIR"` #ITEMS=`ls -1 "$SRC_DIR"`
`ls -1 "$SRC_DIR" >> "$LOCAL_INPUT_FILE"` `find "$SRC_DIR/" -d 1 ! -type d >> "$LOCAL_INPUT_FILE"`
check_status "$?" "$FUNCNAME" "Could not list files within local source directory." check_status "$?" "$FUNCNAME" "Could not list files within local source directory."
fi fi
if [ ! -e "$LOCAL_INPUT_FILE" ] if [ ! -e "$LOCAL_INPUT_FILE" ]
@ -2394,8 +2391,6 @@ then
# #
process_arguments "$@" process_arguments "$@"
# #
# This command starts the that sets the whole framework in motion. # This command starts the that sets the whole framework in motion.
# But only if the file is not sourced. # But only if the file is not sourced.

View File

@ -2,20 +2,26 @@
DEBUG="$1" DEBUG="$1"
VERSION="2.70" VERSION="2.70"
TMP_DIR="ppss" TMP_DIR="/tmp/ppss"
PPSS=./ppss PPSS=./ppss
PPSS_DIR=ppss_dir PPSS_DIR=ppss_dir
export PPSSDEBUG=1 export PPSS_DEBUG=1
HOST_ARCH=`uname`
. "$PPSS"
cleanup () { cleanup () {
for x in $REMOVEFILES for x in $REMOVEFILES
do do
if [ -e ./$x ] if [ -e ./$x ]
then
rm -r ./$x
fi
done
if [ ! -z "$TMP_DIR" ]
then then
rm -r ./$x rm -rf "/$TMP_DIR"
fi fi
done
} }
parseJobStatus () { parseJobStatus () {
@ -25,7 +31,12 @@ parseJobStatus () {
RES=`grep "Status:" "$JOBLOG/$TMP_FILE"` RES=`grep "Status:" "$JOBLOG/$TMP_FILE"`
STATUS=`echo "$RES" | awk '{ print $2 }'` STATUS=`echo "$RES" | awk '{ print $2 }'`
echo "$STATUS" echo "$STATUS"
}
get_contents_of_input_file () {
RES=`cat $PPSS_DIR/INPUT_FILE-$$ | wc -l | awk '{ print $1 }'`
echo "$RES"
} }
oneTimeSetUp () { oneTimeSetUp () {
@ -34,24 +45,19 @@ oneTimeSetUp () {
INPUTFILENORMAL=test-normal.input INPUTFILENORMAL=test-normal.input
INPUTFILESPECIAL=test-special.input INPUTFILESPECIAL=test-special.input
LOCALOUTPUT=ppss_dir/PPSS_LOCAL_OUTPUT LOCALOUTPUT=ppss_dir/PPSS_LOCAL_OUTPUT
REMOVEFILES="$PPSS_DIR test-ppss-*" REMOVEFILES="$PPSS_DIR test-ppss-*"
if [ ! -e "$TMP_DIR" ]
then
mkdir "$TMP_DIR"
fi
cleanup cleanup
} }
testVersion () { testVersion () {
RES=`$PPSS -v` assertEquals "Version mismatch!" "$VERSION" "$SCRIPT_VERSION"
for x in $RES
do
echo "$x" | grep [0-9] >> /dev/null
if [ "$?" == "0" ]
then
assertEquals "Version mismatch!" "$VERSION" "$x"
fi
done
} }
rename-ppss-dir () { rename-ppss-dir () {
@ -70,174 +76,71 @@ oneTimeTearDown () {
then then
cleanup cleanup
fi fi
} }
createDirectoryWithSomeFiles () { createDirectoryWithSomeFiles () {
A="File with Spaces"
B="File\With\Slashes"
c="symnlink1"
d="symnlink2"
TMP_FILE="/tmp/$TMP_DIR" ROOT_DIR=$TMP_DIR/root
if [ ! -e "$TMP_FILE" ] CHILD_1=$ROOT_DIR/child_1
then CHILD_2=$ROOT_DIR/child_2
mkdir "$TMP_FILE"
fi
touch "$A" mkdir -p "$ROOT_DIR"
touch "$B" mkdir -p "$CHILD_1"
ln -s /etc/resolve.conf "$TMP_FILE"/ mkdir -p "$CHILD_2"
ln -s /etc/hosts "$TMP_FILE"/
for x in {1..10}
do
touch "$ROOT_DIR/file-$x"
touch "$CHILD_1/file-$x"
touch "$CHILD_2/file-$x"
done
ln -s /etc/resolve.conf "$ROOT_DIR" 2> /dev/null
ln -s /etc/hosts "$ROOT_DIR" 2> /dev/null
}
testMD5 () {
ARCH=Darwin
set_md5
assertEquals "MD5 executable not set properly - $MD5" "$MD5" "md5"
ARCH=Linux
set_md5
assertEquals "MD5 executable not set properly - $MD5" "$MD5" "md5sum"
ARCH=$HOST_ARCH
}
init_get_all_items () {
RECURSION="$1"
createDirectoryWithSomeFiles
create_working_directory
init_vars > /dev/null 2>&1
export SRC_DIR=$TMP_DIR/root
get_all_items
RES=`get_contents_of_input_file`
} }
testRecursion () { testRecursion () {
createDirectoryWithSomeFiles init_get_all_items 1
#Execution of PPSS with recursion disabled. EXPECTED=32
RES=$( { $PPSS -d /tmp/$TMP_DIR -c 'ls -alh ' -r >> /dev/null ; } 2>&1 ) assertEquals "Recursion not correct." "$EXPECTED" "$RES"
assertEquals "PPSS did not execute properly." 0 "$?"
NUMBER=`find /tmp/$TMP_DIR ! -type d | wc -l`
LOGS=`ls -1 $JOBLOG/* | wc -l`
assertEquals "Did not find equal files and joblogs $TMP_FILE" "$NUMBER" "$LOGS"
rm -rf "/tmp/$TMP_DIR"
rename-ppss-dir $FUNCNAME
}
testSpacesInFilenames () {
createDirectoryWithSomeFiles
#Regular execution of PPSS
RES=$( { $PPSS -d /tmp/$TMP_DIR -c 'ls -alh ' >> /dev/null ; } 2>&1 )
assertEquals "PPSS did not execute properly." 0 "$?"
assertNull "PPSS retured some errors..." "$RES"
if [ ! "$?" == "0" ]
then
echo "RES IS $RES"
fi
grep "SUCCESS" $JOBLOG/* >> /dev/null 2>&1
assertEquals "Found error with space in filename $TMP_FILE" "0" "$?"
NUMBER=`find /tmp/$TMP_DIR ! -type d | wc -l`
LOGS=`ls -1 $JOBLOG/* | wc -l`
assertEquals "Did not find equal files and joblogs $TMP_FILE" "$NUMBER" "$LOGS"
rm -rf "/tmp/$TMP_DIR"
rename-ppss-dir $FUNCNAME
}
testSpecialCharacterHandling () {
RES=$( { $PPSS -f "$INPUTFILESPECIAL" -c 'echo ' >> /dev/null ; } 2>&1 )
assertEquals "PPSS did not execute properly." 0 "$?"
assertNull "PPSS retured some errors..." "$RES"
if [ ! "$?" == "0" ]
then
echo "RES IS $RES"
fi
RES=$( { cat "$INPUTFILESPECIAL" | $PPSS -f - -c 'echo ' >> /dev/null ; } 2>&1 )
assertEquals "PPSS did not execute properly." 0 "$?"
assertNull "PPSS retured some errors..." "$RES"
RES=`find ppss_dir/PPSS_LOCAL_OUTPUT | wc -l | sed 's/\ //g'`
LINES=`wc -l "$INPUTFILESPECIAL" | awk '{ print $1 }'`
assertEquals "To many lock files..." "$((LINES+1))" "$RES"
RES1=`ls -1 $JOBLOG`
RES2=`ls -1 $LOCALOUTPUT`
assertEquals "RES1 $RES1 is not the same as RES2 $RES2" "$RES1" "$RES2"
rename-ppss-dir $FUNCNAME rename-ppss-dir $FUNCNAME
} }
testSkippingOfProcessedItems () { testNoRecursion () {
createDirectoryWithSomeFiles init_get_all_items 0
EXPECTED=12
RES=$( { $PPSS -d /tmp/$TMP_DIR -c 'echo ' >> /dev/null ; } 2>&1 ) assertEquals "Recursion not correct." "$EXPECTED" "$RES"
assertEquals "PPSS did not execute properly." 0 "$?"
assertNull "PPSS retured some errors..." "$RES"
RES=$( { $PPSS -d /tmp/$TMP_DIR -c 'echo ' >> /dev/null ; } 2>&1 ) rename-ppss-dir $FUNCNAME
assertEquals "PPSS did not execute properly." 0 "$?"
assertNull "PPSS retured some errors..." "$RES"
RES=`grep -c -i locked ./$PPSS_DIR/ppss-log* | tail -n 1 | cut -d ":" -f 2`
assertEquals "Skipping of items went wrong." 2 "$RES"
rename-ppss-dir $FUNCNAME-1
RES=$( { $PPSS -f $INPUTFILESPECIAL -c 'echo ' >> /dev/null ; } 2>&1 )
assertEquals "PPSS did not execute properly." 0 "$?"
assertNull "PPSS retured some errors..." "$RES"
RES=$( { $PPSS -f $INPUTFILESPECIAL -c 'echo ' >> /dev/null ; } 2>&1 )
assertEquals "PPSS did not execute properly." 0 "$?"
assertNull "PPSS retured some errors..." "$RES"
RES=`grep -c -i locked ./$PPSS_DIR/ppss-log* | tail -n 1 | cut -d ":" -f 2`
assertEquals "Skipping of items went wrong." 8 "$RES"
rm -rf "/tmp/$TMP_DIR"
rename-ppss-dir $FUNCNAME-2
} }
testExistLogFiles () {
$PPSS -f "$INPUTFILENORMAL" -c 'echo "$ITEM"' >> /dev/null
assertEquals "PPSS did not execute properly." 0 "$?"
for x in $NORMALTESTFILES
do
assertTrue "[ -e $JOBLOG/$x ]"
done
rename-ppss-dir $FUNCNAME
}
getStatusOfJob () {
EXPECTED="$1"
if [ "$EXPECTED" == "SUCCESS" ]
then
$PPSS -f "$INPUTFILENORMAL" -c 'echo ' >> /dev/null
assertEquals "PPSS did not execute properly." 0 "$?"
elif [ "$EXPECTED" == "FAILURE" ]
then
$PPSS -f "$INPUTFILENORMAL" -c 'thiscommandfails ' >> /dev/null
assertEquals "PPSS did not execute properly." 0 "$?"
fi
for x in $NORMALTESTFILES
do
STATUS=`parseJobStatus "$x"`
assertEquals "FAILED WITH STATUS $STATUS." "$EXPECTED" "$STATUS"
done
rename-ppss-dir "$FUNCNAME-$EXPECTED"
}
testErrorHandlingOK () {
getStatusOfJob SUCCESS
}
testErrorHandlingFAIL () {
getStatusOfJob FAILURE
}
. ./shunit2 . ./shunit2

View File

@ -5,4 +5,4 @@ file-42>424>424<2424>424?24<24>24
file-/\<>?:;'{}[] file-/\<>?:;'{}[]
http://www.google.nl http://www.google.nl
ftp://storage.nl ftp://storage.nl
./flac/Beethoven Overtures CD2/01 - Beethoven, Lv - Leonore I - Op.138.flac ./flac/Bééthoven Overtures CD2/01 - Beethoven, Lv - Leonore I - Op.138.flac