[c5c522c] | 1 | #!/bin/bash |
---|
| 2 | |
---|
| 3 | # (C)DatuX - Released under GPL |
---|
| 4 | # Asterisk stresstest script |
---|
| 5 | # Tries to discover asterisk unstability and regressions with sipp and special dialplans. |
---|
| 6 | # Usefull to find out you're using the wrong gcc/glibc/compiler options. |
---|
| 7 | # Configuration on target system is replaced with ./asteriskstress/asterisk/* |
---|
| 8 | |
---|
| 9 | |
---|
| 10 | source testlib || exit 1 |
---|
| 11 | |
---|
| 12 | for PAR in $*; do eval "$PAR=1" &>/dev/null; done |
---|
| 13 | |
---|
| 14 | if [ "$ASTERISK_SKIP_STRESS" ]; then |
---|
| 15 | echo "Skipping asterisk stress test..." |
---|
| 16 | exit 0 |
---|
| 17 | fi |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | DESCRIPTION1="Skip test if we dont have the right option in SYN-3" |
---|
| 21 | CMD=" |
---|
| 22 | if [ -e /etc/syn3-version ]; then |
---|
| 23 | grep '\"V\"' /etc/webint/REG || exit 1 |
---|
| 24 | else |
---|
| 25 | exit 0 |
---|
| 26 | fi |
---|
| 27 | " |
---|
| 28 | VERIFYEXIT=0 |
---|
| 29 | if ! sshtest; then |
---|
| 30 | echo "No voiceserver, test skipped" |
---|
| 31 | exit 0 |
---|
| 32 | fi |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | DESCRIPTION1="Check if box has enough memory (512mb)." |
---|
| 36 | CMD='[ `grep MemTotal /proc/meminfo|egrep -o "([0-9]+)"` -ge 512000 ]' |
---|
| 37 | VERIFYEXIT=0 |
---|
| 38 | sshtest || exit 1 |
---|
| 39 | |
---|
| 40 | #Execute a asterisk cli command |
---|
| 41 | asterisk_cmd() |
---|
| 42 | { |
---|
| 43 | CMD="asterisk -r -x '$ASTERISK_CMD'" |
---|
| 44 | DESCRIPTION1="Asterisk CLI command: $ASTERISK_CMD" |
---|
| 45 | VERIFYEXIT=0 |
---|
| 46 | VERIFYPOSITIVE="$ASTERISK_VERIFYPOSTIVE" |
---|
| 47 | VERIFYNEGATIVE="$ASTERISK_VERIFYNEGATIVE" |
---|
| 48 | sshtest |
---|
| 49 | return $? |
---|
| 50 | } |
---|
| 51 | |
---|
| 52 | #Check if asterisk is crashed or has logged errors |
---|
| 53 | crashcheck() |
---|
| 54 | { |
---|
| 55 | DESCRIPTION1="Check for asterisk crashes/errors... ($CASE)" |
---|
| 56 | CMD=" |
---|
| 57 | echo 'Asterisk core is still responding via CLI?' |
---|
| 58 | echo 'If not responding, either the load is too high or asterisk cant create new threads because of a glibc/gcc incompatiblity. You also need 512 mb memory!' |
---|
| 59 | asterisk -r -x 'core show uptime' | grep 'System uptime' || exit 1 |
---|
| 60 | |
---|
| 61 | echo 'Errors in asterisk logs?' |
---|
| 62 | cat /var/log/asterisk/full | |
---|
| 63 | grep -v 'Voicemail will be lost.' | |
---|
| 64 | grep -v 'RTCP .. transmission error' | |
---|
| 65 | grep ERROR && exit 1 |
---|
| 66 | " |
---|
| 67 | VERIFYEXIT=0 |
---|
| 68 | sshtest || exit 1 |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | #Wait untill asterisk crashes or sipp exists, or a timeout has occurred, |
---|
| 72 | #or on a couple of other optional checks.. |
---|
| 73 | crashwait() |
---|
| 74 | { |
---|
| 75 | (( END=$SECONDS+$MAXTIME )) |
---|
| 76 | |
---|
| 77 | while [ $SECONDS -lt $END ]; do |
---|
| 78 | crashcheck || exit 1 |
---|
| 79 | |
---|
| 80 | if [ "$ASTERISK_VERIFYPOSTIVE" ]; then |
---|
| 81 | DESCRIPTION1="Asterisk status check ($CASE)" |
---|
| 82 | asterisk_cmd || exit 1 |
---|
| 83 | #we only check positive things ONE time, because at the end of the test it might be gone |
---|
| 84 | if [ "$ASTERISK_VERIFYPOSTIVE" ]; then |
---|
| 85 | ASTERISK_VERIFYPOSTIVE= |
---|
| 86 | fi |
---|
| 87 | fi |
---|
| 88 | |
---|
| 89 | if [ "$UAC_NOERRORS" == 1 ]; then |
---|
| 90 | DESCRIPTION1="Sipp client has log no errors? ($CASE)" |
---|
| 91 | CMD=" |
---|
| 92 | test -s /root/asteriskstress/*_*_*errors.log || exit 1 |
---|
| 93 | " |
---|
| 94 | VERIFYEXIT=1 |
---|
| 95 | sshtest || exit 1 |
---|
| 96 | fi |
---|
| 97 | |
---|
| 98 | DESCRIPTION1="Sipp client has ended? ($CASE)" |
---|
| 99 | CMD=" |
---|
| 100 | pgrep -f '^sipp.*trace_screen' || exit 1 |
---|
| 101 | " |
---|
| 102 | VERIFYEXIT=1 |
---|
| 103 | sshtest && return 0 |
---|
| 104 | |
---|
| 105 | echo "Waiting until sipp client is done..., timeout after $MAXTIME seconds. ($CASE)" |
---|
| 106 | sleep 5 |
---|
| 107 | done |
---|
| 108 | echo "Timeout! Test didnt complete in time!" |
---|
| 109 | exit 1 |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | #runs SIPP test scenario for a certain time and check if nothing crashes or acts weird. |
---|
| 113 | sipprun() |
---|
| 114 | { |
---|
| 115 | #Auto-resume part. |
---|
| 116 | #Because these tests take LONG you can run the script with the 'resume' option. |
---|
| 117 | RESUMEFILE=".asteriskstress-$IP/`echo \"$CASE\" | md5sum|cut -f1 -d' '`" |
---|
| 118 | if [ -e $RESUMEFILE ]; then |
---|
| 119 | echo "SKIPPING CASE: $CASE" |
---|
| 120 | return 0 |
---|
| 121 | fi |
---|
| 122 | |
---|
| 123 | COUNT=0 |
---|
| 124 | #restart sipp client in case it crashes (happens a lot :() |
---|
| 125 | while true; do |
---|
| 126 | DESCRIPTION1="Start sipp test client... ($CASE)" |
---|
| 127 | CMD=" |
---|
| 128 | ulimit -c unlimited |
---|
| 129 | rm /root/asteriskstress/core* |
---|
| 130 | rm /root/asteriskstress/*_*_*.log |
---|
| 131 | ulimit -n 100000 |
---|
| 132 | cd /root/asteriskstress |
---|
| 133 | sipp -bind_local -i 127.0.0.1 -mi 127.0.0.1 -ci 127.0.0.1 -recv_timeout 60000 -send_timeout 60000 -bg -nostdin -trace_shortmsg -trace_screen -trace_err $PARS |
---|
| 134 | pgrep -f '^sipp.*trace_screen' || exit 1 |
---|
| 135 | " |
---|
| 136 | VERIFYEXIT=0 |
---|
| 137 | sshtest || exit 1 |
---|
| 138 | |
---|
| 139 | #give sipp a while to start connecting |
---|
| 140 | sleep 5 |
---|
| 141 | |
---|
| 142 | #wait and see what happens... |
---|
| 143 | crashwait |
---|
| 144 | |
---|
| 145 | DESCRIPTION1="sipp client has exited cleanly, without crash? ($CASE)" |
---|
| 146 | CMD=" |
---|
| 147 | pgrep -f '^sipp.*trace_screen' && exit 1 |
---|
| 148 | test -s /root/asteriskstress/*_*_screen.log || exit 1 |
---|
| 149 | " |
---|
| 150 | VERIFYEXIT=0 |
---|
| 151 | sshtest && break # everything went fine...break the loop |
---|
| 152 | |
---|
| 153 | (( COUNT++ )) |
---|
| 154 | echo "### sipp client crashed! restarting test! attempt number $COUNT ###" |
---|
| 155 | done |
---|
| 156 | |
---|
| 157 | DESCRIPTION1="sipp server still running? ($CASE)" |
---|
| 158 | CMD=" |
---|
| 159 | pgrep -f '^sipp.*uas' || exit 1 |
---|
| 160 | " |
---|
| 161 | VERIFYEXIT=0 |
---|
| 162 | sshtest || exit 1 |
---|
| 163 | |
---|
| 164 | #let asterisk restart convienently, to check for hanging threads etc.. |
---|
| 165 | if [ "$ASTERISK_RESTARTCONVENIENT" == "1" ]; then |
---|
| 166 | restart_convenient |
---|
| 167 | fi |
---|
| 168 | |
---|
| 169 | |
---|
| 170 | #Done, mark resume file |
---|
| 171 | touch $RESUMEFILE |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | restart_all() |
---|
| 175 | { |
---|
| 176 | VERIFYEXIT=0 |
---|
| 177 | DESCRIPTION1="Copy config, clear environment, restart asterisk" |
---|
| 178 | CMD=" |
---|
| 179 | svc -d /service/asterisk &>/dev/null |
---|
| 180 | killall -9 sipp |
---|
| 181 | killall -9 safe_asterisk asterisk |
---|
| 182 | sleep 1; |
---|
| 183 | rm /etc/asterisk/* |
---|
| 184 | cp /root/asteriskstress/asterisk/* /etc/asterisk || exit 1 |
---|
| 185 | rm /var/log/asterisk/full; |
---|
| 186 | rm /home/system/asterisk/spool/voicemail/default/1002/INBOX/* |
---|
| 187 | rm /home/system/asterisk/spool/voicemail/default/1002/INBOX/.* |
---|
| 188 | if which svc &>/dev/null; then |
---|
| 189 | #start on syn3: |
---|
| 190 | echo 'Starting SYN-3 asterisk' |
---|
| 191 | svc -do /service/asterisk |
---|
| 192 | else |
---|
| 193 | #start manually |
---|
| 194 | echo 'Starting manual asterisk' |
---|
| 195 | ulimit -n 100000 |
---|
| 196 | asterisk |
---|
| 197 | fi |
---|
| 198 | sleep 3 |
---|
| 199 | " |
---|
| 200 | sshtest || exit 1 |
---|
| 201 | |
---|
| 202 | |
---|
| 203 | DESCRIPTION1="Restart sipp server" |
---|
| 204 | CMD=" |
---|
| 205 | ulimit -n 100000 |
---|
| 206 | sipp -sn uas -cp 18888 -bind_local -i 127.0.0.2 -mi 127.0.0.2 -ci 127.0.0.2 -mp 16000 -p 15060 -bg -nostdin |
---|
| 207 | pgrep -f '^sipp.*uas' || exit 1 |
---|
| 208 | " |
---|
| 209 | VERIFYEXIT=0 |
---|
| 210 | sshtest || exit 1 |
---|
| 211 | |
---|
| 212 | #turn of verbose and debugging, to increase performcance and decrease log size |
---|
| 213 | ASTERISK_CMD="core set verbose 0" |
---|
| 214 | ASTERISK_VERIFYPOSTIVE= |
---|
| 215 | asterisk_cmd || exit 1 |
---|
| 216 | |
---|
| 217 | ASTERISK_CMD="core set debug 0" |
---|
| 218 | ASTERISK_VERIFYPOSITIVE= |
---|
| 219 | asterisk_cmd || exit 1 |
---|
| 220 | |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | #Let asterisk restart when convienent. |
---|
| 224 | #This way we can check for hanging threads. |
---|
| 225 | restart_convenient() |
---|
| 226 | { |
---|
| 227 | CMD="ls -il /var/run/asterisk/asterisk.* > /tmp/oldstatus" |
---|
| 228 | sshtest || exit 1 |
---|
| 229 | |
---|
| 230 | ASTERISK_CMD="restart when convenient" |
---|
| 231 | asterisk_cmd || exit 1 |
---|
| 232 | |
---|
| 233 | (( END=$SECONDS+ $MAXTIME )) |
---|
| 234 | |
---|
| 235 | while [ $SECONDS -lt $END ]; do |
---|
| 236 | DESCRIPTION1="Has asterisk restarted yet? ($CASE)" |
---|
| 237 | CMD=" |
---|
| 238 | ls -il /var/run/asterisk/asterisk.* > /tmp/newstatus |
---|
| 239 | cmp /tmp/oldstatus /tmp/newstatus && exit 1 |
---|
| 240 | " |
---|
| 241 | VERIFYEXIT=0 |
---|
| 242 | sshtest && return 0 |
---|
| 243 | echo "Waiting for asterisk to restart when convenient.." |
---|
| 244 | sleep 5 |
---|
| 245 | done |
---|
| 246 | echo "Timeout! Test didnt complete in time!" |
---|
| 247 | exit 1 |
---|
| 248 | |
---|
| 249 | } |
---|
| 250 | |
---|
| 251 | ################################### PREPERATION ################################# |
---|
| 252 | |
---|
| 253 | if ! [ "$resume" ]; then |
---|
| 254 | rm -r .asteriskstress-$IP &>/dev/null |
---|
| 255 | fi |
---|
| 256 | mkdir .asteriskstress-$IP &>/dev/null |
---|
| 257 | |
---|
| 258 | scptest "asteriskstress" || exit 1 |
---|
| 259 | |
---|
| 260 | |
---|
| 261 | |
---|
| 262 | MAXTIME=3600 |
---|
| 263 | |
---|
| 264 | ################### TEST CASES ########################################## |
---|
| 265 | |
---|
| 266 | #start with a clean asterisk environment |
---|
| 267 | restart_all |
---|
| 268 | |
---|
| 269 | |
---|
| 270 | |
---|
| 271 | |
---|
| 272 | CASE="Meetme test without audio. Asterisk will be unable to create new threads if you have the wrong glibc/gcc/kernelmodule. This also tests the dahdi kernel module." |
---|
| 273 | PARS="-sn uac -s 1000 localhost -users 1000 -m 4000 -d 5000" |
---|
| 274 | ASTERISK_CMD="show channels" |
---|
| 275 | ASTERISK_VERIFYPOSTIVE="MeetMe" |
---|
| 276 | UAC_NOERRORS= |
---|
| 277 | ASTERISK_RESTARTCONVENIENT= #takes too long for meetme |
---|
| 278 | sipprun |
---|
| 279 | #forcefully restart everything, to recover from the heavy meetme test. (takes ages otherwise) |
---|
| 280 | restart_all |
---|
| 281 | |
---|
| 282 | CASE="Meetme test with audio. Causes 100% softinterupts that freese whole box if you have the wrong glibc/gcc/kenelmodule. (This also tests the dahdi kernel module.)" |
---|
| 283 | PARS="-sn uac_pcap -s 1000 localhost -r 20 -m 2000 " |
---|
| 284 | ASTERISK_CMD="show channels" |
---|
| 285 | ASTERISK_VERIFYPOSTIVE="MeetMe" |
---|
| 286 | UAC_NOERRORS= |
---|
| 287 | ASTERISK_RESTARTCONVENIENT= #takes too long for meetme |
---|
| 288 | sipprun |
---|
| 289 | # forcefully restart everything, to recover from the heavy meetme test. (takes ages otherwise) |
---|
| 290 | restart_all |
---|
| 291 | |
---|
| 292 | |
---|
| 293 | CASE="Parking lot test" |
---|
| 294 | PARS="-sn uac_pcap -s 1001 localhost -r 20 -m 2000 " |
---|
| 295 | ASTERISK_CMD="show channels" |
---|
| 296 | ASTERISK_VERIFYPOSTIVE="Park" |
---|
| 297 | UAC_NOERRORS= |
---|
| 298 | ASTERISK_RESTARTCONVENIENT=1 |
---|
| 299 | sipprun |
---|
| 300 | |
---|
| 301 | |
---|
| 302 | CASE="Voicemail test" |
---|
| 303 | PARS="-sn uac_pcap -s 1002 localhost -r 10 -m 1000 " |
---|
| 304 | ASTERISK_CMD="show channels" |
---|
| 305 | ASTERISK_VERIFYPOSTIVE="VoiceMail" |
---|
| 306 | UAC_NOERRORS= |
---|
| 307 | ASTERISK_RESTARTCONVENIENT=1 |
---|
| 308 | sipprun |
---|
| 309 | |
---|
| 310 | |
---|
| 311 | |
---|
| 312 | #call/second rate and total calls for codec tests |
---|
| 313 | #keep this low, because sipp client is checked for errors in this test. |
---|
| 314 | RATE=2 |
---|
| 315 | CALLS=200 |
---|
| 316 | |
---|
| 317 | CASE="Codec g729 transcoding" |
---|
| 318 | PARS="-sn uac_pcap -s 209 localhost -r $RATE -m $CALLS " |
---|
| 319 | ASTERISK_CMD="sip show channels" |
---|
| 320 | ASTERISK_VERIFYPOSTIVE="g729" |
---|
| 321 | UAC_NOERRORS=1 |
---|
| 322 | sipprun |
---|
| 323 | |
---|
| 324 | CASE="Codec g723 transcoding" |
---|
| 325 | PARS="-sn uac_pcap -s 201 localhost -r 1 -m 200 " |
---|
| 326 | ASTERISK_CMD="sip show channels" |
---|
| 327 | ASTERISK_VERIFYPOSTIVE="g723" |
---|
| 328 | UAC_NOERRORS=1 |
---|
| 329 | sipprun |
---|
| 330 | |
---|
| 331 | # CASE="Codec g722 transcoding" |
---|
| 332 | # PARS="-sn uac_pcap -s 213 localhost -r 1 -m 200 " |
---|
| 333 | # ASTERISK_CMD="sip show channels" |
---|
| 334 | # ASTERISK_VERIFYPOSTIVE="g722" |
---|
| 335 | # UAC_NOERRORS=1 |
---|
| 336 | # sipprun |
---|
| 337 | |
---|
| 338 | |
---|
| 339 | CASE="Codec g726 transcoding" |
---|
| 340 | PARS="-sn uac_pcap -s 212 localhost -r $RATE -m $CALLS " |
---|
| 341 | ASTERISK_CMD="sip show channels" |
---|
| 342 | ASTERISK_VERIFYPOSTIVE="g726" |
---|
| 343 | UAC_NOERRORS=1 |
---|
| 344 | ASTERISK_RESTARTCONVENIENT=1 |
---|
| 345 | sipprun |
---|
| 346 | |
---|
| 347 | # CASE="Codec ilbc transcoding" |
---|
| 348 | # PARS="-sn uac_pcap -s 211 localhost -r $RATE -m $CALLS " |
---|
| 349 | # ASTERISK_CMD="sip show channels" |
---|
| 350 | # ASTERISK_VERIFYPOSTIVE="ilbc" |
---|
| 351 | # UAC_NOERRORS=1 |
---|
| 352 | # sipprun |
---|
| 353 | |
---|
| 354 | # CASE="Codec speex transcoding" |
---|
| 355 | # PARS="-sn uac_pcap -s 210 localhost -r $RATE -m $CALLS " |
---|
| 356 | # ASTERISK_CMD="sip show channels" |
---|
| 357 | # ASTERISK_VERIFYPOSTIVE="speex" |
---|
| 358 | # UAC_NOERRORS=1 |
---|
| 359 | # sipprun |
---|
| 360 | |
---|
| 361 | |
---|
| 362 | CASE="Codec lpc10 transcoding" |
---|
| 363 | PARS="-sn uac_pcap -s 208 localhost -r $RATE -m $CALLS " |
---|
| 364 | ASTERISK_CMD="sip show channels" |
---|
| 365 | ASTERISK_VERIFYPOSTIVE="lpc10" |
---|
| 366 | ASTERISK_RESTARTCONVENIENT=1 |
---|
| 367 | UAC_NOERRORS=1 |
---|
| 368 | sipprun |
---|
| 369 | |
---|
| 370 | CASE="Codec slin transcoding" |
---|
| 371 | PARS="-sn uac_pcap -s 207 localhost -r $RATE -m $CALLS " |
---|
| 372 | ASTERISK_CMD="sip show channels" |
---|
| 373 | ASTERISK_VERIFYPOSTIVE="slin" |
---|
| 374 | ASTERISK_RESTARTCONVENIENT=1 |
---|
| 375 | UAC_NOERRORS=1 |
---|
| 376 | sipprun |
---|
| 377 | |
---|
| 378 | CASE="Codec adpcm transcoding" |
---|
| 379 | PARS="-sn uac_pcap -s 206 localhost -r $RATE -m $CALLS " |
---|
| 380 | ASTERISK_CMD="sip show channels" |
---|
| 381 | ASTERISK_VERIFYPOSTIVE="adpcm" |
---|
| 382 | ASTERISK_RESTARTCONVENIENT=1 |
---|
| 383 | UAC_NOERRORS=1 |
---|
| 384 | sipprun |
---|
| 385 | |
---|
| 386 | CASE="Codec g726aal2 transcoding" |
---|
| 387 | PARS="-sn uac_pcap -s 205 localhost -r $RATE -m $CALLS " |
---|
| 388 | ASTERISK_CMD="sip show channels" |
---|
| 389 | ASTERISK_VERIFYPOSTIVE="g726aal2" |
---|
| 390 | ASTERISK_RESTARTCONVENIENT=1 |
---|
| 391 | UAC_NOERRORS=1 |
---|
| 392 | sipprun |
---|
| 393 | |
---|
| 394 | |
---|
| 395 | CASE="Codec alaw (sipp pcap uses this too, so now actual transcoding is done)" |
---|
| 396 | PARS="-sn uac_pcap -s 204 localhost -r $RATE -m $CALLS " |
---|
| 397 | ASTERISK_CMD="sip show channels" |
---|
| 398 | ASTERISK_VERIFYPOSTIVE="alaw" |
---|
| 399 | ASTERISK_RESTARTCONVENIENT=1 |
---|
| 400 | UAC_NOERRORS=1 |
---|
| 401 | sipprun |
---|
| 402 | |
---|
| 403 | CASE="Codec ulaw transcoding" |
---|
| 404 | PARS="-sn uac_pcap -s 203 localhost -r $RATE -m $CALLS " |
---|
| 405 | ASTERISK_CMD="sip show channels" |
---|
| 406 | ASTERISK_VERIFYPOSTIVE="ulaw" |
---|
| 407 | ASTERISK_RESTARTCONVENIENT=1 |
---|
| 408 | UAC_NOERRORS=1 |
---|
| 409 | sipprun |
---|
| 410 | |
---|
| 411 | CASE="Codec gsm transcoding" |
---|
| 412 | PARS="-sn uac_pcap -s 202 localhost -r $RATE -m $CALLS " |
---|
| 413 | ASTERISK_CMD="sip show channels" |
---|
| 414 | ASTERISK_VERIFYPOSTIVE="gsm" |
---|
| 415 | ASTERISK_RESTARTCONVENIENT=1 |
---|
| 416 | UAC_NOERRORS=1 |
---|
| 417 | sipprun |
---|
| 418 | |
---|
| 419 | |
---|
| 420 | #probleem 1: na een test die zowel voicemail als normale nummers belt, blijven er een aantal Dials hangen. |
---|
| 421 | #dus alleen met 1002 en 203 in de stress.csv |
---|
| 422 | CASE="Random test of everything (heavy and takes a lot of time)" |
---|
| 423 | PARS="-sf uac_stress.xml -inf stress.csv localhost -users 100 -m 10000 " |
---|
| 424 | ASTERISK_CMD= |
---|
| 425 | ASTERISK_VERIFYPOSTIVE= |
---|
| 426 | ASTERISK_RESTARTCONVENIENT= #kan niet, ivm probleem 1 |
---|
| 427 | UAC_NOERRORS= |
---|
| 428 | sipprun |
---|
| 429 | |
---|
| 430 | |
---|
| 431 | echo "########################################################" |
---|
| 432 | echo "All tests successfull" |
---|