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 \
|
|
|
|
set debug.verbose 1 \
|
|
|
|
set log.console.level debug
|
2012-04-24 07:36:48 +00:00
|
|
|
assert_echo_works
|
2012-04-23 08:55:26 +00:00
|
|
|
compile_java_classes
|
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() {
|
2014-06-11 07:50:47 +00:00
|
|
|
executeJavaOk org.servalproject.test.ServalDTests 'echo' '-e' 'Hello,\ttab' 'world\0!'
|
2014-02-23 23:27:51 +00:00
|
|
|
assertStdoutIs -e 'Hello,\ttab world\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() {
|
2014-06-11 07:50:47 +00:00
|
|
|
executeJavaOk org.servalproject.test.ServalDTests repeat 50 'echo' 'Hello,' 'world!'
|
2012-04-24 23:34:42 +00:00
|
|
|
assertStdoutLineCount '==' 50
|
2014-02-19 05:05:08 +00:00
|
|
|
assertStdoutGrep --matches=50 '^Hello, world! $'
|
2012-04-24 23:34:42 +00:00
|
|
|
}
|
2012-04-23 08:55:26 +00:00
|
|
|
|
2013-02-15 08:53:34 +00:00
|
|
|
doc_NullArg="Serval JNI null arguments throw exception"
|
|
|
|
test_NullArg() {
|
2014-06-11 07:50:47 +00:00
|
|
|
executeJava org.servalproject.test.ServalDTests 'echo' '(null)'
|
2013-02-15 08:53:34 +00:00
|
|
|
tfw_cat --stdout --stderr
|
|
|
|
assertExitStatus '!=' 0
|
|
|
|
assertStderrGrep 'NullPointerException: null element in argv'
|
|
|
|
}
|
|
|
|
|
2013-07-09 06:54:47 +00:00
|
|
|
doc_help="Serval JNI returns help text"
|
|
|
|
test_help() {
|
2014-06-11 07:50:47 +00:00
|
|
|
executeJavaOk org.servalproject.test.ServalDTests 'help'
|
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
|
|
|
|
}
|
|
|
|
test_PeerList() {
|
2014-06-11 07:50:47 +00:00
|
|
|
executeJavaOk org.servalproject.test.CommandLine 'peers'
|
2014-02-20 04:36:05 +00:00
|
|
|
assertStdoutGrep "$SIDB"
|
|
|
|
tfw_cat --stdout
|
|
|
|
}
|
|
|
|
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
|
|
|
|
}
|
|
|
|
test_DnaLookup() {
|
2014-06-11 07:50:47 +00:00
|
|
|
executeJavaOk --timeout=10 org.servalproject.test.CommandLine 'lookup'
|
2014-02-21 06:09:47 +00:00
|
|
|
tfw_cat --stdout --stderr
|
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() {
|
|
|
|
executeOk_servald --timeout=20 msp listen --service=test_name 512 <<EOF
|
|
|
|
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() {
|
2014-06-11 07:50:47 +00:00
|
|
|
executeJavaOk --timeout=10 org.servalproject.test.CommandLine '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
|
|
|
|
}
|
|
|
|
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
|
|
|
|
2012-04-24 23:34:42 +00:00
|
|
|
runTests "$@"
|