From 91d19df5cb3efdd6f2463daeb6cac29c0f599b66 Mon Sep 17 00:00:00 2001 From: Andrew Bettison Date: Tue, 3 Apr 2012 19:15:39 +0930 Subject: [PATCH] Ressurect testdna script --- server.c | 3 +- testdna | 139 ++++++++++++++++++++++++++++++------------------------- 2 files changed, 77 insertions(+), 65 deletions(-) diff --git a/server.c b/server.c index 8314509e..7f4cc195 100644 --- a/server.c +++ b/server.c @@ -17,6 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include #include #include @@ -128,7 +129,7 @@ int server(char *backing_file,int size,int foregroundMode) exit(-1); FILE *f=fopen(filename,"w"); if (!f) { - WHY("Could not write to PID file"); + WHYF("Could not write to PID file %s", filename); perror("fopen"); exit(-1); } diff --git a/testdna b/testdna index 90c1ca35..6b14768d 100755 --- a/testdna +++ b/testdna @@ -1,29 +1,41 @@ #!/bin/bash -# Stop any existing DNA server -pids=`ps -ef | grep "\./dna" | awk '{ print $2;}' | wc -l` -if [ $pids -gt 0 ]; then - kill `ps -ef | grep "\./dna" | awk '{ print $2;}'` +# The dna executable under test +dna="${0%/*}"/dna + +# Stop any existing DNA servers +pids=$(ps -u$UID | awk '$4 == "dna" {print $1}') +if [ -n "$pids" ]; then + kill $pids fi +# Set up a clean environment +export SERVALINSTANCE_PATH=/tmp/testdna-$UID +rm -rf $SERVALINSTANCE_PATH +mkdir $SERVALINSTANCE_PATH || exit 1 +hlr_dat=$SERVALINSTANCE_PATH/hlr.dat +dnatest_tmp=$SERVALINSTANCE_PATH/dnatest.tmp + # Start DNA server - -if [ -e hlr.dat ]; then - rm hlr.dat -fi -./dna -n -vvv -S 1 -f hlr.dat > dnatest.log 2>&1 & +$dna -n -vvv -S 1 -f $hlr_dat > $SERVALINSTANCE_PATH/dnatest.log 2>&1 & sleep 1 +pids=$(ps -u$UID | awk '$4 == "dna" {print $1}') +if [ -z "$pids" ]; then + echo "FATAL: dna did not start" + cat $SERVALINSTANCE_PATH/dnatest.log + exit 2 +fi # Test creating a new subscriber record # Test: Should return in <<3 sec, rather than time out # Test: Should return OK:SID -/usr/bin/time -p ./dna -d 0427679796 -C > dnatest.tmp 2>&1 -grep "^real" dnatest.tmp | awk '{ if ($2<0.5) print "OK: Create HLR was fast."; else print "FAIL: Create took too long."; }' -sid=`grep "^OK:" dnatest.tmp | cut -f2 -d:` +/usr/bin/time -p $dna -d 0427679796 -C > $dnatest_tmp 2>&1 +grep "^real" $dnatest_tmp | awk '{ if ($2<0.5) print "OK: Create HLR was fast."; else print "FAIL: Create took too long."; }' +sid=`grep "^OK:" $dnatest_tmp | cut -f2 -d:` if [ "x$sid" = "x" ]; then echo "FAIL: Create HLR failed (no OK:SID reply)" echo -n "Got: " - cat dnatest.tmp + cat $dnatest_tmp echo echo "FATAL: Cannot continue" kill %1 @@ -33,13 +45,13 @@ else fi # Test getting short variables -/usr/bin/time -p ./dna -d 0427679796 -R dids > dnatest.tmp 2>&1 -grep "^real" dnatest.tmp | awk '{ if ($2<2.9) printf("FAIL: Read variable didnt wait for all replies (only waited %f sec)\n",$2); else print "OK: Read variable waited for all replies."; }' -ok=`grep "^DIDS:${sid}:0:0427679796" dnatest.tmp | wc -l` +/usr/bin/time -p $dna -d 0427679796 -R dids > $dnatest_tmp 2>&1 +grep "^real" $dnatest_tmp | awk '{ if ($2<2.9) printf("FAIL: Read variable didnt wait for all replies (only waited %f sec)\n",$2); else print "OK: Read variable waited for all replies."; }' +ok=`grep "^DIDS:${sid}:0:0427679796" $dnatest_tmp | wc -l` if [ $ok -lt 1 ]; then echo "FAIL: Read variable didn't find existing value" echo "FAIL: Search by DID may not work." - echo -n "Got: " ; cat dnatest.tmp | egrep -v "^real|^sys|^user" + echo -n "Got: " ; cat $dnatest_tmp | egrep -v "^real|^sys|^user" else echo "OK: Read variable correctly read an existing value" if [ $ok -gt 1 ]; then @@ -52,24 +64,24 @@ else fi # Test setting short variables -/usr/bin/time -p ./dna -s $sid -i 0 -W note="a short literal value" > dnatest.tmp 2>&1 -grep "^real" dnatest.tmp | awk '{ if ($2<0.5) print "OK: Set variable by SID was fast."; else print "FAIL: Set variable by SID was too slow."; }' -ok=`grep "^WROTE:$sid" dnatest.tmp | wc -l` +/usr/bin/time -p $dna -s $sid -i 0 -W note="a short literal value" > $dnatest_tmp 2>&1 +grep "^real" $dnatest_tmp | awk '{ if ($2<0.5) print "OK: Set variable by SID was fast."; else print "FAIL: Set variable by SID was too slow."; }' +ok=`grep "^WROTE:$sid" $dnatest_tmp | wc -l` if [ $ok -ne 1 ]; then echo "FAIL: Set new variable value failed." - echo -n "Got: " ; cat dnatest.tmp | egrep -v "^real|^sys|^user" + echo -n "Got: " ; cat $dnatest_tmp | egrep -v "^real|^sys|^user" echo "Wanted: WROTE:$sid" else echo "OK: Set new variable value succeeded." fi # Test getting short variable by SID, and that setting variables really works. -/usr/bin/time -p ./dna -s $sid -i 0 -R note > dnatest.tmp 2>&1 -grep "^real" dnatest.tmp | awk '{ if ($2<0.5) print "OK: Get variable by SID was fast."; else printf("FAIL: Get variable by SID was too slow (%s sec)\n",$2); }' -ok=`grep "^NOTE:${sid}:0:a short literal value" dnatest.tmp | wc -l` +/usr/bin/time -p $dna -s $sid -i 0 -R note > $dnatest_tmp 2>&1 +grep "^real" $dnatest_tmp | awk '{ if ($2<0.5) print "OK: Get variable by SID was fast."; else printf("FAIL: Get variable by SID was too slow (%s sec)\n",$2); }' +ok=`grep "^NOTE:${sid}:0:a short literal value" $dnatest_tmp | wc -l` if [ $ok -ne 1 ]; then echo "FAIL: Set variable value could not be read back." - echo -n "Got: " ; cat dnatest.tmp | egrep -v "^real|^sys|^user" + echo -n "Got: " ; cat $dnatest_tmp | egrep -v "^real|^sys|^user" echo "FAIL: Search by SID may not work." else echo "OK: Set variable value could be read back." @@ -81,9 +93,9 @@ echo "WARN: Output to file does not work with DID lists (known issue)" if [ -e dnatest.dat ]; then rm dnatest.dat fi -/usr/bin/time -p ./dna -s $sid -O dnatest.dat -i 0 -R note > dnatest.tmp 2>&1 -grep "^real" dnatest.tmp | awk '{ if ($2<0.5) print "OK: Get variable by SID was fast."; else printf("FAIL: Get variable by SID was too slow (%s sec)\n",$2); }' -ok=`grep "^NOTE:${sid}:0" dnatest.tmp | wc -l` +/usr/bin/time -p $dna -s $sid -O dnatest.dat -i 0 -R note > $dnatest_tmp 2>&1 +grep "^real" $dnatest_tmp | awk '{ if ($2<0.5) print "OK: Get variable by SID was fast."; else printf("FAIL: Get variable by SID was too slow (%s sec)\n",$2); }' +ok=`grep "^NOTE:${sid}:0" $dnatest_tmp | wc -l` if [ $ok -ne 1 ]; then echo "FAIL: Set variable value could not be read back without output going to file." else @@ -98,11 +110,11 @@ fi rm dnatest.dat # Test setting multiple instances of short variables -/usr/bin/time -p ./dna -s $sid -i 1 -W note='$414243' >dnatest.tmp 2>&1 -ok=`grep "^WROTE:$sid" dnatest.tmp | wc -l` +/usr/bin/time -p $dna -s $sid -i 1 -W note='$414243' >$dnatest_tmp 2>&1 +ok=`grep "^WROTE:$sid" $dnatest_tmp | wc -l` if [ $ok -ne 1 ]; then echo "FAIL: Set new variable value by instance failed." - echo -n "Got: " ; cat dnatest.tmp | egrep -v "^real|^sys|^user" + echo -n "Got: " ; cat $dnatest_tmp | egrep -v "^real|^sys|^user" else echo "OK: Set new variable value by instance succeeded." fi @@ -111,33 +123,33 @@ fi echo "NOTE:${sid}:0:a short literal value" >dnatest.txt echo "NOTE:${sid}:1:ABC" >>dnatest.txt echo "DONE:${sid}:2" >>dnatest.txt -./dna -s $sid -i -1 -R note > dnatest.tmp 2>&1 -ok=`diff dnatest.tmp dnatest.txt | wc -l` +$dna -s $sid -i -1 -R note > $dnatest_tmp 2>&1 +ok=`diff $dnatest_tmp dnatest.txt | wc -l` if [ $ok -ne 0 ]; then echo "FAIL: Reading multiple variable instances has problems." - echo diff dnatest.tmp dnatest.txt - diff dnatest.tmp dnatest.txt - set ok=`grep ':ABC$' dnatest.tmp | wc -l` + echo diff $dnatest_tmp dnatest.txt + diff $dnatest_tmp dnatest.txt + set ok=`grep ':ABC$' $dnatest_tmp | wc -l` if [ $ok != 1 ]; then echo "FAIL: Specifying variable values by hex may have problems." else echo "OK: Specifying variable values by hex works." fi - diff dnatest.tmp dnatest.txt + diff $dnatest_tmp dnatest.txt else echo "OK: Reading multiple variable instances works." echo "OK: Specifying variable values by hex works." fi -if [ -e dnatest.tmp ]; then - rm dnatest.tmp +if [ -e $dnatest_tmp ]; then + rm $dnatest_tmp fi -/usr/bin/time -p ./dna -s $sid -R notes > dnatest.tmp 2>&1 -grep "^real" dnatest.tmp | awk '{ if ($2<0.5) print "OK: Reading multiple variable instances by SID is fast."; else print "FAIL: Reading multiple variable instances by SID was too slow."; }' +/usr/bin/time -p $dna -s $sid -R notes > $dnatest_tmp 2>&1 +grep "^real" $dnatest_tmp | awk '{ if ($2<0.5) print "OK: Reading multiple variable instances by SID is fast."; else print "FAIL: Reading multiple variable instances by SID was too slow."; }' # Try overwriting an existing variable value without update mode -/usr/bin/time -p ./dna -s $sid -i 0 -W note="replacement short literal value" > dnatest.tmp 2>&1 -grep "^real" dnatest.tmp | awk '{ if ($2<0.5) print "OK: Set variable by SID was fast."; else print "FAIL: Set variable by SID was too slow."; }' -ok=`grep "^WROTE:$sid" dnatest.tmp | wc -l` +/usr/bin/time -p $dna -s $sid -i 0 -W note="replacement short literal value" > $dnatest_tmp 2>&1 +grep "^real" $dnatest_tmp | awk '{ if ($2<0.5) print "OK: Set variable by SID was fast."; else print "FAIL: Set variable by SID was too slow."; }' +ok=`grep "^WROTE:$sid" $dnatest_tmp | wc -l` if [ $ok -eq 1 ]; then echo "FAIL: Accidental overwrite variable value was allowed." else @@ -145,9 +157,9 @@ else fi # Try overwriting an existing variable value with update mode -/usr/bin/time -p ./dna -s $sid -i 0 -U note="replacement short literal value" > dnatest.tmp 2>&1 -grep "^real" dnatest.tmp | awk '{ if ($2<0.5) print "OK: Set variable by SID was fast."; else print "FAIL: Set variable by SID was too slow."; }' -ok=`grep "^WROTE:$sid" dnatest.tmp | wc -l` +/usr/bin/time -p $dna -s $sid -i 0 -U note="replacement short literal value" > $dnatest_tmp 2>&1 +grep "^real" $dnatest_tmp | awk '{ if ($2<0.5) print "OK: Set variable by SID was fast."; else print "FAIL: Set variable by SID was too slow."; }' +ok=`grep "^WROTE:$sid" $dnatest_tmp | wc -l` if [ $ok -ne 1 ]; then echo "FAIL: Purposeful overwrite variable value failed." else @@ -163,8 +175,8 @@ while [ $i -lt 100 ]; do echo "${i}ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-${i}" >>dnatest.in let i=i+1 done -/usr/bin/time -p ./dna -s $sid -i 0 -U note="@dnatest.in" > dnatest.tmp 2>&1 -ok=`grep "^WROTE:$sid" dnatest.tmp | wc -l` +/usr/bin/time -p $dna -s $sid -i 0 -U note="@dnatest.in" > $dnatest_tmp 2>&1 +ok=`grep "^WROTE:$sid" $dnatest_tmp | wc -l` if [ $ok -ne 1 ]; then echo "FAIL: Setting long variable values failed." echo "FAIL: Setting variable value from a file failed." @@ -176,8 +188,8 @@ fi if [ -e dnatest.out ]; then rm dnatest.out fi -/usr/bin/time -p ./dna -vvv -s $sid -O dnatest.out -i 0 -R note 2>&1 | tee dnatest.longread.log > dnatest.tmp 2>&1 -ok=`grep "^NOTE:${sid}:0" dnatest.tmp | wc -l` +/usr/bin/time -p $dna -vvv -s $sid -O dnatest.out -i 0 -R note 2>&1 | tee dnatest.longread.log > $dnatest_tmp 2>&1 +ok=`grep "^NOTE:${sid}:0" $dnatest_tmp | wc -l` if [ $ok -ne 1 ]; then echo "FAIL: Reading long variable values failed." else @@ -199,8 +211,8 @@ rm dnatest.out dnatest.in kill %1 wait # Start DNA server with a BER of 10E-3 -rm hlr.dat -./dna -n -vvv -B 0.001 -S 1 -f hlr.dat >> dnatest.log 2>&1 & +rm $hlr_dat +$dna -n -vvv -B 0.001 -S 1 -f $hlr_dat >> $SERVALINSTANCE_PATH/dnatest.log 2>&1 & sleep 1 # Test creating a new subscriber record @@ -213,15 +225,15 @@ totaltime=0 maxtime=0 while [ $i -lt $iterations ]; do - /usr/bin/time -p ./dna -B 0.001 -d 0427679796 -C > dnatest.tmp 2>&1 + /usr/bin/time -p $dna -B 0.001 -d 0427679796 -C > $dnatest_tmp 2>&1 - thistime=`grep "^real" dnatest.tmp | awk '{ printf("%d\n",$2*1000/'$iterations');}'` + thistime=`grep "^real" $dnatest_tmp | awk '{ printf("%d\n",$2*1000/'$iterations');}'` let totaltime=totaltime+thistime if [ $thistime -gt $maxtime ]; then maxtime=$thistime fi - sid=`grep "^OK:" dnatest.tmp | cut -f2 -d:` + sid=`grep "^OK:" $dnatest_tmp | cut -f2 -d:` if [ "x$sid" = "x" ]; then let fails=fails+1 else @@ -253,8 +265,8 @@ kill %1 wait # Start DNA server with a BER of 10E-4 ber=0.00001 -rm hlr.dat -./dna -n -vvv -B $ber -S 1 -f hlr.dat >> dnatest.log 2>&1 & +rm $hlr_dat +$dna -n -vvv -B $ber -S 1 -f $hlr_dat >> $SERVALINSTANCE_PATH/dnatest.log 2>&1 & sleep 1 @@ -266,8 +278,8 @@ while [ $i -lt 100 ]; do echo "${i}ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-${i}" >>dnatest.in let i=i+1 done -/usr/bin/time -p ./dna -B $ber -s $sid -i 0 -U note="@dnatest.in" > dnatest.tmp 2>&1 -ok=`grep "^WROTE:$sid" dnatest.tmp | wc -l` +/usr/bin/time -p $dna -B $ber -s $sid -i 0 -U note="@dnatest.in" > $dnatest_tmp 2>&1 +ok=`grep "^WROTE:$sid" $dnatest_tmp | wc -l` if [ $ok -ne 1 ]; then echo "FAIL: Setting long variable values failed in the face of packet loss" echo "FAIL: Setting variable value from a file failed in the face of packet loss." @@ -279,8 +291,8 @@ fi if [ -e dnatest.out ]; then rm dnatest.out fi -/usr/bin/time -p ./dna -B $ber -s $sid -O dnatest.out -i 0 -R note > dnatest.tmp 2>&1 -ok=`grep "^NOTE:${sid}:0" dnatest.tmp | wc -l` +/usr/bin/time -p $dna -B $ber -s $sid -O dnatest.out -i 0 -R note > $dnatest_tmp 2>&1 +ok=`grep "^NOTE:${sid}:0" $dnatest_tmp | wc -l` if [ $ok -ne 1 ]; then echo "FAIL: Reading long variable values failed when faced with packet loss (either READ or WRITE cycle failed)." else @@ -303,8 +315,7 @@ fi # Kill server kill %1 - -rm dnatest.tmp +rm -f $dnatest_tmp echo "FAIL: No test for parallel mode with multiple peers" echo "FAIL: No test for fast parallel return if all peers reply"