New set of arguments.
[irspy-moved-to-github.git] / bin / irspy.pl
1 #!/usr/bin/perl -w
2
3 # $Id: irspy.pl,v 1.26 2007-03-07 18:02:00 mike Exp $
4 #
5 # Run like this:
6 #       YAZ_LOG=irspy,irspy_test IRSPY_SAVE_XML=1 perl -I../lib irspy.pl -t Quick localhost:8018/IR-Explain---1 z3950.loc.gov:7090/Voyager bagel.indexdata.dk/gils bagel.indexdata.dk:210/marc
7 #       YAZ_LOG=irspy,irspy_test sudo ./setrlimit -n 3000 -u mike -- perl -I../lib irspy.pl -t Main -a localhost:8018/IR-Explain---1
8 #       YAZ_LOG=irspy,irspy_test perl -I../lib irspy.pl -t Main -a -n 100 localhost:8018/IR-Explain---1
9 #
10 # Available log-levels are as follows:
11 #       irspy -- high-level application logging
12 #       irspy_debug -- low-level debugging (not very interesting)
13 #       irspy_event -- invocations of ZOOM_event() and individual events
14 #       irspy_unhandled -- unhandled events (not very interesting)
15 #       irspy_test -- adding, queueing and running tests
16 #       irspy_task -- adding, queueing and running tasks
17
18 # I have no idea why this directory is not in Ubuntu's default Perl
19 # path, but we need it because just occasionally overload.pm:88
20 # requires Scalar::Util, which is in this directory.
21
22 use lib '/usr/share/perl/5.8.7';
23 use Scalar::Util;
24
25 use strict;
26 use warnings;
27 use Getopt::Std;
28 use ZOOM::IRSpy::Web;
29 use Carp;
30
31 $SIG{__DIE__} = sub {
32     my($msg) = @_;
33     confess($msg);
34 };
35
36 my %opts;
37 if (!getopts('wt:af:n:', \%opts) || @ARGV < 1) {
38     print STDERR "\
39 Usage $0: [options] <IRSpy-database> [<target> ...]
40         -w              Use ZOOM::IRSpy::Web subclass
41         -t <test>       Run the specified <test> [default: all tests]
42         -a              Test all targets (slow!)
43         -f <query>      Test targets found by the specified query
44         -n <number>     Number of connection to keep in active set
45 ";
46     exit 1;
47 }
48
49 my($dbname, @targets) = @ARGV;
50 my $class = "ZOOM::IRSpy";
51 $class .= "::Web" if $opts{w};
52
53 my $spy = $class->new($dbname, "admin", "fruitbat", $opts{n});
54 if (@targets) {
55     $spy->targets(@targets);
56 } elsif ($opts{f}) {
57     $spy->find_targets($opts{f});
58 } elsif (!$opts{a}) {
59     print STDERR "$0: specify -a, -f <query> or list of targets\n";
60     exit 1;
61 }
62
63 $spy->initialise();
64 my $res = $spy->check($opts{t});
65 if ($res == 0) {
66     print "All tests were attempted\n";
67 } else {
68     print "$res tests were skipped\n";
69 }
70
71
72 # Fake the HTML::Mason class that ZOOM::IRSpy::Web uses
73 package HTML::Mason::Commands;
74 BEGIN { our $m = bless {}, "HTML::Mason::Commands" }
75 sub flush_buffer { print shift(), " flushing\n" if 0 }