am f7621d9e: am f9ccead6: Remove invalid atomic image compare swap tests from mustpass.
[platform/upstream/VK-GL-CTS.git] / scripts / build_caselists.py
1 # -*- coding: utf-8 -*-
2
3 from build.common import *
4 from build.config import *
5 from build.build import *
6
7 import os
8 import sys
9 import string
10 import argparse
11 import tempfile
12 import shutil
13
14 class Module:
15         def __init__ (self, name, dirName, binName):
16                 self.name               = name
17                 self.dirName    = dirName
18                 self.binName    = binName
19
20 MODULES = [
21         Module("dE-IT",                 "internal",             "de-internal-tests"),
22         Module("dEQP-EGL",              "egl",                  "deqp-egl"),
23         Module("dEQP-GLES2",    "gles2",                "deqp-gles2"),
24         Module("dEQP-GLES3",    "gles3",                "deqp-gles3"),
25         Module("dEQP-GLES31",   "gles31",               "deqp-gles31"),
26 ]
27
28 DEFAULT_BUILD_DIR       = os.path.join(tempfile.gettempdir(), "deqp-caselists", "{targetName}-{buildType}")
29 DEFAULT_TARGET          = "null"
30
31 def getModuleByName (name):
32         for module in MODULES:
33                 if module.name == name:
34                         return module
35         else:
36                 raise Exception("Unknown module %s" % name)
37
38 def getBuildConfig (buildPathPtrn, targetName, buildType):
39         buildPath = buildPathPtrn.format(
40                 targetName      = targetName,
41                 buildType       = buildType)
42
43         return BuildConfig(buildPath, buildType, ["-DDEQP_TARGET=%s" % targetName])
44
45 def getModulesPath (buildCfg):
46         return os.path.join(buildCfg.getBuildDir(), "modules")
47
48 def getBuiltModules (buildCfg):
49         modules         = []
50         modulesDir      = getModulesPath(buildCfg)
51         modMap          = {m.dirName: m for m in MODULES}
52
53         for entry in os.listdir(modulesDir):
54                 fullPath = os.path.join(modulesDir, entry)
55                 if os.path.isdir(fullPath) and entry in modMap:
56                         modules.append(modMap[entry])
57
58         return modules
59
60 def getCaseListFileName (module):
61         return "%s-cases.xml" % module.name
62
63 def genCaseList (buildCfg, generator, module):
64         workDir = os.path.join(getModulesPath(buildCfg), module.dirName)
65
66         pushWorkingDir(workDir)
67
68         try:
69                 binPath = generator.getBinaryPath(buildCfg.getBuildType(), os.path.join(".", module.binName))
70                 execute([binPath, "--deqp-runmode=xml-caselist"])
71         finally:
72                 popWorkingDir()
73
74 def genAndCopyCaseList (buildCfg, generator, module, dstDir):
75         caseListFile    = getCaseListFileName(module)
76         srcPath                 = os.path.join(getModulesPath(buildCfg), module.dirName, caseListFile)
77         dstPath                 = os.path.join(dstDir, caseListFile)
78
79         if os.path.exists(srcPath):
80                 os.remove(srcPath)
81
82         genCaseList(buildCfg, generator, module)
83
84         if not os.path.exists(srcPath):
85                 raise Exception("%s not generated" % srcPath)
86
87         shutil.copyfile(srcPath, dstPath)
88
89 def parseArgs ():
90         parser = argparse.ArgumentParser(description = "Build test case lists",
91                                                                          formatter_class=argparse.ArgumentDefaultsHelpFormatter)
92         parser.add_argument("-b",
93                                                 "--build-dir",
94                                                 dest="buildDir",
95                                                 default=DEFAULT_BUILD_DIR,
96                                                 help="Temporary build directory")
97         parser.add_argument("-t",
98                                                 "--build-type",
99                                                 dest="buildType",
100                                                 default="Debug",
101                                                 help="Build type")
102         parser.add_argument("-c",
103                                                 "--deqp-target",
104                                                 dest="targetName",
105                                                 default=DEFAULT_TARGET,
106                                                 help="dEQP build target")
107         parser.add_argument("-m",
108                                                 "--modules",
109                                                 dest="modules",
110                                                 help="Comma-separated list of modules to update")
111         parser.add_argument("dst",
112                                                 help="Destination directory for test case lists")
113         return parser.parse_args()
114
115 if __name__ == "__main__":
116         args = parseArgs()
117
118         generator       = ANY_GENERATOR
119         buildCfg        = getBuildConfig(args.buildDir, args.targetName, args.buildType)
120         modules         = None
121
122         if args.modules:
123                 modules = []
124                 for m in args.modules.split(","):
125                         modules.append(getModuleByName(m))
126
127         if modules:
128                 build(buildCfg, generator, [m.binName for m in modules])
129         else:
130                 build(buildCfg, generator)
131                 modules = getBuiltModules(buildCfg)
132
133         for module in modules:
134                 print "Generating test case list for %s" % module.name
135                 genAndCopyCaseList(buildCfg, generator, module, args.dst)