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 outcomes can occur in a TestCase's outcomes list:
30SKIP = "SKIP"
31FAIL = "FAIL"
32PASS = "PASS"
33OKAY = "OKAY"
34TIMEOUT = "TIMEOUT"
35CRASH = "CRASH"
36SLOW = "SLOW"
37FLAKY = "FLAKY"
38NO_VARIANTS = "NO_VARIANTS"
39# These are just for the status files and are mapped below in DEFS:
40FAIL_OK = "FAIL_OK"
41PASS_OR_FAIL = "PASS_OR_FAIL"
42
43ALWAYS = "ALWAYS"
44
45KEYWORDS = {}
46for key in [SKIP, FAIL, PASS, OKAY, TIMEOUT, CRASH, SLOW, FLAKY, FAIL_OK,
47            NO_VARIANTS, PASS_OR_FAIL, ALWAYS]:
48  KEYWORDS[key] = key
49
50DEFS = {FAIL_OK: [FAIL, OKAY],
51        PASS_OR_FAIL: [PASS, FAIL]}
52
53# Support arches, modes to be written as keywords instead of strings.
54VARIABLES = {ALWAYS: True}
55for var in ["debug", "release", "android_arm", "android_arm64", "android_ia32", "android_x87",
56            "arm", "arm64", "ia32", "mips", "mipsel", "mips64el", "x64", "x87", "nacl_ia32",
57            "nacl_x64", "macos", "windows", "linux"]:
58  VARIABLES[var] = var
59
60
61def DoSkip(outcomes):
62  return SKIP in outcomes
63
64
65def IsSlow(outcomes):
66  return SLOW in outcomes
67
68
69def OnlyStandardVariant(outcomes):
70  return NO_VARIANTS in outcomes
71
72
73def IsFlaky(outcomes):
74  return FLAKY in outcomes
75
76
77def IsPassOrFail(outcomes):
78  return ((PASS in outcomes) and (FAIL in outcomes) and
79          (not CRASH in outcomes) and (not OKAY in outcomes))
80
81
82def IsFailOk(outcomes):
83    return (FAIL in outcomes) and (OKAY in outcomes)
84
85
86def _AddOutcome(result, new):
87  global DEFS
88  if new in DEFS:
89    mapped = DEFS[new]
90    if type(mapped) == list:
91      for m in mapped:
92        _AddOutcome(result, m)
93    elif type(mapped) == str:
94      _AddOutcome(result, mapped)
95  else:
96    result.add(new)
97
98
99def _ParseOutcomeList(rule, outcomes, target_dict, variables):
100  result = set([])
101  if type(outcomes) == str:
102   outcomes = [outcomes]
103  for item in outcomes:
104    if type(item) == str:
105      _AddOutcome(result, item)
106    elif type(item) == list:
107      if not eval(item[0], variables): continue
108      for outcome in item[1:]:
109        assert type(outcome) == str
110        _AddOutcome(result, outcome)
111    else:
112      assert False
113  if len(result) == 0: return
114  if rule in target_dict:
115    target_dict[rule] |= result
116  else:
117    target_dict[rule] = result
118
119
120def ReadStatusFile(path, variables):
121  with open(path) as f:
122    global KEYWORDS
123    contents = eval(f.read(), KEYWORDS)
124
125  rules = {}
126  wildcards = {}
127  variables.update(VARIABLES)
128  for section in contents:
129    assert type(section) == list
130    assert len(section) == 2
131    if not eval(section[0], variables): continue
132    section = section[1]
133    assert type(section) == dict
134    for rule in section:
135      assert type(rule) == str
136      if rule[-1] == '*':
137        _ParseOutcomeList(rule, section[rule], wildcards, variables)
138      else:
139        _ParseOutcomeList(rule, section[rule], rules, variables)
140  return rules, wildcards
141