Statistics
| Branch: | Revision:

grapes / src / Tests / test.sh @ 176b8de8

History | View | Annotate | Download (3.57 KB)

1
#!/bin/bash
2
#launch it e.g. like this:
3
#./test.sh -e "offerstreamer-ml" -n 5 -s "-m 1" -p "-b 40 -o 5 -c 25" -f "chbuf" -A "other args"
4
#./test.sh -e "offerstreamer-ml" -f chbuf
5

    
6
PIDS=""
7

    
8
#defaults
9
SOURCE_PORT=6666
10
PEER_PORT_BASE=5555
11
NUM_PEERS=1
12
FILTER="neigh"
13
CLIENT="./topology_test"
14
CLIENT_ARGS=""
15
IFACE=""
16

    
17
CHURN_MAX=30
18
CHURN_MIN=30
19
CHURN_WAIT=10
20
CHURN_PORT_INCR=100
21
STARTUP_WAIT=0
22

    
23
function churn {
24
  # Kill everything we've started on exit (with trap).
25
  trap "ps -o pid= --ppid $BASHPID | xargs kill 2>/dev/null" 0
26

    
27
  MIN=$1
28
  MAX=$2
29
  PAUSE=$3
30
  PORT=$4
31
  PORT_INCREMENT=$5
32

    
33
  if [ $MIN -lt $MAX ]; then
34
    let "RUN=$MIN+($RANDOM%($MAX-$MIN))"
35
  else
36
    RUN=$MIN
37
  fi
38

    
39
  while [ 1 ] ; do
40
#    echo "$VALGRIND $CLIENT $PEER_OPTIONS $IFACE -P $PORT -i 127.0.0.1 -p $SOURCE_PORT $CLIENT_ARGS" > cmd.$PORT
41
    $VALGRIND $CLIENT $PEER_OPTIONS $IFACE -P $PORT -i 127.0.0.1 -p $SOURCE_PORT $CLIENT_ARGS 2>stderr.$PORT > stdout.$PORT &
42
    PID=$!
43
    sleep $RUN
44
    kill $PID
45
    sleep $PAUSE
46
    ((PORT+=PORT_INCREMENT))
47
  done
48

    
49
}
50

    
51

    
52

    
53
#process options
54
while getopts "s:S:p:I:P:N:f:e:v:VX:A:C:c:t:T:w:W:" opt; do
55
  case $opt in
56
    s)
57
      SOURCE_OPTIONS=$OPTARG
58
      ;;
59
    S)
60
      SOURCE_PORT=$OPTARG
61
      ;;
62
    p)
63
      PEER_OPTIONS=$OPTARG
64
      ;;
65
#    P)
66
#      PEER_PORT_BASE=$OPTARG
67
#      ;;
68
    I)
69
     IFACE="-I $OPTARG"
70
     ;;
71
    N)
72
      NUM_PEERS=$OPTARG
73
      ;;
74
    f)  #TODO
75
      FILTER=$OPTARG
76
      ;;
77
    e)
78
      CLIENT=$OPTARG
79
      ;;
80
    v)
81
      VIDEO=$OPTARG
82
      ;;
83
    V)  #TODO
84
      VALGRIND="valgrind --error-exitcode=1 --track-origins=yes  --leak-check=full "
85
      VALGRIND="valgrind --error-exitcode=1 --leak-check=full "
86
      ;;
87
    X)
88
      NUM_PEERS_X=$OPTARG
89
      ;;
90
    A)
91
      CLIENT_ARGS=$OPTARG
92
      ;;
93
    C)
94
      NUM_PEERS_C=$OPTARG
95
      ;;
96
    c)
97
      CHURN_PORT_INCR=$OPTARG
98
      ;;
99
    t)
100
      CHURN_MIN=$OPTARG
101
      ;;
102
    T)
103
      CHURN_MAX=$OPTARG
104
      ;;
105
    w)
106
      CHURN_WAIT=$OPTARG
107
      ;;
108
    W)
109
      STARTUP_WAIT=$OPTARG
110
      ;;
111
    \?)
112
      echo "Invalid option: -$OPTARG" >&2
113
      exit 1
114
      ;;
115
    :)
116
      echo "Option -$OPTARG requires an argument." >&2
117
      exit 1
118
      ;;
119
  esac
120
done
121

    
122
$VALGRIND $CLIENT $SOURCE_OPTIONS $IFACE $CLIENT_ARGS &
123
PIDS=$!
124

    
125
sleep 2
126
((PEER_PORT_MAX=PEER_PORT_BASE + NUM_PEERS - 1))
127
for PORT in `seq $PEER_PORT_BASE 1 $PEER_PORT_MAX`; do
128
    $VALGRIND $CLIENT $PEER_OPTIONS $IFACE -P $PORT -i 127.0.0.1 -p $SOURCE_PORT $CLIENT_ARGS 2>stderr.$PORT > stdout.$PORT &
129
    PIDS="$!,$PIDS"
130
done
131

    
132
((PEER_PORT_BASE = PEER_PORT_MAX + 1))
133
((PEER_PORT_MAX=PEER_PORT_BASE + NUM_PEERS_X - 1))
134
if [ $PEER_PORT_BASE -le $PEER_PORT_MAX ]; then
135
    for PORT in `seq $PEER_PORT_BASE 1 $PEER_PORT_MAX`; do
136
    #  valgrind --track-origins=yes  --leak-check=full \ TODO!!!
137
        FIFO=fifo.$PORT
138
        rm -f $FIFO
139
        mkfifo $FIFO
140
        xterm -e "$CLIENT $PEER_OPTIONS $IFACE -P $PORT -i 127.0.0.1 -p $SOURCE_PORT $CLIENT_ARGS >$FIFO 2>stderr.$PORT | grep '$FILTER' $FIFO" &
141
        PIDS="$!,$PIDS"
142
    done
143
fi
144

    
145
((PEER_PORT_BASE = PEER_PORT_MAX + 1))
146
((PEER_PORT_MAX=PEER_PORT_BASE + NUM_PEERS_C - 1))
147
for PORT in `seq $PEER_PORT_BASE 1 $PEER_PORT_MAX`; do
148
    churn $CHURN_MIN $CHURN_MAX $CHURN_WAIT $PORT $CHURN_PORT_INCR &
149
    sleep $STARTUP_WAIT
150
done
151

    
152
# Kill everything we've stared on exit (with trap).
153
if [ `uname -s` = "Linux" ]; then
154
    echo "Installing linux trap..."
155
    trap "ps -o pid= --ppid $$ | xargs kill -9 2>/dev/null" 0;
156
elif [ `uname -s` = "Darwin" ]; then
157
    echo "Installing darwin trap..."
158

    
159
    trap "ps -o pid= -p '$PIDS' | xargs kill -9 2>/dev/null" 0;
160
fi
161

    
162
#valgrind --track-origins=yes  --leak-check=full TODO!
163
wait