OLD | NEW |
| (Empty) |
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 # These are just for the status files and are mapped below in DEFS: | |
46 FAIL_OK = "FAIL_OK" | |
47 PASS_OR_FAIL = "PASS_OR_FAIL" | |
48 | |
49 ALWAYS = "ALWAYS" | |
50 | |
51 KEYWORDS = {} | |
52 for key in [SKIP, FAIL, PASS, OKAY, TIMEOUT, CRASH, SLOW, FAIL_OK, | |
53 PASS_OR_FAIL, ALWAYS]: | |
54 KEYWORDS[key] = key | |
55 | |
56 DEFS = {FAIL_OK: [FAIL, OKAY], | |
57 PASS_OR_FAIL: [PASS, FAIL]} | |
58 | |
59 # Support arches, modes to be written as keywords instead of strings. | |
60 VARIABLES = {ALWAYS: True} | |
61 for var in ["debug", "release", "android_arm", "android_ia32", "arm", "ia32", | |
62 "mipsel", "x64"]: | |
63 VARIABLES[var] = var | |
64 | |
65 | |
66 def DoSkip(outcomes): | |
67 return SKIP in outcomes or SLOW in outcomes | |
68 | |
69 | |
70 def IsFlaky(outcomes): | |
71 return ((PASS in outcomes) and (FAIL in outcomes) and | |
72 (not CRASH in outcomes) and (not OKAY in outcomes)) | |
73 | |
74 | |
75 def IsFailOk(outcomes): | |
76 return (FAIL in outcomes) and (OKAY in outcomes) | |
77 | |
78 | |
79 def _AddOutcome(result, new): | |
80 global DEFS | |
81 if new in DEFS: | |
82 mapped = DEFS[new] | |
83 if type(mapped) == list: | |
84 for m in mapped: | |
85 _AddOutcome(result, m) | |
86 elif type(mapped) == str: | |
87 _AddOutcome(result, mapped) | |
88 else: | |
89 result.add(new) | |
90 | |
91 | |
92 def _ParseOutcomeList(rule, outcomes, target_dict, variables): | |
93 result = set([]) | |
94 if type(outcomes) == str: | |
95 outcomes = [outcomes] | |
96 for item in outcomes: | |
97 if type(item) == str: | |
98 _AddOutcome(result, item) | |
99 elif type(item) == list: | |
100 if not eval(item[0], variables): continue | |
101 for outcome in item[1:]: | |
102 assert type(outcome) == str | |
103 _AddOutcome(result, outcome) | |
104 else: | |
105 assert False | |
106 if len(result) == 0: return | |
107 if rule in target_dict: | |
108 target_dict[rule] |= result | |
109 else: | |
110 target_dict[rule] = result | |
111 | |
112 | |
113 def ReadStatusFile(path, variables): | |
114 # As long as the old-format .status files are authoritative, just | |
115 # create the converted version on demand and cache it to speed up | |
116 # subsequent runs. | |
117 if path.endswith(".status"): | |
118 newpath = path + "2" | |
119 if not exists(newpath) or getmtime(newpath) < getmtime(path): | |
120 print "Converting status file." | |
121 converted = old_statusfile.ConvertNotation(path).GetOutput() | |
122 with open(newpath, 'w') as f: | |
123 f.write(converted) | |
124 path = newpath | |
125 | |
126 with open(path) as f: | |
127 global KEYWORDS | |
128 contents = eval(f.read(), KEYWORDS) | |
129 | |
130 rules = {} | |
131 wildcards = {} | |
132 variables.update(VARIABLES) | |
133 for section in contents: | |
134 assert type(section) == list | |
135 assert len(section) == 2 | |
136 if not eval(section[0], variables): continue | |
137 section = section[1] | |
138 assert type(section) == dict | |
139 for rule in section: | |
140 assert type(rule) == str | |
141 if rule[-1] == '*': | |
142 _ParseOutcomeList(rule, section[rule], wildcards, variables) | |
143 else: | |
144 _ParseOutcomeList(rule, section[rule], rules, variables) | |
145 return rules, wildcards | |
OLD | NEW |