ppss/ppss-test.sh

230 lines
4.2 KiB
Bash
Raw Normal View History

2010-01-31 22:31:22 +00:00
#!/bin/bash
DEBUG="$1"
VERSION="2.70"
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
for x in $REMOVEFILES
do
if [ -e ./$x ]
then
rm -r ./$x
fi
done
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
get_contents_of_input_file () {
RES=`cat $PPSS_DIR/INPUT_FILE-$$ | wc -l | awk '{ print $1 }'`
echo "$RES"
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
RECURSION="$2"
DIR="$1"
2010-02-09 22:01:05 +00:00
createDirectoryWithSomeFiles
create_working_directory
init_vars > /dev/null 2>&1
2010-06-08 23:10:35 +00:00
export SRC_DIR=$DIR
get_all_items
RES=`get_contents_of_input_file`
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-01-31 22:31:22 +00:00
EXPECTED=32
assertEquals "Recursion not correct." "$EXPECTED" "$RES"
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
EXPECTED=12
2010-01-31 22:31:22 +00:00
assertEquals "Recursion not correct." "$EXPECTED" "$RES"
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
RES2="$RES2$ITEM"$'\n'
done
2010-06-13 14:39:04 +00:00
}
testNumberOfItems () {
createSpecialFilenames
init_get_all_items $TMP_DIR/root 1
RES1=`find $TMP_DIR/root/ ! -type d`
2010-06-08 23:10:35 +00:00
RES1="$RES1"$'\n' # NASTY HACK YUCK
2010-06-13 14:39:04 +00:00
return_all_items
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
cleanup
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
RES=`ls -1 $PPSS_DIR/job_log/ | wc -l | awk '{ print $1}'`
assertEquals "Got wrong number of log files." 40 "$RES"
2010-06-13 14:39:04 +00:00
rename-ppss-dir $FUNCNAME
cleanup
2010-06-08 23:10:35 +00:00
}
2010-01-31 22:31:22 +00:00
. ./shunit2