GenAndroidCTSXML.py revision 3c827367444ee418f129b2c238299f49d3264554
13c827367444ee418f129b2c238299f49d3264554Jarkko Poyryimport argparse 23c827367444ee418f129b2c238299f49d3264554Jarkko Poyryimport string 33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 43c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass TestGroup: 53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry def __init__(self, name, parent = None): 63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry self.parent = parent 73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry self.name = name 83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry self.testGroups = {} 93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry self.testCases = {} 103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if parent: 123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry assert not name in parent.testGroups 133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry parent.testGroups[name] = self 143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry def getName (self): 163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return self.name 173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry def getPath (self): 193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if self.parent: 203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return self.parent.getPath() + "." + self.name 213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else: 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return self.name 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry def hasGroup(self, groupName): 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return groupName in self.testGroups 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry def getGroup(self, groupName): 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return self.testGroups[groupName] 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry def hasTest(self, testName): 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return testName in self.testCases 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry def getTest(self, testName): 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return self.testCases[testName] 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry def hasTestCases(self): 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return len(self.testCases) != 0 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry def hasTestGroups(self): 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return len(self.testGroups) != 0 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry def getTestCases(self): 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return self.testCases.values() 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry def getTestGroups(self): 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return self.testGroups.values() 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass TestCase: 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry def __init__(self, name, parent): 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry self.name = name 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry self.parent = parent 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry assert not name in self.parent.testCases 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry self.parent.testCases[name] = self 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry def getPath (self): 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return self.parent.getPath() + "." + self.name 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry def getName(self): 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return self.name 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyrydef addGroupToHierarchy(rootGroup, path): 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry pathComponents = string.split(path, ".") 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry currentGroup = rootGroup 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry assert pathComponents[0] == rootGroup.getName() 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for i in range(1, len(pathComponents)): 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry component = pathComponents[i] 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if currentGroup.hasGroup(component): 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry currentGroup = currentGroup.getGroup(component) 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else: 743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry currentGroup = TestGroup(component, parent=currentGroup) 753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyrydef addTestToHierarchy(rootGroup, path): 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry pathComponents = string.split(path, ".") 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry currentGroup = rootGroup 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry assert pathComponents[0] == rootGroup.getName() 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for i in range(1, len(pathComponents)): 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry component = pathComponents[i] 843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if i == len(pathComponents) - 1: 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestCase(component, currentGroup) 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else: 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if currentGroup.hasGroup(component): 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry currentGroup = currentGroup.getGroup(component) 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else: 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry currentGroup = TestGroup(component, parent=currentGroup) 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyrydef loadTestHierarchy (input): 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry line = input.readline() 953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry rootGroup = None 963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if line.startswith("GROUP: "): 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry groupName = line[len("GROUP: "):-1] 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry rootGroup = TestGroup(groupName) 1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else: 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry print(line) 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry assert False 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for line in input: 1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if line.startswith("GROUP: "): 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry groupPath = line[len("GROUP: "):-1]; 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addGroupToHierarchy(rootGroup, groupPath) 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry elif line.startswith("TEST: "): 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry testPath = line[len("TEST: "):-1] 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry addTestToHierarchy(rootGroup, testPath) 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry else: 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry assert False 1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return rootGroup 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyrydef writeAndroidCTSTest(test, output): 1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry output.write('<Test name="%s" />\n' % test.getName()) 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyrydef writeAndroidCTSTestCase(group, output): 1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry assert group.hasTestCases() 1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry assert not group.hasTestGroups() 1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry output.write('<TestCase name="%s">\n' % group.getName()) 1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for testCase in group.getTestCases(): 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry writeAndroidCTSTest(testCase, output) 1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry output.write('</TestCase>\n') 1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyrydef writeAndroidCTSTestSuite(group, output): 1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if group.getName() == "performance": 1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return; 1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry output.write('<TestSuite name="%s">\n' % group.getName()) 1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry for childGroup in group.getTestGroups(): 1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if group.getName() == "performance": 1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry continue; 1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if childGroup.hasTestCases(): 1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry assert not childGroup.hasTestGroups() 1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry writeAndroidCTSTestCase(childGroup, output) 1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry elif childGroup.hasTestGroups(): 1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry writeAndroidCTSTestSuite(childGroup, output) 1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry # \note Skips groups without testcases or child groups 1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry output.write('</TestSuite>\n') 1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyrydef writeAndroidCTSFile(rootGroup, output, name="dEQP-GLES3", targetBinaryName="com.drawelements.deqp", appPackageName="com.drawelements.deqp.gles3"): 1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry output.write('<?xml version="1.0" encoding="UTF-8"?>\n') 1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry output.write('<TestPackage name="%s" targetBinaryName="%s" appPackageName="%s" testType="deqpTest">\n' % (name, targetBinaryName, appPackageName)) 1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry writeAndroidCTSTestSuite(rootGroup, output) 1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry output.write('</TestPackage>\n') 1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyryif __name__ == "__main__": 1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry parser = argparse.ArgumentParser() 1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry parser.add_argument('input', type=argparse.FileType('r'), help="Input dEQP test hierarchy in txt format.") 1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry parser.add_argument('output', type=argparse.FileType('w'), help="Output file for Android CTS test file.") 1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry parser.add_argument('--name', dest="name", type=str, required=True, help="Name of the test package") 1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry parser.add_argument('--binary', dest="binary", type=str, default="com.drawelements.deqp", help="Target binary name") 1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry parser.add_argument('--package', dest="package", type=str, required=True, help="Name of the app package") 1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry args = parser.parse_args() 1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry rootGroup = loadTestHierarchy(args.input) 1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry writeAndroidCTSFile(rootGroup, args.output, name=args.name, targetBinaryName=args.binary, appPackageName=args.package) 169