File: testing.exp

package info (click to toggle)
arping 2.26-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,084 kB
  • sloc: sh: 4,691; ansic: 3,894; exp: 405; python: 142; makefile: 34
file content (417 lines) | stat: -rwxr-xr-x 11,457 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
#!/usr/bin/expect -f
#
# Usage: testing.exp <path to arping> <ifname> <ip address> <mac address>
#
# Test all cases against a "normal" machine:
# * Responds to ARP
# * Responds to ping
# * Doesn't respond to broadcast pings.
#
# Abnormal machines, to be tested elsewhere:
# * Proxy ARP
# * Respond to broadcast pings
# * Lost packets
# * Duplicated replies
#
# Tested here:
# * -a
# * -c
# * -d (minimally)
# * -D
# * -e
# * -h
# * -q (soon)
# * -r
# * -R
# * -s (soon)
# * -S (soon)
# * -t
# * -T
# * -u (soon)
# * -v (soon)
# * -w (soon)
# * -W (soon)
#
# Not tested here:
# * -0
# * -A (forced on with mac ping)
# * -b
# * -B
# * -p
# * -P
# * -U
# * -V
# * Mac ping without -T.
#
set bin [lindex $argv 0]
set ifname [lindex $argv 1]
set ip [lindex $argv 2]
set mac [lindex $argv 3]
set bad_ip "1.2.4.3"
set bad_mac "00:11:22:33:44:55"

# Check if "stty -oxtabs" is a thing.
# It is on OpenBSD, but not Linux.
spawn tty
expect eof
spawn "stty" "-oxtabs"
catch wait result
if {[lindex $result 3] == 0} {
    set stty_init "-oxtabs"
}

# Helper functions.
proc want_err {code} {
    lassign [wait] pid spawnid os_error_flag value
    if {$os_error_flag != 0} {
        puts "No error code provided"
        exit 1
    }
    if {$value != $code} {
        puts "Wrong error code. Want $code, got $value"
        exit 1
    }
}


send_user -- "--------------- No options ------------------\n"
spawn $bin
expect -re "ARPing 2\.\d+, by Thomas Habets <thomas@habets.se>\r
usage: arping \\\[ -0aAbdDeFpqrRuUv \\\] \\\[ -w <us> \\\] \\\[ -S <host/ip> \\\]\r
\\\[ -T <host/ip \\\] \\\[ -s <MAC> \\\] \\\[ -t <MAC> \\\] \\\[ -c <count> \\\]\r
\\\[ -i <interface> \\\] <host/ip/MAC | -B>\r
For complete usage info, use --help or check the manpage.\r
"
expect eof
want_err 1

send_user -- "--------------- -h ------------------\n"
spawn $bin -h
expect -re "ARPing 2\.\d+, by Thomas Habets <thomas@habets.se>\r
usage: arping \\\[ -0aAbdDeFpqrRuUv \\\] \\\[ -w <us> \\\] \\\[ -S <host/ip> \\\]\r
\\\[ -T <host/ip \\\] \\\[ -s <MAC> \\\] \\\[ -t <MAC> \\\] \\\[ -c <count> \\\]\r
\\\[ -i <interface> \\\] <host/ip/MAC | -B>\r
For complete usage info, use --help or check the manpage.\r
"
expect eof
want_err 0

send_user -- "--------------- --help ------------------\n"
spawn $bin --help
expect -re "ARPing 2\.\d+, by Thomas Habets <thomas@habets.se>\r
usage: arping \\\[ -0aAbdDeFpqrRuUv \\\] \\\[ -w <us> \\\] \\\[ -S <host/ip> \\\]\r
\\\[ -T <host/ip \\\] \\\[ -s <MAC> \\\] \\\[ -t <MAC> \\\] \\\[ -c <count> \\\]\r
\\\[ -i <interface> \\\] <host/ip/MAC | -B>\r
\r
"
expect "Report bugs to: thomas@habets.se\r
Arping home page: <http://www.habets.pp.se/synscan/>\r
Development repo: http://github.com/ThomasHabets/arping\r
"
expect eof
want_err 0

