Ressurect testdna script

This commit is contained in:
Andrew Bettison 2012-04-03 19:15:39 +09:30
parent c31860986f
commit 91d19df5cb
2 changed files with 77 additions and 65 deletions

View File

@ -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. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
#include <time.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
@ -128,7 +129,7 @@ int server(char *backing_file,int size,int foregroundMode)
exit(-1); exit(-1);
FILE *f=fopen(filename,"w"); FILE *f=fopen(filename,"w");
if (!f) { if (!f) {
WHY("Could not write to PID file"); WHYF("Could not write to PID file %s", filename);
perror("fopen"); perror("fopen");
exit(-1); exit(-1);
} }

139
testdna
View File

@ -1,29 +1,41 @@
#!/bin/bash #!/bin/bash
# Stop any existing DNA server # The dna executable under test
pids=`ps -ef | grep "\./dna" | awk '{ print $2;}' | wc -l` dna="${0%/*}"/dna
if [ $pids -gt 0 ]; then
kill `ps -ef | grep "\./dna" | awk '{ print $2;}'` # Stop any existing DNA servers
pids=$(ps -u$UID | awk '$4 == "dna" {print $1}')
if [ -n "$pids" ]; then
kill $pids
fi 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 # Start DNA server
$dna -n -vvv -S 1 -f $hlr_dat > $SERVALINSTANCE_PATH/dnatest.log 2>&1 &
if [ -e hlr.dat ]; then
rm hlr.dat
fi
./dna -n -vvv -S 1 -f hlr.dat > dnatest.log 2>&1 &
sleep 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 creating a new subscriber record
# Test: Should return in <<3 sec, rather than time out # Test: Should return in <<3 sec, rather than time out
# Test: Should return OK:SID # Test: Should return OK:SID
/usr/bin/time -p ./dna -d 0427679796 -C > dnatest.tmp 2>&1 /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."; }' 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:` sid=`grep "^OK:" $dnatest_tmp | cut -f2 -d:`
if [ "x$sid" = "x" ]; then if [ "x$sid" = "x" ]; then
echo "FAIL: Create HLR failed (no OK:SID reply)" echo "FAIL: Create HLR failed (no OK:SID reply)"
echo -n "Got: " echo -n "Got: "
cat dnatest.tmp cat $dnatest_tmp
echo echo
echo "FATAL: Cannot continue" echo "FATAL: Cannot continue"
kill %1 kill %1
@ -33,13 +45,13 @@ else
fi fi
# Test getting short variables # Test getting short variables
/usr/bin/time -p ./dna -d 0427679796 -R dids > dnatest.tmp 2>&1 /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."; }' 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` ok=`grep "^DIDS:${sid}:0:0427679796" $dnatest_tmp | wc -l`
if [ $ok -lt 1 ]; then if [ $ok -lt 1 ]; then
echo "FAIL: Read variable didn't find existing value" echo "FAIL: Read variable didn't find existing value"
echo "FAIL: Search by DID may not work." 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 else
echo "OK: Read variable correctly read an existing value" echo "OK: Read variable correctly read an existing value"
if [ $ok -gt 1 ]; then if [ $ok -gt 1 ]; then
@ -52,24 +64,24 @@ else
fi fi
# Test setting short variables # Test setting short variables
/usr/bin/time -p ./dna -s $sid -i 0 -W note="a short literal value" > dnatest.tmp 2>&1 /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."; }' 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` ok=`grep "^WROTE:$sid" $dnatest_tmp | wc -l`
if [ $ok -ne 1 ]; then if [ $ok -ne 1 ]; then
echo "FAIL: Set new variable value failed." 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" echo "Wanted: WROTE:$sid"
else else
echo "OK: Set new variable value succeeded." echo "OK: Set new variable value succeeded."
fi fi
# Test getting short variable by SID, and that setting variables really works. # 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 /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); }' 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` ok=`grep "^NOTE:${sid}:0:a short literal value" $dnatest_tmp | wc -l`
if [ $ok -ne 1 ]; then if [ $ok -ne 1 ]; then
echo "FAIL: Set variable value could not be read back." 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." echo "FAIL: Search by SID may not work."
else else
echo "OK: Set variable value could be read back." 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 if [ -e dnatest.dat ]; then
rm dnatest.dat rm dnatest.dat
fi fi
/usr/bin/time -p ./dna -s $sid -O dnatest.dat -i 0 -R note > dnatest.tmp 2>&1 /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); }' 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` ok=`grep "^NOTE:${sid}:0" $dnatest_tmp | wc -l`
if [ $ok -ne 1 ]; then if [ $ok -ne 1 ]; then
echo "FAIL: Set variable value could not be read back without output going to file." echo "FAIL: Set variable value could not be read back without output going to file."
else else
@ -98,11 +110,11 @@ fi
rm dnatest.dat rm dnatest.dat
# Test setting multiple instances of short variables # Test setting multiple instances of short variables
/usr/bin/time -p ./dna -s $sid -i 1 -W note='$414243' >dnatest.tmp 2>&1 /usr/bin/time -p $dna -s $sid -i 1 -W note='$414243' >$dnatest_tmp 2>&1
ok=`grep "^WROTE:$sid" dnatest.tmp | wc -l` ok=`grep "^WROTE:$sid" $dnatest_tmp | wc -l`
if [ $ok -ne 1 ]; then if [ $ok -ne 1 ]; then
echo "FAIL: Set new variable value by instance failed." 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 else
echo "OK: Set new variable value by instance succeeded." echo "OK: Set new variable value by instance succeeded."
fi fi
@ -111,33 +123,33 @@ fi
echo "NOTE:${sid}:0:a short literal value" >dnatest.txt echo "NOTE:${sid}:0:a short literal value" >dnatest.txt
echo "NOTE:${sid}:1:ABC" >>dnatest.txt echo "NOTE:${sid}:1:ABC" >>dnatest.txt
echo "DONE:${sid}:2" >>dnatest.txt echo "DONE:${sid}:2" >>dnatest.txt
./dna -s $sid -i -1 -R note > dnatest.tmp 2>&1 $dna -s $sid -i -1 -R note > $dnatest_tmp 2>&1
ok=`diff dnatest.tmp dnatest.txt | wc -l` ok=`diff $dnatest_tmp dnatest.txt | wc -l`
if [ $ok -ne 0 ]; then if [ $ok -ne 0 ]; then
echo "FAIL: Reading multiple variable instances has problems." echo "FAIL: Reading multiple variable instances has problems."
echo diff dnatest.tmp dnatest.txt echo diff $dnatest_tmp dnatest.txt
diff dnatest.tmp dnatest.txt diff $dnatest_tmp dnatest.txt
set ok=`grep ':ABC$' dnatest.tmp | wc -l` set ok=`grep ':ABC$' $dnatest_tmp | wc -l`
if [ $ok != 1 ]; then if [ $ok != 1 ]; then
echo "FAIL: Specifying variable values by hex may have problems." echo "FAIL: Specifying variable values by hex may have problems."
else else
echo "OK: Specifying variable values by hex works." echo "OK: Specifying variable values by hex works."
fi fi
diff dnatest.tmp dnatest.txt diff $dnatest_tmp dnatest.txt
else else
echo "OK: Reading multiple variable instances works." echo "OK: Reading multiple variable instances works."
echo "OK: Specifying variable values by hex works." echo "OK: Specifying variable values by hex works."
fi fi
if [ -e dnatest.tmp ]; then if [ -e $dnatest_tmp ]; then
rm dnatest.tmp rm $dnatest_tmp
fi fi
/usr/bin/time -p ./dna -s $sid -R notes > dnatest.tmp 2>&1 /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."; }' 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 # 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 /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."; }' 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` ok=`grep "^WROTE:$sid" $dnatest_tmp | wc -l`
if [ $ok -eq 1 ]; then if [ $ok -eq 1 ]; then
echo "FAIL: Accidental overwrite variable value was allowed." echo "FAIL: Accidental overwrite variable value was allowed."
else else
@ -145,9 +157,9 @@ else
fi fi
# Try overwriting an existing variable value with update mode # 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 /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."; }' 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` ok=`grep "^WROTE:$sid" $dnatest_tmp | wc -l`
if [ $ok -ne 1 ]; then if [ $ok -ne 1 ]; then
echo "FAIL: Purposeful overwrite variable value failed." echo "FAIL: Purposeful overwrite variable value failed."
else else
@ -163,8 +175,8 @@ while [ $i -lt 100 ]; do
echo "${i}ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-${i}" >>dnatest.in echo "${i}ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-${i}" >>dnatest.in
let i=i+1 let i=i+1
done done
/usr/bin/time -p ./dna -s $sid -i 0 -U note="@dnatest.in" > dnatest.tmp 2>&1 /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` ok=`grep "^WROTE:$sid" $dnatest_tmp | wc -l`
if [ $ok -ne 1 ]; then if [ $ok -ne 1 ]; then
echo "FAIL: Setting long variable values failed." echo "FAIL: Setting long variable values failed."
echo "FAIL: Setting variable value from a file failed." echo "FAIL: Setting variable value from a file failed."
@ -176,8 +188,8 @@ fi
if [ -e dnatest.out ]; then if [ -e dnatest.out ]; then
rm dnatest.out rm dnatest.out
fi 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 /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` ok=`grep "^NOTE:${sid}:0" $dnatest_tmp | wc -l`
if [ $ok -ne 1 ]; then if [ $ok -ne 1 ]; then
echo "FAIL: Reading long variable values failed." echo "FAIL: Reading long variable values failed."
else else
@ -199,8 +211,8 @@ rm dnatest.out dnatest.in
kill %1 kill %1
wait wait
# Start DNA server with a BER of 10E-3 # Start DNA server with a BER of 10E-3
rm hlr.dat rm $hlr_dat
./dna -n -vvv -B 0.001 -S 1 -f hlr.dat >> dnatest.log 2>&1 & $dna -n -vvv -B 0.001 -S 1 -f $hlr_dat >> $SERVALINSTANCE_PATH/dnatest.log 2>&1 &
sleep 1 sleep 1
# Test creating a new subscriber record # Test creating a new subscriber record
@ -213,15 +225,15 @@ totaltime=0
maxtime=0 maxtime=0
while [ $i -lt $iterations ]; do 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 let totaltime=totaltime+thistime
if [ $thistime -gt $maxtime ]; then if [ $thistime -gt $maxtime ]; then
maxtime=$thistime maxtime=$thistime
fi fi
sid=`grep "^OK:" dnatest.tmp | cut -f2 -d:` sid=`grep "^OK:" $dnatest_tmp | cut -f2 -d:`
if [ "x$sid" = "x" ]; then if [ "x$sid" = "x" ]; then
let fails=fails+1 let fails=fails+1
else else
@ -253,8 +265,8 @@ kill %1
wait wait
# Start DNA server with a BER of 10E-4 # Start DNA server with a BER of 10E-4
ber=0.00001 ber=0.00001
rm hlr.dat rm $hlr_dat
./dna -n -vvv -B $ber -S 1 -f hlr.dat >> dnatest.log 2>&1 & $dna -n -vvv -B $ber -S 1 -f $hlr_dat >> $SERVALINSTANCE_PATH/dnatest.log 2>&1 &
sleep 1 sleep 1
@ -266,8 +278,8 @@ while [ $i -lt 100 ]; do
echo "${i}ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-${i}" >>dnatest.in echo "${i}ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-${i}" >>dnatest.in
let i=i+1 let i=i+1
done done
/usr/bin/time -p ./dna -B $ber -s $sid -i 0 -U note="@dnatest.in" > dnatest.tmp 2>&1 /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` ok=`grep "^WROTE:$sid" $dnatest_tmp | wc -l`
if [ $ok -ne 1 ]; then if [ $ok -ne 1 ]; then
echo "FAIL: Setting long variable values failed in the face of packet loss" 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." 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 if [ -e dnatest.out ]; then
rm dnatest.out rm dnatest.out
fi fi
/usr/bin/time -p ./dna -B $ber -s $sid -O dnatest.out -i 0 -R note > dnatest.tmp 2>&1 /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` ok=`grep "^NOTE:${sid}:0" $dnatest_tmp | wc -l`
if [ $ok -ne 1 ]; then if [ $ok -ne 1 ]; then
echo "FAIL: Reading long variable values failed when faced with packet loss (either READ or WRITE cycle failed)." echo "FAIL: Reading long variable values failed when faced with packet loss (either READ or WRITE cycle failed)."
else else
@ -303,8 +315,7 @@ fi
# Kill server # Kill server
kill %1 kill %1
rm -f $dnatest_tmp
rm dnatest.tmp
echo "FAIL: No test for parallel mode with multiple peers" echo "FAIL: No test for parallel mode with multiple peers"
echo "FAIL: No test for fast parallel return if all peers reply" echo "FAIL: No test for fast parallel return if all peers reply"