tools/page-loader/loader.pl

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rwxr-xr-x

Integrate suggestion from review to improve consistency with existing code.

michael@0 1 #!/usr/bin/perl
michael@0 2 #
michael@0 3 # This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 # License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
michael@0 6
michael@0 7 use strict;
michael@0 8 use CGI::Request;
michael@0 9 use CGI::Carp qw(fatalsToBrowser);
michael@0 10 use Time::HiRes qw(gettimeofday tv_interval);
michael@0 11 use POSIX qw(strftime);
michael@0 12 use DBI;
michael@0 13
michael@0 14 # list of test pages, JS to insert, httpbase, filebase, etc.
michael@0 15 use PageData;
michael@0 16
michael@0 17 use vars qw(%params $req $cgi $dbh $pagedata
michael@0 18 $gStartNow $gStartNowStr
michael@0 19 $gResponseNow $gLogging);
michael@0 20
michael@0 21 $gStartNow = [gettimeofday]; # checkpoint the time
michael@0 22 $gStartNowStr = strftime "%Y%m%d%H%M%S", localtime;
michael@0 23 $gLogging = 1;
michael@0 24
michael@0 25 $req = new CGI::Request; # get the HTTP/CGI request
michael@0 26 $cgi = $req->cgi;
michael@0 27
michael@0 28 $pagedata = PageData->new;
michael@0 29
michael@0 30 setDefaultParams();
michael@0 31
michael@0 32 #XXXdebugcrap
michael@0 33 #warn $params{index}, " ", $params{maxidx};
michael@0 34
michael@0 35 if (!defined($req->param('delay'))) {
michael@0 36 # give the user a form to pick options (but note that going
michael@0 37 # to "loader.pl?delay=1000" immediately starts the test run
michael@0 38 outputForm();
michael@0 39 }
michael@0 40 elsif (!$req->param('id')) {
michael@0 41 initialize(); # do redirect to start the cycle
michael@0 42 }
michael@0 43 elsif ($params{index} > $params{maxidx}) {
michael@0 44 redirectToReport(); # the test is over; spit out a summary
michael@0 45 markTestAsComplete(); # close the meta table entry
michael@0 46 }
michael@0 47 elsif (!isRequestStale()) {
michael@0 48 outputPage(); # otherwise, keep dishing out pages
michael@0 49 updateDataBase(); # client has the response; now write out stats to db
michael@0 50 }
michael@0 51
michael@0 52 # cleanup
michael@0 53 $req = undef;
michael@0 54 $dbh->disconnect() if $dbh; # not strictly required (ignored in some cases anyways)
michael@0 55
michael@0 56 #logMessage(sprintf("Page load server responded in %3d msec, total time %3d msec, pid: %d",
michael@0 57 # 1000*tv_interval($gStartNow, $gResponseNow), 1000*tv_interval($gStartNow), $$))
michael@0 58 # if $gResponseNow; # log only when a test page has been dished out
michael@0 59
michael@0 60 exit 0;
michael@0 61
michael@0 62 #######################################################################
michael@0 63
michael@0 64 sub logMessage {
michael@0 65 print STDERR strftime("[%a %b %d %H:%M:%S %Y] ", localtime), @_, "\n"
michael@0 66 if $gLogging;
michael@0 67 }
michael@0 68
michael@0 69
michael@0 70 sub isRequestStale {
michael@0 71 my $limit = 30*60; # 30 minutes, although if we never stalled on mac I'd make it 3 minutes
michael@0 72 my $ts = decodeHiResTime($params{s_ts});
michael@0 73 my $delta = tv_interval($ts, $gStartNow);
michael@0 74 return undef if $delta < $limit;
michael@0 75 # otherwise, punt this request
michael@0 76 print "Content-type: text/html\n\n";
michael@0 77 print <<"ENDOFHTML";
michael@0 78 <html><head><title>Page Loading Times Test</title></head><body>
michael@0 79 <p><b>The timestamp on the request is too old to continue:<br>
michael@0 80 s_ts=$params{s_ts} was $delta seconds ago. Limit is $limit seconds.</b></p>
michael@0 81 </body></html>
michael@0 82 ENDOFHTML
michael@0 83 return 1; # it's stale
michael@0 84 }
michael@0 85
michael@0 86
michael@0 87 sub initialize {
michael@0 88 updateMetaTable();
michael@0 89 createDataSetTable();
michael@0 90
michael@0 91 # start the test by bouncing off of an echo page
michael@0 92 my $script = $cgi->var("SCRIPT_NAME");
michael@0 93 my $server = $cgi->var("SERVER_NAME");
michael@0 94 my $proto = $ENV{SERVER_PORT} == 443 ? 'https://' : 'http://';
michael@0 95 my $me = $proto . $server . $script;
michael@0 96 $script =~ /^(.*\/).*$/;
michael@0 97 my $loc = "Location: ". $proto . $server . $1 . "echo.pl?";
michael@0 98 for (qw(id index maxcyc delay replace nocache timeout)) {
michael@0 99 $loc .= "$_=$params{$_}\&";
michael@0 100 }
michael@0 101 $loc .= "url=" . $me;
michael@0 102 print $loc, "\n\n";
michael@0 103 }
michael@0 104
michael@0 105
michael@0 106 sub redirectToReport {
michael@0 107 # n.b., can also add '&sort=1' to get a time sorted list
michael@0 108 my $proto = $ENV{SERVER_PORT} == 443 ? 'https://' : 'http://';
michael@0 109 my $loc = "Location: " . $proto . $cgi->var("SERVER_NAME");
michael@0 110 $cgi->var("SCRIPT_NAME") =~ /^(.*\/).*$/;
michael@0 111 $loc .= $1 . "report.pl?id=" . $params{id};
michael@0 112 # To use for a tinderbox, comment out the line above and uncomment this:
michael@0 113 # $loc .= $1 . "dump.pl?id=" . $params{id} . "&purge=1";
michael@0 114 print $loc, "\n\n";
michael@0 115 }
michael@0 116
michael@0 117
michael@0 118 sub generateTestId {
michael@0 119 # use the epoch time, in hex, plus a two-character random.
michael@0 120 return sprintf "%8X%02X", time(), int(256*rand());
michael@0 121 }
michael@0 122
michael@0 123
michael@0 124 sub setDefaultParams {
michael@0 125 $params{id} = $req->param('id') || generateTestId(); # "unique" id for this run
michael@0 126 $params{index} = $req->param('index') || 0; # request index for the test
michael@0 127 $params{maxcyc} = defined($req->param('maxcyc')) ?
michael@0 128 $req->param('maxcyc') : 3; # max visits (zero-based count)
michael@0 129 $params{delay} = $req->param('delay') || 1000; # setTimeout on the next request (msec)
michael@0 130 $params{replace} = $req->param('replace') || 0; # use Location.replace (1) or Location.href (0)
michael@0 131 $params{nocache} = $req->param('nocache') || 0; # serve content via uncacheable path
michael@0 132 $params{c_part} = $req->param('c_part') || 0; # client time elapsed; page head to onload (msec)
michael@0 133 $params{c_intvl} = $req->param('c_intvl') || 0; # client time elapsed; onload to onload event (msec)
michael@0 134 $params{c_ts} = $req->param('c_ts') || 0; # client timestamp (.getTime()) (msec)
michael@0 135 $params{content} = $req->param('content') || "UNKNOWN"; # name of content page for this data
michael@0 136 $params{s_ts} = $req->param('s_ts') || undef; # server timestamp; no default
michael@0 137 $params{timeout} = $req->param('timeout') || 30000; # msec; timer will cancel stalled page loading
michael@0 138 $params{maxidx} = ($params{maxcyc}+1) * $pagedata->length; # total pages loads to be done
michael@0 139 $params{curidx} = $params{index} % $pagedata->length; # current request index into page list
michael@0 140 $params{curcyc} = int(($params{index}-1) / $pagedata->length); # current "cycle" (visit)
michael@0 141 }
michael@0 142
michael@0 143
michael@0 144 sub outputPage {
michael@0 145 my $relpath = $pagedata->url($params{curidx});
michael@0 146 my $file = $pagedata->filebase . $relpath;
michael@0 147 open (HTML, "<$file") ||
michael@0 148 die "Can't open file: $file, $!";
michael@0 149
michael@0 150 my $hook = "<script xmlns='http://www.w3.org/1999/xhtml'>\n";
michael@0 151 $hook .= "var g_moztest_Start = (new Date()).getTime();\n";
michael@0 152 $hook .= "var g_moztest_ServerTime='" . encodeHiResTime($gStartNow) . "';\n";
michael@0 153 $hook .= "var g_moztest_Content='" . $pagedata->name($params{curidx}) . "';\n";
michael@0 154 $hook .= $pagedata->clientJS; # ... and the main body
michael@0 155 $hook .= "var g_moztest_safetyTimer = ";
michael@0 156 $hook .= "window.setTimeout(moztest_safetyValve, " . $params{timeout} . ");";
michael@0 157 $hook .= "</script>\n";
michael@0 158
michael@0 159 my $basepath = $pagedata->httpbase;
michael@0 160 $basepath =~ s/^http:/https:/i
michael@0 161 if $ENV{SERVER_PORT} == 443;
michael@0 162 #warn "basepath: $basepath";
michael@0 163 $basepath =~ s#^(.*?)(/base/)$#$1/nocache$2# if ($params{nocache});
michael@0 164 $hook .= "<base href='". $basepath . $relpath .
michael@0 165 "' xmlns='http://www.w3.org/1999/xhtml' />";
michael@0 166
michael@0 167 my $magic = $pagedata->magicString;
michael@0 168 my $content = "";
michael@0 169 while (<HTML>) {
michael@0 170 s/$magic/$hook/;
michael@0 171 $content .= $_;
michael@0 172 }
michael@0 173
michael@0 174 my $contentTypeHeader;
michael@0 175 my $mimetype = $pagedata->mimetype($params{curidx});
michael@0 176 my $charset = $pagedata->charset($params{curidx});
michael@0 177 if ($charset) {
michael@0 178 $contentTypeHeader = qq{Content-type: $mimetype; charset="$charset"\n\n};
michael@0 179 } else {
michael@0 180 $contentTypeHeader = qq{Content-type: $mimetype\n\n};
michael@0 181 }
michael@0 182 #warn $contentTypeHeader; #XXXjrgm testing...
michael@0 183
michael@0 184 # N.B., these two cookie headers are obsolete, since I pass server info in
michael@0 185 # JS now, to work around a bug in winEmbed with document.cookie. But
michael@0 186 # since I _was_ sending two cookies as part of the test, I have to keep
michael@0 187 # sending two cookies (at least for now, and it's not a bad thing to test)
michael@0 188 #XXX other headers to test/use?
michael@0 189
michael@0 190 $gResponseNow = [gettimeofday]; # for logging
michael@0 191 { # turn on output autoflush, locally in this block
michael@0 192 print "Set-Cookie: moztest_SomeRandomCookie1=somerandomstring\n";
michael@0 193 print "Set-Cookie: moztest_SomeRandomCookie2=somerandomstring\n";
michael@0 194 print $contentTypeHeader;
michael@0 195 local $| = 1;
michael@0 196 print $content;
michael@0 197 }
michael@0 198
michael@0 199 return;
michael@0 200 }
michael@0 201
michael@0 202
michael@0 203 sub encodeHiResTime {
michael@0 204 my $timeref = shift;
michael@0 205 return unless ref($timeref);
michael@0 206 return $$timeref[0] . "-" . $$timeref[1];
michael@0 207 }
michael@0 208
michael@0 209
michael@0 210 sub decodeHiResTime {
michael@0 211 my $timestr = shift;
michael@0 212 return [ split('-', $timestr) ];
michael@0 213 }
michael@0 214
michael@0 215
michael@0 216 sub elapsedMilliSeconds {
michael@0 217 my ($r_time, $timestr) = @_;
michael@0 218 return "NaN" unless $timestr;
michael@0 219 my $delta = tv_interval( [ split('-', $timestr) ], $r_time );
michael@0 220 my $delta = int(($delta*1000) - $params{delay}); # adjust for delay (in msec)
michael@0 221 return $delta;
michael@0 222 }
michael@0 223
michael@0 224
michael@0 225 sub updateDataBase {
michael@0 226 connectToDataBase(); # (may already be cached)
michael@0 227 updateMetaTable();
michael@0 228 updateDataSetTable() unless $params{c_part} == -1; # the initial request
michael@0 229 }
michael@0 230
michael@0 231
michael@0 232 sub connectToDataBase {
michael@0 233 # don't reconnect if already connected. (Other drivers provide this
michael@0 234 # for free I think, but not this one).
michael@0 235 if (!ref($dbh)) {
michael@0 236 $dbh = DBI->connect("DBI:CSV:f_dir=./db", {RaiseError => 1, AutoCommit => 1})
michael@0 237 || die "Cannot connect: " . $DBI::errstr;
michael@0 238 }
michael@0 239 }
michael@0 240
michael@0 241
michael@0 242 #
michael@0 243 # Holds the individual page load data for this id.
michael@0 244 #
michael@0 245 # (Of course, this should really be a single table for all datasets, but
michael@0 246 # that was becoming punitively slow with DBD::CSV. I could have moved to
michael@0 247 # a "real" database, but I didn't want to make that a requirement for
michael@0 248 # installing this on another server and using this test (e.g., install a
michael@0 249 # few modules and you can run this; no sql installation/maintenance required).
michael@0 250 # At some point though, I may switch to some sql db, but hopefully still allow
michael@0 251 # this to be used with a simple flat file db. (Hmm, maybe I should try a *dbm
michael@0 252 # as a compromise (disk based but indexed)).
michael@0 253 #
michael@0 254 sub createDataSetTable {
michael@0 255 my $table = "t" . $params{id};
michael@0 256 return if -f "db/$table"; # don't create it if it exists
michael@0 257 logMessage("createDataSetTable:\tdb/$table");
michael@0 258 connectToDataBase(); # cached
michael@0 259
michael@0 260 my ($sth, $sql);
michael@0 261 $sql = qq{
michael@0 262 CREATE TABLE $table
michael@0 263 (DATETIME CHAR(14),
michael@0 264 ID CHAR(10),
michael@0 265 INDEX INTEGER,
michael@0 266 CUR_IDX INTEGER,
michael@0 267 CUR_CYC INTEGER,
michael@0 268 C_PART INTEGER,
michael@0 269 S_INTVL INTEGER,
michael@0 270 C_INTVL INTEGER,
michael@0 271 CONTENT CHAR(128)
michael@0 272 )
michael@0 273 };
michael@0 274 $sth = $dbh->prepare($sql);
michael@0 275 $sth->execute();
michael@0 276 $sth->finish();
michael@0 277 return 1;
michael@0 278 }
michael@0 279
michael@0 280
michael@0 281 #
michael@0 282 # holds the information about all test runs
michael@0 283 #
michael@0 284 sub createMetaTable {
michael@0 285 my $table = shift;
michael@0 286 return if -f "db/$table"; # don't create it if it exists
michael@0 287 logMessage("createMetaTable:\tdb/$table");
michael@0 288
michael@0 289 my ($sth, $sql);
michael@0 290
michael@0 291 $sql = qq{
michael@0 292 CREATE TABLE $table
michael@0 293 (DATETIME CHAR(14),
michael@0 294 LASTPING CHAR(14),
michael@0 295 ID CHAR(8),
michael@0 296 INDEX INTEGER,
michael@0 297 CUR_IDX INTEGER,
michael@0 298 CUR_CYC INTEGER,
michael@0 299 CUR_CONTENT CHAR(128),
michael@0 300 STATE INTEGER,
michael@0 301 BLESSED INTEGER,
michael@0 302 MAXCYC INTEGER,
michael@0 303 MAXIDX INTEGER,
michael@0 304 REPLACE INTEGER,
michael@0 305 NOCACHE INTEGER,
michael@0 306 DELAY INTEGER,
michael@0 307 REMOTE_USER CHAR(16),
michael@0 308 HTTP_USER_AGENT CHAR(128),
michael@0 309 REMOTE_ADDR CHAR(15),
michael@0 310 USER_EMAIL CHAR(32),
michael@0 311 USER_COMMENT CHAR(256)
michael@0 312 )
michael@0 313 };
michael@0 314 $sth = $dbh->prepare($sql);
michael@0 315 $sth->execute();
michael@0 316 $sth->finish();
michael@0 317 warn 'created meta table';
michael@0 318 return 1;
michael@0 319 }
michael@0 320
michael@0 321
michael@0 322 sub updateMetaTable {
michael@0 323
michael@0 324 connectToDataBase(); # if not already connected
michael@0 325
michael@0 326 my $table = "tMetaTable";
michael@0 327 createMetaTable($table); # just returns if already created
michael@0 328
michael@0 329 my ($sth, $sql);
michael@0 330
michael@0 331 $sql = qq{
michael@0 332 SELECT INDEX, MAXCYC, MAXIDX, REPLACE, NOCACHE,
michael@0 333 DELAY, REMOTE_USER, HTTP_USER_AGENT, REMOTE_ADDR
michael@0 334 FROM $table
michael@0 335 WHERE ID = '$params{id}'
michael@0 336 };
michael@0 337 $sth = $dbh->prepare($sql);
michael@0 338 $sth->execute();
michael@0 339
michael@0 340 my @dataset = ();
michael@0 341 while (my @data = $sth->fetchrow_array()) {
michael@0 342 push @dataset, {index => shift @data,
michael@0 343 maxcyc => shift @data,
michael@0 344 maxidx => shift @data,
michael@0 345 replace => shift @data,
michael@0 346 nocache => shift @data,
michael@0 347 delay => shift @data,
michael@0 348 remote_user => shift @data,
michael@0 349 http_user_agent => shift @data,
michael@0 350 remote_addr => shift @data
michael@0 351 };
michael@0 352 }
michael@0 353 $sth->finish();
michael@0 354 warn "More than one ID: $params{id} ??" if scalar(@dataset) > 1;
michael@0 355
michael@0 356 if (scalar(@dataset) == 0) {
michael@0 357 # this is a new dataset and id
michael@0 358 initMetaTableRecord($table);
michael@0 359 return;
michael@0 360 }
michael@0 361
michael@0 362 #XXX need to check that values are sane, and not update if they don't
michael@0 363 # match certain params. This should not happen in a normal test run.
michael@0 364 # However, if a test url was bookmarked or in history, I might get bogus
michael@0 365 # data collected after the fact. But I have a stale date set on the URL,
michael@0 366 # so that is good enough for now.
michael@0 367 # my $ref = shift @dataset; # check some $ref->{foo}
michael@0 368
michael@0 369 $sql = qq{
michael@0 370 UPDATE $table
michael@0 371 SET LASTPING = ?,
michael@0 372 INDEX = ?,
michael@0 373 CUR_IDX = ?,
michael@0 374 CUR_CYC = ?,
michael@0 375 CUR_CONTENT = ?,
michael@0 376 STATE = ?
michael@0 377 WHERE ID = '$params{id}'
michael@0 378 };
michael@0 379 $sth = $dbh->prepare($sql);
michael@0 380 $sth->execute($gStartNowStr,
michael@0 381 $params{index}-1, # (index-1) is complete; (index) in progress
michael@0 382 ($params{curidx}-1) % $pagedata->length,
michael@0 383 $params{curcyc},
michael@0 384 $params{content},
michael@0 385 'OPEN'
michael@0 386 );
michael@0 387 $sth->finish();
michael@0 388
michael@0 389 }
michael@0 390
michael@0 391
michael@0 392 sub markTestAsComplete {
michael@0 393 connectToDataBase(); # if not already connected
michael@0 394 my $table = "tMetaTable";
michael@0 395 createMetaTable($table); # just returns if already created
michael@0 396 my ($sth, $sql);
michael@0 397 #XXX should probably check if this ID exists first
michael@0 398 $sql = qq{
michael@0 399 UPDATE $table
michael@0 400 SET STATE = "COMPLETE"
michael@0 401 WHERE ID = '$params{id}'
michael@0 402 };
michael@0 403 $sth = $dbh->prepare($sql);
michael@0 404 $sth->execute();
michael@0 405 $sth->finish();
michael@0 406 }
michael@0 407
michael@0 408
michael@0 409 sub initMetaTableRecord {
michael@0 410 # we know this record doesn't exist, so put in the initial values
michael@0 411 my $table = shift;
michael@0 412 my ($sth, $sql);
michael@0 413 $sql = qq{
michael@0 414 INSERT INTO $table
michael@0 415 (DATETIME,
michael@0 416 LASTPING,
michael@0 417 ID,
michael@0 418 INDEX,
michael@0 419 CUR_IDX,
michael@0 420 CUR_CYC,
michael@0 421 CUR_CONTENT,
michael@0 422 STATE,
michael@0 423 BLESSED,
michael@0 424 MAXCYC,
michael@0 425 MAXIDX,
michael@0 426 REPLACE,
michael@0 427 NOCACHE,
michael@0 428 DELAY,
michael@0 429 REMOTE_USER,
michael@0 430 HTTP_USER_AGENT,
michael@0 431 REMOTE_ADDR,
michael@0 432 USER_EMAIL,
michael@0 433 USER_COMMENT
michael@0 434 )
michael@0 435 VALUES (?,?,?,?,
michael@0 436 ?,?,?,?,
michael@0 437 ?,?,?,?,
michael@0 438 ?,?,?,?,
michael@0 439 ?,?,?)
michael@0 440 };
michael@0 441 $sth = $dbh->prepare($sql);
michael@0 442 $sth->execute($gStartNowStr,
michael@0 443 $gStartNowStr,
michael@0 444 $params{id},
michael@0 445 $params{index}-1,
michael@0 446 ($params{curidx}-1) % $pagedata->length,
michael@0 447 $params{curcyc},
michael@0 448 $params{content},
michael@0 449 "INIT",
michael@0 450 0,
michael@0 451 $params{maxcyc},
michael@0 452 $params{maxidx},
michael@0 453 $params{replace},
michael@0 454 $params{nocache},
michael@0 455 $params{delay},
michael@0 456 $cgi->var("REMOTE_USER"),
michael@0 457 $cgi->var("HTTP_USER_AGENT"),
michael@0 458 $cgi->var("REMOTE_ADDR"),
michael@0 459 "",
michael@0 460 ""
michael@0 461 );
michael@0 462 $sth->finish();
michael@0 463 }
michael@0 464
michael@0 465
michael@0 466 sub updateDataSetTable {
michael@0 467 my $table = shift;
michael@0 468 my $table = "t" . $params{id};
michael@0 469
michael@0 470 my ($sth, $sql);
michael@0 471 $sql = qq{
michael@0 472 INSERT INTO $table
michael@0 473 (DATETIME,
michael@0 474 ID,
michael@0 475 INDEX,
michael@0 476 CUR_IDX,
michael@0 477 CUR_CYC,
michael@0 478 C_PART,
michael@0 479 S_INTVL,
michael@0 480 C_INTVL,
michael@0 481 CONTENT
michael@0 482 )
michael@0 483 VALUES (?,?,?,?,
michael@0 484 ?,?,?,?,?)
michael@0 485 };
michael@0 486
michael@0 487 my $s_intvl = elapsedMilliSeconds( $gStartNow, $params{s_ts} );
michael@0 488
michael@0 489 $sth = $dbh->prepare($sql);
michael@0 490 $sth->execute($gStartNowStr,
michael@0 491 $params{id},
michael@0 492 $params{index}-1,
michael@0 493 ($params{curidx}-1) % $pagedata->length,
michael@0 494 $params{curcyc},
michael@0 495 $params{c_part},
michael@0 496 $s_intvl,
michael@0 497 $params{c_intvl},
michael@0 498 $req->param('content'),
michael@0 499 );
michael@0 500 $sth->finish();
michael@0 501
michael@0 502 }
michael@0 503
michael@0 504
michael@0 505 sub outputForm {
michael@0 506 my @prog = split('/', $0); my $prog = $prog[$#prog];
michael@0 507 print "Content-type: text/html\n\n";
michael@0 508 my $bgcolor = $ENV{SERVER_PORT} == 443 ? '#eebb66' : '#ffffff';
michael@0 509 print <<"ENDOFHTML";
michael@0 510 <html>
michael@0 511 <head>
michael@0 512 <title>Page Loading Times Test</title>
michael@0 513 </head>
michael@0 514 <body bgcolor="$bgcolor">
michael@0 515 <h3>Page Loading Times Test</h3>
michael@0 516
michael@0 517 <p>Questions: <a href="mailto:jrgm\@netscape.com">John Morrison</a>
michael@0 518
michael@0 519 ENDOFHTML
michael@0 520 print "&nbsp;&nbsp;-&nbsp;&nbsp;";
michael@0 521 my $script = $cgi->var("SCRIPT_NAME");
michael@0 522 my $server = $cgi->var("SERVER_NAME");
michael@0 523 # pick the "other" protocol (i.e., test is inverted)
michael@0 524 my $proto = $ENV{SERVER_PORT} == 443 ? 'http://' : 'https://';
michael@0 525 my $other = $proto . $server . $script;
michael@0 526 if ($ENV{SERVER_PORT} == 443) {
michael@0 527 print "[&nbsp;<a href='$other'>With no SSL</a>&nbsp;|&nbsp;<b>With SSL</b>&nbsp;]<br>";
michael@0 528 } else {
michael@0 529 print "[&nbsp;<b>With no SSL</b>&nbsp;|&nbsp;<a href='$other'>With SSL</a>&nbsp;]<br>";
michael@0 530 }
michael@0 531 print <<"ENDOFHTML";
michael@0 532
michael@0 533 <form method="get" action="$prog" >
michael@0 534 <table border="1" cellpadding="5" cellspacing="2">
michael@0 535 <tr>
michael@0 536 <td valign="top">
michael@0 537 Page-load to Page-load Delay (msec):<br>
michael@0 538 (Use 1000. Be nice.)
michael@0 539 </td>
michael@0 540 <td valign="top">
michael@0 541 <select name="delay">
michael@0 542 <option value="0">0
michael@0 543 <option value="500">500
michael@0 544 <option selected value="1000">1000
michael@0 545 <option value="2000">2000
michael@0 546 <option value="3000">3000
michael@0 547 <option value="4000">4000
michael@0 548 <option value="5000">5000
michael@0 549 </select>
michael@0 550 </td>
michael@0 551 </tr>
michael@0 552 <tr>
michael@0 553 <td valign="top">
michael@0 554 Number of test cycles to run:<br>
michael@0 555 <br>
michael@0 556 </td>
michael@0 557 <td valign="top">
michael@0 558 <select name="maxcyc">
michael@0 559 <option value="0">1
michael@0 560 <option value="1">2
michael@0 561 <option value="2">3
michael@0 562 <option value="3">4
michael@0 563 <option value="4" selected>5
michael@0 564 <option value="5">6
michael@0 565 <option value="6">7
michael@0 566 </select>
michael@0 567 </td>
michael@0 568 </tr>
michael@0 569 <tr>
michael@0 570 <td valign="top">
michael@0 571 How long to wait before cancelling (msec):<br>
michael@0 572 (Don't change this unless on a very slow link, or very slow machine.)
michael@0 573 </td>
michael@0 574 <td valign="top">
michael@0 575 <select name="timeout">
michael@0 576 <option value="15000">15000
michael@0 577 <option selected value="30000">30000
michael@0 578 <option value="45000">45000
michael@0 579 <option value="60000">60000
michael@0 580 <option value="90000">90000
michael@0 581 </select>
michael@0 582 </td>
michael@0 583 </tr>
michael@0 584 <tr>
michael@0 585 <td valign="top">
michael@0 586 <input type="reset" value="reset">
michael@0 587 </td>
michael@0 588 <td valign="top">
michael@0 589 <input type="submit" value="submit">
michael@0 590 </td>
michael@0 591 </tr>
michael@0 592 </table>
michael@0 593
michael@0 594 <hr>
michael@0 595 <p>
michael@0 596 You can visit the content that will be loaded, minus the embedded
michael@0 597 javascript, by clicking on any of the links below.
michael@0 598 </p>
michael@0 599
michael@0 600 <table border="1" cellpadding="5" cellspacing="2">
michael@0 601 ENDOFHTML
michael@0 602
michael@0 603 my $i;
michael@0 604 print "<tr>\n";
michael@0 605 my $base = $pagedata->httpbase;
michael@0 606 $base =~ s/^http:/https:/i
michael@0 607 if $ENV{SERVER_PORT} == 443;
michael@0 608 for ($i=0; $i<$pagedata->length; $i++) {
michael@0 609 print "<td nowrap><a href='", $base, $pagedata->url($i), "'>";
michael@0 610 print $pagedata->name($i);
michael@0 611 print "</a>\n";
michael@0 612 print "</tr><tr>\n" if (($i+1)%4 == 0);
michael@0 613 }
michael@0 614 print "</tr>" if (($i+1)%4 != 0);
michael@0 615 print "</table></form></body></html>\n";
michael@0 616 return;
michael@0 617 }
michael@0 618

mercurial