8 DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
13 source "$(dir)/../ansi_codes.sh"
17 PAD=$(printf '%0.1s' "."{1..80})
18 printf "${_BOLD}%s${ANSI_RESET}" "$1 "
20 DIFF=$(diff "$(dir)/$4" "$(dir)/$3")
21 if [ "$DIFF" != "" ]; then
22 printf "%*.*s" 0 $((67 - ${#1})) "$PAD"
23 printf " ${_BOLD}${_RED}%s${ANSI_RESET}\n" "[FAILED]"
27 printf "%*.*s" 0 $((66 - ${#1})) "$PAD"
28 printf " ${_BOLD}${_GREEN}%s${ANSI_RESET}\n" "[SUCCESS]"
33 function shutdown_background() {
35 for ((i = ${#array[@]} - 1; i >= 0; i--)); do
36 kill -SIGINT ${array[i]} 2>/dev/null
42 function do_nothing() {
43 echo "do nothing" >/dev/null
47 function test_ast_printing() {
48 "$(dir)/../../build/mavtables" --ast --conf "$(dir)/../mavtables.conf" \
49 | tail -n +2 > "$(dir)/mavtables.log"
53 function test_complex_ast_printing() {
54 "$(dir)/../../build/mavtables" --ast \
55 --conf "$(dir)/complex_config.conf" \
56 | tail -n +2 > "$(dir)/complex_config.log"
60 function test_all_v1_packets_udp() {
61 socat pty,link=./ttyS0,raw,echo=0 pty,link=./ttyS1,raw,echo=0 &
63 "$(dir)/../../build/mavtables" --conf "$(dir)/all_1serial.conf" &
64 "$(dir)/logger.py" 12 26 --udp 127.0.0.1:14500 \
65 > "$(dir)/all_v1_packets_udp_to_udp.log" &
66 "$(dir)/logger.py" 29 39 --serial ./ttyS1 \
67 > "$(dir)/all_v1_packets_udp_to_serial.log" &
69 "$(dir)/packet_scripter.py" 192 168 "$(dir)/all_v1_packets.pks" \
70 --udp 127.0.0.1:14500 --mavlink1
76 function test_all_v2_packets_udp() {
77 socat pty,link=./ttyS0,raw,echo=0 pty,link=./ttyS1,raw,echo=0 &
79 "$(dir)/../../build/mavtables" --conf "$(dir)/all_1serial.conf" &
80 "$(dir)/logger.py" 12 26 --udp 127.0.0.1:14500 \
81 > "$(dir)/all_v2_packets_udp_to_udp.log" &
82 "$(dir)/logger.py" 29 39 --serial ./ttyS1 \
83 > "$(dir)/all_v2_packets_udp_to_serial.log" &
85 "$(dir)/packet_scripter.py" 192 168 "$(dir)/all_v2_packets.pks" \
92 function test_all_v1_packets_serial() {
93 socat pty,link=./ttyS0,raw,echo=0 pty,link=./ttyS1,raw,echo=0 &
94 socat pty,link=./ttyS2,raw,echo=0 pty,link=./ttyS3,raw,echo=0 &
96 "$(dir)/../../build/mavtables" --conf "$(dir)/all_2serial.conf" &
97 "$(dir)/logger.py" 12 26 --udp 127.0.0.1:14500 \
98 > "$(dir)/all_v1_packets_serial_to_udp.log" &
99 "$(dir)/logger.py" 29 39 --serial ./ttyS1 \
100 > "$(dir)/all_v1_packets_serial_to_serial.log" &
102 "$(dir)/packet_scripter.py" 192 168 "$(dir)/all_v1_packets.pks" \
103 --serial ./ttyS3 --mavlink1
109 function test_all_v2_packets_serial() {
110 socat pty,link=./ttyS0,raw,echo=0 pty,link=./ttyS1,raw,echo=0 &
111 socat pty,link=./ttyS2,raw,echo=0 pty,link=./ttyS3,raw,echo=0 &
113 "$(dir)/../../build/mavtables" --conf "$(dir)/all_2serial.conf" &
114 "$(dir)/logger.py" 12 26 --udp 127.0.0.1:14500 \
115 > "$(dir)/all_v2_packets_serial_to_udp.log" &
116 "$(dir)/logger.py" 29 39 --serial ./ttyS1 \
117 > "$(dir)/all_v2_packets_serial_to_serial.log" &
119 "$(dir)/packet_scripter.py" 192 168 "$(dir)/all_v2_packets.pks" \
126 function test_multiple_senders_v1_packets() {
127 socat pty,link=./ttyS0,raw,echo=0 pty,link=./ttyS1,raw,echo=0 &
128 socat pty,link=./ttyS2,raw,echo=0 pty,link=./ttyS3,raw,echo=0 &
130 "$(dir)/../../build/mavtables" --conf "$(dir)/all_2serial.conf" &
131 "$(dir)/logger.py" 12 26 --udp 127.0.0.1:14500 --verbose \
132 | sort --version-sort \
133 > "$(dir)/multiple_senders_v1_packets_to_udp.log" &
134 "$(dir)/logger.py" 10 20 --serial ./ttyS1 --verbose \
135 | sort --version-sort \
136 > "$(dir)/multiple_senders_v1_packets_to_serial.log" &
138 "$(dir)/packet_scripter.py" 192 168 "$(dir)/all_v1_packets.pks" \
139 --udp 127.0.0.1:14500 --mavlink1 &
140 "$(dir)/packet_scripter.py" 172 128 "$(dir)/all_v1_packets.pks" \
141 --udp 127.0.0.1:14500 --mavlink1 &
142 "$(dir)/packet_scripter.py" 127 1 "$(dir)/all_v1_packets.pks" \
143 --serial ./ttyS3 --mavlink1
149 function test_multiple_senders_v2_packets() {
150 socat pty,link=./ttyS0,raw,echo=0 pty,link=./ttyS1,raw,echo=0 &
151 socat pty,link=./ttyS2,raw,echo=0 pty,link=./ttyS3,raw,echo=0 &
153 "$(dir)/../../build/mavtables" --conf "$(dir)/all_2serial.conf" &
154 "$(dir)/logger.py" 12 26 --udp 127.0.0.1:14500 --verbose \
155 | sort --version-sort \
156 > "$(dir)/multiple_senders_v2_packets_to_udp.log" &
157 "$(dir)/logger.py" 10 20 --serial ./ttyS1 --verbose \
158 | sort --version-sort \
159 > "$(dir)/multiple_senders_v2_packets_to_serial.log" &
161 "$(dir)/packet_scripter.py" 192 168 "$(dir)/all_v2_packets.pks" \
162 --udp 127.0.0.1:14500 &
163 "$(dir)/packet_scripter.py" 172 128 "$(dir)/all_v2_packets.pks" \
164 --udp 127.0.0.1:14500 &
165 "$(dir)/packet_scripter.py" 127 1 "$(dir)/all_v2_packets.pks" \
172 function test_routing_v1_packets() {
173 socat pty,link=./ttyS0,raw,echo=0 pty,link=./ttyS1,raw,echo=0 &
175 "$(dir)/../../build/mavtables" --conf "$(dir)/routing.conf" &
176 "$(dir)/logger.py" 127 1 --udp 127.0.0.1:14500 \
177 > "$(dir)/routing_v1_packets_127.1.log" &
178 "$(dir)/logger.py" 192 168 --udp 127.0.0.1:14500 \
179 > "$(dir)/routing_v1_packets_192.168.log" &
180 "$(dir)/logger.py" 172 128 --serial ./ttyS1 \
181 > "$(dir)/routing_v1_packets_172.128.log" &
183 "$(dir)/packet_scripter.py" 10 10 "$(dir)/routing.pks" \
184 --udp 127.0.0.1:14500 --mavlink1
190 function test_routing_v2_packets() {
191 socat pty,link=./ttyS0,raw,echo=0 pty,link=./ttyS1,raw,echo=0 &
193 "$(dir)/../../build/mavtables" --conf "$(dir)/routing.conf" &
194 "$(dir)/logger.py" 127 1 --udp 127.0.0.1:14500 \
195 > "$(dir)/routing_v2_packets_127.1.log" &
196 "$(dir)/logger.py" 192 168 --udp 127.0.0.1:14500 \
197 > "$(dir)/routing_v2_packets_192.168.log" &
198 "$(dir)/logger.py" 172 128 --serial ./ttyS1 \
199 > "$(dir)/routing_v2_packets_172.128.log" &
201 "$(dir)/packet_scripter.py" 10 10 "$(dir)/routing.pks" \
202 --udp 127.0.0.1:14500
208 function test_priority() {
209 perl -e 'for$i(1..50){print "ENCAPSULATED_DATA\n"}' \
210 > "$(dir)/priority.tmp"
211 perl -e 'for$i(1..100){print "ATTITUDE\n"}' \
212 >> "$(dir)/priority.tmp"
213 perl -e 'for$i(1..100){print "GLOBAL_POSITION_INT\n"}' \
214 >> "$(dir)/priority.tmp"
215 perl -e 'for$i(1..50){print "ENCAPSULATED_DATA\n"}' \
216 >> "$(dir)/priority.tmp"
217 socat pty,link=./ttyS0,raw,echo=0 pty,link=./ttyS1,raw,echo=0 &
219 "$(dir)/../../build/mavtables" --conf "$(dir)/priority.conf" &
220 "$(dir)/logger.py" 192 168 --udp 127.0.0.1:14500 > "$(dir)/priority.log" &
222 "$(dir)/packet_scripter.py" 10 10 "$(dir)/priority.tmp" --serial ./ttyS1
224 perl -e 'for$i(1..100){print "ENCAPSULATED_DATA\n"}' \
225 > "$(dir)/priority.tmp"
226 perl -e 'for$i(1..100){print "GLOBAL_POSITION_INT\n"}' \
227 >> "$(dir)/priority.tmp"
228 perl -e 'for$i(1..100){print "ATTITUDE\n"}' \
229 >> "$(dir)/priority.tmp"
234 function test_preload_addresses() {
235 socat pty,link=./ttyS0,raw,echo=0 pty,link=./ttyS1,raw,echo=0 &
237 "$(dir)/../../build/mavtables" --conf "$(dir)/preload.conf" &
238 "$(dir)/logger.py" 10 10 --noheartbeat --serial ./ttyS1 \
239 > "$(dir)/preload.log" &
241 "$(dir)/packet_scripter.py" 123 123 "$(dir)/routing.pks" \
242 --udp 127.0.0.1:14500
248 function test_component_broadcast_fallback() {
249 perl -e 'for$i(0..255){print "MISSION_REQUEST_LIST to 1.$i\n"}' \
250 > "$(dir)/component_broadcast_fallback.tmp"
251 socat pty,link=./ttyS0,raw,echo=0 pty,link=./ttyS1,raw,echo=0 &
253 "$(dir)/../../build/mavtables" \
254 --conf "$(dir)/component_broadcast_fallback.conf" &
255 "$(dir)/logger.py" 1 1 --verbose --serial ./ttyS1 \
256 > "$(dir)/component_broadcast_fallback.log" &
258 "$(dir)/packet_scripter.py" 10 10 \
259 "$(dir)/component_broadcast_fallback.tmp" \
260 --udp 127.0.0.1:14500
262 'for$i(128..255){print "MISSION_REQUEST_LIST from 10.10 to 1.$i\n"}' \
263 > "$(dir)/component_broadcast_fallback.tmp"
269 function test_large_packets() {
270 perl -e 'for$i(1..5000){print "ENCAPSULATED_DATA\n"}' \
271 > "$(dir)/large_packets.tmp"
272 socat pty,link=./ttyS0,raw,echo=0 pty,link=./ttyS1,raw,echo=0 &
273 socat pty,link=./ttyS2,raw,echo=0 pty,link=./ttyS3,raw,echo=0 &
275 "$(dir)/../../build/mavtables" --conf "$(dir)/all_2serial.conf" &
276 "$(dir)/logger.py" 12 26 --udp 127.0.0.1:14500 \
277 > "$(dir)/large_packets_to_udp.log" &
278 "$(dir)/logger.py" 10 20 --serial ./ttyS1 \
279 > "$(dir)/large_packets_to_serial.log" &
281 "$(dir)/packet_scripter.py" 192 168 "$(dir)/large_packets.tmp" \
282 --udp 127.0.0.1:14500 &
283 "$(dir)/packet_scripter.py" 172 128 "$(dir)/large_packets.tmp" \
286 perl -e 'for$i(1..5000){print "ENCAPSULATED_DATA\n"}' \
287 >> "$(dir)/large_packets.tmp"
292 function test_logging_level1() {
293 socat pty,link=./ttyS0,raw,echo=0 pty,link=./ttyS1,raw,echo=0 &
295 "$(dir)/../../build/mavtables" --loglevel 1 --conf "$(dir)/routing.conf" \
296 > "$(dir)/logging_level1.log" &
298 "$(dir)/logger.py" 127 1 --udp 127.0.0.1:14500 > /dev/null &
300 "$(dir)/logger.py" 192 168 --udp 127.0.0.1:14500 > /dev/null &
302 "$(dir)/logger.py" 172 128 --serial ./ttyS1 > /dev/null &
304 "$(dir)/packet_scripter.py" 10 10 "$(dir)/routing.pks" \
305 --udp 127.0.0.1:14500
307 sed -i 's/^.....................//' "$(dir)/logging_level1.log"
308 sed -i 's/:[0-9]*//g' "$(dir)/logging_level1.log"
313 function test_logging_level2() {
314 socat pty,link=./ttyS0,raw,echo=0 pty,link=./ttyS1,raw,echo=0 &
316 "$(dir)/../../build/mavtables" --loglevel 2 --conf "$(dir)/routing.conf" \
317 > "$(dir)/logging_level2.log" &
319 "$(dir)/logger.py" 127 1 --udp 127.0.0.1:14500 > /dev/null &
321 "$(dir)/logger.py" 192 168 --udp 127.0.0.1:14500 > /dev/null &
323 "$(dir)/logger.py" 172 128 --serial ./ttyS1 > /dev/null &
325 "$(dir)/packet_scripter.py" 10 10 "$(dir)/routing.pks" \
326 --udp 127.0.0.1:14500
328 sed -i 's/^.....................//' "$(dir)/logging_level2.log"
329 sed -i 's/:[0-9]*//g' "$(dir)/logging_level2.log"
334 function test_logging_level3() {
335 socat pty,link=./ttyS0,raw,echo=0 pty,link=./ttyS1,raw,echo=0 &
337 "$(dir)/../../build/mavtables" --loglevel 3 --conf "$(dir)/routing.conf" \
338 > "$(dir)/logging_level3.log" &
340 "$(dir)/logger.py" 127 1 --udp 127.0.0.1:14500 > /dev/null &
342 "$(dir)/logger.py" 192 168 --udp 127.0.0.1:14500 > /dev/null &
344 "$(dir)/logger.py" 172 128 --serial ./ttyS1 > /dev/null &
346 "$(dir)/packet_scripter.py" 10 10 "$(dir)/routing.pks" \
347 --udp 127.0.0.1:14500
349 sed -i 's/^.....................//' "$(dir)/logging_level3.log"
350 sed -i 's/:[0-9]*//g' "$(dir)/logging_level3.log"
355 echo -en "${_BOLD}${_BLUE}*---------------------------------------"
356 echo -en "--------------------------------------*\n"
357 echo -en "${_BOLD}${_BLUE}| "
358 echo -en "Integration Tests"
360 echo -en "${_BOLD}${_BLUE}*---------------------------------------"
361 echo -en "--------------------------------------*\n"
362 echo -en "${ANSI_RESET}"
365 rm "$(dir)"/*.log 2>/dev/null
372 echo -en "${_BOLD}${_ITALICS}${_RED}Integration testing is not currently "
373 echo -en "supported on Mac OS X.${ANSI_RESET}\n\n"
381 echo "unknown operating system: $OSTYPE"
387 function check_fail() {
388 if [ "$?" -ne "0" ]; then
394 run_test "Abstract Syntax Tree printing with --ast flag" \
398 run_test "Complex Abstract Syntax Tree printing with --ast flag" \
399 test_complex_ast_printing \
404 run_test "All MAVLink v1.0 packets from UDP to UDP" \
405 test_all_v1_packets_udp \
407 all_v1_packets_udp_to_udp.log
408 run_test "All MAVLink v1.0 packets from UDP to serial port" \
411 all_v1_packets_udp_to_serial.log
412 run_test "All MAVLink v2.0 packets from UDP to UDP" \
413 test_all_v2_packets_udp \
415 all_v2_packets_udp_to_udp.log
416 run_test "All MAVLink v2.0 packets from UDP to serial port" \
419 all_v2_packets_udp_to_serial.log
422 run_test "All MAVLink v1.0 packets from serial port to UDP" \
423 test_all_v1_packets_serial \
425 all_v1_packets_serial_to_udp.log
426 run_test "All MAVLink v1.0 packets from serial port to serial port" \
429 all_v1_packets_serial_to_serial.log
430 run_test "All MAVLink v2.0 packets from serial port to UDP" \
431 test_all_v2_packets_serial \
433 all_v2_packets_serial_to_udp.log
434 run_test "All MAVLink v2.0 packets from serial port to serial port" \
437 all_v2_packets_serial_to_serial.log
440 run_test "Multiple senders with MAVLink v1.0 packets to UDP" \
441 test_multiple_senders_v1_packets \
442 multiple_senders_v1_packets.cmp \
443 multiple_senders_v1_packets_to_udp.log
444 run_test "Multiple senders with MAVLink v1.0 packets to serial port" \
446 multiple_senders_v1_packets.cmp \
447 multiple_senders_v1_packets_to_serial.log
448 run_test "Multiple senders with MAVLink v2.0 packets to UDP" \
449 test_multiple_senders_v2_packets \
450 multiple_senders_v2_packets.cmp \
451 multiple_senders_v2_packets_to_udp.log
452 run_test "Multiple senders with MAVLink v2.0 packets to serial port" \
454 multiple_senders_v2_packets.cmp \
455 multiple_senders_v2_packets_to_serial.log
458 run_test "Routing MAVLink v1.0 packets (part 1 - 127.1)" \
459 test_routing_v1_packets routing_127.1.cmp routing_v1_packets_127.1.log
460 run_test "Routing MAVLink v1.0 packets (part 2 - 192.168)" \
461 do_nothing routing_192.168.cmp routing_v1_packets_192.168.log
462 run_test "Routing MAVLink v1.0 packets (part 3 - 172.128)" \
463 do_nothing routing_172.128.cmp routing_v1_packets_172.128.log
466 run_test "Routing MAVLink v2.0 packets (part 1 - 127.1)" \
467 test_routing_v2_packets routing_127.1.cmp routing_v2_packets_127.1.log
468 run_test "Routing MAVLink v2.0 packets (part 2 - 192.168)" \
469 do_nothing routing_192.168.cmp routing_v2_packets_192.168.log
470 run_test "Routing MAVLink v2.0 packets (part 3 - 172.128)" \
471 do_nothing routing_172.128.cmp routing_v2_packets_172.128.log
474 run_test "High priority packets are transmitted first" \
475 test_priority priority.tmp priority.log
478 run_test "Serial ports can be preloaded with MAVLink addresses" \
479 test_preload_addresses preload.cmp preload.log
482 run_test "Component broadcast fallback and MAVLink subnets" \
483 test_component_broadcast_fallback \
484 component_broadcast_fallback.tmp \
485 component_broadcast_fallback.log
488 run_test "Many large packets with multiple senders to UDP" \
489 test_large_packets large_packets.tmp large_packets_to_udp.log
490 run_test "Many large packets with multiple senders to serial port" \
491 do_nothing large_packets.tmp large_packets_to_serial.log
494 run_test "Logging level 1" \
495 test_logging_level1 logging_level1.cmp logging_level1.log
496 run_test "Logging level 2" \
497 test_logging_level2 logging_level2.cmp logging_level2.log
498 run_test "Logging level 3" \
499 test_logging_level3 logging_level3.cmp logging_level3.log
502 if [ "$FAIL" -ne "0" ]; then