• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _TCUCOMMANDLINE_HPP
2 #define _TCUCOMMANDLINE_HPP
3 /*-------------------------------------------------------------------------
4  * drawElements Quality Program Tester Core
5  * ----------------------------------------
6  *
7  * Copyright 2014 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  * \file
23  * \brief Command line parsing.
24  *//*--------------------------------------------------------------------*/
25 
26 #include "tcuDefs.hpp"
27 #include "deCommandLine.hpp"
28 #include "tcuTestCase.hpp"
29 #include "deUniquePtr.hpp"
30 
31 #include <string>
32 #include <vector>
33 #include <istream>
34 
35 namespace tcu
36 {
37 
38 /*--------------------------------------------------------------------*//*!
39  * \brief Run mode tells whether the test program should run the tests or
40  *		  dump out metadata about the tests.
41  *//*--------------------------------------------------------------------*/
42 enum RunMode
43 {
44 	RUNMODE_EXECUTE = 0,			//! Test program executes the tests.
45 	RUNMODE_DUMP_XML_CASELIST,		//! Test program dumps the list of contained test cases in XML format.
46 	RUNMODE_DUMP_TEXT_CASELIST,		//! Test program dumps the list of contained test cases in plain-text format.
47 	RUNMODE_DUMP_STDOUT_CASELIST,	//! Test program dumps the list of contained test cases in plain-text format into stdout.
48 	RUNMODE_VERIFY_AMBER_COHERENCY, //! Test program verifies that amber tests have coherent capability requirements
49 
50 	RUNMODE_LAST
51 };
52 
53 /*--------------------------------------------------------------------*//*!
54  * \brief Should graphical tests show rendering results on screen.
55  *//*--------------------------------------------------------------------*/
56 enum WindowVisibility
57 {
58 	WINDOWVISIBILITY_WINDOWED = 0,
59 	WINDOWVISIBILITY_FULLSCREEN,
60 	WINDOWVISIBILITY_HIDDEN,
61 
62 	WINDOWVISIBILITY_LAST
63 };
64 
65 /*--------------------------------------------------------------------*//*!
66  * \brief The type of rendering surface the tests should be executed on.
67  *//*--------------------------------------------------------------------*/
68 enum SurfaceType
69 {
70 	SURFACETYPE_WINDOW = 0,			//!< Native window.
71 	SURFACETYPE_OFFSCREEN_NATIVE,	//!< Native offscreen surface, such as pixmap.
72 	SURFACETYPE_OFFSCREEN_GENERIC,	//!< Generic offscreen surface, such as pbuffer.
73 	SURFACETYPE_FBO,				//!< Framebuffer object.
74 
75 	SURFACETYPE_LAST
76 };
77 
78 /*--------------------------------------------------------------------*//*!
79  * \brief Screen rotation, always to clockwise direction.
80  *//*--------------------------------------------------------------------*/
81 enum ScreenRotation
82 {
83 	SCREENROTATION_UNSPECIFIED,		//!< Use default / current orientation.
84 	SCREENROTATION_0,				//!< Set rotation to 0 degrees from baseline.
85 	SCREENROTATION_90,
86 	SCREENROTATION_180,
87 	SCREENROTATION_270,
88 
89 	SCREENROTATION_LAST
90 };
91 
92 class CaseTreeNode;
93 class CasePaths;
94 class Archive;
95 
96 // Match a single path component against a pattern component that may contain *-wildcards.
97 bool matchWildcards(std::string::const_iterator		patternStart,
98 					std::string::const_iterator		patternEnd,
99 					std::string::const_iterator		pathStart,
100 					std::string::const_iterator		pathEnd,
101 					bool							allowPrefix);
102 
103 class CaseListFilter
104 {
105 public:
106 									CaseListFilter				(const de::cmdline::CommandLine& cmdLine, const tcu::Archive& archive);
107 									CaseListFilter				(void);
108 									~CaseListFilter				(void);
109 
110 	//! Check if test group is in supplied test case list.
111 	bool							checkTestGroupName			(const char* groupName) const;
112 
113 	//! Check if test case is in supplied test case list.
114 	bool							checkTestCaseName			(const char* caseName) const;
115 
116 	//! Check if test group passes the case fraction filter.
117 	bool							checkCaseFraction			(int i, const std::string& testCaseName) const;
118 
119 	//! Check if test case runner is of supplied type
checkRunnerType(tcu::TestRunnerType type) const120 	bool							checkRunnerType				(tcu::TestRunnerType type) const { return ((m_runnerType & type) == m_runnerType); }
121 
122 private:
123 	CaseListFilter												(const CaseListFilter&);	// not allowed!
124 	CaseListFilter&					operator=					(const CaseListFilter&);	// not allowed!
125 
126 	CaseTreeNode*					m_caseTree;
127 	de::MovePtr<const CasePaths>	m_casePaths;
128 	std::vector<int>				m_caseFraction;
129 	de::MovePtr<const CasePaths>	m_caseFractionMandatoryTests;
130 	tcu::TestRunnerType				m_runnerType;
131 };
132 
133 /*--------------------------------------------------------------------*//*!
134  * \brief Test command line
135  *
136  * CommandLine handles argument parsing and provides convinience functions
137  * for querying test parameters.
138  *//*--------------------------------------------------------------------*/
139 class CommandLine
140 {
141 public:
142 									CommandLine						(void);
143 									CommandLine						(int argc, const char* const* argv);
144 	explicit						CommandLine						(const std::string& cmdLine);
145 									~CommandLine					(void);
146 
147 	bool							parse							(int argc, const char* const* argv);
148 	bool							parse							(const std::string& cmdLine);
149 
150 	const std::string&				getInitialCmdLine				(void) const;
151 
152 	//! Get log file name (--deqp-log-filename)
153 	const char*						getLogFileName					(void) const;
154 
155 	//! Get logging flags
156 	deUint32						getLogFlags						(void) const;
157 
158 	//! Get run mode (--deqp-runmode)
159 	RunMode							getRunMode						(void) const;
160 
161 	//! Get caselist dump target file pattern (--deqp-caselist-export-file)
162 	const char*						getCaseListExportFile			(void) const;
163 
164 	//! Get default window visibility (--deqp-visibility)
165 	WindowVisibility				getVisibility					(void) const;
166 
167 	//! Get watchdog enable status (--deqp-watchdog)
168 	bool							isWatchDogEnabled				(void) const;
169 
170 	//! Get crash handling enable status (--deqp-crashhandler)
171 	bool							isCrashHandlingEnabled			(void) const;
172 
173 	//! Get base seed for randomization (--deqp-base-seed)
174 	int								getBaseSeed						(void) const;
175 
176 	//! Get test iteration count (--deqp-test-iteration-count)
177 	int								getTestIterationCount			(void) const;
178 
179 	//! Get rendering target width (--deqp-surface-width)
180 	int								getSurfaceWidth					(void) const;
181 
182 	//! Get rendering target height (--deqp-surface-height)
183 	int								getSurfaceHeight				(void) const;
184 
185 	//! Get rendering taget type (--deqp-surface-type)
186 	SurfaceType						getSurfaceType					(void) const;
187 
188 	//! Get screen rotation (--deqp-screen-rotation)
189 	ScreenRotation					getScreenRotation				(void) const;
190 
191 	//! Get GL context factory name (--deqp-gl-context-type)
192 	const char*						getGLContextType				(void) const;
193 
194 	//! Get GL config ID (--deqp-gl-config-id)
195 	int								getGLConfigId					(void) const;
196 
197 	//! Get GL config name (--deqp-gl-config-name)
198 	const char*						getGLConfigName					(void) const;
199 
200 	//! Get GL context flags (--deqp-gl-context-flags)
201 	const char*						getGLContextFlags				(void) const;
202 
203 	//! Get OpenCL platform ID (--deqp-cl-platform-id)
204 	int								getCLPlatformId					(void) const;
205 
206 	//! Get OpenCL device IDs (--deqp-cl-device-ids)
getCLDeviceIds(std::vector<int> & deviceIds) const207 	void							getCLDeviceIds					(std::vector<int>& deviceIds) const	{ deviceIds = getCLDeviceIds(); }
208 	const std::vector<int>&			getCLDeviceIds					(void) const;
209 
210 	//! Get extra OpenCL program build options (--deqp-cl-build-options)
211 	const char*						getCLBuildOptions				(void) const;
212 
213 	//! Get EGL native display factory (--deqp-egl-display-type)
214 	const char*						getEGLDisplayType				(void) const;
215 
216 	//! Get EGL native window factory (--deqp-egl-window-type)
217 	const char*						getEGLWindowType				(void) const;
218 
219 	//! Get EGL native pixmap factory (--deqp-egl-pixmap-type)
220 	const char*						getEGLPixmapType				(void) const;
221 
222 	//! Get Vulkan device ID (--deqp-vk-device-id)
223 	int								getVKDeviceId					(void) const;
224 
225 	//! Get Vulkan device group ID (--deqp-vk-device-group-id)
226 	int								getVKDeviceGroupId				(void) const;
227 
228 	//! Enable development-time test case validation checks
229 	bool							isValidationEnabled				(void) const;
230 
231 	//! Print validation errors to standard error or keep them in the log only.
232 	bool							printValidationErrors			(void) const;
233 
234 	//! Log of decompiled SPIR-V shader source (--deqp-log-decompiled-spirv)
235 	bool							isLogDecompiledSpirvEnabled		(void) const;
236 
237 	//! Should we run tests that exhaust memory (--deqp-test-oom)
238 	bool							isOutOfMemoryTestEnabled		(void) const;
239 
240 	//! Should the shader cache be enabled (--deqp-shadercache)
241 	bool							isShadercacheEnabled			(void) const;
242 
243 	//! Get the filename for shader cache (--deqp-shadercache-filename)
244 	const char*						getShaderCacheFilename			(void) const;
245 
246 	//! Should the shader cache be truncated before run (--deqp-shadercache-truncate)
247 	bool							isShaderCacheTruncateEnabled	(void) const;
248 
249 	//! Get shader optimization recipe (--deqp-optimization-recipe)
250 	int								getOptimizationRecipe		(void) const;
251 
252 	//! Enable optimizing of spir-v (--deqp-optimize-spirv)
253 	bool							isSpirvOptimizationEnabled	(void) const;
254 
255 	//! Enable RenderDoc frame markers (--deqp-renderdoc)
256 	bool							isRenderDocEnabled			(void) const;
257 
258 	//! Get waiver file name (--deqp-waiver-file)
259 	const char*						getWaiverFileName			(void) const;
260 
261 	//! Get case list fraction
262 	const std::vector<int>&			getCaseFraction				(void) const;
263 
264 	//! Get must-list filename
265 	const char*						getCaseFractionMandatoryTests(void) const;
266 
267 	//! Get archive directory path
268 	const char*						getArchiveDir				(void) const;
269 
270 	//! Get runner type (--deqp-runner-type)
271 	tcu::TestRunnerType				getRunnerType				(void) const;
272 
273 	//! Should the run be terminated on first failure (--deqp-terminate-on-fail)
274 	bool							isTerminateOnFailEnabled	(void) const;
275 
276 	/*--------------------------------------------------------------------*//*!
277 	 * \brief Creates case list filter
278 	 * \param archive Resources
279 	 *
280 	 * Creates case list filter based on one of the following parameters:
281 	 *
282 	 * --deqp-case
283 	 * --deqp-caselist
284 	 * --deqp-caselist-file
285 	 * --deqp-caselist-resource
286 	 * --deqp-stdin-caselist
287 	 *
288 	 * Throws std::invalid_argument if parsing fails.
289 	 *//*--------------------------------------------------------------------*/
290 	de::MovePtr<CaseListFilter>		createCaseListFilter		(const tcu::Archive& archive) const;
291 
292 protected:
293 	const de::cmdline::CommandLine&	getCommandLine				(void) const;
294 
295 private:
296 									CommandLine					(const CommandLine&);	// not allowed!
297 	CommandLine&					operator=					(const CommandLine&);	// not allowed!
298 
299 	void							clear						(void);
300 
301 	virtual void					registerExtendedOptions		(de::cmdline::Parser& parser);
302 
303 	de::cmdline::CommandLine		m_cmdLine;
304 	deUint32						m_logFlags;
305 
306 	std::string						m_initialCmdLine;
307 };
308 
309 } // tcu
310 
311 #endif // _TCUCOMMANDLINE_HPP
312