xref: /aosp_15_r20/external/deqp/scripts/build_caselists.py (revision 35238bce31c2a825756842865a792f8cf7f89930)
1# -*- coding: utf-8 -*-
2
3#-------------------------------------------------------------------------
4# drawElements Quality Program utilities
5# --------------------------------------
6#
7# Copyright 2015 The Android Open Source Project
8#
9# Licensed under the Apache License, Version 2.0 (the "License");
10# you may not use this file except in compliance with the License.
11# You may obtain a copy of the License at
12#
13#      http://www.apache.org/licenses/LICENSE-2.0
14#
15# Unless required by applicable law or agreed to in writing, software
16# distributed under the License is distributed on an "AS IS" BASIS,
17# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18# See the License for the specific language governing permissions and
19# limitations under the License.
20#
21#-------------------------------------------------------------------------
22
23from ctsbuild.common import *
24from ctsbuild.config import *
25from ctsbuild.build import *
26
27import os
28import sys
29import string
30import argparse
31import tempfile
32import shutil
33
34class Module:
35    def __init__ (self, name, dirName, binName):
36        self.name = name
37        self.dirName = dirName
38        self.binName = binName
39
40MODULES = [
41    Module("dE-IT", "internal", "de-internal-tests"),
42    Module("dEQP-EGL", "egl", "deqp-egl"),
43    Module("dEQP-GLES2", "gles2", "deqp-gles2"),
44    Module("dEQP-GLES3", "gles3", "deqp-gles3"),
45    Module("dEQP-GLES31", "gles31", "deqp-gles31"),
46    Module("dEQP-VK", "../external/vulkancts/modules/vulkan", "deqp-vk"),
47    Module("dEQP-VKSC", "../external/vulkancts/modules/vulkan", "deqp-vksc"),
48]
49
50DEFAULT_BUILD_DIR = os.path.join(tempfile.gettempdir(), "deqp-caselists", "{targetName}-{buildType}")
51DEFAULT_TARGET = "null"
52
53def getModuleByName (name):
54    for module in MODULES:
55        if module.name == name:
56            return module
57    else:
58        raise Exception("Unknown module %s" % name)
59
60def getBuildConfig (buildPathPtrn, targetName, buildType):
61    buildPath = buildPathPtrn.format(
62        targetName = targetName,
63        buildType = buildType)
64
65    return BuildConfig(buildPath, buildType, ["-DDEQP_TARGET=%s" % targetName])
66
67def getModulesPath (buildCfg):
68    return os.path.join(buildCfg.getBuildDir(), "modules")
69
70def getBuiltModules (buildCfg):
71    modules = []
72    modulesDir = getModulesPath(buildCfg)
73
74    for module in MODULES:
75        fullPath = os.path.join(modulesDir, module.dirName)
76        if os.path.exists(fullPath) and os.path.isdir(fullPath):
77            modules.append(module)
78
79    return modules
80
81def getCaseListFileName (module, caseListType):
82    return "%s-cases.%s" % (module.name, caseListType)
83
84def getCaseListPath (buildCfg, module, caseListType):
85    return os.path.join(getModulesPath(buildCfg), module.dirName, getCaseListFileName(module, caseListType))
86
87def genCaseList (buildCfg, generator, module, caseListType):
88    workDir = os.path.join(getModulesPath(buildCfg), module.dirName)
89
90    pushWorkingDir(workDir)
91
92    try:
93        binPath = generator.getBinaryPath(buildCfg.getBuildType(), os.path.join(".", module.binName))
94        execute([binPath, "--deqp-runmode=%s-caselist" % caseListType])
95    finally:
96        popWorkingDir()
97
98def genAndCopyCaseList (buildCfg, generator, module, dstDir, caseListType):
99    caseListFile = getCaseListFileName(module, caseListType)
100    srcPath = getCaseListPath(buildCfg, module, caseListType)
101    dstPath = os.path.join(dstDir, caseListFile)
102
103    if os.path.exists(srcPath):
104        os.remove(srcPath)
105
106    genCaseList(buildCfg, generator, module, caseListType)
107
108    if not os.path.exists(srcPath):
109        raise Exception("%s not generated" % srcPath)
110
111    shutil.copyfile(srcPath, dstPath)
112
113def parseArgs ():
114    parser = argparse.ArgumentParser(description = "Build test case lists",
115                                     formatter_class=argparse.ArgumentDefaultsHelpFormatter)
116    parser.add_argument("-b",
117                        "--build-dir",
118                        dest="buildDir",
119                        default=DEFAULT_BUILD_DIR,
120                        help="Temporary build directory")
121    parser.add_argument("-t",
122                        "--build-type",
123                        dest="buildType",
124                        default="Debug",
125                        help="Build type")
126    parser.add_argument("-c",
127                        "--deqp-target",
128                        dest="targetName",
129                        default=DEFAULT_TARGET,
130                        help="dEQP build target")
131    parser.add_argument("--case-list-type",
132                        dest="caseListType",
133                        default="xml",
134                        help="Case list type (xml, txt)")
135    parser.add_argument("-m",
136                        "--modules",
137                        dest="modules",
138                        help="Comma-separated list of modules to update")
139    parser.add_argument("dst",
140                        help="Destination directory for test case lists")
141    return parser.parse_args()
142
143if __name__ == "__main__":
144    args = parseArgs()
145
146    generator = ANY_GENERATOR
147    buildCfg = getBuildConfig(args.buildDir, args.targetName, args.buildType)
148    modules = None
149
150    if args.modules:
151        modules = []
152        for m in args.modules.split(","):
153            modules.append(getModuleByName(m))
154
155    if modules:
156        build(buildCfg, generator, [m.binName for m in modules])
157    else:
158        build(buildCfg, generator)
159        modules = getBuiltModules(buildCfg)
160
161    for module in modules:
162        print("Generating test case list for %s" % module.name)
163        genAndCopyCaseList(buildCfg, generator, module, args.dst, args.caseListType)
164