13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#ifndef _TCUTESTCASE_HPP
23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define _TCUTESTCASE_HPP
33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*-------------------------------------------------------------------------
43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program Tester Core
53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ----------------------------------------
63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project
83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License");
103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License.
113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at
123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *      http://www.apache.org/licenses/LICENSE-2.0
143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software
163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS,
173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and
193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License.
203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*!
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Base class for a test case.
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuDefs.hpp"
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "tcuTestContext.hpp"
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <string>
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <vector>
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace tcu
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum TestNodeType
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	NODETYPE_ROOT = 0,		//!< Root for all test packages.
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	NODETYPE_PACKAGE,		//!< Test case package -- same as group, but is omitted from XML dump.
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	NODETYPE_GROUP,			//!< Test case container -- cannot be executed.
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	NODETYPE_SELF_VALIDATE,	//!< Self-validating test case -- can be executed
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	NODETYPE_PERFORMANCE,	//!< Performace test case -- can be executed
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	NODETYPE_CAPABILITY,	//!< Capability score case -- can be executed
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	NODETYPE_ACCURACY		//!< Accuracy test case -- can be executed
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
46ee2e92c10d529b2be9ef1279655f9b65a3f1a407Jarkko Pöyryenum TestNodeClass
47ee2e92c10d529b2be9ef1279655f9b65a3f1a407Jarkko Pöyry{
48ee2e92c10d529b2be9ef1279655f9b65a3f1a407Jarkko Pöyry	NODECLASS_GROUP = 0,	//!< Root or non-leaf in the test hierarchy tree
49ee2e92c10d529b2be9ef1279655f9b65a3f1a407Jarkko Pöyry	NODECLASS_EXECUTABLE,	//!< Non-root leaf in the test hierarchy tree
50ee2e92c10d529b2be9ef1279655f9b65a3f1a407Jarkko Pöyry
51ee2e92c10d529b2be9ef1279655f9b65a3f1a407Jarkko Pöyry	NODECLASS_LAST
52ee2e92c10d529b2be9ef1279655f9b65a3f1a407Jarkko Pöyry};
53ee2e92c10d529b2be9ef1279655f9b65a3f1a407Jarkko Pöyry
54ee2e92c10d529b2be9ef1279655f9b65a3f1a407Jarkko Pöyryinline TestNodeClass getTestNodeTypeClass (TestNodeType type)
55ee2e92c10d529b2be9ef1279655f9b65a3f1a407Jarkko Pöyry{
56ee2e92c10d529b2be9ef1279655f9b65a3f1a407Jarkko Pöyry	switch (type)
57ee2e92c10d529b2be9ef1279655f9b65a3f1a407Jarkko Pöyry	{
58ee2e92c10d529b2be9ef1279655f9b65a3f1a407Jarkko Pöyry		case NODETYPE_ROOT:				return NODECLASS_GROUP;
59ee2e92c10d529b2be9ef1279655f9b65a3f1a407Jarkko Pöyry		case NODETYPE_PACKAGE:			return NODECLASS_GROUP;
60ee2e92c10d529b2be9ef1279655f9b65a3f1a407Jarkko Pöyry		case NODETYPE_GROUP:			return NODECLASS_GROUP;
61ee2e92c10d529b2be9ef1279655f9b65a3f1a407Jarkko Pöyry		case NODETYPE_SELF_VALIDATE:	return NODECLASS_EXECUTABLE;
62ee2e92c10d529b2be9ef1279655f9b65a3f1a407Jarkko Pöyry		case NODETYPE_PERFORMANCE:		return NODECLASS_EXECUTABLE;
63ee2e92c10d529b2be9ef1279655f9b65a3f1a407Jarkko Pöyry		case NODETYPE_CAPABILITY:		return NODECLASS_EXECUTABLE;
64ee2e92c10d529b2be9ef1279655f9b65a3f1a407Jarkko Pöyry		case NODETYPE_ACCURACY:			return NODECLASS_EXECUTABLE;
65ee2e92c10d529b2be9ef1279655f9b65a3f1a407Jarkko Pöyry		default:
66ee2e92c10d529b2be9ef1279655f9b65a3f1a407Jarkko Pöyry			DE_ASSERT(false);
67ee2e92c10d529b2be9ef1279655f9b65a3f1a407Jarkko Pöyry			return NODECLASS_LAST;
68ee2e92c10d529b2be9ef1279655f9b65a3f1a407Jarkko Pöyry	}
69ee2e92c10d529b2be9ef1279655f9b65a3f1a407Jarkko Pöyry}
70ee2e92c10d529b2be9ef1279655f9b65a3f1a407Jarkko Pöyry
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline bool isTestNodeTypeExecutable (TestNodeType type)
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
73ee2e92c10d529b2be9ef1279655f9b65a3f1a407Jarkko Pöyry	return getTestNodeTypeClass(type) == NODECLASS_EXECUTABLE;
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
76ee2e173d445e87e1f98245f4377f66b081cc320dPyry Haulosinline bool isValidTestCaseNameChar (char c)
77ee2e173d445e87e1f98245f4377f66b081cc320dPyry Haulos{
78ee2e173d445e87e1f98245f4377f66b081cc320dPyry Haulos	return de::inRange(c, 'a', 'z') ||
79ee2e173d445e87e1f98245f4377f66b081cc320dPyry Haulos		   de::inRange(c, 'A', 'Z') ||
80ee2e173d445e87e1f98245f4377f66b081cc320dPyry Haulos		   de::inRange(c, '0', '9') ||
81ee2e173d445e87e1f98245f4377f66b081cc320dPyry Haulos		   c == '_' || c == '-';
82ee2e173d445e87e1f98245f4377f66b081cc320dPyry Haulos}
83ee2e173d445e87e1f98245f4377f66b081cc320dPyry Haulos
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*!
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Test case hierarchy node
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Test node forms the backbone of the test case hierarchy. All objects
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * in the hierarchy are derived from this class.
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Each test node has a type and all except the root node have name and
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * description. Root and test group nodes have a list of children.
923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * During test execution TestExecutor iterates the hierarchy. Upon entering
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * the node (both groups and test cases) init() is called. When exiting the
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * node deinit() is called respectively.
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass TestNode
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	enum IterateResult
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	{
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		STOP		= 0,
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry		CONTINUE	= 1
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	};
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	// Methods.
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							TestNode		(TestContext& testCtx, TestNodeType nodeType, const char* name, const char* description);
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							TestNode		(TestContext& testCtx, TestNodeType nodeType, const char* name, const char* description, const std::vector<TestNode*>& children);
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual					~TestNode		(void);
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TestNodeType			getNodeType		(void) const	{ return m_nodeType;			}
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TestContext&			getTestContext	(void) const	{ return m_testCtx;				}
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const char*				getName			(void) const	{ return m_name.c_str();		}
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const char*				getDescription	(void) const	{ return m_description.c_str(); }
115ee2e92c10d529b2be9ef1279655f9b65a3f1a407Jarkko Pöyry	void					getChildren		(std::vector<TestNode*>& children);
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void					addChild		(TestNode* node);
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual void			init			(void);
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual void			deinit			(void);
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual IterateResult	iterate			(void) = 0;
1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprotected:
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	TestContext&			m_testCtx;
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::string				m_name;
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::string				m_description;
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
128ee2e92c10d529b2be9ef1279655f9b65a3f1a407Jarkko Pöyry	const TestNodeType		m_nodeType;
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<TestNode*>	m_children;
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*!
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Test case group node
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Test case group implementations must inherit this class. To save resources
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * during test execution the group must delay creation of any child groups
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * until init() is called.
1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Default deinit() for test group will destroy all child nodes.
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass TestCaseGroup : public TestNode
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							TestCaseGroup	(TestContext& testCtx, const char* name, const char* description);
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							TestCaseGroup	(TestContext& testCtx, const char* name, const char* description, const std::vector<TestNode*>& children);
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual					~TestCaseGroup	(void);
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual IterateResult	iterate			(void);
1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*!
1523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Test case class
1533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
1543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Test case implementations must inherit this class.
1553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
1563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Test case objects are usually constructed when TestExecutor enters parent
1573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * group. Allocating any non-parameter resources, especially target API objects
1583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * must be delayed to init().
1593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
1603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Upon entering the test case TestExecutor calls init(). If initialization
1613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * is successful (no exception is thrown) the executor will then call iterate()
1623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * until test case returns STOP. After that deinit() will be called.
1633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
1643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Before exiting the execution phase (i.e. at returning STOP from iterate())
1653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * the test case must set valid status code to test context (m_testCtx).
1663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
1673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Test case can also signal error condition by throwing an exception. In
1683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * that case the framework will set result code and details based on the
1693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * exception.
1703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
1713c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass TestCase : public TestNode
1723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1733c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
1743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					TestCase			(TestContext& testCtx, const char* name, const char* description);
1753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry					TestCase			(TestContext& testCtx, TestNodeType nodeType, const char* name, const char* description);
1763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	virtual			~TestCase			(void);
1773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1794e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulosclass TestStatus
1804e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos{
1814e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulospublic:
1824e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos						TestStatus		(qpTestResult code, const std::string& description) : m_code(code), m_description(description) {}
1834e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos
1848d98e2a4e7bb97a550d8f6ebcf3f1e227d854eb8Pyry Haulos	bool				isComplete		(void) const { return m_code != QP_TEST_RESULT_LAST;			}
1854e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos	qpTestResult		getCode			(void) const { DE_ASSERT(isComplete()); return m_code;			}
1864e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos	const std::string&	getDescription	(void) const { DE_ASSERT(isComplete()); return m_description;	}
1874e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos
1884e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos	static TestStatus	pass			(const std::string& description)	{ return TestStatus(QP_TEST_RESULT_PASS,	description);	}
1894e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos	static TestStatus	fail			(const std::string& description)	{ return TestStatus(QP_TEST_RESULT_FAIL,	description);	}
1904e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos	static TestStatus	incomplete		(void)								{ return TestStatus(QP_TEST_RESULT_LAST,	"");			}
1914e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos
1924e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulosprivate:
1934e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos	qpTestResult		m_code;
1944e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos	std::string			m_description;
1954e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos} DE_WARN_UNUSED_TYPE;
1964e3ea87b79b12195e79d28ef6ab2be0a847b5d9aPyry Haulos
1973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // tcu
1983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#endif // _TCUTESTCASE_HPP
200