summaryrefslogtreecommitdiffstats
path: root/gfx/angle/src/tests/gles_conformance_tests/generate_gles_conformance_tests.py
blob: 8ed313a169ae90b5bfe74ae4b8140387833ec8db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import os
import re
import sys

def ReadFileAsLines(filename):
    """Reads a file, removing blank lines and lines that start with #"""
    file = open(filename, "r")
    raw_lines = file.readlines()
    file.close()
    lines = []
    for line in raw_lines:
        line = line.strip()
        if len(line) > 0 and not line.startswith("#"):
            lines.append(line)
    return lines

def GetSuiteName(testName):
    return testName[:testName.find("/")]

def GetTestName(testName):
    replacements = { ".test": "", ".": "_" }
    splitTestName = testName.split("/")
    cleanName = splitTestName[-2] + "_" + splitTestName[-1]
    for replaceKey in replacements:
        cleanName = cleanName.replace(replaceKey, replacements[replaceKey])
    return cleanName

def GenerateTests(outFile, testNames):
    # Remove duplicate tests
    testNames = list(set(testNames))
    testSuites = []

    outFile.write("#include \"gles_conformance_tests.h\"\n\n")

    for test in testNames:
        testSuite = GetSuiteName(test)
        if not testSuite in testSuites:
            outFile.write("DEFINE_CONFORMANCE_TEST_CLASS(" + testSuite + ");\n\n")
            testSuites.append(testSuite)

        outFile.write("TYPED_TEST(" + testSuite + ", " + GetTestName(test) + ")\n")
        outFile.write("{\n")
        outFile.write("    run(\"" + test + "\");\n")
        outFile.write("}\n\n")

def GenerateTestList(sourceFile, rootDir):
    tests = [ ]
    fileName, fileExtension = os.path.splitext(sourceFile)
    if fileExtension == ".run":
        lines = ReadFileAsLines(sourceFile)
        for line in lines:
            tests += GenerateTestList(os.path.join(os.path.dirname(sourceFile), line), rootDir)
    elif fileExtension == ".test":
        tests.append(os.path.relpath(os.path.realpath(sourceFile), rootDir).replace("\\", "/"))
    return tests;

def main(argv):
    tests = GenerateTestList(argv[0], argv[1])
    tests.sort()

    output = open(argv[2], 'wb')
    GenerateTests(output, tests)
    output.close()

    return 0

if __name__ == '__main__':
    sys.exit(main(sys.argv[1:]))