send_user -- "--------------- Bad interface ------------------\n"
spawn $bin -i uhtaonuhoes $ip
expect -re "arping: libnet_init.*\r"
expect "\r" {
    # Make sure double-endline is stripped.
    exit 1
}
want_err 1

send_user -- "--------------- Ping IP Simple ------------------\n"
spawn $bin -c 1 $ip
expect -re "ARPING $ip\r
\(42|60\) bytes from $mac \\($ip\\): index=0 time=(.*)sec\r
\r
--- $ip statistics ---\r
1 packets transmitted, 1 packets received,   0% unanswered \\(0 extra\\)\r
rtt min/avg/max/std-dev = \[0-9.\]+/\[0-9.\]+/\[0-9.\]+/0.000 ms\r
"
expect eof
want_err 0

send_user -- "--------------- Ping IP Raw (-r) ------------------\n"
spawn $bin -c 2 -r $ip
expect -re "$mac\r
$mac\r
"
expect eof
want_err 0

send_user -- "--------------- Ping IP Raw audio (-r -a) ------------------\n"
spawn $bin -c 2 -r -a $ip
expect -re "\a$mac\r
\a$mac\r
"
expect eof
want_err 0

send_user -- "--------------- Ping IP Raw audio bad dest (-r -e) ------------------\n"
spawn $bin -c 2 -r -i "$ifname" -e $bad_ip
expect -re "\a\a"
expect eof
want_err 1

send_user -- "--------------- Ping IP reverse raw (-R) ------------------\n"
spawn $bin -c 2 -R $ip
expect -re "$ip\r
$ip\r
"
expect eof
want_err 0

send_user -- "--------------- Ping IP double raw (-R) ------------------\n"
spawn $bin -c 2 -R -r $ip
expect -re "$mac $ip\r
$mac $ip\r
"
expect eof
want_err 0

send_user -- "--------------- Ping IP max 2 (-C) ------------------\n"
spawn $bin -C 2 -c 10 $ip
expect -re "ARPING $ip\r
\(42|60\) bytes from $mac \\($ip\\): index=0 time=(.*)sec\r
\(42|60\) bytes from $mac \\($ip\\): index=1 time=(.*)sec\r
\r
--- $ip statistics ---\r
2 packets transmitted, 2 packets received,   0% unanswered \\(0 extra\\)\r
rtt min/avg/max/std-dev = \[0-9.\]+/\[0-9.\]+/\[0-9.\]+/\[0-9.\]+ ms\r
"
expect eof
want_err 0

send_user -- "--------------- Ping IP x 3 (-c) ------------------\n"
spawn $bin -c 3 $ip
expect -re "ARPING $ip\r
\(42|60\) bytes from $mac \\($ip\\): index=0 time=\[0-9.\]+ \[mu\]?sec\r
\(42|60\) bytes from $mac \\($ip\\): index=1 time=\[0-9.\]+ \[mu\]?sec\r
\(42|60\) bytes from $mac \\($ip\\): index=2 time=\[0-9.\]+ \[mu\]?sec\r
\r
--- $ip statistics ---\r
3 packets transmitted, 3 packets received,   0% unanswered \\(0 extra\\)\r
rtt min/avg/max/std-dev = \[0-9.\]+/\[0-9.\]+/\[0-9.\]+/\[0-9.\]+ ms\r
"
expect eof
want_err 0

send_user -- "--------------- Ping IP x 3 with audio (-a)  ------------------\n"
spawn $bin -c 3 -a $ip
expect -re "ARPING $ip\r
\a\(42|60\) bytes from $mac \\($ip\\): index=0 time=\[0-9.\]+ \[mu\]?sec\r
\a\(42|60\) bytes from $mac \\($ip\\): index=1 time=\[0-9.\]+ \[mu\]?sec\r
\a\(42|60\) bytes from $mac \\($ip\\): index=2 time=\[0-9.\]+ \[mu\]?sec\r
\r
--- $ip statistics ---\r
3 packets transmitted, 3 packets received,   0% unanswered \\(0 extra\\)\r
rtt min/avg/max/std-dev = \[0-9.\]+/\[0-9.\]+/\[0-9.\]+/\[0-9.\]+ ms\r
"
expect eof
want_err 0

