-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathlog_parser.py
203 lines (176 loc) · 5.77 KB
/
log_parser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# -*- coding: utf-8 -*-
#-------------------------------------------------------------------------
# VK-GL-CTS Conformance Submission Verification
# ---------------------------------------------
#
# Copyright 2020-2022 The Khronos Group Inc.
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#-------------------------------------------------------------------------
import argparse
import shlex
import time
import xml.dom.minidom
import re
class StatusCode:
PASS = 'Pass'
FAIL = 'Fail'
WAIVED = 'Waiver'
QUALITY_WARNING = 'QualityWarning'
COMPATIBILITY_WARNING = 'CompatibilityWarning'
PENDING = 'Pending'
NOT_SUPPORTED = 'NotSupported'
RESOURCE_ERROR = 'ResourceError'
INTERNAL_ERROR = 'InternalError'
CRASH = 'Crash'
TIMEOUT = 'Timeout'
WAIVER = 'Waiver'
PARSE_ERROR = 'ParseError'
STATUS_CODE_SET = {
PASS,
FAIL,
WAIVED,
QUALITY_WARNING,
COMPATIBILITY_WARNING,
PENDING,
NOT_SUPPORTED,
RESOURCE_ERROR,
INTERNAL_ERROR,
CRASH,
TIMEOUT,
WAIVER,
PARSE_ERROR
}
@staticmethod
def isValid (code):
return code in StatusCode.STATUS_CODE_SET
class TestCaseResult:
def __init__ (self, name, statusCode, statusDetails, log):
self.name = name
self.statusCode = statusCode
self.statusDetails = statusDetails
self.log = log
def __str__ (self):
return "%s: %s (%s)" % (self.name, self.statusCode, self.statusDetails)
class ParseError(Exception):
def __init__ (self, filename, line, message):
self.filename = filename
self.line = line
self.message = message
def __str__ (self):
return "%s:%d: %s" % (self.filename, self.line, self.message)
def splitContainerLine (line):
return shlex.split(line)
def getNodeText (node):
rc = []
for node in node.childNodes:
if node.nodeType == node.TEXT_NODE:
rc.append(node.data)
return ''.join(rc)
class BatchResultParser:
def __init__ (self, report):
self.report = report
self.lastStatusPrint = time.time()
def parseFile (self, filename):
self.init(filename)
f = open(filename, 'rb')
for line in f:
line = line.decode('utf-8', 'ignore')
self.parseLine(line)
self.curLine += 1
f.close()
return self.testCaseResults, self.sessionInfo
def init (self, filename):
# Results
self.sessionInfo = {}
self.testCaseResults = []
# State
self.curResultText = None
self.curCaseName = None
# Error context
self.curLine = 1
self.filename = filename
def parseLine (self, line):
if len(line) > 0 and line[0] == '#':
self.parseContainerLine(line)
else:
if len(line) > 0 and line.startswith("<TestCaseResult"):
pattern = r'CasePath=\"([^\"]+)\"'
match = re.search(pattern, line)
if not match or self.curCaseName != None:
self.parseError("Invalid <TestCaseResult...\n" + line + "\n")
self.curCaseName = match.group(1)
self.curResultText = line
elif len(line) > 0 and line.startswith("</TestCaseResult>"):
if self.curCaseName == None:
self.parseError("Invalid </TestCaseResult>")
self.curResultText += line
self.parseTestCaseResult(self.curCaseName, self.curResultText)
self.curCaseName = None
self.curResultText = None
elif self.curResultText != None:
self.curResultText += line
def parseContainerLine (self, line):
args = splitContainerLine(line)
if args[0] == "#sessionInfo":
if len(args) < 3:
print(args)
self.parseError("Invalid #sessionInfo")
self.sessionInfo[args[1]] = ' '.join(args[2:])
elif args[0] == "#beginSession" or args[0] == "#endSession":
pass
elif args[0] == "#beginTestCaseResult":
pass # Superseded by XML
elif args[0] == "#endTestCaseResult":
pass # Superseded by XML
elif args[0] == "#terminateTestCaseResult":
pass # Superseded by XML
else:
# Assume this is result text
if self.curResultText != None:
self.curResultText += line
def parseTestCaseResult (self, name, log):
try:
# The XML parser has troubles with invalid characters deliberately included in the shaders.
# This line removes such characters before calling the parser
log = bytes(log, 'utf-8').decode('utf-8', 'ignore')
doc = xml.dom.minidom.parseString(log)
resultItems = doc.getElementsByTagName('Result')
if len(resultItems) != 1:
self.parseError("Expected 1 <Result>, found %d" % len(resultItems))
statusCode = resultItems[0].getAttributeNode('StatusCode').nodeValue
statusDetails = getNodeText(resultItems[0])
except Exception as e:
statusCode = StatusCode.PARSE_ERROR
statusDetails = "XML parsing failed: %s" % str(e)
self.testCaseResults.append(TestCaseResult(name, statusCode, statusDetails, log))
now = time.time()
if now - self.lastStatusPrint > 60:
self.lastStatusPrint = now
self.report.message('Still reading results (%u so far)' % len(self.testCaseResults))
def parseError (self, message):
raise ParseError(self.filename, self.curLine, message)
class CommandLineParser(argparse.ArgumentParser):
def exit(self, status=0, message=None):
if message != None:
raise Exception(message)
raise Exception("invalid command line")
def error(self, message):
raise Exception(message)
def parse_args(self, args=None, namespace=None):
args, argv = self.parse_known_args(args, namespace)
if argv:
self.error("arguments not allowed for submission: %s" % (' '.join(argv)))
return args