1#ifndef _TCUTESTPACKAGE_HPP
2#define _TCUTESTPACKAGE_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 Base class for a test case.
24 *//*--------------------------------------------------------------------*/
25
26#include "tcuDefs.hpp"
27#include "tcuTestCase.hpp"
28#include <map>
29
30namespace tcu
31{
32
33//! Test run summary.
34class TestRunStatus
35{
36public:
37	TestRunStatus (void) { clear(); }
38
39	void clear (void)
40	{
41		numExecuted		= 0;
42		numPassed		= 0;
43		numFailed		= 0;
44		numNotSupported	= 0;
45		numWarnings		= 0;
46		numWaived		= 0;
47		isComplete		= false;
48	}
49
50	int		numExecuted;		//!< Total number of cases executed.
51	int		numPassed;			//!< Number of cases passed.
52	int		numFailed;			//!< Number of cases failed.
53	int		numNotSupported;	//!< Number of cases not supported.
54	int		numWarnings;		//!< Number of QualityWarning / CompatibilityWarning results.
55	int		numWaived;			//!< Number of waived tests.
56	bool	isComplete;			//!< Is run complete.
57};
58
59
60/*--------------------------------------------------------------------*//*!
61 * \brief Test case execution interface.
62 *
63 * TestCaseExecutor provides package-specific resources & initialization
64 * for test cases.
65 *
66 * \todo [2015-03-18 pyry] Replace with following API:
67 *
68 * class TestInstance
69 * {
70 * public:
71 *     TestInstance (TestContext& testCtx);
72 *     tcu::TestResult iterate (void);
73 * };
74 *
75 * class TestInstanceFactory (???)
76 * {
77 * public:
78 *     TestInstance* createInstance (const TestCase* testCase, const std::string& path);
79 * };
80 *//*--------------------------------------------------------------------*/
81class TestCaseExecutor
82{
83public:
84	virtual								~TestCaseExecutor	(void) {}
85
86	virtual void						init				(TestCase* testCase, const std::string& path) = 0;
87	virtual void						deinit				(TestCase* testCase) = 0;
88	virtual TestNode::IterateResult		iterate				(TestCase* testCase) = 0;
89	virtual void						deinitTestPackage	(TestContext& testCtx) { DE_UNREF(testCtx); };
90	virtual bool						usesLocalStatus		()	{ return false; }
91	virtual void						updateGlobalStatus	(tcu::TestRunStatus& status) { DE_UNREF(status); }
92	virtual void						reportDurations		(tcu::TestContext& testCtx, const std::string& packageName, const deInt64& duration, const std::map<std::string, deUint64>& groupsDurationTime) { DE_UNREF(testCtx); DE_UNREF(packageName); DE_UNREF(duration); DE_UNREF(groupsDurationTime); }
93};
94
95/*--------------------------------------------------------------------*//*!
96 * \brief Base class for test packages.
97 *
98 * Test packages are root-level test groups. They also provide package-
99 * specific test case executor, see TestCaseExecutor.
100 *//*--------------------------------------------------------------------*/
101class TestPackage : public TestNode
102{
103public:
104									TestPackage			(TestContext& testCtx, const char* name, const char* description);
105	virtual							~TestPackage		(void);
106
107	virtual TestCaseExecutor*		createExecutor		(void) const = 0;
108
109	// Deprecated
110	virtual Archive*				getArchive			(void) { return DE_NULL; }
111
112	virtual IterateResult			iterate				(void);
113
114	void							setCaseListFilter	(const CaseListFilter* caseListFilter);
115protected:
116	const CaseListFilter*			m_caseListFilter;
117};
118
119// TestPackageRegistry
120
121typedef TestPackage* (*TestPackageCreateFunc)	(TestContext& testCtx);
122
123class TestPackageRegistry
124{
125public:
126	struct PackageInfo
127	{
128		PackageInfo (std::string name_, TestPackageCreateFunc createFunc_) : name(name_), createFunc(createFunc_) {}
129
130		std::string				name;
131		TestPackageCreateFunc	createFunc;
132	};
133
134	static TestPackageRegistry*			getSingleton			(void);
135	static void							destroy					(void);
136
137	void								registerPackage			(const char* name, TestPackageCreateFunc createFunc);
138	const std::vector<PackageInfo*>&	getPackageInfos			(void) const;
139	PackageInfo*						getPackageInfoByName	(const char* name) const;
140	TestPackage*						createPackage			(const char* name, TestContext& testCtx) const;
141
142private:
143										TestPackageRegistry		(void);
144										~TestPackageRegistry	(void);
145
146	static TestPackageRegistry*			getOrDestroy			(bool isCreate);
147
148	// Member variables.
149	std::vector<PackageInfo*>			m_packageInfos;
150};
151
152// TestPackageDescriptor
153
154class TestPackageDescriptor
155{
156public:
157						TestPackageDescriptor		(const char* name, TestPackageCreateFunc createFunc);
158						~TestPackageDescriptor		(void);
159};
160
161// TestPackageRoot
162
163class TestPackageRoot : public TestNode
164{
165public:
166							TestPackageRoot		(TestContext& testCtx);
167							TestPackageRoot		(TestContext& testCtx, const std::vector<TestNode*>& children);
168							TestPackageRoot		(TestContext& testCtx, const TestPackageRegistry* packageRegistry);
169	virtual					~TestPackageRoot	(void);
170
171	virtual IterateResult	iterate				(void);
172};
173
174} // tcu
175
176#endif // _TCUTESTPACKAGE_HPP
177