File: testrunner.sh

package info (click to toggle)
pdns 3.4.1-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 9,084 kB
  • sloc: cpp: 56,420; ansic: 37,838; sh: 12,762; sql: 1,081; makefile: 734; ruby: 560; yacc: 222; lex: 120; perl: 52; python: 15
file content (150 lines) | stat: -rwxr-xr-x 2,642 bytes parent folder | download | duplicates (5)
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/env bash
set -x
new_api=0
mode=$1

# keep the original arguments for new test harness api
orig="$*"

# we could be ran with new API
while [ "$1" != "" ]
do
 if [ "$1" == "--" ]; then
   new_api=1
   mode=$2
   break
 fi
 shift
done

webrick_pid=""
socat_pid=""
zeromq_pid=""
socat=$(which socat)

function start_web() {
 ./unittest_$1.rb >> $mode.log 2>&1 & 
 webrick_pid=$!
 loopcount=0
 while [ $loopcount -lt 20 ]; do
   res=$(curl http://localhost:62434/ping 2>/dev/null)
   if [ "x$res" == "xpong" ]; then break; fi
   sleep 1
   let loopcount=loopcount+1
  done
}

function stop_web() {
 if [ ! -z "$webrick_pid" ]; then
   kill -TERM $webrick_pid
   # wait a moment for it to die
   i=0
   while [ $i -lt 5 ]; do
     sleep 1
     kill -0 $webrick_pid 2>/dev/null
     if [ $? -ne 0 ]; then break; fi
     let i=i+1
   done
 fi
}

function start_zeromq() {
  if [ x"$REMOTEBACKEND_ZEROMQ" == "xyes" ]; then
   ./unittest_zeromq.rb >> $mode.log 2>&1 &
   zeromq_pid=$!
   # need to wait a moment
   sleep 5
  fi
}

function stop_zeromq() {
 if [ ! -z "$zeromq_pid" ]; then
   kill -TERM $zeromq_pid 
   # wait a moment for it to die
   i=0
   while [ $i -lt 5 ]; do
     sleep 1
     kill -0 $zeromq_pid 2>/dev/null
     if [ $? -ne 0 ]; then break; fi
     let i=i+1
   done
   kill -0 $zeromq_pid 2>/dev/null
   if [ $? -eq 0 ]; then kill -9 $zeromq_pid; fi
 fi
}

function start_unix() {
  if [ -z "$socat" -o ! -x "$socat" ]; then
     echo "Cannot find socat - skipping test (non-fatal)"
     exit 0
  fi
  
  $socat unix-listen:/tmp/remotebackend.sock exec:./unittest_pipe.rb &
  socat_pid=$!
  sleep 1
}

function stop_unix() {
 if [ ! -z "$socat_pid" ]; then
   kill -TERM $socat_pid 2>/dev/null
   if [ $? -ne 0 ]; then
     # already dead
     return 
   fi
   # wait a moment for it to die
   i=0
   while [ $i -lt 5 ]; do
     sleep 1
     kill -0 $socat_pid 2>/dev/null
     if [ $? -ne 0 ]; then break; fi
     let i=i+1
   done
 fi
}

function run_test() {
 if [ $new_api -eq 0 ]; then
   ./$mode
 else
    $orig
 fi
}

mode=`basename "$mode"`

case "$mode" in
  test_remotebackend_pipe)
    run_test
  ;;
  test_remotebackend_unix)
    start_unix
    run_test
    stop_unix
  ;;
  test_remotebackend_http)
    start_web "http"
    run_test
    stop_web
  ;;
  test_remotebackend_post)
    start_web "post"
    run_test
    stop_web
  ;;
  test_remotebackend_json)
    start_web "json"
    run_test
    stop_web
  ;;
  test_remotebackend_zeromq)
    start_zeromq 
    run_test
    stop_zeromq
  ;;
  *)
     echo "Usage: $0 test_remotebackend_(pipe|unix|http|post|json|zeromq)"
     exit 1
  ;;
esac

exit $rv