1 import argparse 2 import string 3 4 class TestGroup: 5 def __init__(self, name, parent = None): 6 self.parent = parent 7 self.name = name 8 self.testGroups = [] 9 self.testCases = [] 10 11 if parent: 12 assert not parent.hasGroup(name) 13 parent.testGroups.append(self) 14 15 def getName (self): 16 return self.name 17 18 def getPath (self): 19 if self.parent: 20 return self.parent.getPath() + "." + self.name 21 else: 22 return self.name 23 24 def hasGroup(self, groupName): 25 for group in self.testGroups: 26 if group.getName() == groupName: 27 return True 28 return False 29 30 def getGroup(self, groupName): 31 for group in self.testGroups: 32 if group.getName() == groupName: 33 return group 34 assert False 35 36 def hasTest(self, testName): 37 for test in self.testCases: 38 if test.getName() == testName: 39 return True 40 return False 41 42 def getTest(self, testName): 43 for test in self.testCases: 44 if test.getName() == testName: 45 return test 46 assert False 47 48 def hasTestCases(self): 49 return len(self.testCases) != 0 50 51 def hasTestGroups(self): 52 return len(self.testGroups) != 0 53 54 def getTestCases(self): 55 return self.testCases 56 57 def getTestGroups(self): 58 return self.testGroups 59 60 class TestCase: 61 def __init__(self, name, parent): 62 self.name = name 63 self.parent = parent 64 65 assert not parent.hasTest(name) 66 self.parent.testCases.append(self) 67 68 def getPath (self): 69 return self.parent.getPath() + "." + self.name 70 71 def getName(self): 72 return self.name 73 74 def addTestToHierarchy(rootGroup, path): 75 pathComponents = string.split(path, ".") 76 currentGroup = rootGroup 77 78 assert pathComponents[0] == rootGroup.getName() 79 80 for i in range(1, len(pathComponents)): 81 component = pathComponents[i] 82 83 if i == len(pathComponents) - 1: 84 TestCase(component, currentGroup) 85 else: 86 if currentGroup.hasGroup(component): 87 currentGroup = currentGroup.getGroup(component) 88 else: 89 currentGroup = TestGroup(component, parent=currentGroup) 90 91 def loadTestHierarchy (input, packageName): 92 line = input.readline() 93 rootGroup = None 94 95 if line.startswith(packageName + "."): 96 groupName = packageName 97 rootGroup = TestGroup(groupName) 98 else: 99 print(line) 100 assert False 101 102 for line in input: 103 addTestToHierarchy(rootGroup, line.strip()); 104 105 return rootGroup 106 107 def writeAndroidCTSTest(test, output): 108 output.write('<Test name="%s" />\n' % test.getName()) 109 110 def writeAndroidCTSTestCase(group, output): 111 assert group.hasTestCases() 112 assert not group.hasTestGroups() 113 114 output.write('<TestCase name="%s">\n' % group.getName()) 115 116 for testCase in group.getTestCases(): 117 writeAndroidCTSTest(testCase, output) 118 119 output.write('</TestCase>\n') 120 121 def writeAndroidCTSTestSuite(group, output): 122 if group.getName() == "performance": 123 return; 124 125 output.write('<TestSuite name="%s">\n' % group.getName()) 126 127 for childGroup in group.getTestGroups(): 128 if group.getName() == "performance": 129 continue; 130 131 if childGroup.hasTestCases(): 132 assert not childGroup.hasTestGroups() 133 writeAndroidCTSTestCase(childGroup, output) 134 elif childGroup.hasTestGroups(): 135 writeAndroidCTSTestSuite(childGroup, output) 136 # \note Skips groups without testcases or child groups 137 138 output.write('</TestSuite>\n') 139 140 def writeAndroidCTSFile(rootGroup, output, name, appPackageName): 141 output.write('<?xml version="1.0" encoding="UTF-8"?>\n') 142 output.write('<TestPackage name="%s" appPackageName="%s" testType="deqpTest">\n' % (name, appPackageName)) 143 144 writeAndroidCTSTestSuite(rootGroup, output) 145 146 output.write('</TestPackage>\n') 147 148 if __name__ == "__main__": 149 parser = argparse.ArgumentParser() 150 parser.add_argument('input', type=argparse.FileType('r'), help="Input file containing dEQP test names.") 151 parser.add_argument('output', type=argparse.FileType('w'), help="Output file for Android CTS test file.") 152 parser.add_argument('--name', dest="name", type=str, required=True, help="Name of the test package") 153 parser.add_argument('--package', dest="package", type=str, required=True, help="Name of the app package") 154 155 args = parser.parse_args() 156 157 rootGroup = loadTestHierarchy(args.input, args.name) 158 writeAndroidCTSFile(rootGroup, args.output, name=args.name, appPackageName=args.package) 159