16
16
TMPDIR = 'tmp'
17
17
VERBOSE = False
18
18
19
+ SERVER_HOST = "localhost"
20
+ SERVER_PORT = 8080
21
+
19
22
class TestOptions (OptionParser ):
20
23
def __init__ (self , ** kwargs ):
21
24
OptionParser .__init__ (self , ** kwargs )
@@ -41,7 +44,7 @@ def verifyOptions(self, options):
41
44
if options .browser and options .browserManifestFile :
42
45
print "Warning: ignoring browser argument since manifest file was also supplied"
43
46
if not options .browser and not options .browserManifestFile :
44
- self . error ( "No test browsers found. Use --browserManifest or --browser args." )
47
+ print "No browser arguments supplied, so just starting server on port %s." % SERVER_PORT
45
48
return options
46
49
47
50
def prompt (question ):
@@ -248,6 +251,7 @@ def makeBrowserCommand(browser):
248
251
if (name and name .find (key ) > - 1 ) or path .find (key ) > - 1 :
249
252
command = types [key ](browser )
250
253
command .name = command .name or key
254
+ break
251
255
252
256
if command is None :
253
257
raise Exception ("Unrecognized browser: %s" % browser )
@@ -294,7 +298,9 @@ def setUp(options):
294
298
testBrowsers = makeBrowserCommands (options .browserManifestFile )
295
299
elif options .browser :
296
300
testBrowsers = [makeBrowserCommand ({"path" :options .browser , "name" :None })]
297
- assert len (testBrowsers ) > 0
301
+
302
+ if options .browserManifestFile or options .browser :
303
+ assert len (testBrowsers ) > 0
298
304
299
305
with open (options .manifestFile ) as mf :
300
306
manifestList = json .load (mf )
@@ -319,9 +325,11 @@ def startBrowsers(browsers, options):
319
325
for b in browsers :
320
326
b .setup ()
321
327
print 'Launching' , b .name
328
+ host = 'http://%s:%s' % (SERVER_HOST , SERVER_PORT )
329
+ path = '/test/test_slave.html?'
322
330
qs = 'browser=' + urllib .quote (b .name ) + '&manifestFile=' + urllib .quote (options .manifestFile )
323
331
qs += '&path=' + b .path
324
- b .start ('http://localhost:8080/test/test_slave.html?' + qs )
332
+ b .start (host + path + qs )
325
333
326
334
def teardownBrowsers (browsers ):
327
335
for b in browsers :
@@ -438,26 +446,30 @@ def checkLoad(task, results, browser):
438
446
439
447
def processResults ():
440
448
print ''
441
- numErrors , numEqFailures , numEqNoSnapshot , numFBFFailures = State .numErrors , State .numEqFailures , State .numEqNoSnapshot , State .numFBFFailures
442
- numFatalFailures = (numErrors + numFBFFailures )
443
- if 0 == numEqFailures and 0 == numFatalFailures :
449
+ numFatalFailures = (State .numErrors + State .numFBFFailures )
450
+ if 0 == State .numEqFailures and 0 == numFatalFailures :
444
451
print 'All tests passed.'
445
452
else :
446
453
print 'OHNOES! Some tests failed!'
447
- if 0 < numErrors :
448
- print ' errors:' , numErrors
449
- if 0 < numEqFailures :
450
- print ' different ref/snapshot:' , numEqFailures
451
- if 0 < numFBFFailures :
452
- print ' different first/second rendering:' , numFBFFailures
453
-
454
- if State .masterMode and (0 < numEqFailures or 0 < numEqNoSnapshot ):
454
+ if 0 < State .numErrors :
455
+ print ' errors:' , State .numErrors
456
+ if 0 < State .numEqFailures :
457
+ print ' different ref/snapshot:' , State .numEqFailures
458
+ if 0 < State .numFBFFailures :
459
+ print ' different first/second rendering:' , State .numFBFFailures
460
+
461
+
462
+ def maybeUpdateRefImages (options , browser ):
463
+ if options .masterMode and (0 < State .numEqFailures or 0 < State .numEqNoSnapshot ):
455
464
print "Some eq tests failed or didn't have snapshots."
456
465
print 'Checking to see if master references can be updated...'
466
+ numFatalFailures = (State .numErrors + State .numFBFFailures )
457
467
if 0 < numFatalFailures :
458
468
print ' No. Some non-eq tests failed.'
459
469
else :
460
- ' Yes! The references in tmp/ can be synced with ref/.'
470
+ print ' Yes! The references in tmp/ can be synced with ref/.'
471
+ if options .reftest :
472
+ startReftest (browser )
461
473
if not prompt ('Would you like to update the master copy in ref/?' ):
462
474
print ' OK, not updating.'
463
475
else :
@@ -471,7 +483,8 @@ def processResults():
471
483
print 'done'
472
484
473
485
def startReftest (browser ):
474
- url = "http://127.0.0.1:8080/test/resources/reftest-analyzer.xhtml"
486
+ url = "http://%s:%s" % (SERVER_HOST , SERVER_PORT )
487
+ url += "/test/resources/reftest-analyzer.xhtml"
475
488
url += "#web=/test/eq.log"
476
489
try :
477
490
browser .setup ()
@@ -482,20 +495,8 @@ def startReftest(browser):
482
495
teardownBrowsers ([browser ])
483
496
print "Completed reftest usage."
484
497
485
- def main ( ):
498
+ def runTests ( options , browsers ):
486
499
t1 = time .time ()
487
- optionParser = TestOptions ()
488
- options , args = optionParser .parse_args ()
489
- options = optionParser .verifyOptions (options )
490
- if options == None :
491
- sys .exit (1 )
492
-
493
- httpd = TestServer (('127.0.0.1' , 8080 ), PDFTestHandler )
494
- httpd_thread = threading .Thread (target = httpd .serve_forever )
495
- httpd_thread .setDaemon (True )
496
- httpd_thread .start ()
497
-
498
- browsers = setUp (options )
499
500
try :
500
501
startBrowsers (browsers , options )
501
502
while not State .done :
@@ -506,9 +507,32 @@ def main():
506
507
t2 = time .time ()
507
508
print "Runtime was" , int (t2 - t1 ), "seconds"
508
509
509
- if options .reftest and State .numEqFailures > 0 :
510
+ if options .masterMode :
511
+ maybeUpdateRefImages (options , browsers [0 ])
512
+ elif options .reftest and State .numEqFailures > 0 :
510
513
print "\n Starting reftest harness to examine %d eq test failures." % State .numEqFailures
511
514
startReftest (browsers [0 ])
512
515
516
+ def main ():
517
+ optionParser = TestOptions ()
518
+ options , args = optionParser .parse_args ()
519
+ options = optionParser .verifyOptions (options )
520
+ if options == None :
521
+ sys .exit (1 )
522
+
523
+ httpd = TestServer ((SERVER_HOST , SERVER_PORT ), PDFTestHandler )
524
+ httpd_thread = threading .Thread (target = httpd .serve_forever )
525
+ httpd_thread .setDaemon (True )
526
+ httpd_thread .start ()
527
+
528
+ browsers = setUp (options )
529
+ if len (browsers ) > 0 :
530
+ runTests (options , browsers )
531
+ else :
532
+ # just run the server
533
+ print "Running HTTP server. Press Ctrl-C to quit."
534
+ while True :
535
+ time .sleep (1 )
536
+
513
537
if __name__ == '__main__' :
514
538
main ()
0 commit comments