serval-dna/tests/dna_biterrors

83 lines
2.9 KiB
Plaintext
Raw Normal View History

#!/bin/bash
# Tests for Serval DNA bit error performance.
#
# Copyright 2012 Paul Gardner-Stephen
#
# This program 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.
source "${0%/*}/../testframework.sh"
source "${0%/*}/../testdefs.sh"
# Default teardown function
teardown() {
stop_dna_server
}
# Test case, transcribed from ../testdna
doc_BitErrorCreateSID='Create new SID despite bit errors'
setup_BitErrorCreateSID() {
ber=0.001
setup_dna
start_dna_server -B $ber
}
test_BitErrorCreateSID() {
local iterations=10
local i=0
local fails=0
local totaltime_ms=0
local maxtime_ms=0
while [ $i -lt $iterations ]; do
execute $dna -B $ber -d 0427679796 -C
assertExitStatus '==' 0
sid=`replayStdout | grep '^OK:' | cut -f2 -d:`
let totaltime_ms=totaltime_ms+realtime_ms
[ $realtime_ms -gt $maxtime_ms ] && maxtime_ms=$realtime_ms
if [ -z "$sid" ]; then
let fails=fails+1
echo "# iteration $i: no sid after ${realtime_ms} ms"
else
echo "# iteration $i: sid=$sid after ${realtime_ms} ms"
fi
let i=i+1
done
let meantime_ms=totaltime_ms/iterations
echo "# average time = $meantime_ms ms"
echo "# maximum time = $maxtime_ms ms"
assertExpr --message='packet loss was properly injected' $meantime_ms '>' 25
assertExpr --message="reliable at BER=$ber packet loss" $fails '<=' 4
assertExpr --message="timeout works at BER=$ber packet loss" $totaltime_ms '<=' 3000 '&&' $maxtime_ms '<=' 330
}
# Test case, transcribed from ../testdna
doc_SetVarBigValueBitErrors='Can set variable with multi-packet value despite bit errors'
setup_SetVarBigValueBitErrors() {
ber=0.00001
setup_dna
start_dna_server -B $ber
echo_long_message >$DNATMP/dnatest.in
}
test_SetVarBigValueBitErrors() {
execute $dna -B $ber -s $sid -i 0 -W note="@dnatest.in"
assertExitStatus '==' 0
assertStdoutGrep --matches=1 --message='variable write confirmed' "^WROTE:$sid$"
execute $dna -v verbose -B $ber -s $sid -O $DNATMP/dnatest.out -i 0 -R note
assertExitStatus '==' 0
assertStdoutGrep --matches=1 --message='variable new value returned' "^NOTE:$sid:[0-9]\+:0"
assert --message='long value read correctly' cmp --quiet $DNATMP/dnatest.in $DNATMP/dnatest.out
}
runTests "$@"