mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-02-20 17:33:08 +00:00
Refactor tests: testdefs_java.sh, testdefs_meshms.sh
meshms_add_messages() now puts message texts into TEXT[$n] array instead of "text$n" files
This commit is contained in:
parent
4fbaf8865a
commit
f2772b0ce8
10
testdefs.sh
10
testdefs.sh
@ -1,5 +1,5 @@
|
||||
# Common definitions for all test suites.
|
||||
# Copyright 2012 The Serval Project, Inc.
|
||||
# Copyright 2012 Serval Project Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
@ -321,14 +321,6 @@ foreach_instance_with_pidfile() {
|
||||
foreach_instance "${instances[@]}" "$@"
|
||||
}
|
||||
|
||||
# Utility function for setting up servald JNI fixtures:
|
||||
# - check that libserval.so is present
|
||||
# - set LD_LIBRARY_PATH so that libserval.so can be found
|
||||
setup_servald_so() {
|
||||
assert [ -r "$servald_build_root/libserval.so" ]
|
||||
export LD_LIBRARY_PATH="$servald_build_root"
|
||||
}
|
||||
|
||||
# Utility function for setting up a fixture with a servald server process:
|
||||
# - start a servald server process
|
||||
# - assert that the pidfile is created and correct
|
||||
|
58
testdefs_java.sh
Normal file
58
testdefs_java.sh
Normal file
@ -0,0 +1,58 @@
|
||||
# Definitions for test suites using Java.
|
||||
# Copyright 2014 Serval Project Inc.
|
||||
#
|
||||
# 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%/*}/../testconfig.sh"
|
||||
|
||||
# Utility function for setting up servald JNI fixtures:
|
||||
# - check that libserval.so is present
|
||||
# - set LD_LIBRARY_PATH so that libserval.so can be found
|
||||
setup_servald_so() {
|
||||
assert [ -r "$servald_build_root/libserval.so" ]
|
||||
export LD_LIBRARY_PATH="$servald_build_root"
|
||||
}
|
||||
|
||||
compile_java_classes() {
|
||||
assert --message='Java compiler was detected by ./configure' [ "$JAVAC" ]
|
||||
mkdir classes
|
||||
assert find "$servald_source_root"/java/ -name *.java | xargs $JAVAC -Xlint:unchecked -d classes
|
||||
assert [ -r classes/org/servalproject/servaldna/ServalDCommand.class ]
|
||||
assert [ -r classes/org/servalproject/servaldna/IJniResults.class ]
|
||||
assert [ -r classes/org/servalproject/test/ServalDTests.class ]
|
||||
}
|
||||
|
||||
_executeJava() {
|
||||
local func="${1?}"
|
||||
shift
|
||||
local opts=()
|
||||
while [ $# -ne 0 ]; do
|
||||
case "$1" in
|
||||
--) shift; break;;
|
||||
--*) opts+=("$1"); shift;;
|
||||
*) break;;
|
||||
esac
|
||||
done
|
||||
"$func" "${opts[@]}" --core-backtrace java "-Djava.library.path=$LD_LIBRARY_PATH" -classpath "$PWD/classes" "$@"
|
||||
}
|
||||
|
||||
executeJava() {
|
||||
_executeJava execute "$@"
|
||||
}
|
||||
|
||||
executeJavaOk() {
|
||||
_executeJava executeOk "$@"
|
||||
}
|
||||
|
71
testdefs_meshms.sh
Normal file
71
testdefs_meshms.sh
Normal file
@ -0,0 +1,71 @@
|
||||
# Common definitions for MeshMS test suites.
|
||||
# Copyright 2014 Serval Project Inc.
|
||||
#
|
||||
# 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.
|
||||
|
||||
# Create a file that contains no blank lines.
|
||||
meshms_create_message() {
|
||||
create_file --label="$1" - $2 | sed -e '/^$/d'
|
||||
}
|
||||
|
||||
# Add a sequence of messages of varying sizes up to 1 KiB.
|
||||
meshms_add_messages() {
|
||||
local sid1="${1?}"
|
||||
local sid2="${2?}"
|
||||
local symbols="${3?}"
|
||||
shift 3
|
||||
local texts=("$@")
|
||||
local sent_since_ack=0
|
||||
local i n size msize
|
||||
local size=0
|
||||
for ((i = 0; i < ${#symbols}; ++i)); do
|
||||
local sym="${symbols:$i:1}"
|
||||
let size+=379
|
||||
let msize=size%1021
|
||||
let n=NMESSAGE++
|
||||
local text="${texts[$i]}"
|
||||
case $sym in
|
||||
'>'|'<')
|
||||
if [ -n "$text" ]; then
|
||||
TEXT[$n]="$text"
|
||||
else
|
||||
TEXT[$n]="$(meshms_create_message "message$n" $msize)"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
case $sym in
|
||||
'>')
|
||||
MESSAGE[$n]=">"
|
||||
executeOk_servald meshms send message $sid1 $sid2 "${TEXT[$n]}"
|
||||
let ++sent_since_ack
|
||||
let ++NSENT
|
||||
;;
|
||||
'<')
|
||||
MESSAGE[$n]="<"
|
||||
executeOk_servald meshms send message $sid2 $sid1 "${TEXT[$n]}"
|
||||
let ++NRECV
|
||||
;;
|
||||
'A')
|
||||
MESSAGE[$n]=ACK
|
||||
[ $i -ne 0 -a $sent_since_ack -eq 0 ] && error "two ACKs in a row (at position $i)"
|
||||
executeOk_servald meshms list messages $sid2 $sid1
|
||||
let ++NACK
|
||||
;;
|
||||
*)
|
||||
error "invalid message symbol '$sym' (at position $i)"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
# Common definitions for rhizome test suites.
|
||||
# Copyright 2012 The Serval Project, Inc.
|
||||
# Common definitions for Rhizome test suites.
|
||||
# Copyright 2012 Serval Project Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
|
40
tests/jni
40
tests/jni
@ -2,7 +2,7 @@
|
||||
|
||||
# Tests for Serval DNA JNI entry points.
|
||||
#
|
||||
# Copyright 2012 Serval Project, Inc.
|
||||
# Copyright 2012-2014 Serval Project Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
@ -20,7 +20,7 @@
|
||||
|
||||
source "${0%/*}/../testframework.sh"
|
||||
source "${0%/*}/../testdefs.sh"
|
||||
source "${0%/*}/../testconfig.sh"
|
||||
source "${0%/*}/../testdefs_java.sh"
|
||||
|
||||
setup() {
|
||||
setup_servald
|
||||
@ -32,15 +32,6 @@ setup() {
|
||||
setup_servald_so
|
||||
}
|
||||
|
||||
compile_java_classes() {
|
||||
assert --message='Java compiler was detected by ./configure' [ "$JAVAC" ]
|
||||
mkdir classes
|
||||
assert find "$servald_source_root"/java/ -name *.java | xargs $JAVAC -Xlint:unchecked -d classes
|
||||
assert [ -r classes/org/servalproject/servaldna/ServalDCommand.class ]
|
||||
assert [ -r classes/org/servalproject/servaldna/IJniResults.class ]
|
||||
assert [ -r classes/org/servalproject/test/ServalDTests.class ]
|
||||
}
|
||||
|
||||
# Make sure that the normal echo command-line works, without JNI.
|
||||
assert_echo_works() {
|
||||
executeOk $servald echo -e 'Hello,\ttab' 'world\0!'
|
||||
@ -49,7 +40,7 @@ assert_echo_works() {
|
||||
|
||||
doc_Echo="Serval JNI echo Hello world"
|
||||
test_Echo() {
|
||||
executeOk java "-Djava.library.path=$LD_LIBRARY_PATH" -classpath "$PWD/classes" org.servalproject.test.ServalDTests 'echo' '-e' 'Hello,\ttab' 'world\0!'
|
||||
executeJavaOk org.servalproject.test.ServalDTests 'echo' '-e' 'Hello,\ttab' 'world\0!'
|
||||
assertStdoutIs -e 'Hello,\ttab world\0! \n'
|
||||
}
|
||||
|
||||
@ -66,14 +57,14 @@ test_Delim() {
|
||||
|
||||
doc_Repeat="Serval JNI repeated calls in same process"
|
||||
test_Repeat() {
|
||||
executeOk --core-backtrace java "-Djava.library.path=$LD_LIBRARY_PATH" -classpath "$PWD/classes" org.servalproject.test.ServalDTests repeat 50 'echo' 'Hello,' 'world!'
|
||||
executeJavaOk org.servalproject.test.ServalDTests repeat 50 'echo' 'Hello,' 'world!'
|
||||
assertStdoutLineCount '==' 50
|
||||
assertStdoutGrep --matches=50 '^Hello, world! $'
|
||||
}
|
||||
|
||||
doc_NullArg="Serval JNI null arguments throw exception"
|
||||
test_NullArg() {
|
||||
execute --core-backtrace java "-Djava.library.path=$LD_LIBRARY_PATH" -classpath "$PWD/classes" org.servalproject.test.ServalDTests 'echo' '(null)'
|
||||
executeJava org.servalproject.test.ServalDTests 'echo' '(null)'
|
||||
tfw_cat --stdout --stderr
|
||||
assertExitStatus '!=' 0
|
||||
assertStderrGrep 'NullPointerException: null element in argv'
|
||||
@ -81,13 +72,11 @@ test_NullArg() {
|
||||
|
||||
doc_help="Serval JNI returns help text"
|
||||
test_help() {
|
||||
execute --core-backtrace java "-Djava.library.path=$LD_LIBRARY_PATH" -classpath "$PWD/classes" org.servalproject.test.ServalDTests 'help'
|
||||
tfw_cat --stdout --stderr
|
||||
assertExitStatus '==' 0
|
||||
executeJavaOk org.servalproject.test.ServalDTests 'help'
|
||||
assertStdoutGrep 'Serval DNA version '
|
||||
}
|
||||
|
||||
doc_PeerList="Get peer details via JNI"
|
||||
doc_PeerList="Serval JNI get peer details"
|
||||
setup_PeerList() {
|
||||
configure_servald_server() {
|
||||
add_servald_interface
|
||||
@ -98,7 +87,7 @@ setup_PeerList() {
|
||||
set_instance +A
|
||||
}
|
||||
test_PeerList() {
|
||||
execute --core-backtrace java "-Djava.library.path=$LD_LIBRARY_PATH" -classpath "$PWD/classes" org.servalproject.test.CommandLine 'peers'
|
||||
executeJavaOk org.servalproject.test.CommandLine 'peers'
|
||||
assertStdoutGrep "$SIDB"
|
||||
tfw_cat --stdout
|
||||
}
|
||||
@ -109,7 +98,7 @@ teardown_PeerList() {
|
||||
report_all_servald_servers
|
||||
}
|
||||
|
||||
doc_DnaLookup="DNA Lookup via JNI MDP API"
|
||||
doc_DnaLookup="Serval JNI DNA Lookup"
|
||||
setup_DnaLookup() {
|
||||
configure_servald_server() {
|
||||
add_servald_interface
|
||||
@ -123,9 +112,9 @@ setup_DnaLookup() {
|
||||
set_instance +A
|
||||
}
|
||||
test_DnaLookup() {
|
||||
execute --timeout=10 --core-backtrace java "-Djava.library.path=$LD_LIBRARY_PATH" -classpath "$PWD/classes" org.servalproject.test.CommandLine 'lookup'
|
||||
assertStdoutGrep "$SIDB"
|
||||
executeJavaOk --timeout=10 org.servalproject.test.CommandLine 'lookup'
|
||||
tfw_cat --stdout --stderr
|
||||
assertStdoutGrep "$SIDB"
|
||||
}
|
||||
teardown_DnaLookup() {
|
||||
stop_all_servald_servers
|
||||
@ -134,7 +123,7 @@ teardown_DnaLookup() {
|
||||
report_all_servald_servers
|
||||
}
|
||||
|
||||
doc_serviceDiscovery="Discover network services by name"
|
||||
doc_serviceDiscovery="Serval JNI discover network services by name"
|
||||
listen_service() {
|
||||
executeOk_servald --timeout=20 msp listen --service=test_name 512 <<EOF
|
||||
Hi!
|
||||
@ -158,9 +147,9 @@ setup_serviceDiscovery() {
|
||||
set_instance +A
|
||||
}
|
||||
test_serviceDiscovery() {
|
||||
execute --timeout=10 --core-backtrace java "-Djava.library.path=$LD_LIBRARY_PATH" -classpath "$PWD/classes" org.servalproject.test.CommandLine 'service' 'test_name.*'
|
||||
executeJavaOk --timeout=10 org.servalproject.test.CommandLine 'service' 'test_name.*'
|
||||
assertStdoutGrep "$SIDB"
|
||||
assertStdoutGrep "test_name.msp.port=512"
|
||||
assertStdoutGrep "\<test_name\.msp\.port=512\>"
|
||||
tfw_cat --stdout --stderr
|
||||
}
|
||||
teardown_serviceDiscovery() {
|
||||
@ -169,4 +158,5 @@ teardown_serviceDiscovery() {
|
||||
assert_no_servald_processes
|
||||
report_all_servald_servers
|
||||
}
|
||||
|
||||
runTests "$@"
|
||||
|
@ -21,6 +21,7 @@
|
||||
source "${0%/*}/../testframework.sh"
|
||||
source "${0%/*}/../testdefs.sh"
|
||||
source "${0%/*}/../testdefs_rhizome.sh"
|
||||
source "${0%/*}/../testdefs_meshms.sh"
|
||||
|
||||
shopt -s extglob
|
||||
|
||||
@ -47,6 +48,23 @@ assertJqCmp() {
|
||||
assert --dump-on-fail="$TFWTMP/jqcmp.tmp" --dump-on-fail="$file" "${opts[@]}" cmp "$TFWTMP/jqcmp.tmp" "$file"
|
||||
}
|
||||
|
||||
assertJqIs() {
|
||||
local opts=()
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--) shift; break;;
|
||||
--*) opts+=("$1"); shift;;
|
||||
*) break;;
|
||||
esac
|
||||
done
|
||||
[ $# -eq 3 ] || error "invalid arguments"
|
||||
local json="$1"
|
||||
local jqscript="$2"
|
||||
local text="$3"
|
||||
local jqout="$(jq --raw-output "$jqscript" "$json")"
|
||||
assert "${opts[@]}" [ "$jqout" = "$text" ]
|
||||
}
|
||||
|
||||
assertJqGrep() {
|
||||
local opts=()
|
||||
while [ $# -gt 0 ]; do
|
||||
@ -989,66 +1007,11 @@ test_MeshmsListConversations() {
|
||||
])"
|
||||
}
|
||||
|
||||
# Create a file that contains no blank lines.
|
||||
create_message_file() {
|
||||
create_file "$1" $2
|
||||
sed -i -e '/^$/d' "$1"
|
||||
}
|
||||
|
||||
# Add a sequence of messages of varying sizes up to 1 KiB.
|
||||
add_messages() {
|
||||
local symbols="$1"
|
||||
shift
|
||||
local texts=("$@")
|
||||
local sent_since_ack=0
|
||||
local i n size msize
|
||||
local size=0
|
||||
for ((i = 0; i < ${#symbols}; ++i)); do
|
||||
local sym="${symbols:$i:1}"
|
||||
let size+=379
|
||||
let msize=size%1021
|
||||
let n=NMESSAGE++
|
||||
local text="${texts[$i]}"
|
||||
case $sym in
|
||||
'>'|'<')
|
||||
if [ -n "$text" ]; then
|
||||
echo "$text" >text$n
|
||||
else
|
||||
create_message_file text$n $msize
|
||||
text="$(<text$n)"
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
case $sym in
|
||||
'>')
|
||||
MESSAGE[$n]=">"
|
||||
executeOk_servald meshms send message $SIDA1 $SIDA2 "$text"
|
||||
let ++sent_since_ack
|
||||
let ++NSENT
|
||||
;;
|
||||
'<')
|
||||
MESSAGE[$n]="<"
|
||||
executeOk_servald meshms send message $SIDA2 $SIDA1 "$text"
|
||||
let ++NRECV
|
||||
;;
|
||||
'A')
|
||||
MESSAGE[$n]=ACK
|
||||
[ $i -ne 0 -a $sent_since_ack -eq 0 ] && error "two ACKs in a row (at position $i)"
|
||||
executeOk_servald meshms list messages $SIDA2 $SIDA1
|
||||
let ++NACK
|
||||
;;
|
||||
*)
|
||||
error "invalid message symbol '$sym' (at position $i)"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
doc_MeshmsListMessages="HTTP RESTful list MeshMS messages in one conversation as JSON"
|
||||
setup_MeshmsListMessages() {
|
||||
IDENTITY_COUNT=2
|
||||
setup
|
||||
add_messages '><>>A>A<>><><><>>>A>A><<<<A<>><>>A<<>'
|
||||
meshms_add_messages $SIDA1 $SIDA2 '><>>A>A<>><><><>>>A>A><<<<A<>><>>A<<>'
|
||||
let NROWS=NSENT+NRECV+(NACK?1:0)
|
||||
executeOk_servald meshms list messages $SIDA1 $SIDA2
|
||||
delivered_offset=$(sed -n -e '/^[0-9]\+:[0-9]\+:ACK:delivered$/{n;s/^[0-9]\+:\([0-9]\+\):>:.*/\1/p;q}' "$TFWSTDOUT")
|
||||
@ -1080,13 +1043,13 @@ test_MeshmsListMessages() {
|
||||
case ${MESSAGE[$j]} in
|
||||
'>')
|
||||
assertJq messages.json '.['$i'].type == ">"'
|
||||
assertJqCmp messages.json '.['$i'].text' text$j
|
||||
assertJqIs messages.json '.['$i'].text' "${TEXT[$j]}"
|
||||
assertJq messages.json '.['$i'].delivered == (.['$i'].offset <= '$delivered_offset')'
|
||||
let ++i
|
||||
;;
|
||||
'<')
|
||||
assertJq messages.json '.['$i'].type == "<"'
|
||||
assertJqCmp messages.json '.['$i'].text' text$j
|
||||
assertJqIs messages.json '.['$i'].text' "${TEXT[$j]}"
|
||||
assertJq messages.json '.['$i'].read == (.['$i'].offset <= '$read_offset')'
|
||||
let ++i
|
||||
;;
|
||||
@ -1129,7 +1092,7 @@ setup_MeshmsListMessagesNewSince() {
|
||||
set rhizome.api.restful.newsince_poll_ms 500
|
||||
}
|
||||
setup
|
||||
add_messages '><>>A>A<>><><><>>>A>A><<<<A<>><>>A<<>'
|
||||
meshms_add_messages $SIDA1 $SIDA2 '><>>A>A<>><><><>>>A>A><<<<A<>><>>A<<>'
|
||||
let NROWS=NSENT+NRECV+(NACK?1:0)
|
||||
executeOk curl \
|
||||
--silent --fail --show-error \
|
||||
@ -1181,7 +1144,7 @@ setup_MeshmsListMessagesNewSinceArrival() {
|
||||
set rhizome.api.restful.newsince_poll_ms 500
|
||||
}
|
||||
setup
|
||||
add_messages '><>A>'
|
||||
meshms_add_messages $SIDA1 $SIDA2 '><>A>'
|
||||
let NROWS=NSENT+NRECV+(NACK?1:0)
|
||||
executeOk curl \
|
||||
--silent --fail --show-error \
|
||||
@ -1206,7 +1169,7 @@ test_MeshmsListMessagesNewSinceArrival() {
|
||||
done
|
||||
wait_until [ -e newsince1.json -a -e newsince2.json -a -e newsince3.json ]
|
||||
for message in '>Rumplestiltskin' 'A' '<Howdydoody' '>Eulenspiegel'; do
|
||||
add_messages "${message:0:1}" "${message:1}"
|
||||
meshms_add_messages $SIDA1 $SIDA2 "${message:0:1}" "${message:1}"
|
||||
wait_until --timeout=60 grepall "${message:1}" newsince{1,2,3}.json
|
||||
done
|
||||
fork_terminate_all
|
||||
|
Loading…
x
Reference in New Issue
Block a user