Remove temporary
[anna.git] / example / diameter / launcher / deployments / ft-client / tests / experiment1 / common.sh
1 #!/bin/bash
2
3 #############
4 # FUNCTIONS #
5 #############
6
7 _exit () {
8   echo
9   echo $1
10   echo
11   exit 1
12 }
13
14 sigint_handler() {
15   _exit "Script interrupted. Cleanup & exit ..."
16 }
17
18 # $1: hex formatted file to send to the server
19 send_xml () {
20   ../../operation.sh "sendxml|$1"
21 }
22
23 send_hex () {
24   sleep 1
25   ../../operation.sh "sendhex|$1"
26 }
27
28 # $1: pattern; $2: file
29 check_pattern () {
30   echo "Matching pattern '$1' ..." 
31   cat $2 | tr '\n' ' ' | egrep "$1" >/dev/null
32   res=${PIPESTATUS[2]}
33   [ $? -ne 0 ] && _exit "Test failed: miss pattern !!"
34 }
35
36 test_ok () {
37   echo
38   echo $1
39   echo "Test OK !"
40   echo
41   exit 0
42 }
43
44 test_failed () {
45   echo
46   echo $1
47   echo "Test FAILED !"
48   echo
49   exit 1
50 }
51
52
53 # $1: traffic log to monitor
54 # $2: timeout (request expiration) in seconds
55 # Result: cats the message when completed
56 monitor_4_message () {
57   0>$1
58   rm -f .msg_received
59
60   [ -z "$2" ] && _exit "ERROR: must provide '$FUNCNAME' timeout (second argument)"
61   sleep $2 &
62   local timerPid=$!
63
64   # Monitor for incoming message:
65   tail -n0 -F --pid=$timerPid $1 | while read line 
66   do
67     if echo $line | grep "^</message>" >/dev/null; then
68       echo "Message received"
69       # stop the timer
70       kill -13 $timerPid
71       touch .msg_received
72     fi
73   done
74
75   if [ ! -f .msg_received ]; then
76     echo "Timeout expired"
77     return 1
78   fi
79
80   return 0
81 }
82
83 #############
84 # EXECUTION #
85 #############
86
87 # Trap sigint signal:
88 trap sigint_handler SIGINT
89