📄 functions.sh
字号:
#!/bin/sh## $Id: functions.sh,v 1.117 2004/11/09 18:36:35 ken Exp $#preptest() { local testdir="$1" local testtype="$2" if [ ! -r "$testdir/testparams.sh" ] then echo ' ' "Missing configuration file: $testdir/testparams.sh" exit 1 fi # make sure no results survive from a past run if [ ! -z "$testdir" ] ; then rm -rf "$testdir/OUTPUT"${KLIPS_MODULE} mkdir -p "$testdir/OUTPUT"${KLIPS_MODULE} fi cd $testdir source ./testparams.sh if [ "X$TEST_TYPE" != "X$testtype" ] then echo "Error: TEST_TYPE differs. Check agreement of TESTLIST and testparams.sh" exit 1 fi # get rid of any pluto core files. if [ -z "$XHOST_LIST" ] then XHOST_LIST="EAST WEST JAPAN" fi export XHOST_LIST # Xhost script takes things from the environment. for host in $XHOST_LIST do ROOT=$POOLSPACE/$host/root rm -f $ROOT/var/tmp/core done}lookforcore() { local testdir="$1" if [ -d "$testdir" ] then cd $testdir if [ -f ./testparams.sh ] then source ./testparams.sh fi # get rid of any pluto core files. if [ -z "$XHOST_LIST" ] then XHOST_LIST="EAST WEST JAPAN" fi export XHOST_LIST # Xhost script takes things from the environment. for host in $XHOST_LIST do ROOT=$POOLSPACE/$host/root if [ -f $ROOT/var/tmp/core ] then mv $ROOT/var/tmp/core OUTPUT${KLIPS_MODULE}/pluto.$host.core echo "pluto.$host.core " fi done fi}verboseecho() { if [ -n "${NETJIGVERBOSE}" ] then echo $@ fi}# ??? NOTE:# This seems to only sometimes set $success.# Whatever interesting settings are made seem to be lost by the caller :-(consolediff() { prefix=$1 output=$2 ref=$3 cleanups="cat $output " for fixup in `echo $REF_CONSOLE_FIXUPS` do if [ -f $FIXUPDIR/$fixup ] then case $fixup in *.sed) cleanups="$cleanups | sed -f $FIXUPDIR/$fixup";; *.pl) cleanups="$cleanups | perl $FIXUPDIR/$fixup";; *.awk) cleanups="$cleanups | awk -f $FIXUPDIR/$fixup";; *) echo Unknown fixup type: $fixup;; esac else echo Fixup $fixup not found. success="missing fixup" return fi done fixedoutput=OUTPUT${KLIPS_MODULE}/${prefix}console-fixed.txt rm -f $fixedoutput OUTPUT${KLIPS_MODULE}/${prefix}console.diff $CONSOLEDIFFDEBUG && echo Cleanups is $cleanups eval $cleanups >$fixedoutput # stick terminating newline in for fun. echo >>$fixedoutput if diff -N -u -w -b -B $ref $fixedoutput >OUTPUT${KLIPS_MODULE}/${prefix}console.diff then echo "${prefix}Console output matched" else echo "${prefix}Console output differed" case "$success" in true) failnum=2 ;; esac success=false fi}compat_variables() { if [ -z "$REF_CONSOLE_OUTPUT" ] && [ -n "$REFCONSOLEOUTPUT" ] then REF_CONSOLE_OUTPUT=$REFCONSOLEOUTPUT fi if [ -z "$REF_CONSOLE_FIXUPS" ] && [ -n "$REFCONSOLEFIXUPS" ] then REF_CONSOLE_FIXUPS=$REFCONSOLEFIXUPS fi if [ -z "$REF_PUB_OUTPUT" ] && [ -n "$REFPUBOUTPUT" ] then REF_PUB_OUTPUT=$REFPUBOUTPUT fi if [ -z "$REF_PRIV_OUTPUT" ] && [ -n "$REFPRIVOUTPUT" ] then REF_PRIV_OUTPUT=$REFPRIVOUTPUT fi if [ -z "$PRIV_INPUT" ] && [ -n "$PRIVINPUT" ] then PRIV_INPUT=$PRIVINPUT fi if [ -z "$PUB_INPUT" ] && [ -n "$PUBINPUT" ] then PUB_INPUT=$PUBINPUT fi if [ -z "$INIT_SCRIPT" ] && [ -n "$SCRIPT" ] then INIT_SCRIPT=$SCRIPT fi if [ -z "$EAST_RUN_SCRIPT" ] && [ -n "$RUN_EAST_SCRIPT" ] then EAST_RUN_SCRIPT=$RUN_EAST_SCRIPT fi if [ -z "$WEST_RUN_SCRIPT" ] && [ -n "$RUN_WEST_SCRIPT" ] then WEST_RUN_SCRIPT=$RUN_WEST_SCRIPT fi if [ -z "$EAST_FINAL_SCRIPT" ] && [ -n "$FINAL_EAST_SCRIPT" ] then EAST_FINAL_SCRIPT=$FINAL_EAST_SCRIPT fi if [ -z "$WEST_FINAL_SCRIPT" ] && [ -n "$FINAL_WEST_SCRIPT" ] then WEST_FINAL_SCRIPT=$FINAL_WEST_SCRIPT fi}# this is called to set additional variables that depend upon testparams.shprerunsetup() { if [ -n "$KLIPS_MODULE" ] then HOST_START=$POOLSPACE/$TESTHOST/startmodule.sh EAST_START=$POOLSPACE/$EASTHOST/startmodule.sh WEST_START=$POOLSPACE/$WESTHOST/startmodule.sh REPORT_NAME=${TESTNAME}${KLIPS_MODULE} else HOST_START=$POOLSPACE/$TESTHOST/start.sh EAST_START=$POOLSPACE/$EASTHOST/start.sh WEST_START=$POOLSPACE/$WESTHOST/start.sh REPORT_NAME=${TESTNAME} fi compat_variables; # export variables that are common. export PACKETRATE perl ${OPENSWANSRCDIR}/testing/utils/regress-summarize-results.pl ${REGRESSRESULTS} ${TESTNAME}}setup_additional_hosts() { if [ -n "${ADDITIONAL_HOSTS}" ] then SEP="" HOSTLIST="" for host in ${ADDITIONAL_HOSTS} do HOSTLIST="${HOSTLIST}${SEP}${host}=${POOLSPACE}/${host}/start.sh" SEP="," done echo "-H ${HOSTLIST}" fi}## use this function to run some script on each reference output script.## Start this from testing/*, listing all the test names (directories),# space-separated. The script to run is the first argument.## The script will be provided with three arguments -# 1) the name of the test# 2) the name of the console# which is either "", east or west# 3) and the file where the reference console should be placed.## The current working directory is *NOT* changed before the script is ran.#foreach_ref_console() { script=$1 shift for i in $* do echo $i: if [ -d $i ] then (if [ -f $i/testparams.sh ] then . $i/testparams.sh compat_variables; if [ -n "$REF_CONSOLE_OUTPUT" ] then echo $script $i "" $REF_CONSOLE_OUTPUT $script $i "" $REF_CONSOLE_OUTPUT fi if [ -n "$REF_EAST_CONSOLE_OUTPUT" ] then echo $script $i east $REF_EAST_CONSOLE_OUTPUT $script $i east $REF_EAST_CONSOLE_OUTPUT fi if [ -n "$REF_WEST_CONSOLE_OUTPUT" ] then echo $script $i west $REF_WEST_CONSOLE_OUTPUT $script $i west $REF_WEST_CONSOLE_OUTPUT fi fi) fi done}roguekill() { REPORT_NAME="$1" local rogue_sighted="" if [ -n "$REGRESSRESULTS" ] then rm -f $REGRESSRESULTS/$REPORT_NAME/roguelist.txt mkdir -p $REGRESSRESULTS/$REPORT_NAME fi # search for rogue UML local pointless=false local firstpass=true local other_rogues="" verboseecho "UML_BRAND=$UML_BRAND" for sig in KILL CONT KILL CONT KILL CONT KILL do if $pointless then break; fi pointless=true for i in `grep -s -l '^'"$POOLSPACE"'/[a-z]*/linux\>' /proc/[1-9]*/cmdline` do local pdir=`dirname "$i"` local badpid=`basename $pdir` if [ ! -r $pdir/environ ] || strings $pdir/environ | grep "^UML_BRAND=$UML_BRAND"'$' >/dev/null then echo "${sig}ING ROGUE UML: $badpid `tr '\000' ' ' <$pdir/cmdline`" if [ -n "$REGRESSRESULTS" ] then echo "UML pid $pdir went ROGUE" >>$REGRESSRESULTS/$REPORT_NAME/roguelist.txt fi # the cwd is a good indication of what test was being executed. rogue_sighted=" rogue" pointless=false ls -l $pdir/cwd kill -$sig $badpid elif $firstpass then other_rogues="$other_rogues $badpid" fi done # might take some realtime for a kill to work if ! $pointless then sleep 2 fi firstpass=false done if [ -n "$other_rogues" ] then echo "ROGUES without brand $UML_BRAND:" ps -f -w -p $other_rogues fi stat="$stat$rogue_sighted"}## record results records the status of each test in# $REGRESSRESULTS/$REPORT_NAME/status## If the status is negative, then the "OUTPUT${KLIPS_MODULE}" directory of the test is# copied to $REGRESSRESULTS/$REPORT_NAME/OUTPUT${KLIPS_MODULE} as well.## The file $testname/description.txt if it exists is copied as well.## If $REGRESSRESULTS is not set, then nothing is done.## See testing/utils/regress-summarizeresults.pl for a tool to build a nice# report from these files.## See testing/utils/regress-nightly.sh and regress-stage2.sh for code# that sets up $REGRESSRESULTS.## usage: recordresults testname testtype status REPORTNAME#recordresults() { local testname="$1" local testexpect="$2" local status="$3" local REPORT_NAME="$4" export REGRESSRESULTS roguekill $REPORT_NAME if [ -n "$REGRESSRESULTS" ] then rm -rf $REGRESSRESULTS/$REPORT_NAME mkdir -p $REGRESSRESULTS/$REPORT_NAME console=false packet=false # if there was a core file, add that to status cores=`( lookforcore $testname )` if [ ! -z "$cores" ] then status="$status core" fi # if there was a rogue, add that to status if [ -f $REGRESSRESULTS/$REPORT_NAME/status/roguelist.txt ] then status="$status rogue" fi # note that 0/1 is shell sense. case "$status" in 0) success=true;; 1) success=false; console=true;; 2) success=false; console=false; packet=true;; 99) success="missing 99"; console=false; packet=false;; true) success=true;; false) sucesss=false;; succeed) success=true;; fail) success=false;; yes) success=true;; no) success=false;; skipped) success=skipped;; missing) success=missing;; *) success=false;; esac echo "Recording "'"'"$success: $status"'"'" to $REGRESSRESULTS/$REPORT_NAME/status" echo "$success: $status" >$REGRESSRESULTS/$REPORT_NAME/status echo console=$console >>$REGRESSRESULTS/$REPORT_NAME/status echo packet=$packet >>$REGRESSRESULTS/$REPORT_NAME/status echo "$testexpect" >$REGRESSRESULTS/$REPORT_NAME/expected if [ -f $testname/description.txt ] then cp $testname/description.txt $REGRESSRESULTS/$REPORT_NAME fi # the following is in a subprocess to protect against certain # testparams.sh which exit! ( if [ -r "$testdir/testparams.sh" ] then . "$testdir/testparams.sh" fi case "${TEST_PURPOSE}" in regress) echo ${TEST_PROB_REPORT} >$REGRESSRESULTS/$REPORT_NAME/regress.txt;; goal) echo ${TEST_GOAL_ITEM} >$REGRESSRESULTS/$REPORT_NAME/goal.txt;; exploit) echo ${TEST_EXPLOIT_URL} >$REGRESSRESULTS/$REPORT_NAME/exploit.txt;; *) echo "unknown TEST_PURPOSE (${TEST_PURPOSE})" ;; esac ) case "$success" in false) # ???? why the heck is this code run only when $success is false? # NOTE: ${KLIPS_MODULE} is part of $REPORT_NAME rm -rf $REGRESSRESULTS/$REPORT_NAME/OUTPUT mkdir -p $REGRESSRESULTS/$REPORT_NAME/OUTPUT tar -C $testname/OUTPUT${KLIPS_MODULE} -c -f - . | (cd $REGRESSRESULTS/$REPORT_NAME/OUTPUT && tar xf - ) ;; esac fi case "$status" in 0) echo '******* PASSED '$REPORT_NAME' ********' ;; skipped) echo '******* SKIPPED '$REPORT_NAME' ********' ;; *) echo '******* FAILED '$REPORT_NAME' ********' ;; esac}## pcap_filter west $REF_OUTPUT $WESTOUTPUT $REF_WEST_FILTER#pcap_filter() { HOST= OUTPUT= FILTER= REF_OUTPUT= #echo PCAP_FILTER $@ HOST=$1 REF_OUTPUT=$2 OUTPUT=$3 FILTER=$4 if [ -z "$FILTER" ] then FILTER=cat fi # refilter 3.8 output for 3.7 files unless the case has been updated if [ -z "$THREEEIGHT" ] && $THREEEIGHT then FILTER="$FILTER | sed -f $FIXUPDIR/tcpdump-three-eight.sed" fi if [ -n "$OUTPUT" ] then rm -f OUTPUT${KLIPS_MODULE}/${OUTPUT}.txt verboseecho $TCPDUMP -n -t $TCPDUMPFLAGS '|' "$FILTER" '>' OUTPUT${KLIPS_MODULE}/${OUTPUT}.txt eval "$TCPDUMP -n -t $TCPDUMPFLAGS -r OUTPUT${KLIPS_MODULE}/$OUTPUT.pcap | $FILTER >|OUTPUT${KLIPS_MODULE}/$OUTPUT.txt" rm -f OUTPUT${KLIPS_MODULE}/$OUTPUT.diff if diff -u -w -b -B $REF_OUTPUT OUTPUT${KLIPS_MODULE}/$OUTPUT.txt >OUTPUT${KLIPS_MODULE}/$OUTPUT.diff then printf "%-8s side output matched\n" $HOST else printf "%-8s side output differed\n" $HOST success=false fi fi}# netjigtest - invoke a single UML with input/output setup for KLIPS# testing.## variables are documented in doc/makecheck.html#netjigtest() { prerunsetup success=true failnum=1 PRIVOUTPUT='' PUBOUTPUT='' NJARGS='' if [ -n "$PRIV_INPUT" ] then NJARGS="$NJARGS -p $PRIV_INPUT" fi if [ -n "$PUB_INPUT" ] then NJARGS="$NJARGS -P $PUB_INPUT" fi if [ -n "$REF_CONSOLE_OUTPUT" ] then NJARGS="$NJARGS -c OUTPUT${KLIPS_MODULE}/console.txt" fi if [ -n "$REF_PRIV_OUTPUT" ] then PRIVOUTPUT=`basename $REF_PRIV_OUTPUT .txt ` NJARGS="$NJARGS -r OUTPUT${KLIPS_MODULE}/$PRIVOUTPUT.pcap" fi if [ -n "$REF_PUB_OUTPUT" ] then PUBOUTPUT=`basename $REF_PUB_OUTPUT .txt` NJARGS="$NJARGS -R OUTPUT${KLIPS_MODULE}/$PUBOUTPUT.pcap" fi if [ -n "$NETJIGARGS" ] then NJARGS="$NJARGS $NETJIGARGS" fi if [ "X$ARPREPLY" = "X--arpreply" ] then NJARGS="$NJARGS -a" fi if [ -n "${RUN_SCRIPT}" ] then NJARGS="$NJARGS -s ${RUN_SCRIPT}" fi if [ -n "${FINAL_SCRIPT}" ] then NJARGS="$NJARGS -I ${FINAL_SCRIPT}" fi
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -