summaryrefslogtreecommitdiff
path: root/extra/testing.exp
diff options
context:
space:
mode:
authorThomas Habets <thomas@habets.se>2015-11-27 12:20:28 +0000
committerThomas Habets <thomas@habets.se>2015-11-27 12:20:28 +0000
commitfc5b218cd26a8251974edad4af2f82eafed16f36 (patch)
tree6cb84d38bcaea4f1c8d382c15d97cfa2d8fc2ebf /extra/testing.exp
parent0bda1a7a2c99bfba59afbb7c103c663713cedd8f (diff)
downloadarping-fc5b218cd26a8251974edad4af2f82eafed16f36.tar.gz
Test exit code correctness
Diffstat (limited to 'extra/testing.exp')
-rwxr-xr-xextra/testing.exp55
1 files changed, 55 insertions, 0 deletions
diff --git a/extra/testing.exp b/extra/testing.exp
index 3261f0b..7c94751 100755
--- a/extra/testing.exp
+++ b/extra/testing.exp
@@ -60,6 +60,20 @@ 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
@@ -69,6 +83,7 @@ usage: arping \\\[ -0aAbdDeFpqrRuUv \\\] \\\[ -w <us> \\\] \\\[ -S <host/ip> \\\
For complete usage info, use --help or check the manpage.\r
"
expect eof
+want_err 1
send_user -- "--------------- -h ------------------\n"
spawn $bin -h
@@ -79,6 +94,7 @@ usage: arping \\\[ -0aAbdDeFpqrRuUv \\\] \\\[ -w <us> \\\] \\\[ -S <host/ip> \\\
For complete usage info, use --help or check the manpage.\r
"
expect eof
+want_err 0
send_user -- "--------------- --help ------------------\n"
spawn $bin --help
@@ -93,6 +109,7 @@ 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
@@ -101,6 +118,7 @@ expect "\r" {
# Make sure double-endline is stripped.
exit 1
}
+want_err 1
send_user -- "--------------- Ping IP Simple ------------------\n"
spawn $bin -c 1 $ip
@@ -112,6 +130,7 @@ expect -re "ARPING $ip\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
@@ -119,6 +138,7 @@ 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
@@ -126,11 +146,13 @@ 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
@@ -138,6 +160,7 @@ 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
@@ -145,6 +168,7 @@ 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
@@ -157,6 +181,7 @@ expect -re "ARPING $ip\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
@@ -170,6 +195,7 @@ expect -re "ARPING $ip\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
@@ -183,6 +209,7 @@ expect -re "ARPING $ip\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
@@ -195,6 +222,7 @@ expect -re "ARPING $ip\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"
@@ -207,26 +235,31 @@ expect -re "ARPING $bad_ip\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
@@ -238,6 +271,7 @@ expect -re "ARPING $ip\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
@@ -248,6 +282,7 @@ Timeout\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
@@ -259,6 +294,7 @@ expect -re "ARPING $mac\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
@@ -266,6 +302,7 @@ 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
@@ -273,11 +310,13 @@ 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
@@ -285,6 +324,7 @@ 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
@@ -292,6 +332,7 @@ expect -re "$mac $ip\r
$mac $ip\r
"
expect eof
+want_err 0
send_user -- "--------------- Ping MAC max 2 (-C) ------------------\n"
@@ -305,16 +346,19 @@ expect -re "ARPING $mac\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"
@@ -327,6 +371,7 @@ expect -re "ARPING $mac\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"
@@ -339,24 +384,34 @@ expect -re "ARPING $bad_mac\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"