2008-08-28 10:50:31 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
2012-03-01 11:37:10 +00:00
|
|
|
# Copyright 2012 the V8 project authors. All rights reserved.
|
2008-08-22 13:33:59 +00:00
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions are
|
|
|
|
# met:
|
|
|
|
#
|
|
|
|
# * Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# * Redistributions in binary form must reproduce the above
|
|
|
|
# copyright notice, this list of conditions and the following
|
|
|
|
# disclaimer in the documentation and/or other materials provided
|
|
|
|
# with the distribution.
|
|
|
|
# * Neither the name of Google Inc. nor the names of its
|
|
|
|
# contributors may be used to endorse or promote products derived
|
|
|
|
# from this software without specific prior written permission.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
2008-09-30 15:32:07 +00:00
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
import imp
|
|
|
|
import optparse
|
|
|
|
import os
|
2008-09-25 13:01:26 +00:00
|
|
|
from os.path import join, dirname, abspath, basename, isdir, exists
|
2008-08-22 13:33:59 +00:00
|
|
|
import platform
|
|
|
|
import re
|
2008-08-29 08:06:17 +00:00
|
|
|
import signal
|
2008-08-22 13:33:59 +00:00
|
|
|
import subprocess
|
|
|
|
import sys
|
2008-08-27 10:11:39 +00:00
|
|
|
import tempfile
|
2008-08-22 13:33:59 +00:00
|
|
|
import time
|
2008-09-30 15:32:07 +00:00
|
|
|
import threading
|
2008-08-22 13:33:59 +00:00
|
|
|
import utils
|
2008-09-30 15:32:07 +00:00
|
|
|
from Queue import Queue, Empty
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
VERBOSE = False
|
|
|
|
|
|
|
|
|
|
|
|
# ---------------------------------------------
|
|
|
|
# --- P r o g r e s s I n d i c a t o r s ---
|
|
|
|
# ---------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
class ProgressIndicator(object):
|
|
|
|
|
|
|
|
def __init__(self, cases):
|
|
|
|
self.cases = cases
|
2008-09-30 15:32:07 +00:00
|
|
|
self.queue = Queue(len(cases))
|
|
|
|
for case in cases:
|
|
|
|
self.queue.put_nowait(case)
|
2008-08-22 13:33:59 +00:00
|
|
|
self.succeeded = 0
|
2008-09-30 15:32:07 +00:00
|
|
|
self.remaining = len(cases)
|
|
|
|
self.total = len(cases)
|
|
|
|
self.failed = [ ]
|
2008-10-29 09:52:31 +00:00
|
|
|
self.crashed = 0
|
2008-09-30 15:32:07 +00:00
|
|
|
self.terminate = False
|
|
|
|
self.lock = threading.Lock()
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2008-09-25 12:38:34 +00:00
|
|
|
def PrintFailureHeader(self, test):
|
|
|
|
if test.IsNegative():
|
|
|
|
negative_marker = '[negative] '
|
|
|
|
else:
|
|
|
|
negative_marker = ''
|
|
|
|
print "=== %(label)s %(negative)s===" % {
|
|
|
|
'label': test.GetLabel(),
|
|
|
|
'negative': negative_marker
|
|
|
|
}
|
|
|
|
print "Path: %s" % "/".join(test.path)
|
|
|
|
|
2008-09-30 15:32:07 +00:00
|
|
|
def Run(self, tasks):
|
2008-08-22 13:33:59 +00:00
|
|
|
self.Starting()
|
2008-09-30 15:32:07 +00:00
|
|
|
threads = []
|
|
|
|
# Spawn N-1 threads and then use this thread as the last one.
|
|
|
|
# That way -j1 avoids threading altogether which is a nice fallback
|
|
|
|
# in case of threading problems.
|
|
|
|
for i in xrange(tasks - 1):
|
|
|
|
thread = threading.Thread(target=self.RunSingle, args=[])
|
|
|
|
threads.append(thread)
|
|
|
|
thread.start()
|
|
|
|
try:
|
|
|
|
self.RunSingle()
|
|
|
|
# Wait for the remaining threads
|
|
|
|
for thread in threads:
|
|
|
|
# Use a timeout so that signals (ctrl-c) will be processed.
|
|
|
|
thread.join(timeout=10000000)
|
|
|
|
except Exception, e:
|
|
|
|
# If there's an exception we schedule an interruption for any
|
|
|
|
# remaining threads.
|
|
|
|
self.terminate = True
|
2008-10-01 09:07:45 +00:00
|
|
|
# ...and then reraise the exception to bail out
|
|
|
|
raise
|
2008-09-30 15:32:07 +00:00
|
|
|
self.Done()
|
|
|
|
return not self.failed
|
|
|
|
|
|
|
|
def RunSingle(self):
|
|
|
|
while not self.terminate:
|
|
|
|
try:
|
|
|
|
test = self.queue.get_nowait()
|
|
|
|
except Empty:
|
|
|
|
return
|
2008-08-22 13:33:59 +00:00
|
|
|
case = test.case
|
2008-09-30 15:32:07 +00:00
|
|
|
self.lock.acquire()
|
2008-08-22 13:33:59 +00:00
|
|
|
self.AboutToRun(case)
|
2008-09-30 15:32:07 +00:00
|
|
|
self.lock.release()
|
|
|
|
try:
|
2008-10-01 09:07:45 +00:00
|
|
|
start = time.time()
|
2008-09-30 15:32:07 +00:00
|
|
|
output = case.Run()
|
2008-10-01 09:07:45 +00:00
|
|
|
case.duration = (time.time() - start)
|
2011-04-15 09:41:09 +00:00
|
|
|
except BreakNowException:
|
|
|
|
self.terminate = True
|
2008-09-30 15:32:07 +00:00
|
|
|
except IOError, e:
|
|
|
|
assert self.terminate
|
|
|
|
return
|
|
|
|
if self.terminate:
|
|
|
|
return
|
|
|
|
self.lock.acquire()
|
2008-08-27 10:11:39 +00:00
|
|
|
if output.UnexpectedOutput():
|
2008-09-30 15:32:07 +00:00
|
|
|
self.failed.append(output)
|
2008-10-29 09:52:31 +00:00
|
|
|
if output.HasCrashed():
|
|
|
|
self.crashed += 1
|
2008-08-22 13:33:59 +00:00
|
|
|
else:
|
|
|
|
self.succeeded += 1
|
|
|
|
self.remaining -= 1
|
|
|
|
self.HasRun(output)
|
2008-09-30 15:32:07 +00:00
|
|
|
self.lock.release()
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
def EscapeCommand(command):
|
|
|
|
parts = []
|
|
|
|
for part in command:
|
|
|
|
if ' ' in part:
|
2012-07-03 07:45:58 +00:00
|
|
|
# Escape spaces and double quotes. We may need to escape more characters
|
|
|
|
# for this to work properly.
|
|
|
|
parts.append('"%s"' % part.replace('"', '\\"'))
|
2008-08-22 13:33:59 +00:00
|
|
|
else:
|
|
|
|
parts.append(part)
|
|
|
|
return " ".join(parts)
|
|
|
|
|
|
|
|
|
|
|
|
class SimpleProgressIndicator(ProgressIndicator):
|
|
|
|
|
|
|
|
def Starting(self):
|
|
|
|
print 'Running %i tests' % len(self.cases)
|
|
|
|
|
|
|
|
def Done(self):
|
|
|
|
print
|
2008-09-30 15:32:07 +00:00
|
|
|
for failed in self.failed:
|
2008-09-25 12:38:34 +00:00
|
|
|
self.PrintFailureHeader(failed.test)
|
2008-08-22 13:33:59 +00:00
|
|
|
if failed.output.stderr:
|
|
|
|
print "--- stderr ---"
|
|
|
|
print failed.output.stderr.strip()
|
|
|
|
if failed.output.stdout:
|
|
|
|
print "--- stdout ---"
|
|
|
|
print failed.output.stdout.strip()
|
2008-08-29 12:52:21 +00:00
|
|
|
print "Command: %s" % EscapeCommand(failed.command)
|
2008-10-29 09:52:31 +00:00
|
|
|
if failed.HasCrashed():
|
2009-03-24 12:47:53 +00:00
|
|
|
print "--- CRASHED ---"
|
2009-06-04 09:18:39 +00:00
|
|
|
if failed.HasTimedOut():
|
|
|
|
print "--- TIMEOUT ---"
|
2008-09-30 15:32:07 +00:00
|
|
|
if len(self.failed) == 0:
|
2008-08-22 13:33:59 +00:00
|
|
|
print "==="
|
|
|
|
print "=== All tests succeeded"
|
|
|
|
print "==="
|
|
|
|
else:
|
|
|
|
print
|
|
|
|
print "==="
|
2008-09-30 15:32:07 +00:00
|
|
|
print "=== %i tests failed" % len(self.failed)
|
2008-10-29 09:52:31 +00:00
|
|
|
if self.crashed > 0:
|
|
|
|
print "=== %i tests CRASHED" % self.crashed
|
2008-08-22 13:33:59 +00:00
|
|
|
print "==="
|
|
|
|
|
|
|
|
|
|
|
|
class VerboseProgressIndicator(SimpleProgressIndicator):
|
|
|
|
|
|
|
|
def AboutToRun(self, case):
|
2008-10-01 09:07:45 +00:00
|
|
|
print 'Starting %s...' % case.GetLabel()
|
2008-08-22 13:33:59 +00:00
|
|
|
sys.stdout.flush()
|
|
|
|
|
2008-08-27 10:11:39 +00:00
|
|
|
def HasRun(self, output):
|
|
|
|
if output.UnexpectedOutput():
|
2008-10-29 09:52:31 +00:00
|
|
|
if output.HasCrashed():
|
|
|
|
outcome = 'CRASH'
|
|
|
|
else:
|
|
|
|
outcome = 'FAIL'
|
2008-08-22 13:33:59 +00:00
|
|
|
else:
|
2008-10-01 09:07:45 +00:00
|
|
|
outcome = 'pass'
|
|
|
|
print 'Done running %s: %s' % (output.test.GetLabel(), outcome)
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
class DotsProgressIndicator(SimpleProgressIndicator):
|
|
|
|
|
|
|
|
def AboutToRun(self, case):
|
|
|
|
pass
|
|
|
|
|
2008-08-27 10:11:39 +00:00
|
|
|
def HasRun(self, output):
|
2008-09-30 15:32:07 +00:00
|
|
|
total = self.succeeded + len(self.failed)
|
2008-08-22 13:33:59 +00:00
|
|
|
if (total > 1) and (total % 50 == 1):
|
|
|
|
sys.stdout.write('\n')
|
2008-08-27 10:11:39 +00:00
|
|
|
if output.UnexpectedOutput():
|
2008-10-29 09:52:31 +00:00
|
|
|
if output.HasCrashed():
|
|
|
|
sys.stdout.write('C')
|
|
|
|
sys.stdout.flush()
|
2009-06-04 09:18:39 +00:00
|
|
|
elif output.HasTimedOut():
|
|
|
|
sys.stdout.write('T')
|
|
|
|
sys.stdout.flush()
|
2008-10-29 09:52:31 +00:00
|
|
|
else:
|
|
|
|
sys.stdout.write('F')
|
|
|
|
sys.stdout.flush()
|
2008-08-22 13:33:59 +00:00
|
|
|
else:
|
|
|
|
sys.stdout.write('.')
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
|
|
|
|
|
|
|
class CompactProgressIndicator(ProgressIndicator):
|
|
|
|
|
|
|
|
def __init__(self, cases, templates):
|
|
|
|
super(CompactProgressIndicator, self).__init__(cases)
|
|
|
|
self.templates = templates
|
|
|
|
self.last_status_length = 0
|
|
|
|
self.start_time = time.time()
|
2008-08-27 10:11:39 +00:00
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
def Starting(self):
|
|
|
|
pass
|
2008-08-27 10:11:39 +00:00
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
def Done(self):
|
|
|
|
self.PrintProgress('Done')
|
2008-08-27 10:11:39 +00:00
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
def AboutToRun(self, case):
|
2008-08-27 10:11:39 +00:00
|
|
|
self.PrintProgress(case.GetLabel())
|
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
def HasRun(self, output):
|
2008-08-27 10:11:39 +00:00
|
|
|
if output.UnexpectedOutput():
|
2008-09-25 12:38:34 +00:00
|
|
|
self.ClearLine(self.last_status_length)
|
|
|
|
self.PrintFailureHeader(output.test)
|
2008-08-22 13:33:59 +00:00
|
|
|
stdout = output.output.stdout.strip()
|
|
|
|
if len(stdout):
|
|
|
|
print self.templates['stdout'] % stdout
|
|
|
|
stderr = output.output.stderr.strip()
|
|
|
|
if len(stderr):
|
|
|
|
print self.templates['stderr'] % stderr
|
2008-10-24 08:40:02 +00:00
|
|
|
print "Command: %s" % EscapeCommand(output.command)
|
2008-10-29 09:52:31 +00:00
|
|
|
if output.HasCrashed():
|
2009-03-24 12:47:53 +00:00
|
|
|
print "--- CRASHED ---"
|
2009-06-04 09:18:39 +00:00
|
|
|
if output.HasTimedOut():
|
|
|
|
print "--- TIMEOUT ---"
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
def Truncate(self, str, length):
|
|
|
|
if length and (len(str) > (length - 3)):
|
|
|
|
return str[:(length-3)] + "..."
|
|
|
|
else:
|
|
|
|
return str
|
|
|
|
|
|
|
|
def PrintProgress(self, name):
|
|
|
|
self.ClearLine(self.last_status_length)
|
|
|
|
elapsed = time.time() - self.start_time
|
|
|
|
status = self.templates['status_line'] % {
|
|
|
|
'passed': self.succeeded,
|
|
|
|
'remaining': (((self.total - self.remaining) * 100) // self.total),
|
2008-09-30 15:32:07 +00:00
|
|
|
'failed': len(self.failed),
|
2008-08-22 13:33:59 +00:00
|
|
|
'test': name,
|
|
|
|
'mins': int(elapsed) / 60,
|
|
|
|
'secs': int(elapsed) % 60
|
|
|
|
}
|
|
|
|
status = self.Truncate(status, 78)
|
|
|
|
self.last_status_length = len(status)
|
|
|
|
print status,
|
|
|
|
sys.stdout.flush()
|
|
|
|
|
|
|
|
|
|
|
|
class ColorProgressIndicator(CompactProgressIndicator):
|
|
|
|
|
|
|
|
def __init__(self, cases):
|
|
|
|
templates = {
|
|
|
|
'status_line': "[%(mins)02i:%(secs)02i|\033[34m%%%(remaining) 4d\033[0m|\033[32m+%(passed) 4d\033[0m|\033[31m-%(failed) 4d\033[0m]: %(test)s",
|
|
|
|
'stdout': "\033[1m%s\033[0m",
|
|
|
|
'stderr': "\033[31m%s\033[0m",
|
|
|
|
}
|
|
|
|
super(ColorProgressIndicator, self).__init__(cases, templates)
|
2008-08-27 10:11:39 +00:00
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
def ClearLine(self, last_line_length):
|
|
|
|
print "\033[1K\r",
|
|
|
|
|
|
|
|
|
|
|
|
class MonochromeProgressIndicator(CompactProgressIndicator):
|
|
|
|
|
|
|
|
def __init__(self, cases):
|
|
|
|
templates = {
|
|
|
|
'status_line': "[%(mins)02i:%(secs)02i|%%%(remaining) 4d|+%(passed) 4d|-%(failed) 4d]: %(test)s",
|
|
|
|
'stdout': '%s',
|
|
|
|
'stderr': '%s',
|
|
|
|
}
|
|
|
|
super(MonochromeProgressIndicator, self).__init__(cases, templates)
|
2008-08-27 10:11:39 +00:00
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
def ClearLine(self, last_line_length):
|
|
|
|
print ("\r" + (" " * last_line_length) + "\r"),
|
|
|
|
|
|
|
|
|
|
|
|
PROGRESS_INDICATORS = {
|
|
|
|
'verbose': VerboseProgressIndicator,
|
|
|
|
'dots': DotsProgressIndicator,
|
|
|
|
'color': ColorProgressIndicator,
|
|
|
|
'mono': MonochromeProgressIndicator
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# -------------------------
|
|
|
|
# --- F r a m e w o r k ---
|
|
|
|
# -------------------------
|
|
|
|
|
2011-04-15 09:41:09 +00:00
|
|
|
class BreakNowException(Exception):
|
|
|
|
def __init__(self, value):
|
|
|
|
self.value = value
|
|
|
|
def __str__(self):
|
|
|
|
return repr(self.value)
|
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
class CommandOutput(object):
|
|
|
|
|
2008-10-29 12:51:14 +00:00
|
|
|
def __init__(self, exit_code, timed_out, stdout, stderr):
|
2008-08-22 13:33:59 +00:00
|
|
|
self.exit_code = exit_code
|
2008-10-29 12:51:14 +00:00
|
|
|
self.timed_out = timed_out
|
2008-08-22 13:33:59 +00:00
|
|
|
self.stdout = stdout
|
|
|
|
self.stderr = stderr
|
2009-10-22 19:09:09 +00:00
|
|
|
self.failed = None
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestCase(object):
|
|
|
|
|
2010-08-24 13:34:59 +00:00
|
|
|
def __init__(self, context, path, mode):
|
2008-08-22 13:33:59 +00:00
|
|
|
self.path = path
|
2008-08-27 10:11:39 +00:00
|
|
|
self.context = context
|
2008-10-01 09:07:45 +00:00
|
|
|
self.duration = None
|
2010-08-24 13:34:59 +00:00
|
|
|
self.mode = mode
|
2008-08-27 10:11:39 +00:00
|
|
|
|
|
|
|
def IsNegative(self):
|
|
|
|
return False
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
def TestsIsolates(self):
|
|
|
|
return False
|
|
|
|
|
2008-10-01 09:07:45 +00:00
|
|
|
def CompareTime(self, other):
|
|
|
|
return cmp(other.duration, self.duration)
|
|
|
|
|
2008-09-26 13:06:49 +00:00
|
|
|
def DidFail(self, output):
|
2009-10-22 19:09:09 +00:00
|
|
|
if output.failed is None:
|
|
|
|
output.failed = self.IsFailureOutput(output)
|
|
|
|
return output.failed
|
2008-09-26 13:06:49 +00:00
|
|
|
|
2008-08-27 10:11:39 +00:00
|
|
|
def IsFailureOutput(self, output):
|
|
|
|
return output.exit_code != 0
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2008-09-08 07:04:22 +00:00
|
|
|
def GetSource(self):
|
|
|
|
return "(no source available)"
|
2009-03-24 12:47:53 +00:00
|
|
|
|
2009-02-03 08:35:03 +00:00
|
|
|
def RunCommand(self, command):
|
2008-09-03 07:31:19 +00:00
|
|
|
full_command = self.context.processor(command)
|
2010-08-24 13:34:59 +00:00
|
|
|
output = Execute(full_command,
|
|
|
|
self.context,
|
2010-12-07 11:31:57 +00:00
|
|
|
self.context.GetTimeout(self, self.mode))
|
2009-07-09 06:39:38 +00:00
|
|
|
self.Cleanup()
|
2010-08-24 13:34:59 +00:00
|
|
|
return TestOutput(self,
|
|
|
|
full_command,
|
|
|
|
output,
|
|
|
|
self.context.store_unexpected_output)
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2009-11-09 09:31:57 +00:00
|
|
|
def BeforeRun(self):
|
|
|
|
pass
|
|
|
|
|
2010-08-24 13:34:59 +00:00
|
|
|
def AfterRun(self, result):
|
2009-11-09 09:31:57 +00:00
|
|
|
pass
|
|
|
|
|
2011-03-16 09:45:28 +00:00
|
|
|
def GetCustomFlags(self, mode):
|
|
|
|
return None
|
|
|
|
|
2009-02-03 08:35:03 +00:00
|
|
|
def Run(self):
|
2009-11-09 09:31:57 +00:00
|
|
|
self.BeforeRun()
|
2011-04-15 09:41:09 +00:00
|
|
|
result = None
|
2009-11-09 09:31:57 +00:00
|
|
|
try:
|
|
|
|
result = self.RunCommand(self.GetCommand())
|
2011-04-15 09:41:09 +00:00
|
|
|
except:
|
|
|
|
self.terminate = True
|
2011-05-09 09:02:27 +00:00
|
|
|
raise BreakNowException("User pressed CTRL+C or IO went wrong")
|
2009-11-09 09:31:57 +00:00
|
|
|
finally:
|
2010-08-24 13:34:59 +00:00
|
|
|
self.AfterRun(result)
|
2009-11-09 09:31:57 +00:00
|
|
|
return result
|
2009-02-03 08:35:03 +00:00
|
|
|
|
2009-07-09 06:39:38 +00:00
|
|
|
def Cleanup(self):
|
|
|
|
return
|
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
class TestOutput(object):
|
|
|
|
|
2010-08-24 13:34:59 +00:00
|
|
|
def __init__(self, test, command, output, store_unexpected_output):
|
2008-08-22 13:33:59 +00:00
|
|
|
self.test = test
|
|
|
|
self.command = command
|
|
|
|
self.output = output
|
2010-08-24 13:34:59 +00:00
|
|
|
self.store_unexpected_output = store_unexpected_output
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2008-08-27 10:11:39 +00:00
|
|
|
def UnexpectedOutput(self):
|
2008-10-29 09:52:31 +00:00
|
|
|
if self.HasCrashed():
|
|
|
|
outcome = CRASH
|
2009-06-17 12:19:51 +00:00
|
|
|
elif self.HasTimedOut():
|
|
|
|
outcome = TIMEOUT
|
2008-10-29 09:52:31 +00:00
|
|
|
elif self.HasFailed():
|
2008-08-27 10:11:39 +00:00
|
|
|
outcome = FAIL
|
|
|
|
else:
|
|
|
|
outcome = PASS
|
|
|
|
return not outcome in self.test.outcomes
|
|
|
|
|
2010-08-24 13:34:59 +00:00
|
|
|
def HasPreciousOutput(self):
|
|
|
|
return self.UnexpectedOutput() and self.store_unexpected_output
|
|
|
|
|
2008-10-29 09:52:31 +00:00
|
|
|
def HasCrashed(self):
|
2008-10-31 13:12:35 +00:00
|
|
|
if utils.IsWindows():
|
2008-10-29 09:52:31 +00:00
|
|
|
return 0x80000000 & self.output.exit_code and not (0x3FFFFF00 & self.output.exit_code)
|
|
|
|
else:
|
2008-10-29 12:51:14 +00:00
|
|
|
# Timed out tests will have exit_code -signal.SIGTERM.
|
|
|
|
if self.output.timed_out:
|
|
|
|
return False
|
|
|
|
return self.output.exit_code < 0 and \
|
|
|
|
self.output.exit_code != -signal.SIGABRT
|
2008-10-29 09:52:31 +00:00
|
|
|
|
2009-06-04 09:18:39 +00:00
|
|
|
def HasTimedOut(self):
|
2011-04-15 09:41:09 +00:00
|
|
|
return self.output.timed_out
|
2009-06-17 12:19:51 +00:00
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
def HasFailed(self):
|
2008-09-26 13:06:49 +00:00
|
|
|
execution_failed = self.test.DidFail(self.output)
|
2008-08-27 10:11:39 +00:00
|
|
|
if self.test.IsNegative():
|
|
|
|
return not execution_failed
|
|
|
|
else:
|
|
|
|
return execution_failed
|
|
|
|
|
|
|
|
|
2008-08-29 08:06:17 +00:00
|
|
|
def KillProcessWithID(pid):
|
2008-10-31 13:12:35 +00:00
|
|
|
if utils.IsWindows():
|
2008-08-29 08:06:17 +00:00
|
|
|
os.popen('taskkill /T /F /PID %d' % pid)
|
|
|
|
else:
|
|
|
|
os.kill(pid, signal.SIGTERM)
|
|
|
|
|
|
|
|
|
2008-08-27 10:11:39 +00:00
|
|
|
MAX_SLEEP_TIME = 0.1
|
|
|
|
INITIAL_SLEEP_TIME = 0.0001
|
|
|
|
SLEEP_TIME_FACTOR = 1.25
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2008-10-29 09:52:31 +00:00
|
|
|
SEM_INVALID_VALUE = -1
|
|
|
|
SEM_NOGPFAULTERRORBOX = 0x0002 # Microsoft Platform SDK WinBase.h
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2008-10-29 09:52:31 +00:00
|
|
|
def Win32SetErrorMode(mode):
|
|
|
|
prev_error_mode = SEM_INVALID_VALUE
|
|
|
|
try:
|
|
|
|
import ctypes
|
2011-04-18 07:23:48 +00:00
|
|
|
prev_error_mode = ctypes.windll.kernel32.SetErrorMode(mode)
|
2008-10-29 09:52:31 +00:00
|
|
|
except ImportError:
|
|
|
|
pass
|
|
|
|
return prev_error_mode
|
2009-03-24 12:47:53 +00:00
|
|
|
|
2008-09-02 14:47:10 +00:00
|
|
|
def RunProcess(context, timeout, args, **rest):
|
|
|
|
if context.verbose: print "#", " ".join(args)
|
|
|
|
popen_args = args
|
2011-04-18 07:23:48 +00:00
|
|
|
prev_error_mode = SEM_INVALID_VALUE
|
2008-10-31 13:12:35 +00:00
|
|
|
if utils.IsWindows():
|
2012-03-13 17:19:24 +00:00
|
|
|
popen_args = subprocess.list2cmdline(args)
|
2008-10-29 10:19:21 +00:00
|
|
|
if context.suppress_dialogs:
|
2008-11-19 10:09:21 +00:00
|
|
|
# Try to change the error mode to avoid dialogs on fatal errors. Don't
|
|
|
|
# touch any existing error mode flags by merging the existing error mode.
|
|
|
|
# See http://blogs.msdn.com/oldnewthing/archive/2004/07/27/198410.aspx.
|
2011-04-18 07:23:48 +00:00
|
|
|
error_mode = SEM_NOGPFAULTERRORBOX
|
|
|
|
prev_error_mode = Win32SetErrorMode(error_mode)
|
|
|
|
Win32SetErrorMode(error_mode | prev_error_mode)
|
2008-08-22 13:33:59 +00:00
|
|
|
process = subprocess.Popen(
|
2008-10-31 13:12:35 +00:00
|
|
|
shell = utils.IsWindows(),
|
2008-09-02 14:47:10 +00:00
|
|
|
args = popen_args,
|
|
|
|
**rest
|
2008-08-27 10:11:39 +00:00
|
|
|
)
|
2008-10-31 13:12:35 +00:00
|
|
|
if utils.IsWindows() and context.suppress_dialogs and prev_error_mode != SEM_INVALID_VALUE:
|
2008-10-29 09:52:31 +00:00
|
|
|
Win32SetErrorMode(prev_error_mode)
|
2008-08-29 08:06:17 +00:00
|
|
|
# Compute the end time - if the process crosses this limit we
|
|
|
|
# consider it timed out.
|
|
|
|
if timeout is None: end_time = None
|
|
|
|
else: end_time = time.time() + timeout
|
|
|
|
timed_out = False
|
|
|
|
# Repeatedly check the exit code from the process in a
|
|
|
|
# loop and keep track of whether or not it times out.
|
2008-08-27 10:11:39 +00:00
|
|
|
exit_code = None
|
|
|
|
sleep_time = INITIAL_SLEEP_TIME
|
|
|
|
while exit_code is None:
|
2008-08-29 08:06:17 +00:00
|
|
|
if (not end_time is None) and (time.time() >= end_time):
|
|
|
|
# Kill the process and wait for it to exit.
|
|
|
|
KillProcessWithID(process.pid)
|
|
|
|
exit_code = process.wait()
|
|
|
|
timed_out = True
|
|
|
|
else:
|
|
|
|
exit_code = process.poll()
|
|
|
|
time.sleep(sleep_time)
|
|
|
|
sleep_time = sleep_time * SLEEP_TIME_FACTOR
|
|
|
|
if sleep_time > MAX_SLEEP_TIME:
|
|
|
|
sleep_time = MAX_SLEEP_TIME
|
|
|
|
return (process, exit_code, timed_out)
|
2008-08-27 10:11:39 +00:00
|
|
|
|
|
|
|
|
2008-08-29 12:52:21 +00:00
|
|
|
def PrintError(str):
|
|
|
|
sys.stderr.write(str)
|
|
|
|
sys.stderr.write('\n')
|
|
|
|
|
|
|
|
|
2009-07-09 06:39:38 +00:00
|
|
|
def CheckedUnlink(name):
|
2011-03-18 20:35:07 +00:00
|
|
|
# On Windows, when run with -jN in parallel processes,
|
|
|
|
# OS often fails to unlink the temp file. Not sure why.
|
|
|
|
# Need to retry.
|
|
|
|
# Idea from https://bugs.webkit.org/attachment.cgi?id=75982&action=prettypatch
|
|
|
|
retry_count = 0
|
|
|
|
while retry_count < 30:
|
|
|
|
try:
|
|
|
|
os.unlink(name)
|
|
|
|
return
|
|
|
|
except OSError, e:
|
2011-04-18 07:23:48 +00:00
|
|
|
retry_count += 1
|
2011-03-18 20:35:07 +00:00
|
|
|
time.sleep(retry_count * 0.1)
|
|
|
|
PrintError("os.unlink() " + str(e))
|
2009-07-09 06:39:38 +00:00
|
|
|
|
2008-08-29 08:06:17 +00:00
|
|
|
def Execute(args, context, timeout=None):
|
2008-08-27 10:11:39 +00:00
|
|
|
(fd_out, outname) = tempfile.mkstemp()
|
|
|
|
(fd_err, errname) = tempfile.mkstemp()
|
2008-08-29 08:06:17 +00:00
|
|
|
(process, exit_code, timed_out) = RunProcess(
|
2008-08-27 10:11:39 +00:00
|
|
|
context,
|
2008-08-29 08:06:17 +00:00
|
|
|
timeout,
|
2008-08-22 13:33:59 +00:00
|
|
|
args = args,
|
2008-08-27 10:11:39 +00:00
|
|
|
stdout = fd_out,
|
|
|
|
stderr = fd_err,
|
2008-08-22 13:33:59 +00:00
|
|
|
)
|
2008-08-27 10:11:39 +00:00
|
|
|
os.close(fd_out)
|
|
|
|
os.close(fd_err)
|
|
|
|
output = file(outname).read()
|
|
|
|
errors = file(errname).read()
|
2008-08-29 12:52:21 +00:00
|
|
|
CheckedUnlink(outname)
|
|
|
|
CheckedUnlink(errname)
|
2008-10-29 12:51:14 +00:00
|
|
|
return CommandOutput(exit_code, timed_out, output, errors)
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
|
2008-08-29 08:06:17 +00:00
|
|
|
def ExecuteNoCapture(args, context, timeout=None):
|
|
|
|
(process, exit_code, timed_out) = RunProcess(
|
2008-08-27 10:11:39 +00:00
|
|
|
context,
|
2008-08-29 08:06:17 +00:00
|
|
|
timeout,
|
2008-08-27 10:11:39 +00:00
|
|
|
args = args,
|
|
|
|
)
|
2008-10-29 12:51:14 +00:00
|
|
|
return CommandOutput(exit_code, False, "", "")
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
def CarCdr(path):
|
|
|
|
if len(path) == 0:
|
|
|
|
return (None, [ ])
|
|
|
|
else:
|
|
|
|
return (path[0], path[1:])
|
|
|
|
|
|
|
|
|
2011-05-09 09:02:27 +00:00
|
|
|
# Use this to run several variants of the tests, e.g.:
|
|
|
|
# VARIANT_FLAGS = [[], ['--always_compact', '--noflush_code']]
|
|
|
|
VARIANT_FLAGS = [[],
|
|
|
|
['--stress-opt', '--always-opt'],
|
|
|
|
['--nocrankshaft']]
|
|
|
|
|
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
class TestConfiguration(object):
|
|
|
|
|
|
|
|
def __init__(self, context, root):
|
|
|
|
self.context = context
|
|
|
|
self.root = root
|
|
|
|
|
2008-08-27 10:11:39 +00:00
|
|
|
def Contains(self, path, file):
|
|
|
|
if len(path) > len(file):
|
|
|
|
return False
|
|
|
|
for i in xrange(len(path)):
|
|
|
|
if not path[i].match(file[i]):
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
2008-08-28 13:17:47 +00:00
|
|
|
def GetTestStatus(self, sections, defs):
|
|
|
|
pass
|
|
|
|
|
2011-05-09 09:02:27 +00:00
|
|
|
def VariantFlags(self):
|
|
|
|
return VARIANT_FLAGS
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
class TestSuite(object):
|
|
|
|
|
|
|
|
def __init__(self, name):
|
|
|
|
self.name = name
|
|
|
|
|
|
|
|
def GetName(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
|
|
|
|
class TestRepository(TestSuite):
|
|
|
|
|
|
|
|
def __init__(self, path):
|
2008-08-29 11:01:05 +00:00
|
|
|
normalized_path = abspath(path)
|
|
|
|
super(TestRepository, self).__init__(basename(normalized_path))
|
|
|
|
self.path = normalized_path
|
2008-08-22 13:33:59 +00:00
|
|
|
self.is_loaded = False
|
|
|
|
self.config = None
|
|
|
|
|
|
|
|
def GetConfiguration(self, context):
|
|
|
|
if self.is_loaded:
|
|
|
|
return self.config
|
|
|
|
self.is_loaded = True
|
|
|
|
file = None
|
|
|
|
try:
|
|
|
|
(file, pathname, description) = imp.find_module('testcfg', [ self.path ])
|
2009-02-25 10:09:42 +00:00
|
|
|
module = imp.load_module('testcfg', file, pathname, description)
|
2008-08-22 13:33:59 +00:00
|
|
|
self.config = module.GetConfiguration(context, self.path)
|
|
|
|
finally:
|
|
|
|
if file:
|
|
|
|
file.close()
|
|
|
|
return self.config
|
|
|
|
|
|
|
|
def GetBuildRequirements(self, path, context):
|
|
|
|
return self.GetConfiguration(context).GetBuildRequirements()
|
|
|
|
|
2012-03-07 12:51:31 +00:00
|
|
|
def DownloadData(self, context):
|
|
|
|
config = self.GetConfiguration(context)
|
|
|
|
if 'DownloadData' in dir(config):
|
|
|
|
config.DownloadData()
|
|
|
|
|
2010-08-24 13:34:59 +00:00
|
|
|
def AddTestsToList(self, result, current_path, path, context, mode):
|
2012-03-07 12:51:31 +00:00
|
|
|
config = self.GetConfiguration(context)
|
|
|
|
for v in config.VariantFlags():
|
|
|
|
tests = config.ListTests(current_path, path, mode, v)
|
2010-08-24 13:34:59 +00:00
|
|
|
for t in tests: t.variant_flags = v
|
|
|
|
result += tests
|
|
|
|
|
2008-08-28 13:17:47 +00:00
|
|
|
def GetTestStatus(self, context, sections, defs):
|
|
|
|
self.GetConfiguration(context).GetTestStatus(sections, defs)
|
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
class LiteralTestSuite(TestSuite):
|
|
|
|
|
|
|
|
def __init__(self, tests):
|
|
|
|
super(LiteralTestSuite, self).__init__('root')
|
|
|
|
self.tests = tests
|
|
|
|
|
|
|
|
def GetBuildRequirements(self, path, context):
|
|
|
|
(name, rest) = CarCdr(path)
|
|
|
|
result = [ ]
|
|
|
|
for test in self.tests:
|
2008-08-27 10:11:39 +00:00
|
|
|
if not name or name.match(test.GetName()):
|
2008-08-22 13:33:59 +00:00
|
|
|
result += test.GetBuildRequirements(rest, context)
|
|
|
|
return result
|
|
|
|
|
2012-03-07 12:51:31 +00:00
|
|
|
def DownloadData(self, path, context):
|
|
|
|
(name, rest) = CarCdr(path)
|
|
|
|
for test in self.tests:
|
|
|
|
if not name or name.match(test.GetName()):
|
|
|
|
test.DownloadData(context)
|
|
|
|
|
2011-03-21 12:57:25 +00:00
|
|
|
def ListTests(self, current_path, path, context, mode, variant_flags):
|
2008-08-22 13:33:59 +00:00
|
|
|
(name, rest) = CarCdr(path)
|
|
|
|
result = [ ]
|
|
|
|
for test in self.tests:
|
|
|
|
test_name = test.GetName()
|
2008-08-27 10:11:39 +00:00
|
|
|
if not name or name.match(test_name):
|
2008-08-22 13:33:59 +00:00
|
|
|
full_path = current_path + [test_name]
|
2010-08-24 13:34:59 +00:00
|
|
|
test.AddTestsToList(result, full_path, path, context, mode)
|
2008-08-22 13:33:59 +00:00
|
|
|
return result
|
|
|
|
|
2008-08-28 13:17:47 +00:00
|
|
|
def GetTestStatus(self, context, sections, defs):
|
|
|
|
for test in self.tests:
|
|
|
|
test.GetTestStatus(context, sections, defs)
|
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2010-08-24 13:34:59 +00:00
|
|
|
SUFFIX = {
|
|
|
|
'debug' : '_g',
|
|
|
|
'release' : '' }
|
|
|
|
FLAGS = {
|
2012-03-16 14:33:55 +00:00
|
|
|
'debug' : ['--nobreak-on-abort', '--enable-slow-asserts', '--debug-code', '--verify-heap'],
|
|
|
|
'release' : ['--nobreak-on-abort']}
|
2010-08-24 13:34:59 +00:00
|
|
|
TIMEOUT_SCALEFACTOR = {
|
|
|
|
'debug' : 4,
|
|
|
|
'release' : 1 }
|
2008-08-27 10:11:39 +00:00
|
|
|
|
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
class Context(object):
|
|
|
|
|
2010-08-24 13:34:59 +00:00
|
|
|
def __init__(self, workspace, buildspace, verbose, vm, timeout, processor, suppress_dialogs, store_unexpected_output):
|
2008-08-22 13:33:59 +00:00
|
|
|
self.workspace = workspace
|
|
|
|
self.buildspace = buildspace
|
2008-08-27 10:11:39 +00:00
|
|
|
self.verbose = verbose
|
|
|
|
self.vm_root = vm
|
|
|
|
self.timeout = timeout
|
2008-09-03 07:31:19 +00:00
|
|
|
self.processor = processor
|
2008-10-29 10:19:21 +00:00
|
|
|
self.suppress_dialogs = suppress_dialogs
|
2010-08-24 13:34:59 +00:00
|
|
|
self.store_unexpected_output = store_unexpected_output
|
2008-08-27 10:11:39 +00:00
|
|
|
|
|
|
|
def GetVm(self, mode):
|
2009-03-19 17:09:07 +00:00
|
|
|
name = self.vm_root + SUFFIX[mode]
|
|
|
|
if utils.IsWindows() and not name.endswith('.exe'):
|
|
|
|
name = name + '.exe'
|
|
|
|
return name
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2010-08-24 13:34:59 +00:00
|
|
|
def GetVmCommand(self, testcase, mode):
|
|
|
|
return [self.GetVm(mode)] + self.GetVmFlags(testcase, mode)
|
|
|
|
|
|
|
|
def GetVmFlags(self, testcase, mode):
|
2011-03-16 09:45:28 +00:00
|
|
|
flags = testcase.GetCustomFlags(mode)
|
|
|
|
if flags is None:
|
|
|
|
flags = FLAGS[mode]
|
|
|
|
return testcase.variant_flags + flags
|
2010-08-24 13:34:59 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
def GetTimeout(self, testcase, mode):
|
|
|
|
result = self.timeout * TIMEOUT_SCALEFACTOR[mode]
|
|
|
|
if '--stress-opt' in self.GetVmFlags(testcase, mode):
|
2012-02-09 08:47:18 +00:00
|
|
|
return result * 4
|
2010-12-07 11:31:57 +00:00
|
|
|
else:
|
|
|
|
return result
|
2010-08-24 13:34:59 +00:00
|
|
|
|
2010-01-18 13:17:38 +00:00
|
|
|
def RunTestCases(cases_to_run, progress, tasks):
|
2008-08-22 13:33:59 +00:00
|
|
|
progress = PROGRESS_INDICATORS[progress](cases_to_run)
|
2011-04-15 09:41:09 +00:00
|
|
|
result = 0
|
|
|
|
try:
|
|
|
|
result = progress.Run(tasks)
|
|
|
|
except Exception, e:
|
|
|
|
print "\n", e
|
|
|
|
return result
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
|
2008-09-02 12:20:15 +00:00
|
|
|
def BuildRequirements(context, requirements, mode, scons_flags):
|
|
|
|
command_line = (['scons', '-Y', context.workspace, 'mode=' + ",".join(mode)]
|
|
|
|
+ requirements
|
|
|
|
+ scons_flags)
|
2008-08-27 10:11:39 +00:00
|
|
|
output = ExecuteNoCapture(command_line, context)
|
2008-08-22 13:33:59 +00:00
|
|
|
return output.exit_code == 0
|
|
|
|
|
|
|
|
|
|
|
|
# -------------------------------------------
|
|
|
|
# --- T e s t C o n f i g u r a t i o n ---
|
|
|
|
# -------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
SKIP = 'skip'
|
|
|
|
FAIL = 'fail'
|
|
|
|
PASS = 'pass'
|
|
|
|
OKAY = 'okay'
|
|
|
|
TIMEOUT = 'timeout'
|
|
|
|
CRASH = 'crash'
|
2008-08-27 10:11:39 +00:00
|
|
|
SLOW = 'slow'
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Expression(object):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class Constant(Expression):
|
|
|
|
|
|
|
|
def __init__(self, value):
|
|
|
|
self.value = value
|
|
|
|
|
|
|
|
def Evaluate(self, env, defs):
|
|
|
|
return self.value
|
|
|
|
|
|
|
|
|
|
|
|
class Variable(Expression):
|
|
|
|
|
|
|
|
def __init__(self, name):
|
|
|
|
self.name = name
|
|
|
|
|
|
|
|
def GetOutcomes(self, env, defs):
|
|
|
|
if self.name in env: return ListSet([env[self.name]])
|
|
|
|
else: return Nothing()
|
|
|
|
|
2010-12-10 12:05:28 +00:00
|
|
|
def Evaluate(self, env, defs):
|
|
|
|
return env[self.name]
|
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
class Outcome(Expression):
|
|
|
|
|
|
|
|
def __init__(self, name):
|
|
|
|
self.name = name
|
|
|
|
|
|
|
|
def GetOutcomes(self, env, defs):
|
|
|
|
if self.name in defs:
|
2008-08-27 10:11:39 +00:00
|
|
|
return defs[self.name].GetOutcomes(env, defs)
|
2008-08-22 13:33:59 +00:00
|
|
|
else:
|
|
|
|
return ListSet([self.name])
|
|
|
|
|
|
|
|
|
|
|
|
class Set(object):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class ListSet(Set):
|
|
|
|
|
|
|
|
def __init__(self, elms):
|
|
|
|
self.elms = elms
|
2008-08-27 10:11:39 +00:00
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
def __str__(self):
|
|
|
|
return "ListSet%s" % str(self.elms)
|
|
|
|
|
|
|
|
def Intersect(self, that):
|
|
|
|
if not isinstance(that, ListSet):
|
|
|
|
return that.Intersect(self)
|
|
|
|
return ListSet([ x for x in self.elms if x in that.elms ])
|
|
|
|
|
|
|
|
def Union(self, that):
|
|
|
|
if not isinstance(that, ListSet):
|
|
|
|
return that.Union(self)
|
|
|
|
return ListSet(self.elms + [ x for x in that.elms if x not in self.elms ])
|
2008-08-27 10:11:39 +00:00
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
def IsEmpty(self):
|
|
|
|
return len(self.elms) == 0
|
|
|
|
|
|
|
|
|
|
|
|
class Everything(Set):
|
|
|
|
|
|
|
|
def Intersect(self, that):
|
|
|
|
return that
|
|
|
|
|
|
|
|
def Union(self, that):
|
|
|
|
return self
|
2008-08-27 10:11:39 +00:00
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
def IsEmpty(self):
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
class Nothing(Set):
|
|
|
|
|
|
|
|
def Intersect(self, that):
|
|
|
|
return self
|
|
|
|
|
|
|
|
def Union(self, that):
|
|
|
|
return that
|
2008-08-27 10:11:39 +00:00
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
def IsEmpty(self):
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
class Operation(Expression):
|
|
|
|
|
|
|
|
def __init__(self, left, op, right):
|
|
|
|
self.left = left
|
|
|
|
self.op = op
|
|
|
|
self.right = right
|
|
|
|
|
|
|
|
def Evaluate(self, env, defs):
|
|
|
|
if self.op == '||' or self.op == ',':
|
|
|
|
return self.left.Evaluate(env, defs) or self.right.Evaluate(env, defs)
|
|
|
|
elif self.op == 'if':
|
|
|
|
return False
|
|
|
|
elif self.op == '==':
|
|
|
|
inter = self.left.GetOutcomes(env, defs).Intersect(self.right.GetOutcomes(env, defs))
|
|
|
|
return not inter.IsEmpty()
|
2012-03-01 11:37:10 +00:00
|
|
|
elif self.op == '!=':
|
|
|
|
inter = self.left.GetOutcomes(env, defs).Intersect(self.right.GetOutcomes(env, defs))
|
|
|
|
return inter.IsEmpty()
|
2008-08-22 13:33:59 +00:00
|
|
|
else:
|
|
|
|
assert self.op == '&&'
|
|
|
|
return self.left.Evaluate(env, defs) and self.right.Evaluate(env, defs)
|
|
|
|
|
|
|
|
def GetOutcomes(self, env, defs):
|
|
|
|
if self.op == '||' or self.op == ',':
|
|
|
|
return self.left.GetOutcomes(env, defs).Union(self.right.GetOutcomes(env, defs))
|
|
|
|
elif self.op == 'if':
|
|
|
|
if self.right.Evaluate(env, defs): return self.left.GetOutcomes(env, defs)
|
|
|
|
else: return Nothing()
|
|
|
|
else:
|
|
|
|
assert self.op == '&&'
|
|
|
|
return self.left.GetOutcomes(env, defs).Intersect(self.right.GetOutcomes(env, defs))
|
|
|
|
|
|
|
|
|
|
|
|
def IsAlpha(str):
|
|
|
|
for char in str:
|
|
|
|
if not (char.isalpha() or char.isdigit() or char == '_'):
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
class Tokenizer(object):
|
|
|
|
"""A simple string tokenizer that chops expressions into variables,
|
|
|
|
parens and operators"""
|
|
|
|
|
|
|
|
def __init__(self, expr):
|
|
|
|
self.index = 0
|
|
|
|
self.expr = expr
|
|
|
|
self.length = len(expr)
|
|
|
|
self.tokens = None
|
|
|
|
|
|
|
|
def Current(self, length = 1):
|
2008-08-27 10:11:39 +00:00
|
|
|
if not self.HasMore(length): return ""
|
2008-08-22 13:33:59 +00:00
|
|
|
return self.expr[self.index:self.index+length]
|
|
|
|
|
|
|
|
def HasMore(self, length = 1):
|
|
|
|
return self.index < self.length + (length - 1)
|
|
|
|
|
|
|
|
def Advance(self, count = 1):
|
|
|
|
self.index = self.index + count
|
|
|
|
|
|
|
|
def AddToken(self, token):
|
|
|
|
self.tokens.append(token)
|
|
|
|
|
|
|
|
def SkipSpaces(self):
|
2008-08-27 10:11:39 +00:00
|
|
|
while self.HasMore() and self.Current().isspace():
|
2008-08-22 13:33:59 +00:00
|
|
|
self.Advance()
|
|
|
|
|
|
|
|
def Tokenize(self):
|
|
|
|
self.tokens = [ ]
|
|
|
|
while self.HasMore():
|
|
|
|
self.SkipSpaces()
|
|
|
|
if not self.HasMore():
|
|
|
|
return None
|
|
|
|
if self.Current() == '(':
|
|
|
|
self.AddToken('(')
|
|
|
|
self.Advance()
|
2008-08-27 10:11:39 +00:00
|
|
|
elif self.Current() == ')':
|
2008-08-22 13:33:59 +00:00
|
|
|
self.AddToken(')')
|
|
|
|
self.Advance()
|
|
|
|
elif self.Current() == '$':
|
|
|
|
self.AddToken('$')
|
|
|
|
self.Advance()
|
|
|
|
elif self.Current() == ',':
|
|
|
|
self.AddToken(',')
|
|
|
|
self.Advance()
|
|
|
|
elif IsAlpha(self.Current()):
|
|
|
|
buf = ""
|
|
|
|
while self.HasMore() and IsAlpha(self.Current()):
|
|
|
|
buf += self.Current()
|
|
|
|
self.Advance()
|
|
|
|
self.AddToken(buf)
|
|
|
|
elif self.Current(2) == '&&':
|
|
|
|
self.AddToken('&&')
|
|
|
|
self.Advance(2)
|
|
|
|
elif self.Current(2) == '||':
|
|
|
|
self.AddToken('||')
|
|
|
|
self.Advance(2)
|
|
|
|
elif self.Current(2) == '==':
|
|
|
|
self.AddToken('==')
|
|
|
|
self.Advance(2)
|
2012-03-01 11:37:10 +00:00
|
|
|
elif self.Current(2) == '!=':
|
|
|
|
self.AddToken('!=')
|
|
|
|
self.Advance(2)
|
2008-08-22 13:33:59 +00:00
|
|
|
else:
|
|
|
|
return None
|
|
|
|
return self.tokens
|
|
|
|
|
|
|
|
|
|
|
|
class Scanner(object):
|
|
|
|
"""A simple scanner that can serve out tokens from a given list"""
|
|
|
|
|
|
|
|
def __init__(self, tokens):
|
|
|
|
self.tokens = tokens
|
|
|
|
self.length = len(tokens)
|
|
|
|
self.index = 0
|
|
|
|
|
|
|
|
def HasMore(self):
|
|
|
|
return self.index < self.length
|
|
|
|
|
|
|
|
def Current(self):
|
|
|
|
return self.tokens[self.index]
|
|
|
|
|
|
|
|
def Advance(self):
|
|
|
|
self.index = self.index + 1
|
|
|
|
|
|
|
|
|
|
|
|
def ParseAtomicExpression(scan):
|
|
|
|
if scan.Current() == "true":
|
|
|
|
scan.Advance()
|
|
|
|
return Constant(True)
|
|
|
|
elif scan.Current() == "false":
|
|
|
|
scan.Advance()
|
|
|
|
return Constant(False)
|
|
|
|
elif IsAlpha(scan.Current()):
|
|
|
|
name = scan.Current()
|
|
|
|
scan.Advance()
|
|
|
|
return Outcome(name.lower())
|
|
|
|
elif scan.Current() == '$':
|
|
|
|
scan.Advance()
|
|
|
|
if not IsAlpha(scan.Current()):
|
|
|
|
return None
|
|
|
|
name = scan.Current()
|
|
|
|
scan.Advance()
|
|
|
|
return Variable(name.lower())
|
|
|
|
elif scan.Current() == '(':
|
|
|
|
scan.Advance()
|
|
|
|
result = ParseLogicalExpression(scan)
|
|
|
|
if (not result) or (scan.Current() != ')'):
|
|
|
|
return None
|
|
|
|
scan.Advance()
|
|
|
|
return result
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
2012-03-01 11:37:10 +00:00
|
|
|
BINARIES = ['==', '!=']
|
2008-08-22 13:33:59 +00:00
|
|
|
def ParseOperatorExpression(scan):
|
|
|
|
left = ParseAtomicExpression(scan)
|
|
|
|
if not left: return None
|
|
|
|
while scan.HasMore() and (scan.Current() in BINARIES):
|
|
|
|
op = scan.Current()
|
|
|
|
scan.Advance()
|
|
|
|
right = ParseOperatorExpression(scan)
|
|
|
|
if not right:
|
|
|
|
return None
|
|
|
|
left = Operation(left, op, right)
|
|
|
|
return left
|
|
|
|
|
|
|
|
|
|
|
|
def ParseConditionalExpression(scan):
|
|
|
|
left = ParseOperatorExpression(scan)
|
|
|
|
if not left: return None
|
2008-10-31 07:27:03 +00:00
|
|
|
while scan.HasMore() and (scan.Current() == 'if'):
|
2008-08-22 13:33:59 +00:00
|
|
|
scan.Advance()
|
|
|
|
right = ParseOperatorExpression(scan)
|
|
|
|
if not right:
|
|
|
|
return None
|
2012-03-01 11:37:10 +00:00
|
|
|
left = Operation(left, 'if', right)
|
2008-08-22 13:33:59 +00:00
|
|
|
return left
|
|
|
|
|
|
|
|
|
|
|
|
LOGICALS = ["&&", "||", ","]
|
|
|
|
def ParseLogicalExpression(scan):
|
|
|
|
left = ParseConditionalExpression(scan)
|
|
|
|
if not left: return None
|
|
|
|
while scan.HasMore() and (scan.Current() in LOGICALS):
|
|
|
|
op = scan.Current()
|
|
|
|
scan.Advance()
|
|
|
|
right = ParseConditionalExpression(scan)
|
|
|
|
if not right:
|
|
|
|
return None
|
|
|
|
left = Operation(left, op, right)
|
|
|
|
return left
|
|
|
|
|
|
|
|
|
|
|
|
def ParseCondition(expr):
|
|
|
|
"""Parses a logical expression into an Expression object"""
|
2008-08-27 10:11:39 +00:00
|
|
|
tokens = Tokenizer(expr).Tokenize()
|
2008-08-22 13:33:59 +00:00
|
|
|
if not tokens:
|
|
|
|
print "Malformed expression: '%s'" % expr
|
|
|
|
return None
|
|
|
|
scan = Scanner(tokens)
|
|
|
|
ast = ParseLogicalExpression(scan)
|
|
|
|
if not ast:
|
|
|
|
print "Malformed expression: '%s'" % expr
|
|
|
|
return None
|
2008-10-31 13:12:35 +00:00
|
|
|
if scan.HasMore():
|
|
|
|
print "Malformed expression: '%s'" % expr
|
|
|
|
return None
|
2008-08-22 13:33:59 +00:00
|
|
|
return ast
|
|
|
|
|
|
|
|
|
|
|
|
class ClassifiedTest(object):
|
|
|
|
|
|
|
|
def __init__(self, case, outcomes):
|
|
|
|
self.case = case
|
|
|
|
self.outcomes = outcomes
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
def TestsIsolates(self):
|
|
|
|
return self.case.TestsIsolates()
|
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
class Configuration(object):
|
|
|
|
"""The parsed contents of a configuration file"""
|
|
|
|
|
|
|
|
def __init__(self, sections, defs):
|
|
|
|
self.sections = sections
|
|
|
|
self.defs = defs
|
|
|
|
|
|
|
|
def ClassifyTests(self, cases, env):
|
|
|
|
sections = [s for s in self.sections if s.condition.Evaluate(env, self.defs)]
|
|
|
|
all_rules = reduce(list.__add__, [s.rules for s in sections], [])
|
|
|
|
unused_rules = set(all_rules)
|
|
|
|
result = [ ]
|
2008-09-25 12:38:34 +00:00
|
|
|
all_outcomes = set([])
|
2008-08-22 13:33:59 +00:00
|
|
|
for case in cases:
|
|
|
|
matches = [ r for r in all_rules if r.Contains(case.path) ]
|
|
|
|
outcomes = set([])
|
|
|
|
for rule in matches:
|
2008-08-27 10:11:39 +00:00
|
|
|
outcomes = outcomes.union(rule.GetOutcomes(env, self.defs))
|
2008-08-22 13:33:59 +00:00
|
|
|
unused_rules.discard(rule)
|
2008-08-27 10:11:39 +00:00
|
|
|
if not outcomes:
|
|
|
|
outcomes = [PASS]
|
|
|
|
case.outcomes = outcomes
|
2008-09-25 12:38:34 +00:00
|
|
|
all_outcomes = all_outcomes.union(outcomes)
|
2008-08-22 13:33:59 +00:00
|
|
|
result.append(ClassifiedTest(case, outcomes))
|
2008-09-25 12:38:34 +00:00
|
|
|
return (result, list(unused_rules), all_outcomes)
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Section(object):
|
|
|
|
"""A section of the configuration file. Sections are enabled or
|
|
|
|
disabled prior to running the tests, based on their conditions"""
|
|
|
|
|
|
|
|
def __init__(self, condition):
|
|
|
|
self.condition = condition
|
|
|
|
self.rules = [ ]
|
|
|
|
|
|
|
|
def AddRule(self, rule):
|
|
|
|
self.rules.append(rule)
|
|
|
|
|
|
|
|
|
|
|
|
class Rule(object):
|
|
|
|
"""A single rule that specifies the expected outcome for a single
|
|
|
|
test."""
|
|
|
|
|
2008-08-27 10:11:39 +00:00
|
|
|
def __init__(self, raw_path, path, value):
|
|
|
|
self.raw_path = raw_path
|
2008-08-22 13:33:59 +00:00
|
|
|
self.path = path
|
|
|
|
self.value = value
|
|
|
|
|
|
|
|
def GetOutcomes(self, env, defs):
|
|
|
|
set = self.value.GetOutcomes(env, defs)
|
|
|
|
assert isinstance(set, ListSet)
|
|
|
|
return set.elms
|
2008-08-27 10:11:39 +00:00
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
def Contains(self, path):
|
|
|
|
if len(self.path) > len(path):
|
|
|
|
return False
|
|
|
|
for i in xrange(len(self.path)):
|
2008-08-27 10:11:39 +00:00
|
|
|
if not self.path[i].match(path[i]):
|
2008-08-22 13:33:59 +00:00
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
HEADER_PATTERN = re.compile(r'\[([^]]+)\]')
|
2008-08-27 10:11:39 +00:00
|
|
|
RULE_PATTERN = re.compile(r'\s*([^: ]*)\s*:(.*)')
|
2008-08-22 13:33:59 +00:00
|
|
|
DEF_PATTERN = re.compile(r'^def\s*(\w+)\s*=(.*)$')
|
2008-08-27 10:11:39 +00:00
|
|
|
PREFIX_PATTERN = re.compile(r'^\s*prefix\s+([\w\_\.\-\/]+)$')
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
def ReadConfigurationInto(path, sections, defs):
|
|
|
|
current_section = Section(Constant(True))
|
|
|
|
sections.append(current_section)
|
2008-08-27 10:11:39 +00:00
|
|
|
prefix = []
|
2008-08-22 13:33:59 +00:00
|
|
|
for line in utils.ReadLinesFrom(path):
|
|
|
|
header_match = HEADER_PATTERN.match(line)
|
|
|
|
if header_match:
|
|
|
|
condition_str = header_match.group(1).strip()
|
|
|
|
condition = ParseCondition(condition_str)
|
|
|
|
new_section = Section(condition)
|
|
|
|
sections.append(new_section)
|
|
|
|
current_section = new_section
|
|
|
|
continue
|
|
|
|
rule_match = RULE_PATTERN.match(line)
|
|
|
|
if rule_match:
|
2008-08-27 10:11:39 +00:00
|
|
|
path = prefix + SplitPath(rule_match.group(1).strip())
|
|
|
|
value_str = rule_match.group(2).strip()
|
2008-08-22 13:33:59 +00:00
|
|
|
value = ParseCondition(value_str)
|
|
|
|
if not value:
|
|
|
|
return False
|
2008-08-27 10:11:39 +00:00
|
|
|
current_section.AddRule(Rule(rule_match.group(1), path, value))
|
2008-08-22 13:33:59 +00:00
|
|
|
continue
|
|
|
|
def_match = DEF_PATTERN.match(line)
|
|
|
|
if def_match:
|
|
|
|
name = def_match.group(1).lower()
|
|
|
|
value = ParseCondition(def_match.group(2).strip())
|
|
|
|
if not value:
|
|
|
|
return False
|
|
|
|
defs[name] = value
|
|
|
|
continue
|
2008-08-27 10:11:39 +00:00
|
|
|
prefix_match = PREFIX_PATTERN.match(line)
|
|
|
|
if prefix_match:
|
|
|
|
prefix = SplitPath(prefix_match.group(1).strip())
|
|
|
|
continue
|
2008-08-22 13:33:59 +00:00
|
|
|
print "Malformed line: '%s'." % line
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
# ---------------
|
|
|
|
# --- M a i n ---
|
|
|
|
# ---------------
|
|
|
|
|
|
|
|
|
2008-09-02 15:20:38 +00:00
|
|
|
ARCH_GUESS = utils.GuessArchitecture()
|
2011-08-31 14:12:25 +00:00
|
|
|
TIMEOUT_DEFAULT = 60;
|
2008-09-02 15:20:38 +00:00
|
|
|
|
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
def BuildOptions():
|
|
|
|
result = optparse.OptionParser()
|
2008-08-27 10:11:39 +00:00
|
|
|
result.add_option("-m", "--mode", help="The test modes in which to run (comma-separated)",
|
|
|
|
default='release')
|
2008-08-22 13:33:59 +00:00
|
|
|
result.add_option("-v", "--verbose", help="Verbose output",
|
|
|
|
default=False, action="store_true")
|
2008-09-02 12:20:15 +00:00
|
|
|
result.add_option("-S", dest="scons_flags", help="Flag to pass through to scons",
|
|
|
|
default=[], action="append")
|
2008-08-22 13:33:59 +00:00
|
|
|
result.add_option("-p", "--progress",
|
|
|
|
help="The style of progress indicator (verbose, dots, color, mono)",
|
|
|
|
choices=PROGRESS_INDICATORS.keys(), default="mono")
|
|
|
|
result.add_option("--no-build", help="Don't build requirements",
|
|
|
|
default=False, action="store_true")
|
2009-09-10 12:59:49 +00:00
|
|
|
result.add_option("--build-only", help="Only build requirements, don't run the tests",
|
|
|
|
default=False, action="store_true")
|
2011-08-05 09:44:30 +00:00
|
|
|
result.add_option("--build-system", help="Build system in use (scons or gyp)",
|
|
|
|
default='scons')
|
2008-08-22 13:33:59 +00:00
|
|
|
result.add_option("--report", help="Print a summary of the tests to be run",
|
|
|
|
default=False, action="store_true")
|
2012-03-07 12:51:31 +00:00
|
|
|
result.add_option("--download-data", help="Download missing test suite data",
|
|
|
|
default=False, action="store_true")
|
2008-08-27 10:11:39 +00:00
|
|
|
result.add_option("-s", "--suite", help="A test suite",
|
|
|
|
default=[], action="append")
|
|
|
|
result.add_option("-t", "--timeout", help="Timeout in seconds",
|
2011-08-31 14:12:25 +00:00
|
|
|
default=-1, type="int")
|
2008-09-02 15:20:38 +00:00
|
|
|
result.add_option("--arch", help='The architecture to run tests for',
|
2008-09-09 05:37:00 +00:00
|
|
|
default='none')
|
2009-10-28 09:38:09 +00:00
|
|
|
result.add_option("--snapshot", help="Run the tests with snapshot turned on",
|
|
|
|
default=False, action="store_true")
|
2008-09-09 05:37:00 +00:00
|
|
|
result.add_option("--simulator", help="Run tests with architecture simulator",
|
|
|
|
default='none')
|
2008-09-03 07:31:19 +00:00
|
|
|
result.add_option("--special-command", default=None)
|
2009-03-12 06:52:24 +00:00
|
|
|
result.add_option("--valgrind", help="Run tests through valgrind",
|
|
|
|
default=False, action="store_true")
|
2008-09-08 07:04:22 +00:00
|
|
|
result.add_option("--cat", help="Print the source of the tests",
|
|
|
|
default=False, action="store_true")
|
2008-09-25 12:38:34 +00:00
|
|
|
result.add_option("--warn-unused", help="Report unused rules",
|
|
|
|
default=False, action="store_true")
|
2008-09-30 15:32:07 +00:00
|
|
|
result.add_option("-j", help="The number of parallel tasks to run",
|
|
|
|
default=1, type="int")
|
2008-10-01 09:07:45 +00:00
|
|
|
result.add_option("--time", help="Print timing information after running",
|
|
|
|
default=False, action="store_true")
|
2008-10-29 10:19:21 +00:00
|
|
|
result.add_option("--suppress-dialogs", help="Suppress Windows dialogs for crashing tests",
|
|
|
|
dest="suppress_dialogs", default=True, action="store_true")
|
|
|
|
result.add_option("--no-suppress-dialogs", help="Display Windows dialogs for crashing tests",
|
|
|
|
dest="suppress_dialogs", action="store_false")
|
2012-01-25 12:37:59 +00:00
|
|
|
result.add_option("--mips-arch-variant", help="mips architecture variant: mips32r1/mips32r2", default="mips32r2");
|
2011-07-26 05:56:45 +00:00
|
|
|
result.add_option("--shell", help="Path to V8 shell", default="d8")
|
2011-03-18 20:35:07 +00:00
|
|
|
result.add_option("--isolates", help="Whether to test isolates", default=False, action="store_true")
|
2010-12-07 11:31:57 +00:00
|
|
|
result.add_option("--store-unexpected-output",
|
2010-08-24 13:34:59 +00:00
|
|
|
help="Store the temporary JS files from tests that fails",
|
|
|
|
dest="store_unexpected_output", default=True, action="store_true")
|
2010-12-07 11:31:57 +00:00
|
|
|
result.add_option("--no-store-unexpected-output",
|
2010-08-24 13:34:59 +00:00
|
|
|
help="Deletes the temporary JS files from tests that fails",
|
|
|
|
dest="store_unexpected_output", action="store_false")
|
2010-12-07 11:31:57 +00:00
|
|
|
result.add_option("--stress-only",
|
|
|
|
help="Only run tests with --always-opt --stress-opt",
|
|
|
|
default=False, action="store_true")
|
|
|
|
result.add_option("--nostress",
|
|
|
|
help="Don't run crankshaft --always-opt --stress-op test",
|
|
|
|
default=False, action="store_true")
|
2011-01-10 13:54:42 +00:00
|
|
|
result.add_option("--shard-count",
|
|
|
|
help="Split testsuites into this number of shards",
|
|
|
|
default=1, type="int")
|
|
|
|
result.add_option("--shard-run",
|
|
|
|
help="Run this shard from the split up tests.",
|
|
|
|
default=1, type="int")
|
2010-12-16 12:14:56 +00:00
|
|
|
result.add_option("--noprof", help="Disable profiling support",
|
|
|
|
default=False)
|
2008-08-22 13:33:59 +00:00
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
def ProcessOptions(options):
|
|
|
|
global VERBOSE
|
|
|
|
VERBOSE = options.verbose
|
2008-08-27 10:11:39 +00:00
|
|
|
options.mode = options.mode.split(',')
|
|
|
|
for mode in options.mode:
|
|
|
|
if not mode in ['debug', 'release']:
|
|
|
|
print "Unknown mode %s" % mode
|
|
|
|
return False
|
2008-09-09 05:37:00 +00:00
|
|
|
if options.simulator != 'none':
|
|
|
|
# Simulator argument was set. Make sure arch and simulator agree.
|
|
|
|
if options.simulator != options.arch:
|
|
|
|
if options.arch == 'none':
|
|
|
|
options.arch = options.simulator
|
|
|
|
else:
|
|
|
|
print "Architecture %s does not match sim %s" %(options.arch, options.simulator)
|
|
|
|
return False
|
|
|
|
# Ensure that the simulator argument is handed down to scons.
|
|
|
|
options.scons_flags.append("simulator=" + options.simulator)
|
|
|
|
else:
|
|
|
|
# If options.arch is not set by the command line and no simulator setting
|
|
|
|
# was found, set the arch to the guess.
|
|
|
|
if options.arch == 'none':
|
|
|
|
options.arch = ARCH_GUESS
|
2009-07-14 11:39:45 +00:00
|
|
|
options.scons_flags.append("arch=" + options.arch)
|
2011-08-31 14:12:25 +00:00
|
|
|
# Simulators are slow, therefore allow a longer default timeout.
|
|
|
|
if options.timeout == -1:
|
2012-07-11 15:15:04 +00:00
|
|
|
if options.arch in ['android', 'arm', 'mipsel']:
|
2011-08-31 14:12:25 +00:00
|
|
|
options.timeout = 2 * TIMEOUT_DEFAULT;
|
|
|
|
else:
|
|
|
|
options.timeout = TIMEOUT_DEFAULT;
|
2009-10-28 09:38:09 +00:00
|
|
|
if options.snapshot:
|
|
|
|
options.scons_flags.append("snapshot=on")
|
2010-12-07 11:31:57 +00:00
|
|
|
global VARIANT_FLAGS
|
2012-01-25 12:37:59 +00:00
|
|
|
if options.mips_arch_variant:
|
|
|
|
options.scons_flags.append("mips_arch_variant=" + options.mips_arch_variant)
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
if options.stress_only:
|
|
|
|
VARIANT_FLAGS = [['--stress-opt', '--always-opt']]
|
2011-04-01 13:27:28 +00:00
|
|
|
if options.nostress:
|
|
|
|
VARIANT_FLAGS = [[],['--nocrankshaft']]
|
2011-08-10 11:07:31 +00:00
|
|
|
if options.shell.endswith("d8"):
|
2011-06-29 08:22:36 +00:00
|
|
|
if options.special_command:
|
|
|
|
options.special_command += " --test"
|
|
|
|
else:
|
2011-08-10 11:07:31 +00:00
|
|
|
options.special_command = "@ --test"
|
2010-12-16 12:14:56 +00:00
|
|
|
if options.noprof:
|
|
|
|
options.scons_flags.append("prof=off")
|
|
|
|
options.scons_flags.append("profilingsupport=off")
|
2011-08-05 09:44:30 +00:00
|
|
|
if options.build_system == 'gyp':
|
|
|
|
if options.build_only:
|
|
|
|
print "--build-only not supported for gyp, please build manually."
|
|
|
|
options.build_only = False
|
2008-08-22 13:33:59 +00:00
|
|
|
return True
|
|
|
|
|
|
|
|
|
2011-08-05 08:04:47 +00:00
|
|
|
def DoSkip(case):
|
|
|
|
return (SKIP in case.outcomes) or (SLOW in case.outcomes)
|
|
|
|
|
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
REPORT_TEMPLATE = """\
|
|
|
|
Total: %(total)i tests
|
2008-08-27 10:11:39 +00:00
|
|
|
* %(skipped)4d tests will be skipped
|
2011-08-05 08:04:47 +00:00
|
|
|
* %(timeout)4d tests are expected to timeout sometimes
|
2008-08-27 10:11:39 +00:00
|
|
|
* %(nocrash)4d tests are expected to be flaky but not crash
|
|
|
|
* %(pass)4d tests are expected to pass
|
|
|
|
* %(fail_ok)4d tests are expected to fail that we won't fix
|
|
|
|
* %(fail)4d tests are expected to fail that we should fix\
|
2008-08-22 13:33:59 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
def PrintReport(cases):
|
|
|
|
def IsFlaky(o):
|
|
|
|
return (PASS in o) and (FAIL in o) and (not CRASH in o) and (not OKAY in o)
|
|
|
|
def IsFailOk(o):
|
|
|
|
return (len(o) == 2) and (FAIL in o) and (OKAY in o)
|
2011-08-05 08:04:47 +00:00
|
|
|
unskipped = [c for c in cases if not DoSkip(c)]
|
2008-08-22 13:33:59 +00:00
|
|
|
print REPORT_TEMPLATE % {
|
|
|
|
'total': len(cases),
|
|
|
|
'skipped': len(cases) - len(unskipped),
|
2011-08-05 08:04:47 +00:00
|
|
|
'timeout': len([t for t in unskipped if TIMEOUT in t.outcomes]),
|
2008-08-22 13:33:59 +00:00
|
|
|
'nocrash': len([t for t in unskipped if IsFlaky(t.outcomes)]),
|
|
|
|
'pass': len([t for t in unskipped if list(t.outcomes) == [PASS]]),
|
|
|
|
'fail_ok': len([t for t in unskipped if IsFailOk(t.outcomes)]),
|
|
|
|
'fail': len([t for t in unskipped if list(t.outcomes) == [FAIL]])
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-27 10:11:39 +00:00
|
|
|
class Pattern(object):
|
|
|
|
|
|
|
|
def __init__(self, pattern):
|
|
|
|
self.pattern = pattern
|
|
|
|
self.compiled = None
|
|
|
|
|
|
|
|
def match(self, str):
|
|
|
|
if not self.compiled:
|
|
|
|
pattern = "^" + self.pattern.replace('*', '.*') + "$"
|
|
|
|
self.compiled = re.compile(pattern)
|
|
|
|
return self.compiled.match(str)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.pattern
|
|
|
|
|
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
def SplitPath(s):
|
|
|
|
stripped = [ c.strip() for c in s.split('/') ]
|
2008-08-27 10:11:39 +00:00
|
|
|
return [ Pattern(s) for s in stripped if len(s) > 0 ]
|
|
|
|
|
|
|
|
|
2008-09-03 07:31:19 +00:00
|
|
|
def GetSpecialCommandProcessor(value):
|
|
|
|
if (not value) or (value.find('@') == -1):
|
|
|
|
def ExpandCommand(args):
|
|
|
|
return args
|
|
|
|
return ExpandCommand
|
|
|
|
else:
|
|
|
|
pos = value.find('@')
|
2009-03-27 03:27:04 +00:00
|
|
|
import urllib
|
2009-03-27 03:13:46 +00:00
|
|
|
prefix = urllib.unquote(value[:pos]).split()
|
|
|
|
suffix = urllib.unquote(value[pos+1:]).split()
|
2008-09-03 07:31:19 +00:00
|
|
|
def ExpandCommand(args):
|
|
|
|
return prefix + args + suffix
|
|
|
|
return ExpandCommand
|
|
|
|
|
|
|
|
|
2011-03-31 08:12:17 +00:00
|
|
|
BUILT_IN_TESTS = ['mjsunit', 'cctest', 'message', 'preparser']
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
|
2008-09-25 12:38:34 +00:00
|
|
|
def GetSuites(test_root):
|
2008-09-25 13:01:26 +00:00
|
|
|
def IsSuite(path):
|
|
|
|
return isdir(path) and exists(join(path, 'testcfg.py'))
|
|
|
|
return [ f for f in os.listdir(test_root) if IsSuite(join(test_root, f)) ]
|
2008-09-25 12:38:34 +00:00
|
|
|
|
|
|
|
|
2008-10-01 09:07:45 +00:00
|
|
|
def FormatTime(d):
|
|
|
|
millis = round(d * 1000) % 1000
|
|
|
|
return time.strftime("%M:%S.", time.gmtime(d)) + ("%03i" % millis)
|
|
|
|
|
2011-01-10 13:54:42 +00:00
|
|
|
def ShardTests(tests, options):
|
|
|
|
if options.shard_count < 2:
|
|
|
|
return tests
|
|
|
|
if options.shard_run < 1 or options.shard_run > options.shard_count:
|
|
|
|
print "shard-run not a valid number, should be in [1:shard-count]"
|
|
|
|
print "defaulting back to running all tests"
|
|
|
|
return tests
|
2011-04-15 09:41:09 +00:00
|
|
|
count = 0
|
2011-01-10 13:54:42 +00:00
|
|
|
shard = []
|
|
|
|
for test in tests:
|
|
|
|
if count % options.shard_count == options.shard_run - 1:
|
2011-04-15 09:41:09 +00:00
|
|
|
shard.append(test)
|
2011-01-10 13:54:42 +00:00
|
|
|
count += 1
|
|
|
|
return shard
|
2008-10-01 09:07:45 +00:00
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
def Main():
|
|
|
|
parser = BuildOptions()
|
|
|
|
(options, args) = parser.parse_args()
|
|
|
|
if not ProcessOptions(options):
|
|
|
|
parser.print_help()
|
|
|
|
return 1
|
|
|
|
|
|
|
|
workspace = abspath(join(dirname(sys.argv[0]), '..'))
|
2008-09-25 12:38:34 +00:00
|
|
|
suites = GetSuites(join(workspace, 'test'))
|
|
|
|
repositories = [TestRepository(join(workspace, 'test', name)) for name in suites]
|
2008-08-27 10:11:39 +00:00
|
|
|
repositories += [TestRepository(a) for a in options.suite]
|
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
root = LiteralTestSuite(repositories)
|
|
|
|
if len(args) == 0:
|
2008-08-27 10:11:39 +00:00
|
|
|
paths = [SplitPath(t) for t in BUILT_IN_TESTS]
|
2008-08-22 13:33:59 +00:00
|
|
|
else:
|
|
|
|
paths = [ ]
|
|
|
|
for arg in args:
|
|
|
|
path = SplitPath(arg)
|
|
|
|
paths.append(path)
|
|
|
|
|
2009-03-12 06:52:24 +00:00
|
|
|
# Check for --valgrind option. If enabled, we overwrite the special
|
|
|
|
# command flag with a command that uses the run-valgrind.py script.
|
|
|
|
if options.valgrind:
|
|
|
|
run_valgrind = join(workspace, "tools", "run-valgrind.py")
|
|
|
|
options.special_command = "python -u " + run_valgrind + " @"
|
|
|
|
|
2011-08-05 09:44:30 +00:00
|
|
|
if options.build_system == 'gyp':
|
|
|
|
SUFFIX['debug'] = ''
|
|
|
|
|
2009-03-19 17:09:07 +00:00
|
|
|
shell = abspath(options.shell)
|
|
|
|
buildspace = dirname(shell)
|
2010-08-24 13:34:59 +00:00
|
|
|
|
2008-08-27 10:11:39 +00:00
|
|
|
context = Context(workspace, buildspace, VERBOSE,
|
2009-03-19 17:09:07 +00:00
|
|
|
shell,
|
2008-09-03 07:31:19 +00:00
|
|
|
options.timeout,
|
2009-03-12 06:52:24 +00:00
|
|
|
GetSpecialCommandProcessor(options.special_command),
|
2010-08-24 13:34:59 +00:00
|
|
|
options.suppress_dialogs,
|
|
|
|
options.store_unexpected_output)
|
2009-03-19 17:09:07 +00:00
|
|
|
# First build the required targets
|
2008-08-22 13:33:59 +00:00
|
|
|
if not options.no_build:
|
|
|
|
reqs = [ ]
|
|
|
|
for path in paths:
|
|
|
|
reqs += root.GetBuildRequirements(path, context)
|
|
|
|
reqs = list(set(reqs))
|
|
|
|
if len(reqs) > 0:
|
2009-03-19 17:09:07 +00:00
|
|
|
if options.j != 1:
|
|
|
|
options.scons_flags += ['-j', str(options.j)]
|
2008-09-02 12:20:15 +00:00
|
|
|
if not BuildRequirements(context, reqs, options.mode, options.scons_flags):
|
2008-08-22 13:33:59 +00:00
|
|
|
return 1
|
|
|
|
|
2009-09-10 12:59:49 +00:00
|
|
|
# Just return if we are only building the targets for running the tests.
|
|
|
|
if options.build_only:
|
|
|
|
return 0
|
2010-08-24 13:34:59 +00:00
|
|
|
|
2008-08-28 13:17:47 +00:00
|
|
|
# Get status for tests
|
|
|
|
sections = [ ]
|
|
|
|
defs = { }
|
|
|
|
root.GetTestStatus(context, sections, defs)
|
|
|
|
config = Configuration(sections, defs)
|
|
|
|
|
2012-03-07 12:51:31 +00:00
|
|
|
# Download missing test suite data if requested.
|
|
|
|
if options.download_data:
|
|
|
|
for path in paths:
|
|
|
|
root.DownloadData(path, context)
|
|
|
|
|
2008-08-28 13:17:47 +00:00
|
|
|
# List the tests
|
2008-08-27 10:11:39 +00:00
|
|
|
all_cases = [ ]
|
|
|
|
all_unused = [ ]
|
2008-09-08 07:04:22 +00:00
|
|
|
unclassified_tests = [ ]
|
2008-09-25 12:38:34 +00:00
|
|
|
globally_unused_rules = None
|
2008-08-22 13:33:59 +00:00
|
|
|
for path in paths:
|
|
|
|
for mode in options.mode:
|
2008-08-27 10:11:39 +00:00
|
|
|
env = {
|
2008-09-02 12:42:10 +00:00
|
|
|
'mode': mode,
|
2008-10-31 13:12:35 +00:00
|
|
|
'system': utils.GuessOS(),
|
2009-03-31 15:23:58 +00:00
|
|
|
'arch': options.arch,
|
2011-04-01 13:27:28 +00:00
|
|
|
'simulator': options.simulator,
|
2011-07-06 08:20:30 +00:00
|
|
|
'isolates': options.isolates
|
2008-08-27 10:11:39 +00:00
|
|
|
}
|
2011-03-21 12:57:25 +00:00
|
|
|
test_list = root.ListTests([], path, context, mode, [])
|
2008-09-08 07:04:22 +00:00
|
|
|
unclassified_tests += test_list
|
2008-09-25 12:38:34 +00:00
|
|
|
(cases, unused_rules, all_outcomes) = config.ClassifyTests(test_list, env)
|
|
|
|
if globally_unused_rules is None:
|
|
|
|
globally_unused_rules = set(unused_rules)
|
|
|
|
else:
|
|
|
|
globally_unused_rules = globally_unused_rules.intersection(unused_rules)
|
2011-01-10 13:54:42 +00:00
|
|
|
all_cases += ShardTests(cases, options)
|
2008-08-27 10:11:39 +00:00
|
|
|
all_unused.append(unused_rules)
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2008-09-08 07:04:22 +00:00
|
|
|
if options.cat:
|
|
|
|
visited = set()
|
|
|
|
for test in unclassified_tests:
|
|
|
|
key = tuple(test.path)
|
|
|
|
if key in visited:
|
|
|
|
continue
|
|
|
|
visited.add(key)
|
|
|
|
print "--- begin source: %s ---" % test.GetLabel()
|
|
|
|
source = test.GetSource().strip()
|
|
|
|
print source
|
|
|
|
print "--- end source: %s ---" % test.GetLabel()
|
|
|
|
return 0
|
|
|
|
|
2008-09-25 12:38:34 +00:00
|
|
|
if options.warn_unused:
|
|
|
|
for rule in globally_unused_rules:
|
|
|
|
print "Rule for '%s' was not used." % '/'.join([str(s) for s in rule.path])
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2011-08-05 08:04:47 +00:00
|
|
|
if not options.isolates:
|
|
|
|
all_cases = [c for c in all_cases if not c.TestsIsolates()]
|
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
if options.report:
|
2008-08-27 10:11:39 +00:00
|
|
|
PrintReport(all_cases)
|
|
|
|
|
2008-10-01 09:07:45 +00:00
|
|
|
result = None
|
2010-01-18 13:17:38 +00:00
|
|
|
cases_to_run = [ c for c in all_cases if not DoSkip(c) ]
|
|
|
|
if len(cases_to_run) == 0:
|
2008-08-22 13:33:59 +00:00
|
|
|
print "No tests to run."
|
2008-08-27 13:47:52 +00:00
|
|
|
return 0
|
2008-08-22 13:33:59 +00:00
|
|
|
else:
|
2008-08-27 10:11:39 +00:00
|
|
|
try:
|
2008-10-01 09:07:45 +00:00
|
|
|
start = time.time()
|
2010-01-18 13:17:38 +00:00
|
|
|
if RunTestCases(cases_to_run, options.progress, options.j):
|
2008-10-01 09:07:45 +00:00
|
|
|
result = 0
|
2008-08-27 13:47:52 +00:00
|
|
|
else:
|
2008-10-01 09:07:45 +00:00
|
|
|
result = 1
|
|
|
|
duration = time.time() - start
|
2008-08-27 10:11:39 +00:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
print "Interrupted"
|
|
|
|
return 1
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2008-10-01 09:07:45 +00:00
|
|
|
if options.time:
|
|
|
|
# Write the times to stderr to make it easy to separate from the
|
|
|
|
# test output.
|
|
|
|
print
|
|
|
|
sys.stderr.write("--- Total time: %s ---\n" % FormatTime(duration))
|
2010-01-18 13:17:38 +00:00
|
|
|
timed_tests = [ t.case for t in cases_to_run if not t.case.duration is None ]
|
2008-10-01 09:07:45 +00:00
|
|
|
timed_tests.sort(lambda a, b: a.CompareTime(b))
|
|
|
|
index = 1
|
|
|
|
for entry in timed_tests[:20]:
|
|
|
|
t = FormatTime(entry.duration)
|
|
|
|
sys.stderr.write("%4i (%s) %s\n" % (index, t, entry.GetLabel()))
|
|
|
|
index += 1
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(Main())
|