xr-smtp-test (1120B)
1 #!/usr/bin/perl 2 3 use strict; 4 use Net::SMTP; 5 use Time::HiRes qw(sleep gettimeofday tv_interval); 6 7 $|++; 8 9 die <<"ENDUSAGE" if ($#ARGV != 4); 10 11 Usage: $0 ENDPOINT FROM-ADDRESS TO-ADDRESS THREADS DURATION 12 Will start THREADS to send dummy e-mails to TO-ADDRESS. The test will run 13 for DURATION seconds. ENDPOINT is the IP address to connect to. 14 15 ENDUSAGE 16 17 my ($endpoint, $from, $address, $threads, $duration) = @ARGV; 18 for my $i (1..$threads) { 19 next if (fork()); 20 21 my $t_start = [gettimeofday()]; 22 my $runs = 0; 23 while (tv_interval($t_start) < $duration) { 24 $runs++; 25 my $t_run = [gettimeofday()]; 26 my $smtp = Net::SMTP->new($endpoint, Timeout => 5) 27 or die ("Cannot start SMTP\n"); 28 $smtp->mail($from); 29 $smtp->to($address); 30 $smtp->data(); 31 $smtp->datasend("To: $address\n"); 32 $smtp->datasend("Subject: Testing mail\n"); 33 $smtp->datasend("\n"); 34 $smtp->datasend("This is just a test message.\n"); 35 $smtp->dataend(); 36 $smtp->quit(); 37 print(tv_interval($t_run), "\n"); 38 } 39 exit(0); 40 } 41 42 while(wait() != -1) { 43 }