1 # -*- coding: utf-8 -*-
3 #-------------------------------------------------------------------------
4 # drawElements Quality Program utilities
5 # --------------------------------------
7 # Copyright 2016 The Android Open Source Project
9 # Licensed under the Apache License, Version 2.0 (the "License");
10 # you may not use this file except in compliance with the License.
11 # You may obtain a copy of the License at
13 # http://www.apache.org/licenses/LICENSE-2.0
15 # Unless required by applicable law or agreed to in writing, software
16 # distributed under the License is distributed on an "AS IS" BASIS,
17 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 # See the License for the specific language governing permissions and
19 # limitations under the License.
21 #-------------------------------------------------------------------------
23 from build.common import *
24 from build.config import ANY_GENERATOR
25 from build.build import build
26 from build_caselists import Module, getModuleByName, getBuildConfig, genCaseList, getCaseListPath, DEFAULT_BUILD_DIR, DEFAULT_TARGET
27 from fnmatch import fnmatch
31 import xml.etree.cElementTree as ElementTree
32 import xml.dom.minidom as minidom
34 APK_NAME = "com.drawelements.deqp.apk"
36 GENERATED_FILE_WARNING = """
37 This file has been automatically generated. Edit with caution.
41 def __init__ (self, path, copyright = None):
43 self.copyright = copyright
46 def __init__ (self, name, filters, glconfig = None, rotation = None, surfacetype = None, required = False, runtime = None):
48 self.glconfig = glconfig
49 self.rotation = rotation
50 self.surfacetype = surfacetype
51 self.required = required
52 self.filters = filters
53 self.expectedRuntime = runtime
56 def __init__ (self, module, configurations):
58 self.configurations = configurations
61 def __init__ (self, project, version, packages):
62 self.project = project
63 self.version = version
64 self.packages = packages
70 def __init__ (self, type, filename):
72 self.filename = filename
79 def __init__ (self, name):
84 def __init__ (self, name):
86 self.configurations = []
89 def __init__(self, major, minor):
94 return (self.major << 16) | (self.minor)
96 def getModuleGLESVersion (module):
98 'dEQP-EGL': GLESVersion(2,0),
99 'dEQP-GLES2': GLESVersion(2,0),
100 'dEQP-GLES3': GLESVersion(3,0),
101 'dEQP-GLES31': GLESVersion(3,1)
103 return versions[module.name] if module.name in versions else None
105 def getSrcDir (mustpass):
106 return os.path.join(mustpass.project.path, mustpass.version, "src")
108 def getTmpDir (mustpass):
109 return os.path.join(mustpass.project.path, mustpass.version, "tmp")
111 def getModuleShorthand (module):
112 assert module.name[:5] == "dEQP-"
113 return module.name[5:].lower()
115 def getCaseListFileName (package, configuration):
116 return "%s-%s.txt" % (getModuleShorthand(package.module), configuration.name)
118 def getDstCaseListPath (mustpass, package, configuration):
119 return os.path.join(mustpass.project.path, mustpass.version, getCaseListFileName(package, configuration))
121 def getCTSPackageName (package):
122 return "com.drawelements.deqp." + getModuleShorthand(package.module)
124 def getCommandLine (config):
127 if config.glconfig != None:
128 cmdLine += "--deqp-gl-config-name=%s " % config.glconfig
130 if config.rotation != None:
131 cmdLine += "--deqp-screen-rotation=%s " % config.rotation
133 if config.surfacetype != None:
134 cmdLine += "--deqp-surface-type=%s " % config.surfacetype
136 cmdLine += "--deqp-watchdog=enable"
140 def readCaseList (filename):
142 with open(filename, 'rb') as f:
144 if line[:6] == "TEST: ":
145 cases.append(line[6:].strip())
148 def getCaseList (buildCfg, generator, module):
149 build(buildCfg, generator, [module.binName])
150 genCaseList(buildCfg, generator, module, "txt")
151 return readCaseList(getCaseListPath(buildCfg, module, "txt"))
153 def readPatternList (filename):
155 with open(filename, 'rb') as f:
158 if len(line) > 0 and line[0] != '#':
162 def applyPatterns (caseList, patterns, filename, op):
165 curList = copy(caseList)
166 trivialPtrns = [p for p in patterns if p.find('*') < 0]
167 regularPtrns = [p for p in patterns if p.find('*') >= 0]
169 # Apply trivial (just case paths)
170 allCasesSet = set(caseList)
171 for path in trivialPtrns:
172 if path in allCasesSet:
174 errors.append((path, "Same case specified more than once"))
177 errors.append((path, "Test case not found"))
179 curList = [c for c in curList if c not in matched]
181 for pattern in regularPtrns:
182 matchedThisPtrn = set()
185 if fnmatch(case, pattern):
186 matchedThisPtrn.add(case)
188 if len(matchedThisPtrn) == 0:
189 errors.append((pattern, "Pattern didn't match any cases"))
191 matched = matched | matchedThisPtrn
192 curList = [c for c in curList if c not in matched]
194 for pattern, reason in errors:
195 print "ERROR: %s: %s" % (reason, pattern)
198 die("Found %s invalid patterns while processing file %s" % (len(errors), filename))
200 return [c for c in caseList if op(c in matched)]
202 def applyInclude (caseList, patterns, filename):
203 return applyPatterns(caseList, patterns, filename, lambda b: b)
205 def applyExclude (caseList, patterns, filename):
206 return applyPatterns(caseList, patterns, filename, lambda b: not b)
208 def readPatternLists (mustpass):
210 for package in mustpass.packages:
211 for cfg in package.configurations:
212 for filter in cfg.filters:
213 if not filter.filename in lists:
214 lists[filter.filename] = readPatternList(os.path.join(getSrcDir(mustpass), filter.filename))
217 def applyFilters (caseList, patternLists, filters):
219 for filter in filters:
220 ptrnList = patternLists[filter.filename]
221 if filter.type == Filter.TYPE_INCLUDE:
222 res = applyInclude(res, ptrnList, filter.filename)
224 assert filter.type == Filter.TYPE_EXCLUDE
225 res = applyExclude(res, ptrnList, filter.filename)
228 def appendToHierarchy (root, casePath):
229 def findChild (node, name):
230 for child in node.children:
231 if child.name == name:
236 components = casePath.split('.')
238 for component in components[:-1]:
239 nextNode = findChild(curNode, component)
241 nextNode = TestGroup(component)
242 curNode.children.append(nextNode)
245 if not findChild(curNode, components[-1]):
246 curNode.children.append(TestCase(components[-1]))
248 def buildTestHierachy (caseList):
250 for case in caseList:
251 appendToHierarchy(root, case)
254 def buildTestCaseMap (root):
257 def recursiveBuild (curNode, prefix):
258 curPath = prefix + curNode.name
259 if isinstance(curNode, TestCase):
260 caseMap[curPath] = curNode
262 for child in curNode.children:
263 recursiveBuild(child, curPath + '.')
265 for child in root.children:
266 recursiveBuild(child, '')
270 def include (filename):
271 return Filter(Filter.TYPE_INCLUDE, filename)
273 def exclude (filename):
274 return Filter(Filter.TYPE_EXCLUDE, filename)
276 def insertXMLHeaders (mustpass, doc):
277 if mustpass.project.copyright != None:
278 doc.insert(0, ElementTree.Comment(mustpass.project.copyright))
279 doc.insert(1, ElementTree.Comment(GENERATED_FILE_WARNING))
281 def prettifyXML (doc):
282 uglyString = ElementTree.tostring(doc, 'utf-8')
283 reparsed = minidom.parseString(uglyString)
284 return reparsed.toprettyxml(indent='\t', encoding='utf-8')
286 def genSpecXML (mustpass):
287 mustpassElem = ElementTree.Element("Mustpass", version = mustpass.version)
288 insertXMLHeaders(mustpass, mustpassElem)
290 for package in mustpass.packages:
291 packageElem = ElementTree.SubElement(mustpassElem, "TestPackage", name = package.module.name)
293 for config in package.configurations:
294 configElem = ElementTree.SubElement(packageElem, "Configuration",
296 caseListFile = getCaseListFileName(package, config),
297 commandLine = getCommandLine(config))
301 def addOptionElement (parent, optionName, optionValue):
302 ElementTree.SubElement(parent, "option", name=optionName, value=optionValue)
304 def genAndroidTestXml (mustpass):
305 RUNNER_CLASS = "com.drawelements.deqp.runner.DeqpTestRunner"
306 configElement = ElementTree.Element("configuration")
308 for package in mustpass.packages:
309 for config in package.configurations:
310 testElement = ElementTree.SubElement(configElement, "test")
311 testElement.set("class", RUNNER_CLASS)
312 addOptionElement(testElement, "deqp-package", package.module.name)
313 addOptionElement(testElement, "deqp-caselist-file", getCaseListFileName(package,config))
314 # \todo [2015-10-16 kalle]: Replace with just command line? - requires simplifications in the runner/tests as well.
315 if config.glconfig != None:
316 addOptionElement(testElement, "deqp-gl-config-name", config.glconfig)
318 if config.surfacetype != None:
319 addOptionElement(testElement, "deqp-surface-type", config.surfacetype)
321 if config.rotation != None:
322 addOptionElement(testElement, "deqp-screen-rotation", config.rotation)
324 if config.expectedRuntime != None:
325 addOptionElement(testElement, "runtime-hint", config.expectedRuntime)
328 addOptionElement(testElement, "deqp-config-required", "true")
330 insertXMLHeaders(mustpass, configElement)
334 def genMustpass (mustpass, moduleCaseLists):
335 print "Generating mustpass '%s'" % mustpass.version
337 patternLists = readPatternLists(mustpass)
339 for package in mustpass.packages:
340 allCasesInPkg = moduleCaseLists[package.module]
342 for config in package.configurations:
343 filtered = applyFilters(allCasesInPkg, patternLists, config.filters)
344 dstFile = getDstCaseListPath(mustpass, package, config)
346 print " Writing deqp caselist: " + dstFile
347 writeFile(dstFile, "\n".join(filtered) + "\n")
349 specXML = genSpecXML(mustpass)
350 specFilename = os.path.join(mustpass.project.path, mustpass.version, "mustpass.xml")
352 print " Writing spec: " + specFilename
353 writeFile(specFilename, prettifyXML(specXML))
355 # TODO: Which is the best selector mechanism?
356 if (mustpass.version == "master"):
357 androidTestXML = genAndroidTestXml(mustpass)
358 androidTestFilename = os.path.join(mustpass.project.path, "AndroidTest.xml")
360 print " Writing AndroidTest.xml: " + androidTestFilename
361 writeFile(androidTestFilename, prettifyXML(androidTestXML))
365 def genMustpassLists (mustpassLists, generator, buildCfg):
368 # Getting case lists involves invoking build, so we want to cache the results
369 for mustpass in mustpassLists:
370 for package in mustpass.packages:
371 if not package.module in moduleCaseLists:
372 moduleCaseLists[package.module] = getCaseList(buildCfg, generator, package.module)
374 for mustpass in mustpassLists:
375 genMustpass(mustpass, moduleCaseLists)
377 def parseCmdLineArgs ():
378 parser = argparse.ArgumentParser(description = "Build Android CTS mustpass",
379 formatter_class=argparse.ArgumentDefaultsHelpFormatter)
380 parser.add_argument("-b",
383 default=DEFAULT_BUILD_DIR,
384 help="Temporary build directory")
385 parser.add_argument("-t",
390 parser.add_argument("-c",
393 default=DEFAULT_TARGET,
394 help="dEQP build target")
395 return parser.parse_args()
397 def parseBuildConfigFromCmdLineArgs ():
398 args = parseCmdLineArgs()
399 return getBuildConfig(args.buildDir, args.targetName, args.buildType)