-
Notifications
You must be signed in to change notification settings - Fork 6
/
loopbacktest.sh
executable file
·114 lines (97 loc) · 2.89 KB
/
loopbacktest.sh
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
#!/bin/sh
#loopbacktest.sh
# David Young
# July 10, 2008
# script used in "make test" to ensure ion is functioning properly.
# script is expected to be run by automake, meaning:
# 1: Environment variable "srcdir" exists and points to the root directory of
# the ion source code.
# 2: The current working directory contains the built programs of ion.
# message sent over ion
IONMESSAGE="iontestmessage"
IONSENDFILE=./ionsendfile.txt
IONRECEIVEFILE=./ionreceivefile.txt
# adding ./ to path is VERY BAD. Do as I say, not as I do.
PRELOOPBACKPATH=${PATH}
PATH=".:${PATH}"
export PATH
CONFIGDIR="${srcdir}/configs/loopback-udp"
echo "Use config files in ${CONFIGDIR}"
echo "Added . to PATH. This is a very bad thing to do."
echo "PATH = ${PATH}"
echo
echo "Starting ION..."
echo "${srcdir}/ionstart -i ${CONFIGDIR}/loopback-udp.ionrc -b ${CONFIGDIR}/loopback-udp.bprc -p ${CONFIGDIR}/loopback-udp.ipnrc"
"${srcdir}/ionstart" -i "${CONFIGDIR}/loopback-udp.ionrc" -b "${CONFIGDIR}/loopback-udp.bprc" -p "${CONFIGDIR}/loopback-udp.ipnrc"
# create the test message in a sent file
echo "${IONMESSAGE}" > "${IONSENDFILE}"
# the exclamation point signals the bundle sender to quit
echo "!" >> "${IONSENDFILE}"
# receive the message and store it in a file via test bundle sink
echo
echo "Starting Message Listener..."
echo "bpsink ipn:1.1 > ${IONRECEIVEFILE} &"
bpsink ipn:1.1 > "${IONRECEIVEFILE}" &
BPSINKPID=${!}
# send the message in the file via test bundle source
sleep 5
echo
echo "Sending message..."
echo "bpsource ipn:1.1 < ${IONSENDFILE} &"
bpsource ipn:1.1 < "${IONSENDFILE}" &
BPSOURCEPID=${!}
# sleep and kill process in case it didn't end properly
sleep 5
echo
echo "Killing bpsource if it is still running..."
kill -9 ${BPSOURCEPID} >/dev/null 2>&1
# bpsink does not self-terminate, so send it SIGINT
sleep 5
echo
echo "Sending bpsink SIGINT..."
kill -2 ${BPSINKPID} >/dev/null 2>&1
# in case bpsink is unresponsive, send SIGKILL
sleep 5
echo "Killing bpsink..."
kill -9 ${BPSINKPID} >/dev/null 2>&1
echo
echo "Contents sent from ${IONSENDFILE}:"
cat "${IONSENDFILE}"
echo
echo "Contents received to ${IONRECEIVEFILE}:"
cat "${IONRECEIVEFILE}"
# compare the sent message to the received one
echo
echo "Comparing ${IONSENDFILE} to ${IONRECEIVEFILE}..."
grep "${IONMESSAGE}" "${IONRECEIVEFILE}" >/dev/null 2>/dev/null
RETVAL=${?}
if test "${RETVAL}" -ne 0 ; then
echo "Files do not match."
else
echo "Files match."
fi
# shut down ion processes
echo
echo "Stopping ion..."
echo "${srcdir}/ionstop"
"${srcdir}/ionstop"
# clean up
echo
echo "Cleaning up..."
echo
rm "${IONSENDFILE}" "${IONRECEIVEFILE}"
echo "Done"
echo "Any error messages may be found in ion.log"
PATH="${PRELOOPBACKPATH}"
export PATH
echo
echo "Removed . from PATH."
echo "PATH = ${PATH}"
echo
# return the result of the match
if test "${RETVAL}" -ne 0 ; then
echo "Returning '${RETVAL}' for failure."
else
echo "Returning '${RETVAL}' for success."
fi
exit ${RETVAL}