Statistics
| Branch: | Revision:

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

History | View | Annotate | Download (3.57 KB)

1 fa213294 Luca
#!/bin/bash
2
#launch it e.g. like this:
3 90b7deba Andrea Zito
#./test.sh -e "offerstreamer-ml" -n 5 -s "-m 1" -p "-b 40 -o 5 -c 25" -f "chbuf" -A "other args"
4 fa213294 Luca
#./test.sh -e "offerstreamer-ml" -f chbuf
5
6 90b7deba Andrea Zito
PIDS=""
7 fa213294 Luca
8
#defaults
9
SOURCE_PORT=6666
10
PEER_PORT_BASE=5555
11
NUM_PEERS=1
12
FILTER="neigh"
13
CLIENT="./topology_test"
14 90b7deba Andrea Zito
CLIENT_ARGS=""
15
IFACE=""
16 fa213294 Luca
17 fe2ba9bc luca abeni
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 fa213294 Luca
#process options
54 fe2ba9bc luca abeni
while getopts "s:S:p:I:P:N:f:e:v:VX:A:C:c:t:T:w:W:" opt; do
55 fa213294 Luca
  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 fe2ba9bc luca abeni
#    P)
66
#      PEER_PORT_BASE=$OPTARG
67
#      ;;
68 90b7deba Andrea Zito
    I)
69
     IFACE="-I $OPTARG"
70
     ;;
71 fa213294 Luca
    N)
72
      NUM_PEERS=$OPTARG
73
      ;;
74 90b7deba Andrea Zito
    f)  #TODO
75 fa213294 Luca
      FILTER=$OPTARG
76
      ;;
77
    e)
78
      CLIENT=$OPTARG
79
      ;;
80
    v)
81
      VIDEO=$OPTARG
82
      ;;
83 90b7deba Andrea Zito
    V)  #TODO
84 f7074f9e luca
      VALGRIND="valgrind --error-exitcode=1 --track-origins=yes  --leak-check=full "
85
      VALGRIND="valgrind --error-exitcode=1 --leak-check=full "
86 fa213294 Luca
      ;;
87
    X)
88
      NUM_PEERS_X=$OPTARG
89
      ;;
90 90b7deba Andrea Zito
    A)
91
      CLIENT_ARGS=$OPTARG
92
      ;;
93 fe2ba9bc luca abeni
    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 fa213294 Luca
    \?)
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 90b7deba Andrea Zito
$VALGRIND $CLIENT $SOURCE_OPTIONS $IFACE $CLIENT_ARGS &
123
PIDS=$!
124 fa213294 Luca
125 1aa763ee Luca
sleep 2
126 fa213294 Luca
((PEER_PORT_MAX=PEER_PORT_BASE + NUM_PEERS - 1))
127
for PORT in `seq $PEER_PORT_BASE 1 $PEER_PORT_MAX`; do
128 90b7deba Andrea Zito
    $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 fa213294 Luca
done
131
132
((PEER_PORT_BASE = PEER_PORT_MAX + 1))
133
((PEER_PORT_MAX=PEER_PORT_BASE + NUM_PEERS_X - 1))
134 90b7deba Andrea Zito
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 fe2ba9bc luca abeni
        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 90b7deba Andrea Zito
        PIDS="$!,$PIDS"
142
    done
143
fi
144 fa213294 Luca
145 fe2ba9bc luca abeni
((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 90b7deba Andrea Zito
# 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 fa213294 Luca
159 90b7deba Andrea Zito
    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 fa213294 Luca
wait