Home | History | Annotate | Download | only in local
      1 # Copyright 2012 the V8 project authors. All rights reserved.
      2 # Redistribution and use in source and binary forms, with or without
      3 # modification, are permitted provided that the following conditions are
      4 # met:
      5 #
      6 #     * Redistributions of source code must retain the above copyright
      7 #       notice, this list of conditions and the following disclaimer.
      8 #     * Redistributions in binary form must reproduce the above
      9 #       copyright notice, this list of conditions and the following
     10 #       disclaimer in the documentation and/or other materials provided
     11 #       with the distribution.
     12 #     * Neither the name of Google Inc. nor the names of its
     13 #       contributors may be used to endorse or promote products derived
     14 #       from this software without specific prior written permission.
     15 #
     16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     17 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     18 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     19 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     20 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27 
     28 
     29 # These imports are required for the on-demand conversion from
     30 # old to new status file format.
     31 from os.path import exists
     32 from os.path import getmtime
     33 
     34 from . import old_statusfile
     35 
     36 
     37 # These outcomes can occur in a TestCase's outcomes list:
     38 SKIP = "SKIP"
     39 FAIL = "FAIL"
     40 PASS = "PASS"
     41 OKAY = "OKAY"
     42 TIMEOUT = "TIMEOUT"
     43 CRASH = "CRASH"
     44 SLOW = "SLOW"
     45 FLAKY = "FLAKY"
     46 # These are just for the status files and are mapped below in DEFS:
     47 FAIL_OK = "FAIL_OK"
     48 PASS_OR_FAIL = "PASS_OR_FAIL"
     49 
     50 ALWAYS = "ALWAYS"
     51 
     52 KEYWORDS = {}
     53 for key in [SKIP, FAIL, PASS, OKAY, TIMEOUT, CRASH, SLOW, FLAKY, FAIL_OK,
     54             PASS_OR_FAIL, ALWAYS]:
     55   KEYWORDS[key] = key
     56 
     57 DEFS = {FAIL_OK: [FAIL, OKAY],
     58         PASS_OR_FAIL: [PASS, FAIL]}
     59 
     60 # Support arches, modes to be written as keywords instead of strings.
     61 VARIABLES = {ALWAYS: True}
     62 for var in ["debug", "release", "android_arm", "android_ia32", "arm", "ia32",
     63             "mipsel", "x64", "nacl_ia32", "nacl_x64"]:
     64   VARIABLES[var] = var
     65 
     66 
     67 def DoSkip(outcomes):
     68   return SKIP in outcomes or SLOW in outcomes
     69 
     70 
     71 def IsFlaky(outcomes):
     72   return FLAKY in outcomes
     73 
     74 
     75 def IsPassOrFail(outcomes):
     76   return ((PASS in outcomes) and (FAIL in outcomes) and
     77           (not CRASH in outcomes) and (not OKAY in outcomes))
     78 
     79 
     80 def IsFailOk(outcomes):
     81     return (FAIL in outcomes) and (OKAY in outcomes)
     82 
     83 
     84 def _AddOutcome(result, new):
     85   global DEFS
     86   if new in DEFS:
     87     mapped = DEFS[new]
     88     if type(mapped) == list:
     89       for m in mapped:
     90         _AddOutcome(result, m)
     91     elif type(mapped) == str:
     92       _AddOutcome(result, mapped)
     93   else:
     94     result.add(new)
     95 
     96 
     97 def _ParseOutcomeList(rule, outcomes, target_dict, variables):
     98   result = set([])
     99   if type(outcomes) == str:
    100    outcomes = [outcomes]
    101   for item in outcomes:
    102     if type(item) == str:
    103       _AddOutcome(result, item)
    104     elif type(item) == list:
    105       if not eval(item[0], variables): continue
    106       for outcome in item[1:]:
    107         assert type(outcome) == str
    108         _AddOutcome(result, outcome)
    109     else:
    110       assert False
    111   if len(result) == 0: return
    112   if rule in target_dict:
    113     target_dict[rule] |= result
    114   else:
    115     target_dict[rule] = result
    116 
    117 
    118 def ReadStatusFile(path, variables):
    119   # As long as the old-format .status files are authoritative, just
    120   # create the converted version on demand and cache it to speed up
    121   # subsequent runs.
    122   if path.endswith(".status"):
    123     newpath = path + "2"
    124     if not exists(newpath) or getmtime(newpath) < getmtime(path):
    125       print "Converting status file."
    126       converted = old_statusfile.ConvertNotation(path).GetOutput()
    127       with open(newpath, 'w') as f:
    128         f.write(converted)
    129     path = newpath
    130 
    131   with open(path) as f:
    132     global KEYWORDS
    133     contents = eval(f.read(), KEYWORDS)
    134 
    135   rules = {}
    136   wildcards = {}
    137   variables.update(VARIABLES)
    138   for section in contents:
    139     assert type(section) == list
    140     assert len(section) == 2
    141     if not eval(section[0], variables): continue
    142     section = section[1]
    143     assert type(section) == dict
    144     for rule in section:
    145       assert type(rule) == str
    146       if rule[-1] == '*':
    147         _ParseOutcomeList(rule, section[rule], wildcards, variables)
    148       else:
    149         _ParseOutcomeList(rule, section[rule], rules, variables)
    150   return rules, wildcards
    151