ppss/ppss-test.sh

241 lines
5.1 KiB
Bash
Raw Normal View History

2010-01-31 22:31:22 +00:00
#!/bin/bash
DEBUG="$1"
2010-03-01 22:07:19 +00:00
VERSION="2.57b1"
2010-01-31 22:31:22 +00:00
TMP_DIR="ppss"
2010-02-07 21:34:05 +00:00
PPSS=./ppss
2010-01-31 22:31:22 +00:00
PPSS_DIR=ppss_dir
2010-03-07 19:48:00 +00:00
export PPSSDEBUG=1
2010-01-31 22:31:22 +00:00
cleanup () {
for x in $REMOVEFILES
do
if [ -e ./$x ]
then
rm -r ./$x
fi
done
}
parseJobStatus () {
TMP_FILE="$1"
RES=`grep "Status:" "$JOBLOG/$TMP_FILE"`
STATUS=`echo "$RES" | awk '{ print $2 }'`
echo "$STATUS"
}
oneTimeSetUp () {
JOBLOG=./$PPSS_DIR/job_log
INPUTFILENORMAL=test-normal.input
INPUTFILESPECIAL=test-special.input
LOCALOUTPUT=ppss_dir/PPSS_LOCAL_OUTPUT
2010-02-07 19:14:48 +00:00
REMOVEFILES="$PPSS_DIR test-ppss-*"
2010-01-31 22:31:22 +00:00
cleanup
}
testVersion () {
2010-03-06 23:26:07 +00:00
RES=`$PPSS -v`
2010-01-31 22:31:22 +00:00
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 () {
TEST="$1"
if [ -e "$PPSS_DIR" ] && [ -d "$PPSS_DIR" ] && [ ! -z "$TEST" ]
then
mv "$PPSS_DIR" test-ppss-"$TEST"
fi
}
oneTimeTearDown () {
if [ ! "$DEBUG" == "debug" ]
then
cleanup
fi
}
createDirectoryWithSomeFiles () {
A="File with Spaces"
B="File\With\Slashes"
2010-02-09 22:01:05 +00:00
c="symnlink1"
d="symnlink2"
2010-01-31 22:31:22 +00:00
2010-02-09 22:01:05 +00:00
TMP_FILE="/tmp/$TMP_DIR"
if [ ! -e "$TMP_FILE" ]
then
mkdir "$TMP_FILE"
fi
touch "$A"
touch "$B"
ln -s /etc/resolve.conf "$TMP_FILE"/
ln -s /etc/hosts "$TMP_FILE"/
2010-01-31 22:31:22 +00:00
}
2010-02-09 22:01:05 +00:00
testRecursion () {
2010-01-31 22:31:22 +00:00
createDirectoryWithSomeFiles
2010-02-09 22:01:05 +00:00
#Execution of PPSS with recursion disabled.
2010-03-06 23:26:07 +00:00
RES=$( { $PPSS -d /tmp/$TMP_DIR -c 'ls -alh ' -r >> /dev/null ; } 2>&1 )
2010-02-09 22:01:05 +00:00
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
2010-03-06 23:26:07 +00:00
RES=$( { $PPSS -d /tmp/$TMP_DIR -c 'ls -alh ' >> /dev/null ; } 2>&1 )
2010-01-31 22:31:22 +00:00
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" "$?"
2010-02-09 22:01:05 +00:00
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"
2010-01-31 22:31:22 +00:00
rm -rf "/tmp/$TMP_DIR"
rename-ppss-dir $FUNCNAME
}
testSpecialCharacterHandling () {
2010-03-06 23:26:07 +00:00
RES=$( { $PPSS -f "$INPUTFILESPECIAL" -c 'echo ' >> /dev/null ; } 2>&1 )
2010-01-31 22:31:22 +00:00
assertEquals "PPSS did not execute properly." 0 "$?"
assertNull "PPSS retured some errors..." "$RES"
if [ ! "$?" == "0" ]
then
echo "RES IS $RES"
fi
RES=`find ppss_dir/PPSS_LOCAL_OUTPUT | wc -l | sed 's/\ //g'`
2010-02-07 19:31:12 +00:00
LINES=`wc -l "$INPUTFILESPECIAL" | awk '{ print $1 }'`
assertEquals "To many lock files..." "$((LINES+1))" "$RES"
2010-01-31 22:31:22 +00:00
RES1=`ls -1 $JOBLOG`
RES2=`ls -1 $LOCALOUTPUT`
assertEquals "RES1 $RES1 is not the same as RES2 $RES2" "$RES1" "$RES2"
rename-ppss-dir $FUNCNAME
}
testSkippingOfProcessedItems () {
createDirectoryWithSomeFiles
2010-03-06 23:26:07 +00:00
RES=$( { $PPSS -d /tmp/$TMP_DIR -c 'echo ' >> /dev/null ; } 2>&1 )
2010-01-31 22:31:22 +00:00
assertEquals "PPSS did not execute properly." 0 "$?"
assertNull "PPSS retured some errors..." "$RES"
2010-03-06 23:26:07 +00:00
RES=$( { $PPSS -d /tmp/$TMP_DIR -c 'echo ' >> /dev/null ; } 2>&1 )
2010-01-31 22:31:22 +00:00
assertEquals "PPSS did not execute properly." 0 "$?"
assertNull "PPSS retured some errors..." "$RES"
2010-03-06 23:26:07 +00:00
grep -i skip ./$PPSS_DIR/* >> /dev/null 2>&1
2010-01-31 22:31:22 +00:00
assertEquals "Skipping of items went wrong." 0 "$?"
rename-ppss-dir $FUNCNAME-1
2010-03-06 23:26:07 +00:00
RES=$( { $PPSS -f $INPUTFILESPECIAL -c 'echo ' >> /dev/null ; } 2>&1 )
2010-01-31 22:31:22 +00:00
assertEquals "PPSS did not execute properly." 0 "$?"
assertNull "PPSS retured some errors..." "$RES"
2010-03-06 23:26:07 +00:00
RES=$( { $PPSS -f $INPUTFILESPECIAL -c 'echo ' >> /dev/null ; } 2>&1 )
2010-01-31 22:31:22 +00:00
assertEquals "PPSS did not execute properly." 0 "$?"
assertNull "PPSS retured some errors..." "$RES"
2010-03-06 23:26:07 +00:00
grep -i skip ./$PPSS_DIR/* >> /dev/null 2>&1
2010-01-31 22:31:22 +00:00
assertEquals "Skipping of items went wrong." 0 "$?"
rm -rf "/tmp/$TMP_DIR"
rename-ppss-dir $FUNCNAME-2
}
testExistLogFiles () {
2010-03-06 23:26:07 +00:00
$PPSS -f "$INPUTFILENORMAL" -c 'echo "$ITEM"' >> /dev/null
2010-01-31 22:31:22 +00:00
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
2010-03-06 23:26:07 +00:00
$PPSS -f "$INPUTFILENORMAL" -c 'echo ' >> /dev/null
2010-01-31 22:31:22 +00:00
assertEquals "PPSS did not execute properly." 0 "$?"
elif [ "$EXPECTED" == "FAILURE" ]
then
2010-03-06 23:26:07 +00:00
$PPSS -f "$INPUTFILENORMAL" -c 'thiscommandfails ' >> /dev/null
2010-01-31 22:31:22 +00:00
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