2012-04-23 08:55:26 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Tests for Serval DNA JNI entry points.
|
|
|
|
#
|
2014-06-11 07:50:47 +00:00
|
|
|
# Copyright 2012-2014 Serval Project Inc.
|
2012-04-23 08:55:26 +00:00
|
|
|
#
|
|
|
|
# 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"
|
2014-06-11 07:50:47 +00:00
|
|
|
source "${0%/*}/../testdefs_java.sh"
|
2012-04-23 08:55:26 +00:00
|
|
|
|
|
|
|
setup() {
|
2012-05-20 04:18:02 +00:00
|
|
|
setup_servald
|
2014-02-12 02:37:31 +00:00
|
|
|
executeOk_servald config \
|
2016-10-12 06:38:26 +00:00
|
|
|
set debug.jni 1 \
|
|
|
|
set debug.verbose 1 \
|
|
|
|
set log.console.level debug
|
2012-04-24 07:36:48 +00:00
|
|
|
assert_echo_works
|
2016-11-08 04:21:15 +00:00
|
|
|
assert_java_classes_exist
|
2012-04-24 07:36:48 +00:00
|
|
|
setup_servald_so
|
2012-04-23 08:55:26 +00:00
|
|
|
}
|
|
|
|
|
2012-04-24 07:36:48 +00:00
|
|
|
# Make sure that the normal echo command-line works, without JNI.
|
|
|
|
assert_echo_works() {
|
2012-11-07 06:42:04 +00:00
|
|
|
executeOk $servald echo -e 'Hello,\ttab' 'world\0!'
|
|
|
|
assertStdoutIs -e 'Hello,\ttab\nworld\0!\n'
|
2012-04-23 08:55:26 +00:00
|
|
|
}
|
|
|
|
|
2012-04-24 07:45:50 +00:00
|
|
|
doc_Echo="Serval JNI echo Hello world"
|
2012-04-23 08:55:26 +00:00
|
|
|
test_Echo() {
|
2016-10-12 06:38:26 +00:00
|
|
|
executeJavaOk org.servalproject.test.CommandLine 'echo' '-e' 'Hello,\ttab' 'world\0!'
|
|
|
|
tfw_cat --stdout --stderr
|
|
|
|
assertStdoutIs -e 'Hello,\ttab\nworld\0!\n'
|
2012-04-23 08:55:26 +00:00
|
|
|
}
|
|
|
|
|
2012-04-24 07:45:50 +00:00
|
|
|
doc_Delim="Serval non-JNI output delimiter environment variable"
|
|
|
|
setup_Delim() {
|
2012-05-20 04:18:02 +00:00
|
|
|
setup_servald
|
2012-04-24 07:45:50 +00:00
|
|
|
assert_echo_works
|
|
|
|
}
|
|
|
|
test_Delim() {
|
|
|
|
export SERVALD_OUTPUT_DELIMITER=:::
|
2012-05-20 04:18:02 +00:00
|
|
|
executeOk $servald echo 'Hello,' 'world!'
|
2012-04-24 07:45:50 +00:00
|
|
|
assertStdoutIs 'Hello,:::world!:::'
|
|
|
|
}
|
|
|
|
|
2012-04-24 23:34:42 +00:00
|
|
|
doc_Repeat="Serval JNI repeated calls in same process"
|
|
|
|
test_Repeat() {
|
2016-10-12 06:38:26 +00:00
|
|
|
executeJavaOk org.servalproject.test.CommandLine --repeat 50 'echo' 'Hello,' 'world!'
|
|
|
|
assertStdoutLineCount '==' 100
|
|
|
|
assertStdoutGrep --matches=50 '^Hello,$'
|
|
|
|
assertStdoutGrep --matches=50 '^world!$'
|
2012-04-24 23:34:42 +00:00
|
|
|
}
|
2012-04-23 08:55:26 +00:00
|
|
|
|
2014-11-03 02:22:54 +00:00
|
|
|
doc_NullArg="Serval JNI null arguments dont throw exception"
|
2013-02-15 08:53:34 +00:00
|
|
|
test_NullArg() {
|
2016-10-12 06:38:26 +00:00
|
|
|
executeJavaOk org.servalproject.test.CommandLine 'echo' '(null)'
|
2013-02-15 08:53:34 +00:00
|
|
|
tfw_cat --stdout --stderr
|
|
|
|
}
|
|
|
|
|
2016-10-12 06:38:26 +00:00
|
|
|
doc_version="Serval JNI returns version text"
|
|
|
|
test_version() {
|
|
|
|
executeJavaOk org.servalproject.test.CommandLine 'version'
|
2013-07-09 06:54:47 +00:00
|
|
|
assertStdoutGrep 'Serval DNA version '
|
|
|
|
}
|
|
|
|
|
2014-06-11 07:50:47 +00:00
|
|
|
doc_PeerList="Serval JNI get peer details"
|
2014-02-20 04:36:05 +00:00
|
|
|
setup_PeerList() {
|
|
|
|
configure_servald_server() {
|
|
|
|
add_servald_interface
|
|
|
|
}
|
|
|
|
setup
|
|
|
|
foreach_instance +A +B create_single_identity
|
|
|
|
start_servald_instances +A +B
|
|
|
|
set_instance +A
|
2016-10-12 06:38:26 +00:00
|
|
|
executeOk_servald 'id' 'peers'
|
|
|
|
tfw_cat --stdout --stderr
|
2014-02-20 04:36:05 +00:00
|
|
|
}
|
|
|
|
test_PeerList() {
|
2016-10-12 06:38:26 +00:00
|
|
|
executeJavaOk org.servalproject.test.CommandLine 'id' 'peers'
|
|
|
|
tfw_cat --stdout --stderr
|
2014-02-20 04:36:05 +00:00
|
|
|
assertStdoutGrep "$SIDB"
|
|
|
|
}
|
|
|
|
teardown_PeerList() {
|
|
|
|
stop_all_servald_servers
|
|
|
|
kill_all_servald_processes
|
|
|
|
assert_no_servald_processes
|
|
|
|
report_all_servald_servers
|
|
|
|
}
|
2013-02-15 08:53:34 +00:00
|
|
|
|
2014-06-11 07:50:47 +00:00
|
|
|
doc_DnaLookup="Serval JNI DNA Lookup"
|
2014-02-21 06:09:47 +00:00
|
|
|
setup_DnaLookup() {
|
|
|
|
configure_servald_server() {
|
|
|
|
add_servald_interface
|
2014-02-24 06:17:16 +00:00
|
|
|
executeOk_servald config \
|
|
|
|
set debug.mdprequests on \
|
|
|
|
set mdp.enable_inet on
|
2014-02-21 06:09:47 +00:00
|
|
|
}
|
|
|
|
setup
|
|
|
|
foreach_instance +A +B create_single_identity
|
|
|
|
start_servald_instances +A +B
|
|
|
|
set_instance +A
|
2016-10-12 06:38:26 +00:00
|
|
|
executeOk_servald dna lookup "$DIDB" 10000
|
|
|
|
tfw_cat --stdout --stderr
|
2014-02-21 06:09:47 +00:00
|
|
|
}
|
|
|
|
test_DnaLookup() {
|
2016-10-12 06:38:26 +00:00
|
|
|
executeJavaOk --timeout=10 org.servalproject.test.ServalDTests 'lookup'
|
2014-06-11 07:50:47 +00:00
|
|
|
assertStdoutGrep "$SIDB"
|
2014-02-21 06:09:47 +00:00
|
|
|
}
|
|
|
|
teardown_DnaLookup() {
|
|
|
|
stop_all_servald_servers
|
|
|
|
kill_all_servald_processes
|
|
|
|
assert_no_servald_processes
|
|
|
|
report_all_servald_servers
|
|
|
|
}
|
|
|
|
|
2014-06-11 07:50:47 +00:00
|
|
|
doc_serviceDiscovery="Serval JNI discover network services by name"
|
2014-05-09 00:32:44 +00:00
|
|
|
listen_service() {
|
2014-06-23 04:53:30 +00:00
|
|
|
executeOk_servald --timeout=20 msp listen --once --service=test_name 512 <<EOF
|
2014-05-09 00:32:44 +00:00
|
|
|
Hi!
|
|
|
|
EOF
|
|
|
|
tfw_cat --stderr
|
|
|
|
}
|
|
|
|
setup_serviceDiscovery() {
|
|
|
|
configure_servald_server() {
|
|
|
|
add_servald_interface
|
|
|
|
executeOk_servald config \
|
|
|
|
set debug.mdprequests on \
|
|
|
|
set mdp.enable_inet on \
|
|
|
|
set log.console.level debug
|
|
|
|
}
|
|
|
|
setup
|
|
|
|
set_instance +A
|
|
|
|
foreach_instance +A +B create_single_identity
|
|
|
|
start_servald_instances +A +B
|
|
|
|
set_instance +B
|
|
|
|
fork %service listen_service
|
|
|
|
set_instance +A
|
|
|
|
}
|
|
|
|
test_serviceDiscovery() {
|
2016-10-12 06:38:26 +00:00
|
|
|
executeJavaOk --timeout=10 org.servalproject.test.ServalDTests 'service' 'test_name.*'
|
2014-05-09 00:32:44 +00:00
|
|
|
assertStdoutGrep "$SIDB"
|
2014-06-11 07:50:47 +00:00
|
|
|
assertStdoutGrep "\<test_name\.msp\.port=512\>"
|
2014-05-09 00:32:44 +00:00
|
|
|
tfw_cat --stdout --stderr
|
2018-03-27 06:46:11 +00:00
|
|
|
executeOk_servald --timeout=20 msp connect "$SIDB" 512 <<EOF
|
2014-06-23 04:53:30 +00:00
|
|
|
Hi!
|
|
|
|
EOF
|
|
|
|
fork_wait %service
|
2014-05-09 00:32:44 +00:00
|
|
|
}
|
|
|
|
teardown_serviceDiscovery() {
|
|
|
|
stop_all_servald_servers
|
|
|
|
kill_all_servald_processes
|
|
|
|
assert_no_servald_processes
|
|
|
|
report_all_servald_servers
|
|
|
|
}
|
2014-06-11 07:50:47 +00:00
|
|
|
|
2015-05-25 02:16:37 +00:00
|
|
|
doc_servaldThread="Start servald in a JVM thread"
|
|
|
|
setup_servaldThread() {
|
|
|
|
setup
|
|
|
|
set_instance +A
|
|
|
|
create_single_identity
|
2016-10-12 06:38:26 +00:00
|
|
|
executeOk_servald config \
|
|
|
|
set debug.jni 1 \
|
2016-10-20 02:43:05 +00:00
|
|
|
set debug.server 1 \
|
2016-10-12 06:38:26 +00:00
|
|
|
set debug.verbose 1 \
|
|
|
|
set log.console.level debug
|
2015-05-25 02:16:37 +00:00
|
|
|
}
|
|
|
|
test_servaldThread() {
|
2016-10-12 06:38:26 +00:00
|
|
|
fork %server executeJavaOk --stdout-file=server_stdout --stderr-file=server_stderr org.servalproject.test.ServalDTests 'server'
|
|
|
|
wait_until --timeout=10 grep '^Started server' server_stdout
|
|
|
|
PID=$($SED -n -e '/^Started server/s/.* pid=\([0-9]\+\).*/\1/p' server_stdout)
|
|
|
|
assert [ -n "$PID" ]
|
|
|
|
assert kill -0 $PID 2>/dev/null
|
|
|
|
executeOk_servald status
|
|
|
|
extract_stdout_keyvalue status 'status' '.*'
|
|
|
|
extract_stdout_keyvalue pid 'pid' '[0-9]\+'
|
|
|
|
extract_stdout_keyvalue tid 'tid' '[0-9]\+'
|
|
|
|
assert [ "$status" = running ]
|
|
|
|
assert [ "$pid" -eq "$PID" ]
|
|
|
|
assert [ "$tid" -ne "$PID" ]
|
|
|
|
sleep 1
|
|
|
|
executeOk_servald stop
|
|
|
|
fork_wait %server
|
|
|
|
tfw_cat server_stdout server_stderr
|
2015-05-25 02:16:37 +00:00
|
|
|
}
|
|
|
|
|
2012-04-24 23:34:42 +00:00
|
|
|
runTests "$@"
|