blob: 7e96cc37150058a00bc0bf4f175f57c5b281dadb [file] [log] [blame]
Ben Murdochb8a8cc12014-11-26 15:28:44 +00001# 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
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000028import os
Ben Murdochb8a8cc12014-11-26 15:28:44 +000029
30# These outcomes can occur in a TestCase's outcomes list:
31SKIP = "SKIP"
32FAIL = "FAIL"
33PASS = "PASS"
34OKAY = "OKAY"
35TIMEOUT = "TIMEOUT"
36CRASH = "CRASH"
37SLOW = "SLOW"
Emily Bernierd0a1eb72015-03-24 16:35:39 -040038FAST_VARIANTS = "FAST_VARIANTS"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000039NO_VARIANTS = "NO_VARIANTS"
40# These are just for the status files and are mapped below in DEFS:
41FAIL_OK = "FAIL_OK"
42PASS_OR_FAIL = "PASS_OR_FAIL"
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000043FAIL_SLOPPY = "FAIL_SLOPPY"
Ben Murdochb8a8cc12014-11-26 15:28:44 +000044
45ALWAYS = "ALWAYS"
46
47KEYWORDS = {}
Ben Murdochda12d292016-06-02 14:46:10 +010048for key in [SKIP, FAIL, PASS, OKAY, TIMEOUT, CRASH, SLOW, FAIL_OK,
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000049 FAST_VARIANTS, NO_VARIANTS, PASS_OR_FAIL, FAIL_SLOPPY, ALWAYS]:
Ben Murdochb8a8cc12014-11-26 15:28:44 +000050 KEYWORDS[key] = key
51
52DEFS = {FAIL_OK: [FAIL, OKAY],
53 PASS_OR_FAIL: [PASS, FAIL]}
54
55# Support arches, modes to be written as keywords instead of strings.
56VARIABLES = {ALWAYS: True}
Ben Murdoch4a90d5f2016-03-22 12:00:34 +000057for var in ["debug", "release", "big", "little",
58 "android_arm", "android_arm64", "android_ia32", "android_x87",
59 "android_x64", "arm", "arm64", "ia32", "mips", "mipsel", "mips64",
60 "mips64el", "x64", "x87", "nacl_ia32", "nacl_x64", "ppc", "ppc64",
Ben Murdochda12d292016-06-02 14:46:10 +010061 "s390", "s390x", "macos", "windows", "linux", "aix"]:
Ben Murdochb8a8cc12014-11-26 15:28:44 +000062 VARIABLES[var] = var
63
64
65def DoSkip(outcomes):
66 return SKIP in outcomes
67
68
69def IsSlow(outcomes):
70 return SLOW in outcomes
71
72
73def OnlyStandardVariant(outcomes):
74 return NO_VARIANTS in outcomes
75
76
Emily Bernierd0a1eb72015-03-24 16:35:39 -040077def OnlyFastVariants(outcomes):
78 return FAST_VARIANTS in outcomes
79
80
Ben Murdochb8a8cc12014-11-26 15:28:44 +000081def IsPassOrFail(outcomes):
82 return ((PASS in outcomes) and (FAIL in outcomes) and
83 (not CRASH in outcomes) and (not OKAY in outcomes))
84
85
86def IsFailOk(outcomes):
87 return (FAIL in outcomes) and (OKAY in outcomes)
88
89
90def _AddOutcome(result, new):
91 global DEFS
92 if new in DEFS:
93 mapped = DEFS[new]
94 if type(mapped) == list:
95 for m in mapped:
96 _AddOutcome(result, m)
97 elif type(mapped) == str:
98 _AddOutcome(result, mapped)
99 else:
100 result.add(new)
101
102
103def _ParseOutcomeList(rule, outcomes, target_dict, variables):
104 result = set([])
105 if type(outcomes) == str:
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000106 outcomes = [outcomes]
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000107 for item in outcomes:
108 if type(item) == str:
109 _AddOutcome(result, item)
110 elif type(item) == list:
111 if not eval(item[0], variables): continue
112 for outcome in item[1:]:
113 assert type(outcome) == str
114 _AddOutcome(result, outcome)
115 else:
116 assert False
117 if len(result) == 0: return
118 if rule in target_dict:
119 target_dict[rule] |= result
120 else:
121 target_dict[rule] = result
122
123
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000124def ReadContent(path):
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000125 with open(path) as f:
126 global KEYWORDS
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000127 return eval(f.read(), KEYWORDS)
128
129
130def ReadStatusFile(path, variables):
131 contents = ReadContent(path)
Ben Murdochb8a8cc12014-11-26 15:28:44 +0000132
133 rules = {}
134 wildcards = {}
135 variables.update(VARIABLES)
136 for section in contents:
137 assert type(section) == list
138 assert len(section) == 2
139 if not eval(section[0], variables): continue
140 section = section[1]
141 assert type(section) == dict
142 for rule in section:
143 assert type(rule) == str
144 if rule[-1] == '*':
145 _ParseOutcomeList(rule, section[rule], wildcards, variables)
146 else:
147 _ParseOutcomeList(rule, section[rule], rules, variables)
148 return rules, wildcards
Ben Murdoch4a90d5f2016-03-22 12:00:34 +0000149
150
151def PresubmitCheck(path):
152 contents = ReadContent(path)
153 root_prefix = os.path.basename(os.path.dirname(path)) + "/"
154 status = {"success": True}
155 def _assert(check, message): # Like "assert", but doesn't throw.
156 if not check:
157 print("%s: Error: %s" % (path, message))
158 status["success"] = False
159 try:
160 for section in contents:
161 _assert(type(section) == list, "Section must be a list")
162 _assert(len(section) == 2, "Section list must have exactly 2 entries")
163 section = section[1]
164 _assert(type(section) == dict,
165 "Second entry of section must be a dictionary")
166 for rule in section:
167 _assert(type(rule) == str, "Rule key must be a string")
168 _assert(not rule.startswith(root_prefix),
169 "Suite name prefix must not be used in rule keys")
170 _assert(not rule.endswith('.js'),
171 ".js extension must not be used in rule keys.")
172 return status["success"]
173 except Exception as e:
174 print e
175 return False