ppss/ppss-test.sh

254 lines
4.8 KiB
Bash
Raw Normal View History

2010-01-31 22:31:22 +00:00
#!/bin/bash
DEBUG="$1"
2010-06-27 08:59:22 +00:00
VERSION="2.80"
TMP_DIR="/tmp/ppss"
2010-02-07 21:34:05 +00:00
PPSS=./ppss
2010-01-31 22:31:22 +00:00
PPSS_DIR=ppss_dir
export PPSS_DEBUG=1
HOST_ARCH=`uname`
2010-06-08 23:10:35 +00:00
SPECIAL_DIR=$TMP_DIR/root/special
. "$PPSS"
2010-01-31 22:31:22 +00:00
cleanup () {
2010-06-13 14:39:04 +00:00
unset RES1
unset RES2
2010-06-27 08:59:22 +00:00
GLOBAL_COUNTER=1
if [ ! "$DEBUG" = "debug" ]
then
for x in $REMOVEFILES
do
if [ -e ./$x ]
then
rm -r ./$x
fi
done
fi
if [ ! -z "$TMP_DIR" ]
2010-01-31 22:31:22 +00:00
then
rm -rf "/$TMP_DIR"
2010-01-31 22:31:22 +00:00
fi
}
parseJobStatus () {
TMP_FILE="$1"
RES=`grep "Status:" "$JOBLOG/$TMP_FILE"`
STATUS=`echo "$RES" | awk '{ print $2 }'`
echo "$STATUS"
}
2010-01-31 22:31:22 +00:00
2010-06-27 08:59:22 +00:00
get_item_count_of_input_file () {
2010-06-27 08:59:22 +00:00
if [ -e "$PPSS_DIR/INPUT_FILE-$$" ]
then
CONTENTS_OF_INPUTFILE=`cat $PPSS_DIR/INPUT_FILE-$$ | wc -l | awk '{ print $1 }'`
echo "$CONTENTS_OF_INPUTFILE"
else
echo "Error, file $PPSS_DIR/INPUT_FILE-$$ does not exist."
fi
2010-01-31 22:31:22 +00:00
}
oneTimeSetUp () {
JOBLOG=./$PPSS_DIR/job_log
INPUTFILENORMAL=test-normal.input
2010-06-08 23:10:35 +00:00
INPUTFILESPECIAL_DIR=test-special.input
2010-01-31 22:31:22 +00:00
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
if [ ! -e "$TMP_DIR" ]
then
mkdir "$TMP_DIR"
fi
2010-01-31 22:31:22 +00:00
cleanup
}
testVersion () {
assertEquals "Version mismatch!" "$VERSION" "$SCRIPT_VERSION"
2010-01-31 22:31:22 +00:00
}
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 () {
ROOT_DIR=$TMP_DIR/root
CHILD_1=$ROOT_DIR/child_1
CHILD_2=$ROOT_DIR/child_2
2010-01-31 22:31:22 +00:00
mkdir -p "$ROOT_DIR"
mkdir -p "$CHILD_1"
mkdir -p "$CHILD_2"
2010-01-31 22:31:22 +00:00
for x in {1..10}
do
2010-06-08 23:10:35 +00:00
touch "$ROOT_DIR/file-$x"
touch "$CHILD_1/file-$x"
touch "$CHILD_2/file-$x"
done
2010-02-09 22:01:05 +00:00
ln -s /etc/resolve.conf "$ROOT_DIR" 2> /dev/null
ln -s /etc/hosts "$ROOT_DIR" 2> /dev/null
}
2010-02-09 22:01:05 +00:00
2010-06-08 23:10:35 +00:00
createSpecialFilenames () {
ERROR=0
mkdir -p "$SPECIAL_DIR"
touch "$SPECIAL_DIR/a file with spaces"
touch "$SPECIAL_DIR/a\\'file\\'with\\'quotes"
touch "$SPECIAL_DIR/a{file}with{curly}brackets}"
touch "$SPECIAL_DIR/a(file)with(parenthesis)"
touch "$SPECIAL_DIR/a\\file\\with\\backslashes"
touch "$SPECIAL_DIR/a!file!with!exclamationmarks"
touch "$SPECIAL_DIR/a filé with special characters"
touch "$SPECIAL_DIR/a\"file\"with\"double\"quotes"
}
testMD5 () {
2010-02-09 22:01:05 +00:00
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
2010-02-09 22:01:05 +00:00
}
init_get_all_items () {
2010-02-09 22:01:05 +00:00
2010-06-08 23:10:35 +00:00
DIR="$1"
2010-06-27 08:59:22 +00:00
RECURSION="$2"
2010-02-09 22:01:05 +00:00
createDirectoryWithSomeFiles
create_working_directory
2010-06-08 23:10:35 +00:00
export SRC_DIR=$DIR
2010-06-27 08:59:22 +00:00
init_vars > /dev/null 2>&1
get_all_items
2010-01-31 22:31:22 +00:00
}
testRecursion () {
2010-01-31 22:31:22 +00:00
2010-06-08 23:10:35 +00:00
init_get_all_items $TMP_DIR/root 1
2010-06-27 08:59:22 +00:00
RESULT=`get_item_count_of_input_file`
EXPECTED=32
2010-06-27 08:59:22 +00:00
assertEquals "Recursion not correct." "$EXPECTED" "$RESULT"
2010-01-31 22:31:22 +00:00
rename-ppss-dir $FUNCNAME
}
testNoRecursion () {
2010-01-31 22:31:22 +00:00
2010-06-08 23:10:35 +00:00
init_get_all_items $TMP_DIR/root 0
2010-06-27 08:59:22 +00:00
RESULT=`get_item_count_of_input_file`
EXPECTED=12
2010-01-31 22:31:22 +00:00
2010-06-27 08:59:22 +00:00
assertEquals "Recursion not correct." "$EXPECTED" "$RESULT"
2010-01-31 22:31:22 +00:00
rename-ppss-dir $FUNCNAME
2010-01-31 22:31:22 +00:00
}
2010-06-08 23:10:35 +00:00
testGetItem () {
createSpecialFilenames
init_get_all_items $TMP_DIR/root 1
get_item
if [ -z "$ITEM" ]
then
ERROR=1
else
ERROR=0
fi
EXPECTED=0
assertEquals "Get item failed." "$EXPECTED" "$ERROR"
i=1
ERROR=0
while get_item
do
((i++))
done
EXPECTED=40
assertEquals "Got wrong number of items." "$EXPECTED" "$i"
2010-06-13 14:39:04 +00:00
rename-ppss-dir $FUNCNAME
cleanup
}
2010-06-08 23:10:35 +00:00
2010-06-13 14:39:04 +00:00
return_all_items () {
2010-06-08 23:10:35 +00:00
while get_item
do
2010-06-27 08:59:22 +00:00
ALL_ITEMS="$ALL_ITEMS$ITEM"$'\n'
2010-06-08 23:10:35 +00:00
done
2010-06-27 08:59:22 +00:00
echo "$ALL_ITEMS"
2010-06-13 14:39:04 +00:00
}
testNumberOfItems () {
createSpecialFilenames
2010-06-27 08:59:22 +00:00
RESULT=`init_get_all_items $TMP_DIR/root 1`
2010-06-13 14:39:04 +00:00
RES1=`find $TMP_DIR/root/ ! -type d`
2010-06-27 08:59:22 +00:00
RES2=`return_all_items`
echo "$RES1" > a
echo "$RES2" > b
2010-06-13 14:39:04 +00:00
2010-06-08 23:10:35 +00:00
assertEquals "Input file and actual files not the same!" "$RES1" "$RES2"
2010-06-13 14:39:04 +00:00
rename-ppss-dir $FUNCNAME
2010-06-08 23:10:35 +00:00
}
2010-06-13 14:39:04 +00:00
testNumberOfLogfiles () {
2010-06-08 23:10:35 +00:00
createSpecialFilenames
init_get_all_items $TMP_DIR/root 1
COMMAND='echo '
while get_item
do
commando "$ITEM"
done
RESULT=`ls -1 $PPSS_DIR/job_log/ | wc -l | awk '{ print $1}'`
EXPECTED=40
assertEquals "Got wrong number of log files." "$EXPECTED" "$RESULT"
rename-ppss-dir $FUNCNAME
}
testUserInputFile () {
cleanup
INPUT_FILE=test-special.input
create_working_directory
init_vars > /dev/null 2>&1
get_all_items
RESULT=`return_all_items`
echo "- $RESULT"
2010-06-13 14:39:04 +00:00
rename-ppss-dir $FUNCNAME
2010-06-08 23:10:35 +00:00
}
2010-01-31 22:31:22 +00:00
. ./shunit2