Skip to content
Snippets Groups Projects
Commit 04abd0ef authored by Thiago H. S. Picharski's avatar Thiago H. S. Picharski Committed by Danilo K. S. Yorinori
Browse files

Added test-client.sh responsible to test the client strength


This script writes results to standard output if it does not receive option
and "test-client.log" if "--logfile" is passed.

Signed-off-by: default avatarThiago H. S. Picharski <thsp08@c3sl.ufpr.br>
Acked-by: default avatarDiego Giovane Pasqualin <dgp06@c3sl.ufpr.br>
Signed-off-by: default avatarDanilo K. S. Yorinori <danilok@c3sl.ufpr.br>
parent 8f6ca2f1
Branches
Tags
No related merge requests found
#!/bin/bash
# Copyright (C) 2010 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
#
# This file is part of client
#
# client is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
#------------------------------------------------------------------------------
# function: initFiles
# Load ${fileC[]} data to ${fileN[]} files, with corresponding index.
function initFiles()
{
declare idc
for (( idc=1 ; idc <= ${#fileC[@]} ; idc+=1 )); do
mkdir -p $(dirname ${fileN[$idc]})
printf "${fileC[$idc]}" > ${fileN[$idc]}
done
}
#------------------------------------------------------------------------------
# function: execTest
# Run test progamed in ${testF[]} and format result message.
function execTest()
{
initFiles
eval "${command[$(echo ${testF[$idc]} | cut -d'-' -f4)]}"
eval "${command[$(echo ${testF[$idc]} | cut -d'-' -f3)]}"
message=$(echo "${msg[$(echo ${testF[$idc]} | cut -d'-' -f2)]}" |
cut -d'*' -f1)
fileToCat=$(echo "${msg[$(echo ${testF[$idc]} | cut -d'-' -f2)]}" |
cut -d'*' -f2)
printf "[ Test $((${idc}+1))/${total} ] Running: \"$(basename "${APP}"
) ${param[$(echo ${testF[$idc]} | cut -d'-'\
-f1)]}\" with ${message}\n\nResult:\n" "$(test -n "${fileToCat}" &&
cat "${fileToCat}")"
${APP} ${param[$(echo ${testF[$idc]} | cut -d'-' -f1)]}
ret=$?
if $($(cut -d'-' -f5 <<< ${testF[$idc]})); then
op=-ne
else
op=-eq
fi
if test ${ret} ${op} 0; then
printf "\nOK: application returned ${ret}\n"
else
printf "\nFAILURE: application returned ${ret}\n"
fi
}
#------------------------------------------------------------------------------
# Settings to this script
PREFIX=$(pwd)
APP="${PREFIX}/run.sh"
LOGFILE="${PREFIX}/test-client.log"
LEVEL=1
#------------------------------------------------------------------------------
# Parameters passed to application
param[1]=""
param[2]="--update"
param[3]="${param[2]} ${param[2]}"
param[4]="--inventory"
param[5]="${param[4]} ${param[4]}"
param[6]="${param[5]} test.xml"
param[7]="${param[4]} test.xml"
param[8]="AAA"
#------------------------------------------------------------------------------
# Files content. There are loaded with iniFiles()
fileC[1]="<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<collect><inep><number type=\"int\" value=\"1234\"/></inep><inventory>
<disk type=\"tree\"><hdd quantity=\"3\"><hdd0>
<model value=\"ST3250823AS_5ND23ZJA\" type=\"string\"/>
<size value=\"232\" type=\"int\"/><used value=\"0\" type=\"int\"/></hdd0><hdd1>
<model value=\"SAMSUNG_SP2504C_S09QJ1UYB10582\" type=\"string\"/>
<size value=\"232\" type=\"int\"/><used value=\"0\" type=\"int\"/></hdd1><hdd2>
<model value=\"SAMSUNG_SP2504C_S09QJ1UYB10589\" type=\"string\"/>
<size value=\"232\" type=\"int\"/><used value=\"0\" type=\"int\"/></hdd2></hdd>
</disk><memory><size type=\"int\" value=\"3989\"/></memory><os>
<distro type=\"string\" value=\"Debian GNU/Linux 5.0 \"/>
<kernel type=\"string\" value=\"2.6.27.21-opteron\"/>
<type type=\"string\" value=\"Linux\"/></os><processor>
<model type=\"string\" value=\"AMD Opteron(tm) Processor 242\"/></processor>
</inventory><mac-address><number type=\"string\" value=\"00:e0:81:2e:fd:ee\"/>
</mac-address><use><network><RX type=\"int\" value=\"\"/>
<TX type=\"int\" value=\"\"/></network></use></collect>"
fileC[2]="12017000"
fileC[3]="phost=\npport=\npuid=\nppasswd="
fileC[4]="0.1.0"
#------------------------------------------------------------------------------
# Files name manipulated. ${fileN[]} with index equal to ${fileC[]} is loaded
# with it's content.
fileN[1]="${PREFIX}/../data/collect_data.xml"
fileN[2]="${PREFIX}/conf/inep"
fileN[3]="${PREFIX}/conf/proxy"
fileN[4]="${PREFIX}/conf/version"
fileN[5]="${PREFIX}/bin"
fileN[6]="${PREFIX}/bin/client"
fileN[7]="${PREFIX}/common.sh"
fileN[8]="${PREFIX}/conf"
fileN[9]="${PREFIX}/lib"
fileN[10]="${PREFIX}/.bin-excluded"
fileN[11]="${PREFIX}/bin/client.bkp"
fileN[12]="${PREFIX}/.common.sh-excluded"
fileN[13]="${PREFIX}/.conf-excluded"
fileN[14]="${PREFIX}/.lib-excluded"
fileN[15]="${PREFIX}/run.sh"
#------------------------------------------------------------------------------
# url used in connection tests.
url[1]="http\:\/\/colombard\.c3sl\.ufpr\.br\:8080\/axis\/Seed2\.jws"
url[2]="colombard\.c3sl\.ufpr\.br\:8080\/axis\/Seed2\.jws"
url[3]="http\:\/\/Seed2\.jws"
url[4]="AAA"
url[5]="http\:\/\/www\.google\.com\.br"
#------------------------------------------------------------------------------
# Sintax: "[Message]*[file to print with cat(1)]"
# ps. The local to print file contents is defined by %s
msg[1]="all files intacts*"
msg[2]="corrupted ${fileN[2]} file \n\nContent:\n%s*${fileN[2]}"
msg[3]="corrupted ${fileN[3]} file \n\nContent:\n%s*${fileN[3]}"
msg[4]="corrupted ${fileN[1]} file \n\nContent:\n%s*${fileN[1]}"
msg[5]="corrupted ${fileN[4]} file \n\nContent:\n%s*${fileN[4]}"
msg[6]="deleted ${fileN[2]} file*"
msg[7]="deleted ${fileN[3]} file*"
msg[8]="deleted ${fileN[1]} file*"
msg[9]="deleted ${fileN[4]} file*"
msg[10]="deleted ${fileN[5]} directory*"
msg[11]="deleted ${fileN[8]} directory*"
msg[12]="deleted ${fileN[9]} directory*"
msg[13]="corrupted ${fileN[6]} executable*"
msg[14]="deleted ${fileN[6]} executable*"
msg[15]="corrupted ${fileN[7]} script*"
msg[16]="deleted ${fileN[7]} script*"
msg[17]="connection to \"${url[1]}\" server*"
msg[18]="connection to \"${url[2]}\" server*"
msg[19]="connection to \"${url[3]}\" server*"
msg[20]="connection to \"${url[4]}\" server*"
msg[21]="connection to \"${url[5]}\" server*"
#------------------------------------------------------------------------------
# commands used in tests.
command[1]="sort -R ${fileN[1]} -o ${fileN[1]}"
command[2]="printf \"\nbdd9398636d20d714e0a9adb75c15978\" >> ${fileN[2]}"
command[3]="printf \"bdd9398636d20d714e0a9adb75c15978\" > ${fileN[2]}"
command[4]="printf \"bdd9398636d20d714e0a9adb75c15978\" > ${fileN[3]}"
command[5]="sed -i 's/phost=/phost=bdd9398636d20d714e0a9adb75c15978/g'\
${fileN[3]}"
command[6]="sed -i 's/pport=/pport=bdd9398636d20d714e0a9adb75c15978/g'\
${fileN[3]}"
command[7]="sed -i 's/puid=/puid=bdd9398636d20d714e0a9adb75c15978/g'\
${fileN[3]}"
command[8]="sed -i 's/ppasswd=/ppasswd=bdd9398636d20d714e0a9adb75c15978/g'\
${fileN[3]}"
command[9]="mv -f ${fileN[5]} ${fileN[10]}"
command[10]="mv -f ${fileN[6]} ${fileN[11]}"
command[11]="mv -f ${fileN[7]} ${fileN[12]}"
command[12]="mv -f ${fileN[8]} ${fileN[13]}"
command[13]="mv -f ${fileN[9]} ${fileN[14]}"
command[14]="mv -f ${fileN[10]} ${fileN[5]}"
command[15]="mv -f ${fileN[11]} ${fileN[6]}"
command[16]="mv -f ${fileN[12]} ${fileN[7]}"
command[17]="mv -f ${fileN[13]} ${fileN[8]}"
command[18]="mv -f ${fileN[14]} ${fileN[9]}"
command[19]="sort -R ${fileN[11]} -o ${fileN[6]}"
command[20]="cp -a $(which ls) ${fileN[7]}"
command[21]="${command[10]}; ${command[19]}"
command[22]="${command[11]}; ${command[20]}"
command[23]="rm -f ${fileN1[1]}"
command[24]="rm -f ${fileN[2]}"
command[25]="rm -f ${fileN[3]}"
command[26]="rm -f ${fileN[4]}"
command[27]="sed -i 's/phost=/phost=127.0.0.1/g' ${fileN[3]}"
command[28]="sed -i 's/pport=/pport=3128/g' ${fileN[3]}"
command[29]="sed -i 's/puid=/puid=user0/g' ${fileN[3]}"
command[30]="sed -i 's/ppasswd=/ppasswd=1234/g' ${fileN[3]}"
command[31]="${command[27]}; ${command[28]}; ${command[29]}; ${command[30]}"
command[32]="sed -i 's/^url\=\".*\"$/url\=\"${url[1]}\"/g' ${fileN[15]}"
command[33]="sed -i 's/^url\=\".*\"$/url\=\"${url[2]}\"/g' ${fileN[15]}"
command[34]="sed -i 's/^url\=\".*\"$/url\=\"${url[3]}\"/g' ${fileN[15]}"
command[35]="sed -i 's/^url\=\".*\"$/url\=\"${url[4]}\"/g' ${fileN[15]}"
command[36]="sed -i 's/^url\=\".*\"$/url\=\"${url[5]}\"/g' ${fileN[15]}"
command[37]="sed -i 's/\$.dirname.\/run.log/\/dev\/stdout/g' run.sh"
command[38]="sed -i 's/\/dev\/stdout/\$\{dirname\}\/run.log/g' run.sh"
command[39]="${command[27]}; ${command[28]}"
command[40]="${command[29]}; ${command[30]}"
command[41]="${command[27]}; ${command[28]}; ${command[29]}"
command[42]="${command[28]}; ${command[29]}; ${command[30]}"
command[43]="${command[27]}; ${command[28]}; ${command[30]}"
#------------------------------------------------------------------------------
# Vector index to each test step: "param[]-msg[]-command[]-command[]-failTest"
# failTest is a boolean value, if test not must fail failTest must be false.
# Last command is used by default to restore at normal state files.
testF=(
"1-1-37-32-false" # index 0
"1-2-2-0-true"
"1-2-3-0-true"
"1-3-4-0-true"
"1-3-5-0-true"
"1-3-6-0-true"
"1-3-7-0-true"
"1-3-8-0-true"
"1-3-31-0-true"
"1-3-39-0-true"
"1-3-40-0-true"
"1-3-41-0-true"
"1-3-42-0-true"
"1-3-43-0-true"
"1-4-1-0-true"
"1-6-24-0-true"
"1-7-25-0-true"
"1-8-23-0-true"
"1-9-26-0-true"
"2-1-0-0-false"
"2-2-2-0-true"
"2-2-3-0-true"
"2-3-4-0-true"
"2-3-5-0-true"
"2-3-6-0-true"
"2-3-7-0-true"
"2-3-8-0-true"
"2-4-1-0-true"
"2-6-24-0-true"
"2-7-25-0-true"
"2-8-23-0-true"
"2-9-26-0-true"
"4-1-0-0-false"
"4-2-2-0-true"
"4-2-3-0-true"
"4-3-4-0-true"
"4-3-5-0-true"
"4-3-6-0-true"
"4-3-7-0-true"
"4-3-8-0-true"
"4-4-1-0-true"
"4-6-24-0-true"
"4-7-25-0-true"
"4-8-23-0-true"
"4-9-26-0-true" # index 44
"1-0-0-0-false" # index 45
"2-0-0-0-false"
"3-0-0-0-true"
"4-0-0-0-false"
"5-0-0-0-true"
"6-0-0-0-true"
"7-0-0-0-true"
"8-0-0-0-true" # index 52
"1-10-9-0-true" # index 53
"1-14-10-14-true"
"1-16-11-15-true"
"1-11-12-16-true"
"1-12-13-17-true"
"1-13-21-18-true"
"1-15-22-15-true"
"2-10-9-16-true"
"2-14-10-14-true"
"2-16-11-15-true"
"2-11-12-16-true"
"2-12-13-17-true"
"2-13-21-18-true"
"2-15-22-15-true"
"4-10-9-16-true"
"4-14-10-14-true"
"4-16-11-15-true"
"4-11-12-16-true"
"4-12-13-17-true"
"4-13-21-18-true"
"4-15-22-15-true"
"1-1-0-16-false" # index 74
"1-17-32-0-true" # index 75
"1-18-33-0-true"
"1-19-34-0-true"
"1-20-35-0-true"
"1-21-36-0-true"
"2-17-32-0-true"
"2-18-33-0-true"
"2-19-34-0-true"
"2-20-35-0-true"
"2-21-36-0-true"
"4-17-32-0-true"
"4-18-33-0-true"
"4-19-34-0-true"
"4-20-35-0-true"
"4-21-36-0-true" # index 89
"1-1-38-32-false") # index 90
#------------------------------------------------------------------------------
# Defines test categories.
# sintax: "[category name]-[testF[] begin index]-[testF[] end index]"
testType[1]="files treatment-0-44"
testType[2]="parameters-45-52"
testType[3]="application struct-53-74"
testType[4]="server connection-75-89"
testType[5]="restoring application-90-90"
total=${#testF[@]}
#------------------------------------------------------------------------------
# main code
# run each test category
if (( $# == 1 )) && [[ $1 == "--logfile" ]]; then
exec 1>> ${LOGFILE} 2>&1
printf "" > ${LOGFILE}
fi
printf "application path: ${PREFIX}\n"
printf "###############################################################%s\n\n"\
"###########################"
for (( i=1 ; i <= ${#testType[@]} ; i+=1 )); do
testName=$(echo ${testType[$i]} | cut -d'-' -f1)
begin=$(echo ${testType[$i]} | cut -d'-' -f2)
end=$(echo ${testType[$i]} | cut -d'-' -f3)
printf "Testing ${testName}...\n\n"
for (( idc=${begin} ; idc <= ${end} ; idc+=1 )); do
printf "*--------------------------------------------------------%s\n"\
"---------------------------------"
execTest
done
printf "\nEnd test of ${testName}.\n"
printf "###########################################################%s\n\n"\
"###############################"
done
exit 0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment