forked from servalproject/serval-dna
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjni
executable file
·200 lines (186 loc) · 5.67 KB
/
jni
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/bin/bash
# Tests for Serval DNA JNI entry points.
#
# 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
# 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%/*}/../testdefs_java.sh"
setup() {
setup_servald
executeOk_servald config \
set debug.jni 1 \
set debug.verbose 1 \
set log.console.level debug
assert_echo_works
assert_java_classes_exist
setup_servald_so
}
# 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() {
executeJavaOk org.servalproject.test.CommandLine 'echo' '-e' 'Hello,\ttab' 'world\0!'
tfw_cat --stdout --stderr
assertStdoutIs -e 'Hello,\ttab\nworld\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() {
executeJavaOk org.servalproject.test.CommandLine --repeat 50 'echo' 'Hello,' 'world!'
assertStdoutLineCount '==' 100
assertStdoutGrep --matches=50 '^Hello,$'
assertStdoutGrep --matches=50 '^world!$'
}
doc_NullArg="Serval JNI null arguments dont throw exception"
test_NullArg() {
executeJavaOk org.servalproject.test.CommandLine 'echo' '(null)'
tfw_cat --stdout --stderr
}
doc_version="Serval JNI returns version text"
test_version() {
executeJavaOk org.servalproject.test.CommandLine 'version'
assertStdoutGrep 'Serval DNA version '
}
doc_PeerList="Serval JNI get peer details"
setup_PeerList() {
configure_servald_server() {
add_servald_interface
}
setup
foreach_instance +A +B create_single_identity
start_servald_instances +A +B
set_instance +A
executeOk_servald 'id' 'peers'
tfw_cat --stdout --stderr
}
test_PeerList() {
executeJavaOk org.servalproject.test.CommandLine 'id' 'peers'
tfw_cat --stdout --stderr
assertStdoutGrep "$SIDB"
}
teardown_PeerList() {
stop_all_servald_servers
kill_all_servald_processes
assert_no_servald_processes
report_all_servald_servers
}
doc_DnaLookup="Serval JNI DNA Lookup"
setup_DnaLookup() {
configure_servald_server() {
add_servald_interface
executeOk_servald config \
set debug.mdprequests on \
set mdp.enable_inet on
}
setup
foreach_instance +A +B create_single_identity
start_servald_instances +A +B
set_instance +A
executeOk_servald dna lookup "$DIDB" 10000
tfw_cat --stdout --stderr
}
test_DnaLookup() {
executeJavaOk --timeout=10 org.servalproject.test.ServalDTests 'lookup'
assertStdoutGrep "$SIDB"
}
teardown_DnaLookup() {
stop_all_servald_servers
kill_all_servald_processes
assert_no_servald_processes
report_all_servald_servers
}
doc_serviceDiscovery="Serval JNI discover network services by name"
listen_service() {
executeOk_servald --timeout=20 msp listen --once --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() {
executeJavaOk --timeout=10 org.servalproject.test.ServalDTests 'service' 'test_name.*'
assertStdoutGrep "$SIDB"
assertStdoutGrep "\<test_name\.msp\.port=512\>"
tfw_cat --stdout --stderr
executeOk_servald --timeout=20 msp connect $SIDB 512 <<EOF
Hi!
EOF
fork_wait %service
}
teardown_serviceDiscovery() {
stop_all_servald_servers
kill_all_servald_processes
assert_no_servald_processes
report_all_servald_servers
}
doc_servaldThread="Start servald in a JVM thread"
setup_servaldThread() {
setup
set_instance +A
create_single_identity
executeOk_servald config \
set debug.jni 1 \
set debug.server 1 \
set debug.verbose 1 \
set log.console.level debug
}
test_servaldThread() {
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
}
runTests "$@"