blob: 456e1a006285df575c3f14fe6c9386e730fb6446 [file] [log] [blame]
Jarkko Pöyry3c77ed42015-01-06 12:54:34 -08001#-------------------------------------------------------------------------
2# drawElements Quality Program utilities
3# --------------------------------------
4#
5# Copyright 2015 The Android Open Source Project
6#
7# Licensed under the Apache License, Version 2.0 (the "License");
8# you may not use this file except in compliance with the License.
9# You may obtain a copy of the License at
10#
11# http://www.apache.org/licenses/LICENSE-2.0
12#
13# Unless required by applicable law or agreed to in writing, software
14# distributed under the License is distributed on an "AS IS" BASIS,
15# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16# See the License for the specific language governing permissions and
17# limitations under the License.
18#
19#-------------------------------------------------------------------------
20
Jarkko Poyry3c827362014-09-02 11:48:52 +030021import re
22import sys
23from xml.dom.minidom import Document
24
25class TestCase:
26 def __init__(self, casePath, description, caseType):
27 self.casePath = casePath
28 self.description = description
29 self.caseType = caseType
30 self.children = []
31
32def findAllMatches(haystack, needle):
33 matches = []
34 ndx = -1
35 while True:
36 ndx = haystack.find(needle, ndx+1)
37 if (ndx == -1):
38 break
39 matches.append(ndx)
40 return matches
41
42def createAncestors(casePath):
43 parentCase = None
44 for dotNdx in findAllMatches(casePath, "."):
45 ancestorPath = casePath[:dotNdx]
46 if ancestorPath not in caseNameHash:
47 case = TestCase(ancestorPath, "Test Group", "TestGroup")
48 parentCase.children.append(case)
49 caseNameHash[ancestorPath] = case
50 parentCase = case
51 parentCase = caseNameHash[ancestorPath]
52 return parentCase
53
54def exportCase (doc, parent, testCase):
55 #print testCase.name, testCase.caseType
56 element = doc.createElement("TestCase")
57 element.setAttribute("Name", testCase.casePath.rsplit(".", 2)[-1])
58 element.setAttribute("Description", testCase.description)
59 element.setAttribute("CaseType", testCase.caseType)
60 parent.appendChild(element)
61 for child in testCase.children:
62 exportCase(doc, element, child)
63
64# Main.
65
66packageName = sys.argv[1]
67
68rootCase = TestCase(packageName, packageName, "TestPackage" )
69caseNameHash = { packageName:rootCase }
70caseRE = re.compile(r"^\s*([a-zA-Z0-9_\.\-]+) '([^']*)' (\w+)\s*$".replace(" ", r"\s+"))
71
72lines = open(packageName + ".cases").readlines()
73numMatches = 0
74for line in lines:
75 line = line[:-1]
76 if line.startswith(packageName + "."):
77 m = caseRE.match(line)
78 if m:
79 casePath = m.group(1)
80 description = m.group(2)
81 caseType = m.group(3)
82 parent = createAncestors(casePath)
83 parent.children.append(TestCase(casePath, description, caseType))
84 numMatches += 1
85
86# Create XML document.
87doc = Document()
88element = doc.createElement("TestCaseList")
89doc.appendChild(element)
90for testCase in rootCase.children:
91 exportCase(doc, element, testCase)
92
93# Dump XML document.
94xml = doc.toprettyxml(indent=" ")
95open(packageName + "-cases.xml", "wt").write(xml)
96
97print "%d cases converted." % numMatches
98