1 import os 2 import re 3 import sys 4 5 def ReadFileAsLines(filename): 6 """Reads a file, removing blank lines and lines that start with #""" 7 file = open(filename, "r") 8 raw_lines = file.readlines() 9 file.close() 10 lines = [] 11 for line in raw_lines: 12 line = line.strip() 13 if len(line) > 0 and not line.startswith("#"): 14 lines.append(line) 15 return lines 16 17 def GetSuiteName(testName): 18 return testName[:testName.find("/")] 19 20 def GetTestName(testName): 21 replacements = { ".test": "", ".": "_" } 22 splitTestName = testName.split("/") 23 cleanName = splitTestName[-2] + "_" + splitTestName[-1] 24 for replaceKey in replacements: 25 cleanName = cleanName.replace(replaceKey, replacements[replaceKey]) 26 return cleanName 27 28 def GenerateTests(outFile, testNames): 29 # Remove duplicate tests 30 testNames = list(set(testNames)) 31 32 outFile.write("#include \"gles_conformance_tests.h\"\n\n") 33 34 for test in testNames: 35 outFile.write("TEST(" + GetSuiteName(test) + ", " + GetTestName(test) + ")\n") 36 outFile.write("{\n") 37 outFile.write(" RunConformanceTest(\"" + test + "\", GetCurrentConfig());\n") 38 outFile.write("}\n\n") 39 40 def GenerateTestList(sourceFile, rootDir): 41 tests = [ ] 42 fileName, fileExtension = os.path.splitext(sourceFile) 43 if fileExtension == ".run": 44 lines = ReadFileAsLines(sourceFile) 45 for line in lines: 46 tests += GenerateTestList(os.path.join(os.path.dirname(sourceFile), line), rootDir) 47 elif fileExtension == ".test": 48 tests.append(os.path.relpath(os.path.realpath(sourceFile), rootDir).replace("\\", "/")) 49 return tests; 50 51 def main(argv): 52 tests = GenerateTestList(argv[0], argv[1]) 53 tests.sort() 54 55 output = open(argv[2], 'wb') 56 GenerateTests(output, tests) 57 output.close() 58 59 return 0 60 61 if __name__ == '__main__': 62 sys.exit(main(sys.argv[1:])) 63