2012-04-03 09:48:57 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2012-04-10 03:11:15 +00:00
|
|
|
# Tests for Serval DNA HLR operations.
|
|
|
|
#
|
2012-04-05 10:17:57 +00:00
|
|
|
# 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.
|
|
|
|
|
2012-04-03 09:48:57 +00:00
|
|
|
source "${0%/*}/../testframework.sh"
|
2012-04-10 03:11:15 +00:00
|
|
|
source "${0%/*}/../testdefs.sh"
|
2012-04-05 10:17:57 +00:00
|
|
|
|
|
|
|
# Default teardown function
|
|
|
|
teardown() {
|
|
|
|
stop_dna_server
|
|
|
|
}
|
|
|
|
|
|
|
|
# Utility function
|
|
|
|
create_sid() {
|
|
|
|
execute $dna "$@" -d 0427679796 -C
|
|
|
|
assertExitStatus '==' 0
|
|
|
|
assertStdoutGrep --matches=1 '^OK:'
|
|
|
|
sid=`replayStdout | grep '^OK:' | cut -f2 -d:`
|
|
|
|
}
|
|
|
|
|
|
|
|
# Utility function
|
|
|
|
set_short_var() {
|
|
|
|
execute $dna -s $sid -i 0 -W note="a short literal value"
|
|
|
|
assertExitStatus '==' 0
|
|
|
|
}
|
|
|
|
|
|
|
|
# Utility function
|
|
|
|
echo_long_message() {
|
|
|
|
local i=0
|
|
|
|
while [ $i -lt 100 ]; do
|
|
|
|
echo "${i}ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-${i}"
|
|
|
|
let i=i+1
|
|
|
|
done
|
2012-04-03 09:48:57 +00:00
|
|
|
}
|
|
|
|
|
2012-04-05 10:17:57 +00:00
|
|
|
# Test case, transcribed from ../testdna
|
|
|
|
doc_CreateSID='Create new SID'
|
|
|
|
setup_CreateSID() {
|
2012-04-10 03:11:15 +00:00
|
|
|
setup_dna
|
2012-04-05 10:17:57 +00:00
|
|
|
start_dna_server
|
|
|
|
}
|
2012-04-03 09:48:57 +00:00
|
|
|
test_CreateSID() {
|
2012-04-05 10:17:57 +00:00
|
|
|
create_sid
|
|
|
|
assertRealTime '<' 0.5
|
|
|
|
assertExpr --stdout --message='valid SID was returned' "$sid" '~' '[0-9A-F]+'
|
|
|
|
}
|
|
|
|
|
|
|
|
# Test case, transcribed from ../testdna
|
|
|
|
doc_GetShortVar='Get short variable'
|
|
|
|
setup_GetShortVar() {
|
2012-04-10 03:11:15 +00:00
|
|
|
setup_dna
|
2012-04-05 10:17:57 +00:00
|
|
|
start_dna_server
|
|
|
|
create_sid
|
|
|
|
}
|
|
|
|
test_GetShortVar() {
|
|
|
|
execute $dna -d 0427679796 -R dids
|
2012-04-03 09:48:57 +00:00
|
|
|
assertExitStatus '==' 0
|
2012-04-05 10:17:57 +00:00
|
|
|
assertRealTime '>' 2.9 # Waited for all replies
|
|
|
|
assertStdoutGrep --message='received an existing DID' "^DIDS:${sid}:[0-9]\+:0:0427679796"
|
|
|
|
assertStdoutGrep --matches=1 --message='filtered out duplicate responses' "^DIDS:${sid}:[0-9]\+:0:0427679796"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Test case, transcribed from ../testdna
|
|
|
|
doc_SetShortVar='Set short variable'
|
|
|
|
setup_SetShortVar() {
|
2012-04-10 03:11:15 +00:00
|
|
|
setup_dna
|
2012-04-05 10:17:57 +00:00
|
|
|
start_dna_server
|
|
|
|
create_sid
|
|
|
|
}
|
|
|
|
test_SetShortVar() {
|
|
|
|
set_short_var
|
2012-04-03 09:48:57 +00:00
|
|
|
assertRealTime '<' 0.5
|
2012-04-05 10:17:57 +00:00
|
|
|
assertStdoutGrep --matches=1 --message='variable write confirmed' "^WROTE:$sid$"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Test case, transcribed from ../testdna
|
|
|
|
doc_SetGetShortVar='Set then get short variable'
|
|
|
|
setup_SetGetShortVar() {
|
2012-04-10 03:11:15 +00:00
|
|
|
setup_dna
|
2012-04-05 10:17:57 +00:00
|
|
|
start_dna_server
|
|
|
|
create_sid
|
|
|
|
set_short_var
|
|
|
|
}
|
|
|
|
test_SetGetShortVar() {
|
|
|
|
execute $dna -s $sid -i 0 -R note
|
|
|
|
assertExitStatus '==' 0
|
|
|
|
assertRealTime '<' 0.5
|
|
|
|
assertStdoutGrep --matches=1 --message='read variable correctly' "^NOTE:$sid:[0-9]\+:0:a short literal value"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Test case, transcribed from ../testdna
|
|
|
|
doc_GetShortVarToFile='Get variable into a file'
|
|
|
|
setup_GetShortVarToFile() {
|
2012-04-10 03:11:15 +00:00
|
|
|
setup_dna
|
2012-04-05 10:17:57 +00:00
|
|
|
start_dna_server
|
|
|
|
create_sid
|
|
|
|
set_short_var
|
|
|
|
}
|
|
|
|
test_GetShortVarToFile() {
|
|
|
|
echo "WARNING: Known issue: output to file does not work with DID lists"
|
2012-04-10 03:11:15 +00:00
|
|
|
dnatest_dat=$DNATMP/dnatest.dat
|
2012-04-05 10:17:57 +00:00
|
|
|
execute $dna -s $sid -O $dnatest_dat -i 0 -R note
|
|
|
|
assertExitStatus '==' 0
|
|
|
|
assertRealTime '<' 0.5
|
|
|
|
assertStdoutGrep --matches=1 --message='read variable into file' "^NOTE:$sid:[0-9]\+:0"
|
|
|
|
assertFileContents $dnatest_dat 'a short literal value'
|
|
|
|
}
|
|
|
|
|
|
|
|
# Test case, transcribed from ../testdna
|
|
|
|
doc_SetMultiShortVar='Set multiple instances of a short variable'
|
|
|
|
setup_SetMultiShortVar() {
|
2012-04-10 03:11:15 +00:00
|
|
|
setup_dna
|
2012-04-05 10:17:57 +00:00
|
|
|
start_dna_server
|
|
|
|
create_sid
|
|
|
|
set_short_var
|
|
|
|
}
|
|
|
|
test_SetMultiShortVar() {
|
|
|
|
execute $dna -s $sid -i 1 -W note='$414243'
|
|
|
|
assertExitStatus '==' 0
|
|
|
|
assertRealTime '<' 0.5
|
|
|
|
assertStdoutGrep --matches=1 --message='variable write confirmed' "^WROTE:$sid$"
|
|
|
|
execute $dna -s $sid -i 1 -R note
|
|
|
|
assertExitStatus '==' 0
|
|
|
|
assertRealTime '<' 0.5
|
|
|
|
assertStdoutGrep --matches=1 --message='new variable correctly set in hex' "^NOTE:$sid:[0-9]\+:1:ABC$"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Test case, transcribed from ../testdna
|
|
|
|
doc_GetMultiShortVar='Get multiple instances of a short variable'
|
|
|
|
setup_GetMultiShortVar() {
|
2012-04-10 03:11:15 +00:00
|
|
|
setup_dna
|
2012-04-05 10:17:57 +00:00
|
|
|
start_dna_server
|
|
|
|
create_sid
|
|
|
|
set_short_var
|
|
|
|
execute $dna -s $sid -i 1 -W note='$414243'
|
|
|
|
assertExitStatus '==' 0
|
|
|
|
execute $dna -s $sid -i 2 -W note
|
|
|
|
assertExitStatus '==' 0
|
|
|
|
}
|
|
|
|
test_GetMultiShortVar() {
|
|
|
|
execute $dna -s $sid -m -R note
|
|
|
|
assertExitStatus '==' 0
|
|
|
|
assertRealTime '<' 0.5
|
|
|
|
assertStdoutGrep --matches=1 --message='first variable read correctly' "^NOTE:$sid:[0-9]\+:0:a short literal value$"
|
|
|
|
assertStdoutGrep --matches=1 --message='second variable read correctly' "^NOTE:$sid:[0-9]\+:1:ABC$"
|
|
|
|
assertStdoutGrep --matches=1 --message='third variable read correctly' "^NOTE:$sid:[0-9]\+:2$"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Test case, transcribed from ../testdna
|
|
|
|
doc_OverwriteVarNoUpdate='Set does not overwrite variable'
|
|
|
|
setup_OverwriteVarNoUpdate() {
|
2012-04-10 03:11:15 +00:00
|
|
|
setup_dna
|
2012-04-05 10:17:57 +00:00
|
|
|
start_dna_server
|
|
|
|
create_sid
|
|
|
|
set_short_var
|
|
|
|
}
|
|
|
|
test_OverwriteVarNoUpdate() {
|
|
|
|
execute $dna -s $sid -i 0 -W note="replacement short literal value"
|
|
|
|
assertExitStatus '==' 0
|
|
|
|
assertRealTime '<' 0.5
|
|
|
|
assertStdoutGrep --matches=0 --message='variable write not confirmed' "^WROTE:$sid$"
|
|
|
|
execute $dna -s $sid -i 0 -R note
|
|
|
|
assertExitStatus '==' 0
|
|
|
|
assertRealTime '<' 0.5
|
|
|
|
assertStdoutGrep --matches=1 --message='variable retains original value' "^NOTE:$sid:[0-9]\+:0:a short literal value"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Test case, transcribed from ../testdna
|
|
|
|
doc_UpdateVar='Update overwrites variable'
|
|
|
|
setup_UpdateVar() {
|
2012-04-10 03:11:15 +00:00
|
|
|
setup_dna
|
2012-04-05 10:17:57 +00:00
|
|
|
start_dna_server
|
|
|
|
create_sid
|
|
|
|
set_short_var
|
|
|
|
}
|
|
|
|
test_UpdateVar() {
|
|
|
|
execute $dna -s $sid -i 0 -U note="replacement short literal value"
|
|
|
|
assertExitStatus '==' 0
|
|
|
|
assertRealTime '<' 0.5
|
|
|
|
assertStdoutGrep --matches=1 --message='variable write confirmed' "^WROTE:$sid$"
|
|
|
|
execute $dna -s $sid -i 0 -R note
|
|
|
|
assertExitStatus '==' 0
|
|
|
|
assertRealTime '<' 0.5
|
|
|
|
assertStdoutGrep --matches=1 --message='variable has new value' "^NOTE:$sid:[0-9]\+:0:replacement short literal value"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Test case, transcribed from ../testdna
|
|
|
|
doc_UpdateVarBigValue='Can set variable with multi-packet value'
|
|
|
|
setup_UpdateVarBigValue() {
|
2012-04-10 03:11:15 +00:00
|
|
|
setup_dna
|
2012-04-05 10:17:57 +00:00
|
|
|
start_dna_server
|
|
|
|
create_sid
|
|
|
|
set_short_var
|
2012-04-10 03:11:15 +00:00
|
|
|
echo_long_message >$DNATMP/dnatest.in
|
2012-04-05 10:17:57 +00:00
|
|
|
}
|
|
|
|
test_UpdateVarBigValue() {
|
|
|
|
execute $dna -s $sid -i 0 -U note="@dnatest.in"
|
|
|
|
assertExitStatus '==' 0
|
|
|
|
assertRealTime '<' 0.5
|
|
|
|
assertStdoutGrep --matches=1 --message='variable write confirmed' "^WROTE:$sid$"
|
2012-04-10 03:11:15 +00:00
|
|
|
execute $dna -v verbose -s $sid -O $DNATMP/dnatest.out -i 0 -R note
|
2012-04-05 10:17:57 +00:00
|
|
|
assertExitStatus '==' 0
|
|
|
|
assertRealTime '<' 0.5
|
|
|
|
assertStdoutGrep --matches=1 --message='variable new value returned' "^NOTE:$sid:[0-9]\+:0"
|
2012-04-10 03:11:15 +00:00
|
|
|
assert --message='long value read correctly' cmp --quiet $DNATMP/dnatest.in $DNATMP/dnatest.out
|
2012-04-03 09:48:57 +00:00
|
|
|
}
|
|
|
|
|
2012-04-05 10:17:57 +00:00
|
|
|
runTests "$@"
|