mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-28 00:48:54 +00:00
139 lines
4.4 KiB
Bash
Executable File
139 lines
4.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Tests for Serval DNA JNI entry points.
|
|
#
|
|
# 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
|
|
# 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"
|
|
source "${0%/*}/../testconfig.sh"
|
|
|
|
setup() {
|
|
setup_servald
|
|
executeOk_servald config \
|
|
set debug.verbose 1 \
|
|
set log.console.level debug
|
|
assert_echo_works
|
|
compile_java_classes
|
|
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!'
|
|
assertStdoutIs -e 'Hello,\ttab\nworld\0!\n'
|
|
}
|
|
|
|
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!'
|
|
assertStdoutIs -e 'Hello,\ttab world\0! \n'
|
|
}
|
|
|
|
doc_Delim="Serval non-JNI output delimiter environment variable"
|
|
setup_Delim() {
|
|
setup_servald
|
|
assert_echo_works
|
|
}
|
|
test_Delim() {
|
|
export SERVALD_OUTPUT_DELIMITER=:::
|
|
executeOk $servald echo 'Hello,' 'world!'
|
|
assertStdoutIs 'Hello,:::world!:::'
|
|
}
|
|
|
|
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!'
|
|
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)'
|
|
tfw_cat --stdout --stderr
|
|
assertExitStatus '!=' 0
|
|
assertStderrGrep 'NullPointerException: null element in argv'
|
|
}
|
|
|
|
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
|
|
assertStdoutGrep 'Serval DNA version '
|
|
}
|
|
|
|
doc_PeerList="Get peer details via JNI"
|
|
setup_PeerList() {
|
|
configure_servald_server() {
|
|
add_servald_interface
|
|
}
|
|
setup
|
|
foreach_instance +A +B create_single_identity
|
|
start_servald_instances +A +B
|
|
set_instance +A
|
|
}
|
|
test_PeerList() {
|
|
execute --core-backtrace java "-Djava.library.path=$LD_LIBRARY_PATH" -classpath "$PWD/classes" org.servalproject.test.CommandLine 'peers'
|
|
assertStdoutGrep "$SIDB"
|
|
tfw_cat --stdout
|
|
}
|
|
teardown_PeerList() {
|
|
stop_all_servald_servers
|
|
kill_all_servald_processes
|
|
assert_no_servald_processes
|
|
report_all_servald_servers
|
|
}
|
|
|
|
doc_DnaLookup="DNA Lookup via JNI MDP API"
|
|
setup_DnaLookup() {
|
|
configure_servald_server() {
|
|
add_servald_interface
|
|
executeOk_servald config \
|
|
set debug.mdprequests on \
|
|
set mdp.enable_inet on
|
|
}
|
|
setup
|
|
set_instance +A
|
|
foreach_instance +A +B create_single_identity
|
|
start_servald_instances +A +B
|
|
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"
|
|
tfw_cat --stdout --stderr
|
|
}
|
|
teardown_DnaLookup() {
|
|
stop_all_servald_servers
|
|
kill_all_servald_processes
|
|
assert_no_servald_processes
|
|
report_all_servald_servers
|
|
}
|
|
|
|
runTests "$@"
|