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
23import os
24import sys
25import string
26import argparse
27import tempfile
28import shutil
29
30scriptPath = os.path.join(os.path.dirname(__file__), "..", "..", "..", "scripts")
31sys.path.insert(0, scriptPath)
32
33from ctsbuild.common import *
34from ctsbuild.config import *
35from ctsbuild.build import *
36
37
38class Module:
39	def __init__ (self, name, api):
40		self.name		= name
41		self.api        = api
42
43MODULES = [
44	Module("dEQP-EGL",		"EGL"),
45	Module("dEQP-GLES2",	"GLES2"),
46	Module("dEQP-GLES3",	"GLES3"),
47	Module("dEQP-GLES31",	"GLES31"),
48	Module("dEQP-GL45-ES3",	"GL45"),
49	Module("dEQP-GL45-ES31","GL45"),
50	Module("KHR-GLES3",		"GLES3"),
51	Module("KHR-GLES2",		"GLES2"),
52	Module("KHR-GLES31",	"GLES31"),
53	Module("KHR-GLES32",	"GLES32"),
54	Module("KHR-NOCTX-ES2",	"GLES2"),
55	Module("KHR-NOCTX-ES32","GLES32"),
56	Module("GTF-GLES2",		"GLES2" ),
57	Module("GTF-GLES3",		"GLES3" ),
58	Module("GTF-GLES31",	"GLES31"),
59	Module("KHR-GL46",		"GL46"),
60	Module("KHR-GL45",		"GL45"),
61	Module("KHR-GL44",		"GL44"),
62	Module("KHR-GL43",		"GL43"),
63	Module("KHR-GL42",		"GL42"),
64	Module("KHR-GL42-COMPAT",	"GL42-COMPAT"),
65	Module("KHR-GL41",		"GL41"),
66	Module("KHR-GL40",		"GL40"),
67	Module("KHR-GL33",		"GL33"),
68	Module("KHR-GL32",		"GL32"),
69	Module("KHR-GL31",		"GL31"),
70	Module("KHR-GL30",		"GL30"),
71	Module("GTF-GL46",		"GL46"),
72	Module("GTF-GL45",		"GL45"),
73	Module("GTF-GL44",		"GL44"),
74	Module("GTF-GL43",		"GL43"),
75	Module("GTF-GL42",		"GL42"),
76	Module("GTF-GL41",		"GL41"),
77	Module("GTF-GL40",		"GL40"),
78	Module("GTF-GL33",		"GL33"),
79	Module("GTF-GL32",		"GL32"),
80	Module("GTF-GL31",		"GL31"),
81	Module("GTF-GL30",		"GL30"),
82	Module("KHR-NOCTX-GL30","GL30"),
83	Module("KHR-NOCTX-GL40","GL40"),
84	Module("KHR-NOCTX-GL43","GL43"),
85	Module("KHR-NOCTX-GL45","GL45"),
86	Module("KHR-Single-GL43","GL43"),
87	Module("KHR-Single-GL44","GL44"),
88	Module("KHR-Single-GL45","GL45"),
89	Module("KHR-Single-GL46","GL46"),
90	Module("KHR-Single-GLES32","GLES32"),
91]
92GLCTS_BIN_NAME = "glcts"
93GLCTS_DIR_NAME = "external/openglcts/modules/"
94DEFAULT_BUILD_DIR	= os.path.join(tempfile.gettempdir(), "deqp-caselists", "{targetName}-{buildType}")
95DEFAULT_TARGET		= "null"
96
97def getModuleByName (name):
98	for module in MODULES:
99		if module.name == name:
100			return module
101	else:
102		raise Exception("Unknown module %s" % name)
103
104def getBuildConfig (buildPathPtrn, targetName, buildType):
105	buildPath = buildPathPtrn.format(
106		targetName	= targetName,
107		buildType	= buildType)
108
109	return BuildConfig(buildPath, buildType, ["-DDEQP_TARGET=%s" % targetName])
110
111def getModulesPath (buildCfg):
112	return os.path.join(buildCfg.getBuildDir(), GLCTS_DIR_NAME)
113
114def getCaseListFileName (module, caseListType):
115	mname = module.name
116	if mname == "KHR-NOCTX-ES2" or mname == "KHR-NOCTX-ES32" or mname == "KHR-NOCTX-GL30" or mname == "KHR-NOCTX-GL40" or mname == "KHR-NOCTX-GL43" or mname == "KHR-NOCTX-GL45":
117		mname =  "KHR-NoContext"
118	return "%s-cases.%s" % (mname, caseListType)
119
120def getCaseListPath (buildCfg, module, caseListType):
121	workDir = getModulesPath(buildCfg)
122
123	return os.path.join(workDir, getCaseListFileName(module, caseListType))
124
125def genCaseList (buildCfg, generator, caseListType):
126	workDir = getModulesPath(buildCfg)
127
128	pushWorkingDir(workDir)
129
130	try:
131		binPath = generator.getBinaryPath(buildCfg.getBuildType(), os.path.join(".", GLCTS_BIN_NAME))
132		execute([binPath, "--deqp-runmode=%s-caselist" % caseListType])
133	finally:
134		popWorkingDir()
135
136def genAndCopyCaseList (buildCfg, generator, module, dstDir, caseListType):
137	caseListFile	= getCaseListFileName(module, caseListType)
138	srcPath			= getCaseListPath(buildCfg, module, caseListType)
139	dstPath			= os.path.join(dstDir, caseListFile)
140
141	if os.path.exists(srcPath):
142		os.remove(srcPath)
143
144	genCaseList(buildCfg, generator, module, caseListType)
145
146	if not os.path.exists(srcPath):
147		raise Exception("%s not generated" % srcPath)
148
149	shutil.copyfile(srcPath, dstPath)
150