send_user -- "--------- Ping IP x 2 with inverted audio (-e)  ------------\n"
spawn $bin -c 2 -e $ip
expect -re "ARPING $ip\r
\(42|60\) bytes from $mac \\($ip\\): index=0 time=\[0-9.\]+ \[mu\]?sec\r
\(42|60\) bytes from $mac \\($ip\\): index=1 time=\[0-9.\]+ \[mu\]?sec\r
\r
--- $ip statistics ---\r
2 packets transmitted, 2 packets received,   0% unanswered \\(0 extra\\)\r
rtt min/avg/max/std-dev = \[0-9.\]+/\[0-9.\]+/\[0-9.\]+/\[0-9.\]+ ms\r
"
expect eof
want_err 0

send_user -- "--------- Ping IP x 2 with inverted audio, bad IP (-e)  ------------\n"
spawn $bin -c 2 -i "$ifname" -e "$bad_ip"
expect -re "ARPING $bad_ip\r
\aTimeout\r
\aTimeout\r
\r
--- $bad_ip statistics ---\r
2 packets transmitted, 0 packets received, 100% unanswered \\(0 extra\\)\r
\r
"
expect eof
want_err 1

send_user -- "--------- Ping IP x 2 with inverted audio (-e -D)  ------------\n"
spawn $bin -c 2 -e -D $ip
expect "!!\t  0% packet loss (0 extra)\r\n"
expect eof
want_err 0

send_user -- "--------- Ping IP x 2 with inverted audio, bad IP (-e -D)  ------------\n"
spawn $bin -c 2 -e -i $ifname -D "$bad_ip"
expect "\a.\a.\t100% packet loss (0 extra)\r\n"
expect eof
want_err 1

send_user -- "--------------- Ping IP cisco style (-D) ------------------\n"
spawn $bin -c 3 -D $ip
expect "!!!\t  0% packet loss (0 extra)\r\n"
expect eof
want_err 0

send_user -- "--------------- Ping IP cisco style with audio (-D -a) -----------\n"
spawn $bin -c 3 -D -a $ip
expect "\a!\a!\a!\t  0% packet loss (0 extra)\r\n"
expect eof
want_err 0

send_user -- "--------------- Ping IP Targeted (-t) ------------------\n"
spawn $bin -c 1 -t $mac $ip
expect -re "ARPING $ip\r
\(42|60\) bytes from $mac \\($ip\\): index=0 time=(.*)sec\r
\r
--- $ip statistics ---\r
1 packets transmitted, 1 packets received,   0% unanswered \\(0 extra\\)\r
rtt min/avg/max/std-dev = \[0-9.\]+/\[0-9.\]+/\[0-9.\]+/0.000 ms\r
"
expect eof
want_err 0

send_user -- "--------------- Ping IP Mistargeted (-t) ------------------\n"
spawn $bin -c 1 -t $bad_mac $ip
expect "ARPING $ip\r
Timeout\r
\r
--- $ip statistics ---\r
1 packets transmitted, 0 packets received, 100% unanswered \\(0 extra\\)\r
"
expect eof
want_err 1

send_user -- "--------------- Ping MAC with IP destination ------------------\n"
spawn $bin -A -c 1 -T $ip $mac
expect -re "ARPING $mac\r
\(42|60\) bytes from $ip \\($mac\\): icmp_seq=0 time=(.*)sec\r
\r
--- $mac statistics ---\r
1 packets transmitted, 1 packets received,   0% unanswered \\(0 extra\\)\r
rtt min/avg/max/std-dev = \[0-9.\]+/\[0-9.\]+/\[0-9.\]+/0.000 ms\r
"
expect eof
want_err 0

send_user -- "--------------- Ping MAC Raw (-r) ------------------\n"
spawn $bin -c 2 -r -T $ip $mac
expect -re "$ip\r
$ip\r
"
expect eof
want_err 0

send_user -- "--------------- Ping MAC Raw audio (-r -a) ------------------\n"
spawn $bin -c 2 -a -r -T $ip $mac
expect -re "\a$ip\r
\a$ip\r
"
expect eof
want_err 0

