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