Debian Codegraph @

ci/test-06-options-f-h.pl

raw
1 #!/usr/bin/perl -w
2
3 use Test::Command tests => 24;
4 use File::Temp;
5
6 # -f file read list of targets from a file ( - means stdin) (only if no -g specified)
7 # -g generate target list (only if no -f specified)
8 # (specify the start and end IP in the target list, or supply a IP netmask)
9 # (ex. ../src/fping -g 192.168.1.0 192.168.1.255 or ../src/fping -g 192.168.1.0/24)
10 # -H n Set the IP TTL value (Time To Live hops)
11
12 my $tmpfile = File::Temp->new();
13 print $tmpfile "127.0.0.1\n127.0.0.2\n";
14 close($tmpfile);
15
16 # fping without option (-> equivalent to 'fping -f -')
17 {
18 my $cmd = Test::Command->new(cmd => "cat ".$tmpfile->filename." | fping");
19 $cmd->exit_is_num(0);
20 $cmd->stdout_is_eq("127.0.0.1 is alive\n127.0.0.2 is alive\n");
21 $cmd->stderr_is_eq("");
22 }
23
24 # fping -f -
25 {
26 my $cmd = Test::Command->new(cmd => "cat ".$tmpfile->filename." | fping -f -");
27 $cmd->exit_is_num(0);
28 $cmd->stdout_is_eq("127.0.0.1 is alive\n127.0.0.2 is alive\n");
29 $cmd->stderr_is_eq("");
30 }
31
32 # fping -f file
33 {
34 my $cmd = Test::Command->new(cmd => "fping -f ".$tmpfile->filename);
35 $cmd->exit_is_num(0);
36 $cmd->stdout_is_eq("127.0.0.1 is alive\n127.0.0.2 is alive\n");
37 $cmd->stderr_is_eq("");
38 }
39
40 # fping -g (range)
41 {
42 my $cmd = Test::Command->new(cmd => "fping -g 127.0.0.1 127.0.0.5");
43 $cmd->exit_is_num(0);
44 $cmd->stdout_is_eq("127.0.0.1 is alive\n127.0.0.2 is alive\n127.0.0.3 is alive\n127.0.0.4 is alive\n127.0.0.5 is alive\n");
45 $cmd->stderr_is_eq("");
46 }
47
48 # fping -g (cidr)
49 {
50 my $cmd = Test::Command->new(cmd => "fping -g 127.0.0.1/30");
51 $cmd->exit_is_num(0);
52 $cmd->stdout_is_eq("127.0.0.1 is alive\n127.0.0.2 is alive\n");
53 $cmd->stderr_is_eq("");
54 }
55
56 # fping -g (cidr - long prefixes)
57 {
58 my $cmd = Test::Command->new(cmd => "fping -g 127.0.0.2/31");
59 $cmd->exit_is_num(0);
60 $cmd->stdout_is_eq("127.0.0.2 is alive\n127.0.0.3 is alive\n");
61 $cmd->stderr_is_eq("");
62 }
63
64 # fping -g (cidr - too long prefixes)
65 {
66 my $cmd = Test::Command->new(cmd => "fping -g 127.0.0.2/33");
67 $cmd->exit_is_num(1);
68 $cmd->stdout_is_eq("");
69 $cmd->stderr_is_eq("fping: netmask must be between 1 and 32 (is: 33)\n");
70 }
71
72 # fping -H
73 {
74 my $cmd = Test::Command->new(cmd => "fping -H 1 127.0.0.1");
75 $cmd->exit_is_num(0);
76 $cmd->stdout_is_eq("127.0.0.1 is alive\n");
77 $cmd->stderr_is_eq("");
78 }