send_user -- "--------------- Ping MAC Raw audio bad dest (-r -e) ------------------\n"
spawn $bin -c 2 -r -e -T $ip $bad_mac
expect -re "\a\a"
expect eof
want_err 1

send_user -- "--------------- Ping MAC reverse raw (-R) ------------------\n"
spawn $bin -c 2 -R -T $ip $mac
expect -re "$mac\r
$mac\r
"
expect eof
want_err 0

send_user -- "--------------- Ping MAC double raw (-a -R) ------------------\n"
spawn $bin -c 2 -R -r -T $ip $mac
expect -re "$mac $ip\r
$mac $ip\r
"
expect eof
want_err 0


send_user -- "--------------- Ping MAC max 2 (-C) ------------------\n"
spawn $bin -A -C 2 -c 10 -T $ip $mac
expect -re "ARPING $mac\r
\(42|60\) bytes from $ip \\($mac\\): icmp_seq=0 time=(.*)sec\r
\(42|60\) bytes from $ip \\($mac\\): icmp_seq=1 time=(.*)sec\r
\r
--- $mac statistics ---\r
2 packets transmitted, 2 packets received,   0% unanswered \\(0 extra\\)\r
rtt min/avg/max/std-dev = \[0-9.\]+/\[0-9.\]+/\[0-9.\]+/\[0-9.\]+ ms\r
"
expect eof
want_err 0

send_user -- "--------------- Ping MAC cisco style (-D) ------------------\n"
spawn $bin -A -c 3 -D -T $ip $mac
expect "!!!\t  0% packet loss (0 extra)\r\n"
expect eof
want_err 0

send_user -- "--------------- Ping MAC cisco style with audio (-D -a) -----------\n"
spawn $bin -A -c 3 -D -a -T $ip $mac
expect "\a!\a!\a!\t  0% packet loss (0 extra)\r\n"
expect eof
want_err 0

send_user -- "--------- Ping MAC x 2 with inverted audio (-e)  ------------\n"
spawn $bin -c 2 -T $ip "$mac"
expect -re "ARPING $mac\r
\(42|60\) bytes from $ip \\($mac\\): icmp_seq=0 time=(.*)sec\r
\(42|60\) bytes from $ip \\($mac\\): icmp_seq=1 time=(.*)sec\r
\r
--- $mac statistics ---\r
2 packets transmitted, 2 packets received,   0% unanswered \\(0 extra\\)\r
rtt min/avg/max/std-dev = \[0-9.\]+/\[0-9.\]+/\[0-9.\]+/\[0-9.\]+ ms\r
"
expect eof
want_err 0

send_user -- "--------- Ping MAC x 2 with inverted audio, bad dest (-e)  ------------\n"
spawn $bin -e -c 2 -T $ip "$bad_mac"
expect -re "ARPING $bad_mac\r
\aTimeout\r
\aTimeout\r
\r
--- $bad_mac statistics ---\r
2 packets transmitted, 0 packets received, 100% unanswered \\(0 extra\\)\r
\r
"
expect eof
want_err 1

send_user -- "--------- Ping MAC x 2 with inverted audio (-e -D)  ------------\n"
spawn $bin -A -e -c 2 -D -T $ip $mac
expect "!!\t  0% packet loss (0 extra)\r\n"
expect eof
want_err 0

send_user -- "--------- Ping MAC x 2 with inverted audio, bad dest (-e -D)  ------------\n"
spawn $bin -A -c 2 -e -i $ifname -D -T $ip $bad_mac
expect "\a.\a.\t100% packet loss (0 extra)\r\n"
expect eof
want_err 1

send_user -- "--------- Detect duplicate  ------------\n"
spawn $bin -c 2 -d $ip
expect eof
want_err 0

send_user -- "--------- Detect duplicate of self  ------------\n"
spawn $bin -c 2 -d
expect eof
want_err 0

send_user -- "--------- Too many args  ------------\n"
spawn $bin -c 2 1.1.1.1 1.1.1.1
expect eof
want_err 1

send_user -- "---------------------------------------------------------\n"
send_user -- "All tests passed\n"