perl code to test my C based CGI application

C

chris

Already tried cgi newsgroup to no avail.

I'm a Perl begginner, and it's starting to look like Perl is the best
way to do this. I have a C based CGI executable that receives a single
arguement via HTTP POST method as follows:

<form method="POST" action="http://mypc-01/scripts/MyCGI.exe"
name="postToCGI">

I'd like to load test it by creating a Perl script that simply calls
it with same argument over and over and over. How can I do this?

thanks.

chris
 
D

David K. Wall

[a CGI program written in C]
I'd like to load test it by creating a Perl script that simply
calls it with same argument over and over and over. How can I do
this?

See

perldoc lwpcook

It has examples that should get you started.
 
C

chris

Purl Gurl said:
Are you a beg-ginner or a beginner?

"argument"




http://stein.cshl.org/~lstein/torture/torture.html


Purl Gurl

Spell correcting in a newsgroup? yikes.

Thanks everyone. I found a nice example by Jason Mathews and modified a bit:

#!/bin/perl
# based on sample script by Jason Mathews 28-March-1996

for ($count=1; $count < 11; $count++)
{
$ENV{'GATEWAY_INTERFACE'} = "CGI/1.1";
$ENV{'SCRIPT_NAME'} = "C:/Inetpub/Scripts/MyCGIUtility.exe";
$ENV{'SERVER_PROTOCOL'} = "HTTP/1.0";

#
# Set all environment variables that are referenced in your
# CGI program. For example, only REQUEST_METHOD, QUERY_STRING,
# and CONTENT_LENGTH are referenced in the dump.cgi program.
#######################################################################

$| = 1;

# CGI form input

$cgi_input = 'acctid=501020000246';

#
# POST method
#

print "----------------------------------------------------\n";
print "simulating a POST method:\n";

# Setup environment

$ENV{'REQUEST_METHOD'} = "POST";
$ENV{'CONTENT_LENGTH'} = length($cgi_input);
$ENV{'CONTENT_TYPE'} = "application/x-www-form-urlencoded";

open(PIPE, "| MyCGIUtility.exe");
print PIPE $cgi_input;
close(PIPE);

} # end for

chris
 
E

Eric Schwartz

Thanks everyone. I found a nice example by Jason Mathews and modified a bit:

<snip>

I guess it depends on what you're testing. What you did will test the
program, but outside its normal execution environment
(Webserver+CGI). You're essentially simulating a CGI environment, and
then testing. This isn't a big problem, but you need to also test it
in a real CGI environment, as you always have the risk that your
simulation isn't necessarily good enough.

-=Eric
 
C

chris

Purl Gurl said:
My presumption is you do not care to improve your spelling skills,
which is often a reason for poor spelling skills.



Yours is a nice example, although inefficient. It does not load
test your software, however.

A single iteration of your example code is no different than eleven
iterations. Either your program works right or it doesn't. Your
efficiency would be greatly improved by moving your environment
variables outside your looping mechanism; no need to set those
variables eleven times. Same is true for your $| flushing. This
only needs to be set once. A simple system() call would be quicker
than opening a filehandle.

Nice example which could be improved significantly, keeping in
mind your example does not load test.


Purl Gurl

Thanks. I moved all my env vars and flushing outside the loop now.

I plan to run this script from 10 different client boxes at the same
time, that will all be hitting the CGI server, so I think it will give
me somehwhat of a load test. I suppose it's more of a performance
test.

chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top