From: schemers@leland.Stanford.EDU (Roland Schemers)
Subject: client tester...
Summary: go4gw client tester module
Organization: Distributed Computing Group, Stanford University
Date: Wed, 30 Sep 92 04:02:42 GMT

Not sure if anyone has written one (shame shame if not :-), but
here is a go4gw module called "test" which is used to test a client's
behavior of nasty conditions. There a plenty more tests that this
thing could do, but its a start :-) Nothing funner then writing 
buggy code :-)

To test it, install it in you go4gw.conf file as:

test:-2:/usr/local/etc/g2test:Client tester:

Then setup a link to point to it:

Name=Client Tester
Type=1
Port=4320
Path=test
Host=your.go4gw.host

Then you can see how clients handle large directories, invalid
protocol packets, connection refused, unknown hosts, timeouts,
long titles, etc.

I just wrote this sitting at the terminal at home, so I haven't
tested it against anything but the curses gopher client. I wrote
it so I could bomb proof my Motif gopher (which is moving along).

Roland

#!/usr/local/bin/perl

#----------------------------------------------------------------------
# variables you should change:

$test_unused_port = 31234;
$test_bogus_host  = "this.isa.host.not";
$test_unused_ip   = "36.53.10.241";

#----------------------------------------------------------------------

sub test_main {
 local($_) = @_;

 if (/^$/) {
    &Greply("0Test Help\t$Ggw help\t$Ghost\t$Gport");
    &Greply("0Connecion refused test\t$Ggw nop\t$Ghost\t$test_unused_port");
    &Greply("0Bogus host\t$Ggw nop\t$test_bogus_host\t$Gport");
    &Greply("0Connect timeout\t$Ggw nop\t$test_unused_ip\t$Gport");
    &Greply("7Slow File (N seconds)\t$Ggw file_t\t$Ghost\t$Gport");
    &Greply("7File (N lines)\t$Ggw file\t$Ghost\t$Gport");
    &Greply("1Invalid directory format\t$Ggw invalid_dir\t$Ghost\t$Gport");
    &Greply("1No trailing '.'\t$Ggw no_dot\t$Ghost\t$Gport");
    &Greply("1Long Title (1K) directory\t$Ggw long_dir\t$Ghost\t$Gport");
    &Greply("7Large directory (N entries)\t$Ggw large_dir\t$Ghost\t$Gport");
    &Greply("7Slow directory (N seconds)\t$Ggw slow_dir\t$Ghost\t$Gport");
    &Greply(".");
    exit(0);
 }

 /^help/ && &do_help;
 /^nop/ && &do_nop;
 /^invalid_dir/ && &do_invalid_dir;
 /^slow_dir\s+(.*)/ && &do_slow_dir($1);
 /^large_dir\s+(.*)/ && &do_large_dir($1);
 /^file\s+(.*)/ && &do_file($1);
 /^n_file\s+(.*)/ && &do_n_file($1);
 /^very_slow_dir/ && &do_very_slow_dir;
 /^no_dot/ && &do_no_dot;
 /^file_timeout\s+(.*)/ && &do_file_timeout($1);
 /^file_t\s+(.*)/ && &do_file_t($1);

exit(0);
}

sub do_invalid_dir {

   &Greply("0Foobar 1 \t$Ggw nop\t$Ghost\t$Gport");
   &Greply("0Foobar\t$Ggw nop");
   &Greply("0Foobar\t$Ggw nop\t$Ghost\t$Gport");
   &Greply(".");
 exit(0);
}

sub do_slow_dir {
  local($n)=@_;
 for ($i=0; $i < 10; $i++) {
   $x=int($i);
   &Greply("0Foobar $x\tfoo\t$Ghost\t$Gport");
   sleep($n);
 }
 &Greply(".");
 exit(0);
}


sub do_no_dot {
  local($n)=@_;
 for ($i=0; $i < 10; $i++) {
   $x=int($i);
   &Greply("0Foobar $x\tfoo\t$Ghost\t$Gport");
 }
 exit(0);
}

sub do_large_dir {
  local($n)=@_;
 for ($i=0; $i < $n; $i++) {
   $x=int($i);
   &Greply("0Foobar $x\t$Ggw nop\t$Ghost\t$Gport");
 }
 &Greply(".");
 exit(0);
}

sub do_file {
local($n)=@_;

   &Greply("0 $n line file\t$Ggw n_file $n\t$Ghost\t$Gport");
   &Greply(".");
   exit(0);
}

sub do_n_file {
  local($n)=@_;
  local($size,$i);
  $i=0;
  while($size < $n) {
    $line = "This is line number $i ****************************************";
    $size += length($line);
    &Greply("$line");
    $i++;
  }
 &Greply(".");
 exit(0);
}

sub do_long_dir {
   $foo = 'x' x 1024;
   &Greply("1$foo\t\t\$Ghost\t$Gport");
   &Greply(".");
 exit(0);
}

sub do_nop  {
    &Greply("This is nothing!");
    &Greply(".");
    exit(0);
}

sub do_file_t {
    local($n)=@_;
    &Greply("0File timeout ($n seconds)\t$Ggw file_timeout $n\t$Ghost\t$Gport");
    &Greply(".");
    exit(0);
}

sub do_file_timeout  {
    local($n)=@_;
    &Greply("file timeout!");
    sleep($n);
    &Greply(".");
    exit(0);
}

sub do_help {
print<<EOF;

Connecion refused       - sends file request to a (hopefully) unused port.
                          ($test_unused_port)

Bogus host              - sends file request to a hostname that doesn't exist.
                          ($test_bogus_host)
           
Connect timeout         - sends file request to a IP address that doesn't 
                          exist. ($test_unused_ip)

Slow File (N seconds)   - Enter the number of seconds it takes the test gateway
                          to return a file.

File (N lines)           - Enter the number of lines you want to be returned.

Invalid directory format - Sends back a directory with a entry that doesn't  
                           contain a host and port field.

No trailing '.'          - Sends back a directory that doesn't end with a '.'

Long Title (1K) dir      - Sends back a directory that contains a title 
                           that is 1K long.

Large dir (N entries)    - Sends back a directory that contains N entries.

Slow dir (N seconds)     - Sends back a directory that contains 10 items,
                           and takes N seconds between sending each item.
EOF
    &Greply(".");
    exit(0);
}
1; # for require



-- 
Roland J. Schemers III              |            Networking Systems
Systems Programmer                  |            168 Pine Hall   (415)-723-6740
Distributed Computing Group         |            Stanford, CA 94305-4122
Stanford University                 |            schemers@Slapshot.Stanford.EDU
Newsgroups: comp.infosystems.gopher