源码:1. fvt-setup-1: To perform initial setup.
2. fvt-server-2: To perform server commands.
3. fvt-client-3: To perform client commands.
4. fvt-cleanup: To cleanup the temporary files,
in order to prepare for the repetition
of the above test cases.
源码:#!/bin/bash
#
# Name: test-bucket-1
#
# Purpose:
# Performs the test-bucket number 1 for Product X.
# (Actually, this is a sample shell script,
# which invokes some system commands
# to illustrate how to construct a Bash script)
#
# Notes:
# 1) The environment variable TEST_VAR must be set
# (as an example).
# 2) To invoke this shell script and redirect standard
# output and standard error to a file (such as
# test-bucket-1.out) do the following (the -s flag
# is "silent mode" to avoid prompts to the user):
#
# ./test-bucket-1 -s 2>&1 | tee test-bucket-1.out
#
# Return codes:
# 0 = All commands were successful
# 1 = At least one command failed, see the output file
# and search for the keyword "ERROR".
#
########################################################
# For more sophisticated usage of getopt in Linux,
# see the samples file: /usr/lib/getopt/parse.bash
TEMP=`getopt hs $*`
if [ $? != 0 ]
then
echo "$CALLER: Unknown flag(s)"
usage
fi
# Note quotes around `$TEMP': they are essential!
eval set -- "$TEMP"
while true
do
case "$1" in
-h) usage "HELP"; shift;; # Help requested
-s) SILENT="yes"; shift;; # Prompt not needed
--) shift ; break ;;
*) echo "Internal error!" ; exit 1 ;;
esac
done
# ------------------------------------------------
# The following environment variables must be set
# ------------------------------------------------
if [ -z "$TEST_VAR" ]
then
echo "Environment variable TEST_VAR is not set."
usage
fi
关于此脚本的说明如下:
使用语句 CALLER=`basename $0` 可以得到正在运行的脚本名称。这样的话,无须在脚本中硬编码脚本名称。因此当复制脚本时,采用新派生的脚本可以减少工作量。
调用脚本时,语句 TEMP=`getopt hs $*` 用于得到输入变量(例如 -h 代表帮助,-s 代表安静模式)。
语句 [ -z "$X" ] 和 echo "The environment variable X is not set." 以及 usage 都是用于检测字符串是否为空 (-z),如果为空,随后就执行 echo 语句以显示未设置字符串并调用下面要讨论的 "usage" 函数。
若脚本未使用标志,可以使用变量 "$#",它可以返回正在传递到脚本的变量数量。
if [ "$SILENT" = "yes" ]
then
RESPONSE="y"
else
echo "The $CALLER will be performed."
echo "Do you wish to proceed [y or n]? "
read RESPONSE # Wait for response
[ -z "$RESPONSE" ] && RESPONSE="n"
fi
case "$RESPONSE" in
[yY]|[yY][eE]|[yY][eE][sS])
;;
*)
echo "$CALLER terminated with rc=1."
exit 1
;;
esac
# ----------------------------------
# Subroutine to terminate abnormally
# ----------------------------------
terminate()
{
echo "The execution of $CALLER was not successful."
echo "$CALLER terminated, exiting now with rc=1."
dateTest=`date`
echo "End of testing at: $dateTest"
echo ""
exit 1
}
Access -create -component Development -login ted -authority plead -verbose
if [ $? -ne 0 ]
then
echo "ERROR found in Access -create -component Development -login ted
-authority plead"
let "errorCounter = errorCounter + 1"
fi
Access -create -component Development -login pat -authority general -verbose
if [ $? -ne 0 ]
then
echo "ERROR found in Access -create -component Development -login pat
-authority general"
let "errorCounter = errorCounter + 1"
fi
Access -create -component Development -login jim -authority general -verbose
if [ $? -ne 0 ]
then
echo "ERROR found in Access -create -component Development -login jim
-authority general"
let "errorCounter = errorCounter + 1"
fi
……而是创建一个如下所示的函数,此函数也可以处理返回码,如果有必要,还可以增加错误计数器:
源码:
CreateAccess()
{
Access -create -component $1 -login $2 -authority $3 -verbose
if [ $? -ne 0 ]
then
echo "ERROR found in Access -create -component $1 -login $2 -authority $3"
let "errorCounter = errorCounter + 1"
fi
}
源码:
# -------------------------------------------
# The commands are called in a subroutine
# so that return code can be
# checked for possible errors.
# -------------------------------------------
ListFile()
{
echo "ls -al $1"
ls -al $1
if [ $? -ne 0 ]
then
echo "ERROR found in: ls -al $1"
let "errorCounter = errorCounter + 1"
fi
}
源码:
# --------------
# Exit
# --------------
if [ $errorCounter -ne 0 ]
then
echo ""
echo "*** $errorCounter ERRORS found during ***"
echo "*** the execution of this test case. ***"
terminate
else
echo ""
echo "*** Yeah! No errors were found during ***"
echo "*** the execution of this test case. Yeah! ***"
fi
Creating Users...
User pat was created successfully.
...
Well done! No errors were found during the
execution of this test case
fvt-common-1 complete.
End of testing at: Tue Apr 18 12:56:33 EDT 2000
当遇到错误时输出文件最后部分的示例如下所示:
源码:
ERROR found in Report -view DefectView
*** 1 ERRORS found during the execution of this test case. ***
The populate action for the CMVC family was not successful.
Recreating the family may be necessary before
running fvt-client-3 again, that is, you must use 'rmdb',
'rmfamily', 'mkfamily' and 'mkdb -d',
then issue: fvt-common-1 and optionally, fvt-server-2.
fvt-client-3 terminated, exiting now with rc=1.
End of testing at: Wed Jan 24 17:06:06 EST 2001