X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=hostinfo-test%2Fhostinfo-test.pl;h=fbc27d8673f71e2d55321d797384fedb7de43697;hb=e43e15284e3c91f9cdc2ba1e48b81f2c5ebe36fc;hp=d265f748db745f1d94127516baf48458d80379d8;hpb=61a6dfc7f7e2f2d50b189fec66f734def9b1140c;p=virt-hostinfo.git diff --git a/hostinfo-test/hostinfo-test.pl b/hostinfo-test/hostinfo-test.pl index d265f74..fbc27d8 100755 --- a/hostinfo-test/hostinfo-test.pl +++ b/hostinfo-test/hostinfo-test.pl @@ -19,7 +19,8 @@ use strict; -#use Sys::Virt; +use Pod::Usage; +use Getopt::Long; =pod @@ -39,10 +40,6 @@ a guest (virtual machine). This command is used to make/test hostinfo requests. You can use this to test that the hostinfo system is working end-to-end. -On its own, the command will make a simple 'ping' request, just -to check that the path from the guest to the C (daemon) -inside the host is working: - # hostinfo-test or: @@ -50,16 +47,108 @@ or: # hostinfo-test error: no response ping request +=head1 OPTIONS + +=over 4 + +=cut + +my $help; + +=item B<--help> + +Display brief help. + +=cut + +my $version; + +=item B<--version> + +Display version number and exit. + +=cut + +my $serial = "/dev/ttyS1"; + +=item B<--serial /dev/ttyS?> | B<-s /dev/ttyS?> + +Select the serial device to use. The default is C. + +If you use the wrong serial device, you will get no response from +hostinfo commands, so choosing the correct device is important. To +find out which serial device to use, you should get the host system +administrator to run L on the host. + =cut +my $verbose; + +=item B<--verbose> | B<-v> + +Verbose messages. + +=cut + +GetOptions ("help|?" => \$help, + "version" => \$version, + "serial|s=s" => \$serial, + "verbose|v" => \$verbose, + ) or pod2usage (2); +pod2usage (1) if $help; +if ($version) { + print "@VERSION@\n"; + exit +} + +# Set the serial port to raw mode, no echo. +system ("stty raw -echo < $serial") == 0 or die "stty: $?"; + +open SERIAL, "+<$serial" or die "$serial: $!"; + +my $echodata; +my @chars = ('a'..'z', 'A'..'Z', '0'..'9'); +$echodata .= $chars[rand @chars] foreach (1..16); + +print qq{<<< PING "$echodata"\n} if $verbose; +print SERIAL qq{PING "$echodata"\r\n}; + +local $SIG{ALRM} = sub { die "error: no response from ping test\n" }; +alarm 3; + +my $input = ; +print ">>> $input" if $verbose; + +close SERIAL; + +if ($input !~ /^1\.\d+ 200 $echodata/) { + die "error: incorrect or unexpected response from ping test\n"; +} + +exit 0; + +=head1 TROUBLESHOOTING + +=over 4 + +=item * + +Use I<-v> option to get more verbose messages. + +=item * + +Look in the system log files on the host. +=item * +Follow the I section in L manpage. +=back =head1 RETURN VALUE -This command returns 0 if the test succeeded, or 1 if the test failed -or there was an error. +This command returns 0 if the test succeeded, or 1 if the command +failed or there was some other error. =head1 SEE ALSO