DO NOT MERGE Do not require signed zero support in ldexp tests() am: 5b076d99a8 ...
[platform/upstream/VK-GL-CTS.git] / scripts / build_caselists.py
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
23 from build.common import *
24 from build.config import *
25 from build.build import *
26
27 import os
28 import sys
29 import string
30 import argparse
31 import tempfile
32 import shutil
33
34 class Module:
35         def __init__ (self, name, dirName, binName):
36                 self.name               = name
37                 self.dirName    = dirName
38                 self.binName    = binName
39
40 MODULES = [
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 ]
47
48 DEFAULT_BUILD_DIR       = os.path.join(tempfile.gettempdir(), "deqp-caselists", "{targetName}-{buildType}")
49 DEFAULT_TARGET          = "null"
50
51 def getModuleByName (name):
52         for module in MODULES:
53                 if module.name == name:
54                         return module
55         else:
56                 raise Exception("Unknown module %s" % name)
57
58 def getBuildConfig (buildPathPtrn, targetName, buildType):
59         buildPath = buildPathPtrn.format(
60                 targetName      = targetName,
61                 buildType       = buildType)
62
63         return BuildConfig(buildPath, buildType, ["-DDEQP_TARGET=%s" % targetName])
64
65 def getModulesPath (buildCfg):
66         return os.path.join(buildCfg.getBuildDir(), "modules")
67
68 def getBuiltModules (buildCfg):
69         modules         = []
70         modulesDir      = getModulesPath(buildCfg)
71
72         for module in MODULES:
73                 fullPath = os.path.join(modulesDir, module.dirName)
74                 if os.path.exists(fullPath) and os.path.isdir(fullPath):
75                         modules.append(module)
76
77         return modules
78
79 def getCaseListFileName (module, caseListType):
80         return "%s-cases.%s" % (module.name, caseListType)
81
82 def getCaseListPath (buildCfg, module, caseListType):
83         return os.path.join(getModulesPath(buildCfg), module.dirName, getCaseListFileName(module, caseListType))
84
85 def genCaseList (buildCfg, generator, module, caseListType):
86         workDir = os.path.join(getModulesPath(buildCfg), module.dirName)
87
88         pushWorkingDir(workDir)
89
90         try:
91                 binPath = generator.getBinaryPath(buildCfg.getBuildType(), os.path.join(".", module.binName))
92                 execute([binPath, "--deqp-runmode=%s-caselist" % caseListType])
93         finally:
94                 popWorkingDir()
95
96 def genAndCopyCaseList (buildCfg, generator, module, dstDir, caseListType):
97         caseListFile    = getCaseListFileName(module, caseListType)
98         srcPath                 = getCaseListPath(buildCfg, module, caseListType)
99         dstPath                 = os.path.join(dstDir, caseListFile)
100
101         if os.path.exists(srcPath):
102                 os.remove(srcPath)
103
104         genCaseList(buildCfg, generator, module, caseListType)
105
106         if not os.path.exists(srcPath):
107                 raise Exception("%s not generated" % srcPath)
108
109         shutil.copyfile(srcPath, dstPath)
110
111 def parseArgs ():
112         parser = argparse.ArgumentParser(description = "Build test case lists",
113                                                                          formatter_class=argparse.ArgumentDefaultsHelpFormatter)
114         parser.add_argument("-b",
115                                                 "--build-dir",
116                                                 dest="buildDir",
117                                                 default=DEFAULT_BUILD_DIR,
118                                                 help="Temporary build directory")
119         parser.add_argument("-t",
120                                                 "--build-type",
121                                                 dest="buildType",
122                                                 default="Debug",
123                                                 help="Build type")
124         parser.add_argument("-c",
125                                                 "--deqp-target",
126                                                 dest="targetName",
127                                                 default=DEFAULT_TARGET,
128                                                 help="dEQP build target")
129         parser.add_argument("--case-list-type",
130                                                 dest="caseListType",
131                                                 default="xml",
132                                                 help="Case list type (xml, txt)")
133         parser.add_argument("-m",
134                                                 "--modules",
135                                                 dest="modules",
136                                                 help="Comma-separated list of modules to update")
137         parser.add_argument("dst",
138                                                 help="Destination directory for test case lists")
139         return parser.parse_args()
140
141 if __name__ == "__main__":
142         args = parseArgs()
143
144         generator       = ANY_GENERATOR
145         buildCfg        = getBuildConfig(args.buildDir, args.targetName, args.buildType)
146         modules         = None
147
148         if args.modules:
149                 modules = []
150                 for m in args.modules.split(","):
151                         modules.append(getModuleByName(m))
152
153         if modules:
154                 build(buildCfg, generator, [m.binName for m in modules])
155         else:
156                 build(buildCfg, generator)
157                 modules = getBuiltModules(buildCfg)
158
159         for module in modules:
160                 print "Generating test case list for %s" % module.name
161                 genAndCopyCaseList(buildCfg, generator, module, args.dst, args.caseListType)