wrapper for irspy.pl
[irspy-moved-to-github.git] / bin / irspy.pl
1 #!/usr/bin/perl
2
3 # Run like this:
4 #       YAZ_LOG=irspy,irspy_test IRSPY_SAVE_XML=1 perl -I../lib irspy.pl -t Quick localhost:8018/IR-Explain---1 Z39.50:amicus.oszk.hu:1616/ANY
5 #       YAZ_LOG=irspy,irspy_test sudo ./setrlimit -n 3000 -u mike -- perl -I../lib irspy.pl -t Main -a localhost:8018/IR-Explain---1
6 #       YAZ_LOG=irspy,irspy_test perl -I../lib irspy.pl -t Main -a -n 100 localhost:8018/IR-Explain---1
7 #
8 # Available log-levels are as follows:
9 #       irspy -- high-level application logging
10 #       irspy_debug -- low-level debugging (not very interesting)
11 #       irspy_event -- invocations of ZOOM_event() and individual events
12 #       irspy_unhandled -- unhandled events (not very interesting)
13 #       irspy_test -- adding, queueing and running tests
14 #       irspy_task -- adding, queueing and running tasks
15
16 # I have no idea why this directory is not in Ubuntu's default Perl
17 # path, but we need it because just occasionally overload.pm:88
18 # requires Scalar::Util, which is in this directory.
19 #use lib '/usr/share/perl/5.8.7';
20
21 use Scalar::Util;
22 use Getopt::Std;
23 use ZOOM::IRSpy::Web;
24 use Carp;
25
26 use strict;
27 use warnings;
28
29 $SIG{__DIE__} = sub {
30     my($msg) = @_;
31     confess($msg);
32 };
33
34 my %opts;
35 if (!getopts('dwt:af:n:m:M:', \%opts) || @ARGV < 1) {
36     print STDERR "\
37 Usage $0: [options] <IRSpy-database> [<target> ...]
38         -d              debug
39         -w              Use ZOOM::IRSpy::Web subclass
40         -t <test>       Run the specified <test> [default: all tests]
41         -a              Test all targets (slow!)
42         -f <query>      Test targets found by the specified query
43         -n <number>     Number of connection to keep in active set
44         -m <n>,<i>      Only test targets whose hash mod <n> is <i>
45         -M max_depth    maximum number of nested template calls and variables/params
46 ";
47     exit 1;
48 }
49
50 my($dbname, @targets) = @ARGV;
51 my $class = "ZOOM::IRSpy";
52 $class .= "::Web" if $opts{w};
53
54 if ($opts{M} && $opts{M} > 0) {
55     no warnings;
56     $ZOOM::IRSpy::xslt_max_depth = $opts{M};
57 }
58 if ($opts{d}) { 
59     no warnings;
60     $ZOOM::IRSpy::debug = $opts{d};
61 }
62
63 my $spy = $class->new($dbname, "admin", "fruitbat", $opts{n});
64 if (@targets) {
65     $spy->targets(@targets);
66 } elsif ($opts{f}) {
67     $spy->find_targets($opts{f});
68 } elsif (!$opts{a}) {
69     print STDERR "$0: specify -a, -f <query> or list of targets\n";
70     exit 2;
71 }
72
73 if (defined $opts{m}) {
74     my($n, $i) = ($opts{m} =~ /^(\d+),(\d+)$/);
75     if (!defined $n) {
76         print STDERR "$0: argument to -m must be of the form <n>,<i>\n";
77         exit 3;
78     }
79     $spy->restrict_modulo($n, $i);
80 }
81
82 $spy->initialise($opts{t});
83 my $res = $spy->check();
84 if ($res == 0) {
85     print "All tests were attempted\n";
86 } else {
87     print "$res tests were skipped\n";
88 }
89
90
91 # Fake the HTML::Mason class that ZOOM::IRSpy::Web uses
92 package HTML::Mason::Commands;
93 BEGIN { our $m = bless {}, "HTML::Mason::Commands" }
94 sub flush_buffer { print shift(), " flushing\n" if 0 }