Documentation fixes.
[virt-hostinfo.git] / hostinfo-test / hostinfo-test.pl
1 #!/usr/bin/perl -w
2 # @configure_input@
3 # virt-hostinfo
4 # Copyright (C) 2009 Red Hat Inc.
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20 use strict;
21
22 use Pod::Usage;
23 use Getopt::Long;
24
25 =pod
26
27 =head1 NAME
28
29 hostinfo-test - make or test hostinfo requests from a virtual machine
30
31 =head1 SYNOPSIS
32
33  hostinfo-test [--options]
34
35 =head1 DESCRIPTION
36
37 I<Note:> It only makes sense to use this command from inside
38 a guest (virtual machine).
39
40 This command is used to make/test hostinfo requests.  You can
41 use this to test that the hostinfo system is working end-to-end.
42
43  # hostinfo-test
44
45 or:
46
47  # hostinfo-test
48  error: no response ping request
49
50 =head1 OPTIONS
51
52 =over 4
53
54 =cut
55
56 my $help;
57
58 =item B<--help>
59
60 Display brief help.
61
62 =cut
63
64 my $version;
65
66 =item B<--version>
67
68 Display version number and exit.
69
70 =cut
71
72 my $serial = "/dev/ttyS1";
73
74 =item B<--serial /dev/ttyS?> | B<-s /dev/ttyS?>
75
76 Select the serial device to use.  The default is C</dev/ttyS1>.
77
78 If you use the wrong serial device, you will get no response from
79 hostinfo commands, so choosing the correct device is important.  To
80 find out which serial device to use, you should get the host system
81 administrator to run L<hostinfo-status(8)> on the host.
82
83 =cut
84
85 my $verbose;
86
87 =item B<--verbose> | B<-v>
88
89 Verbose messages.
90
91 =cut
92
93 GetOptions ("help|?" => \$help,
94             "version" => \$version,
95             "serial|s=s" => \$serial,
96             "verbose|v" => \$verbose,
97     ) or pod2usage (2);
98 pod2usage (1) if $help;
99 if ($version) {
100     print "@VERSION@\n";
101     exit
102 }
103
104 # Set the serial port to raw mode, no echo.
105 system ("stty raw -echo < $serial") == 0 or die "stty: $?";
106
107 open SERIAL, "+<$serial" or die "$serial: $!";
108
109 my $echodata;
110 my @chars = ('a'..'z', 'A'..'Z', '0'..'9');
111 $echodata .= $chars[rand @chars] foreach (1..16);
112
113 print qq{<<< PING "$echodata"\n} if $verbose;
114 print SERIAL qq{PING "$echodata"\r\n};
115
116 local $SIG{ALRM} = sub { die "error: no response from ping test\n" };
117 alarm 3;
118
119 my $input = <SERIAL>;
120 print ">>> $input" if $verbose;
121
122 close SERIAL;
123
124 if ($input !~ /^1\.\d+ 200 $echodata/) {
125     die "error: incorrect or unexpected response from ping test\n";
126 }
127
128 exit 0;
129
130 =head1 TROUBLESHOOTING
131
132 =over 4
133
134 =item *
135
136 Use I<-v> option to get more verbose messages.
137
138 =item *
139
140 Look in the system log files on the host.
141
142 =item *
143
144 Follow the I<TROUBLESHOOTING> section in L<hostinfo(8)> manpage.
145
146 =back
147
148 =head1 RETURN VALUE
149
150 This command returns 0 if the test succeeded, or non-zero if the
151 command failed or there was some other error.
152
153 =head1 SEE ALSO
154
155 L<hostinfo(8)>,
156 L<hostinfo-set(8)>,
157 L<hostinfo-status(8)>,
158 L<hostinfo-protocol(5)>,
159 L<virt-install(1)>,
160 L<virt-manager(1)>,
161 L<http://fedoraproject.org/wiki/Features/Hostinfo>,
162 L<http://libvirt.org/>.
163
164 =head1 AUTHORS
165
166 Richard W.M. Jones (C<rjones at redhat dot com>)
167
168 =head1 COPYRIGHT
169
170 Copyright (C) 2009 Red Hat Inc.
171 L<http://fedoraproject.org/wiki/Features/Hostinfo>
172
173 This program is free software; you can redistribute it and/or modify
174 it under the terms of the GNU General Public License as published by
175 the Free Software Foundation; either version 2 of the License, or
176 (at your option) any later version.
177
178 This program is distributed in the hope that it will be useful,
179 but WITHOUT ANY WARRANTY; without even the implied warranty of
180 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
181 GNU General Public License for more details.
182
183 You should have received a copy of the GNU General Public License
184 along with this program; if not, write to the Free Software
185 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.