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