2010-01-31 22:31:22 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
DEBUG="$1"
|
2012-01-29 22:05:18 +00:00
|
|
|
VERSION="2.98"
|
2010-06-06 20:45:56 +00:00
|
|
|
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
|
2010-06-06 20:45:56 +00:00
|
|
|
export PPSS_DEBUG=1
|
|
|
|
HOST_ARCH=`uname`
|
2010-06-08 23:10:35 +00:00
|
|
|
SPECIAL_DIR=$TMP_DIR/root/special
|
2010-06-06 20:45:56 +00:00
|
|
|
. "$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
|
2010-06-27 23:46:01 +00:00
|
|
|
if [ ! "$DEBUG" = "debug" ]
|
|
|
|
then
|
2010-06-06 20:45:56 +00:00
|
|
|
for x in $REMOVEFILES
|
|
|
|
do
|
|
|
|
if [ -e ./$x ]
|
|
|
|
then
|
|
|
|
rm -r ./$x
|
|
|
|
fi
|
|
|
|
done
|
2010-06-27 23:46:01 +00:00
|
|
|
fi
|
|
|
|
|
2011-12-25 02:08:08 +00:00
|
|
|
if [ ! -z "$TMP_DIR" ] && [ -e "$TMP_DIR" ]
|
|
|
|
then
|
|
|
|
rm -rf "$TMP_DIR"
|
|
|
|
fi
|
2010-01-31 22:31:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
parseJobStatus () {
|
|
|
|
|
|
|
|
TMP_FILE="$1"
|
|
|
|
|
|
|
|
RES=`grep "Status:" "$JOBLOG/$TMP_FILE"`
|
|
|
|
STATUS=`echo "$RES" | awk '{ print $2 }'`
|
|
|
|
echo "$STATUS"
|
2010-06-06 20:45:56 +00:00
|
|
|
}
|
2010-01-31 22:31:22 +00:00
|
|
|
|
2010-06-27 08:59:22 +00:00
|
|
|
get_item_count_of_input_file () {
|
2010-06-06 20:45:56 +00:00
|
|
|
|
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
|
|
|
|
2010-06-06 20:45:56 +00:00
|
|
|
if [ ! -e "$TMP_DIR" ]
|
|
|
|
then
|
2011-12-25 02:08:08 +00:00
|
|
|
mkdir -p "$TMP_DIR"
|
2010-06-06 20:45:56 +00:00
|
|
|
fi
|
|
|
|
|
2010-01-31 22:31:22 +00:00
|
|
|
cleanup
|
|
|
|
}
|
|
|
|
|
|
|
|
testVersion () {
|
|
|
|
|
2010-06-06 20:45:56 +00:00
|
|
|
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 () {
|
|
|
|
|
2010-06-06 20:45:56 +00:00
|
|
|
ROOT_DIR=$TMP_DIR/root
|
|
|
|
CHILD_1=$ROOT_DIR/child_1
|
|
|
|
CHILD_2=$ROOT_DIR/child_2
|
2011-12-25 02:08:08 +00:00
|
|
|
|
|
|
|
if [ ! -e "$ROOT_DIR" ]
|
|
|
|
then
|
|
|
|
mkdir -p "$ROOT_DIR"
|
|
|
|
fi
|
2010-01-31 22:31:22 +00:00
|
|
|
|
2011-12-25 02:08:08 +00:00
|
|
|
if [ ! -e "$CHILD_1" ]
|
|
|
|
then
|
|
|
|
mkdir -p "$CHILD_1"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -e "$CHILD_2" ]
|
|
|
|
then
|
|
|
|
mkdir -p "$CHILD_2"
|
|
|
|
fi
|
2010-01-31 22:31:22 +00:00
|
|
|
|
2010-06-06 20:45:56 +00:00
|
|
|
for x in {1..10}
|
|
|
|
do
|
2010-06-08 23:10:35 +00:00
|
|
|
touch "$ROOT_DIR/file-$x"
|
2010-06-06 20:45:56 +00:00
|
|
|
touch "$CHILD_1/file-$x"
|
|
|
|
touch "$CHILD_2/file-$x"
|
|
|
|
done
|
2010-02-09 22:01:05 +00:00
|
|
|
|
2010-06-06 20:45:56 +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"
|
|
|
|
}
|
|
|
|
|
2010-06-06 20:45:56 +00:00
|
|
|
testMD5 () {
|
2010-02-09 22:01:05 +00:00
|
|
|
|
2011-08-23 22:26:51 +00:00
|
|
|
export USE_MD5=1
|
|
|
|
init_vars > /dev/null 2>&1
|
2010-06-06 20:45:56 +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
|
|
|
}
|
|
|
|
|
2010-06-06 20:45:56 +00:00
|
|
|
init_get_all_items () {
|
2010-02-09 22:01:05 +00:00
|
|
|
|
2010-06-08 23:10:35 +00:00
|
|
|
DIR="$1"
|
2011-12-28 23:03:27 +00:00
|
|
|
TRAVERSAL="$2"
|
2010-02-09 22:01:05 +00:00
|
|
|
createDirectoryWithSomeFiles
|
2010-06-06 20:45:56 +00:00
|
|
|
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
|
2010-06-06 20:45:56 +00:00
|
|
|
get_all_items
|
2010-01-31 22:31:22 +00:00
|
|
|
}
|
|
|
|
|
2010-06-06 20:45:56 +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`
|
2010-06-06 20:45:56 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2010-06-06 20:45:56 +00:00
|
|
|
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`
|
2010-06-06 20:45:56 +00:00
|
|
|
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
|
|
|
|
2010-06-06 20:45:56 +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
|
|
|
}
|
|
|
|
|
2011-12-28 23:03:27 +00:00
|
|
|
|
|
|
|
testInvalidProcessingOfitemVariable() {
|
|
|
|
|
|
|
|
createSpecialFilenames
|
|
|
|
init_get_all_items $TMP_DIR/root 1
|
|
|
|
COMMAND='echo $ITEM'
|
|
|
|
while get_item
|
|
|
|
do
|
|
|
|
commando "$ITEM"
|
|
|
|
done
|
|
|
|
RESULT=$(grep '$ITEM' $PPSS_DIR/job_log/*)
|
|
|
|
EXPECTED=""
|
|
|
|
assertEquals "Got incorrect processing of ITEM variable." "$EXPECTED" "$RESULT"
|
|
|
|
rename-ppss-dir $FUNCNAME
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
2011-12-25 02:08:08 +00:00
|
|
|
COMMAND='echo hoi'
|
2010-06-08 23:10:35 +00:00
|
|
|
while get_item
|
|
|
|
do
|
|
|
|
commando "$ITEM"
|
|
|
|
done
|
2010-06-27 23:46:01 +00:00
|
|
|
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`
|
2010-07-17 20:32:02 +00:00
|
|
|
ORIGINAL=`cat $INPUT_FILE`
|
|
|
|
assertEquals "User input processing not ok." "$RESULT" "$ORIGINAL"
|
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
|