Debian Codegraph @

tests/CI/runUnittests.sh

raw symbols SCIP
1 #!/usr/bin/env bash
2 CIDIR=$(dirname $(readlink -fn $0))
3 NO_EXPECT=0
4 source $CIDIR/ci.functions
5 ASTETCDIR=$DESTDIR/etc/asterisk
6
7 asterisk_corefile_glob() {
8 local pattern=$(/sbin/sysctl -n kernel.core_pattern)
9
10 # If core_pattern is a pipe there isn't much we can do
11 if [[ ${pattern:0:1} == "|" ]] ; then
12 echo "core*"
13 else
14 echo "${pattern%%%*}*"
15 fi
16 }
17
18 run_tests_expect() {
19 $EXPECT <<-EOF
20 spawn sudo $ASTERISK ${USER_GROUP:+-U ${USER_GROUP%%:*} -G ${USER_GROUP##*:}} -fcng -C $CONFFILE
21 match_max 512
22 set timeout 600
23 expect -notransfer "Asterisk Ready."
24 send "core show settings\r"
25 expect -notransfer "CLI>"
26 send "${UNITTEST_COMMAND:-test execute all}\r"
27 expect -notransfer -ex "Test(s) Executed"
28 expect -notransfer "CLI>"
29 send "test show results failed\r"
30 expect -notransfer "CLI>"
31 send "test generate results xml ${OUTPUTFILE}\r"
32 expect -notransfer "CLI>"
33 send "core stop now\r"
34 expect -notransfer "Executing last minute cleanups"
35 wait
36 EOF
37 }
38
39 run_tests_socket() {
40 sudo $ASTERISK ${USER_GROUP:+-U ${USER_GROUP%%:*} -G ${USER_GROUP##*:}} -gn -C $CONFFILE
41 for n in {1..5} ; do
42 sleep 3
43 $ASTERISK -rx "core waitfullybooted" -C $CONFFILE && break
44 done
45 sleep 1
46 $ASTERISK -rx "core show settings" -C $CONFFILE
47 $ASTERISK -rx "${UNITTEST_COMMAND:-test execute all}" -C $CONFFILE
48 $ASTERISK -rx "test show results failed" -C $CONFFILE
49 $ASTERISK -rx "test generate results xml $OUTPUTFILE" -C $CONFFILE
50 $ASTERISK -rx "core stop now" -C $CONFFILE
51 }
52
53 # If DESTDIR is used to install and run asterisk from non standard locations,
54 # the directory entries in asterisk.conf need to be munged to prepend DESTDIR.
55 ALTERED=$(head -10 "$ASTETCDIR/asterisk.conf" | grep -q "DESTDIR" && echo yes)
56 if [ x"$ALTERED" = x ] ; then
57 # In the section that starts with [directories and ends with a blank line,
58 # replace "=> " with "=> ${DESTDIR}"
59 sed -i -r -e "/^\[directories/,/^$/ s@=>\s+@=> ${DESTDIR}@" "$ASTETCDIR/asterisk.conf"
60 fi
61
62 cat <<-EOF > "$ASTETCDIR/logger.conf"
63 [logfiles]
64 full => notice,warning,error,debug,verbose
65 console => notice,warning,error
66 EOF
67
68 echo "[default]" > "$ASTETCDIR/extensions.conf"
69
70 cat <<-EOF > "$ASTETCDIR/manager.conf"
71 [general]
72 enabled=yes
73 bindaddr=127.0.0.1
74 port=5038
75
76 [test]
77 secret=test
78 read = system,call,log,verbose,agent,user,config,dtmf,reporting,cdr,dialplan
79 write = system,call,agent,user,config,command,reporting,originate
80 EOF
81
82 cat <<-EOF > "$ASTETCDIR/http.conf"
83 [general]
84 enabled=yes
85 bindaddr=127.0.0.1
86 bindport=8088
87 EOF
88
89 cat <<-EOF > "$ASTETCDIR/modules.conf"
90 [modules]
91 autoload=yes
92 noload=res_mwi_external.so
93 noload=res_mwi_external_ami.so
94 noload=res_ari_mailboxes.so
95 noload=res_stasis_mailbox.so
96 EOF
97
98 cat <<-EOF >> "$ASTETCDIR/sorcery.conf"
99 [res_pjsip_pubsub]
100 resource_list=memory
101 EOF
102
103 ASTERISK="$DESTDIR/usr/sbin/asterisk"
104 CONFFILE=$ASTETCDIR/asterisk.conf
105 OUTPUTDIR=${OUTPUT_DIR:-tests/CI/output/}
106 OUTPUTFILE=${OUTPUT_XML:-${OUTPUTDIR}/unittests-results.xml}
107 EXPECT="$(which expect 2>/dev/null || : )"
108
109 [ ! -d ${OUTPUTDIR} ] && mkdir -p $OUTPUTDIR
110 [ x"$USER_GROUP" != x ] && sudo chown -R $USER_GROUP $OUTPUTDIR
111
112 rm -rf $ASTETCDIR/extensions.{ael,lua} || :
113
114 set -x
115 if [ x"$EXPECT" != x -a $NO_EXPECT -eq 0 ] ; then
116 run_tests_expect
117 else
118 run_tests_socket
119 fi
120
121 # Cleanup "just in case"
122 sudo killall -qe -ABRT $ASTERISK
123
124 runner rsync -vaH $DESTDIR/var/log/asterisk/. $OUTPUTDIR
125 set +x
126
127 [ x"$USER_GROUP" != x ] && sudo chown -R $USER_GROUP $OUTPUTDIR
128
129 for core in $(asterisk_corefile_glob)
130 do
131 if [ -f "$core" ] && [ "${core##*.}" != "txt" ]
132 then
133 echo "*** Found a core file ($core) after running unit tests ***"
134 set -x
135 sudo $DESTDIR/var/lib/asterisk/scripts/ast_coredumper --outputdir=$OUTPUTDIR --no-default-search $core
136 fi
137 done
138
139 exit 0