1 #ifndef _TCUTESTCASE_HPP
2 #define _TCUTESTCASE_HPP
3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program Tester Core
5 * ----------------------------------------
7 * Copyright 2014 The Android Open Source Project
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 * \brief Base class for a test case.
24 *//*--------------------------------------------------------------------*/
26 #include "tcuDefs.hpp"
27 #include "tcuTestContext.hpp"
37 NODETYPE_ROOT = 0, //!< Root for all test packages.
38 NODETYPE_PACKAGE, //!< Test case package -- same as group, but is omitted from XML dump.
39 NODETYPE_GROUP, //!< Test case container -- cannot be executed.
40 NODETYPE_SELF_VALIDATE, //!< Self-validating test case -- can be executed
41 NODETYPE_PERFORMANCE, //!< Performace test case -- can be executed
42 NODETYPE_CAPABILITY, //!< Capability score case -- can be executed
43 NODETYPE_ACCURACY //!< Accuracy test case -- can be executed
48 NODECLASS_GROUP = 0, //!< Root or non-leaf in the test hierarchy tree
49 NODECLASS_EXECUTABLE, //!< Non-root leaf in the test hierarchy tree
57 RUNNERTYPE_NONE = (1u << 0),
58 RUNNERTYPE_AMBER = (1u << 1)
61 inline TestNodeClass getTestNodeTypeClass (TestNodeType type)
65 case NODETYPE_ROOT: return NODECLASS_GROUP;
66 case NODETYPE_PACKAGE: return NODECLASS_GROUP;
67 case NODETYPE_GROUP: return NODECLASS_GROUP;
68 case NODETYPE_SELF_VALIDATE: return NODECLASS_EXECUTABLE;
69 case NODETYPE_PERFORMANCE: return NODECLASS_EXECUTABLE;
70 case NODETYPE_CAPABILITY: return NODECLASS_EXECUTABLE;
71 case NODETYPE_ACCURACY: return NODECLASS_EXECUTABLE;
74 return NODECLASS_LAST;
78 inline bool isTestNodeTypeExecutable (TestNodeType type)
80 return getTestNodeTypeClass(type) == NODECLASS_EXECUTABLE;
83 inline bool isValidTestCaseNameChar (char c)
85 return de::inRange(c, 'a', 'z') ||
86 de::inRange(c, 'A', 'Z') ||
87 de::inRange(c, '0', '9') ||
91 /*--------------------------------------------------------------------*//*!
92 * \brief Test case hierarchy node
94 * Test node forms the backbone of the test case hierarchy. All objects
95 * in the hierarchy are derived from this class.
97 * Each test node has a type and all except the root node have name and
98 * description. Root and test group nodes have a list of children.
100 * During test execution TestExecutor iterates the hierarchy. Upon entering
101 * the node (both groups and test cases) init() is called. When exiting the
102 * node deinit() is called respectively.
103 *//*--------------------------------------------------------------------*/
114 TestNode (TestContext& testCtx, TestNodeType nodeType, const char* name, const char* description);
115 TestNode (TestContext& testCtx, TestNodeType nodeType, const char* name, const char* description, const std::vector<TestNode*>& children);
116 virtual ~TestNode (void);
118 TestNodeType getNodeType (void) const { return m_nodeType; }
119 TestContext& getTestContext (void) const { return m_testCtx; }
120 const char* getName (void) const { return m_name.c_str(); }
121 const char* getDescription (void) const { return m_description.c_str(); }
122 void getChildren (std::vector<TestNode*>& children) const;
123 void addChild (TestNode* node);
124 bool empty () const { return m_children.empty(); }
126 virtual void init (void);
127 virtual void deinit (void);
128 virtual IterateResult iterate (void) = 0;
129 virtual TestRunnerType getRunnerType (void) const { return RUNNERTYPE_NONE; }
130 virtual bool validateRequirements () { return true; }
132 TestContext& m_testCtx;
134 std::string m_description;
137 const TestNodeType m_nodeType;
138 std::vector<TestNode*> m_children;
141 /*--------------------------------------------------------------------*//*!
142 * \brief Test case group node
144 * Test case group implementations must inherit this class. To save resources
145 * during test execution the group must delay creation of any child groups
146 * until init() is called.
148 * Default deinit() for test group will destroy all child nodes.
149 *//*--------------------------------------------------------------------*/
150 class TestCaseGroup : public TestNode
153 TestCaseGroup (TestContext& testCtx, const char* name, const char* description);
154 TestCaseGroup (TestContext& testCtx, const char* name, const char* description, const std::vector<TestNode*>& children);
155 virtual ~TestCaseGroup (void);
157 virtual IterateResult iterate (void);
160 /*--------------------------------------------------------------------*//*!
161 * \brief Test case class
163 * Test case implementations must inherit this class.
165 * Test case objects are usually constructed when TestExecutor enters parent
166 * group. Allocating any non-parameter resources, especially target API objects
167 * must be delayed to init().
169 * Upon entering the test case TestExecutor calls init(). If initialization
170 * is successful (no exception is thrown) the executor will then call iterate()
171 * until test case returns STOP. After that deinit() will be called.
173 * Before exiting the execution phase (i.e. at returning STOP from iterate())
174 * the test case must set valid status code to test context (m_testCtx).
176 * Test case can also signal error condition by throwing an exception. In
177 * that case the framework will set result code and details based on the
179 *//*--------------------------------------------------------------------*/
180 class TestCase : public TestNode
183 TestCase (TestContext& testCtx, const char* name, const char* description);
184 TestCase (TestContext& testCtx, TestNodeType nodeType, const char* name, const char* description);
185 virtual ~TestCase (void);
191 TestStatus (qpTestResult code, const std::string& description) : m_code(code), m_description(description) {}
193 bool isComplete (void) const { return m_code != QP_TEST_RESULT_LAST; }
194 qpTestResult getCode (void) const { DE_ASSERT(isComplete()); return m_code; }
195 const std::string& getDescription (void) const { DE_ASSERT(isComplete()); return m_description; }
197 static TestStatus pass (const std::string& description) { return TestStatus(QP_TEST_RESULT_PASS, description); }
198 static TestStatus fail (const std::string& description) { return TestStatus(QP_TEST_RESULT_FAIL, description); }
199 static TestStatus incomplete (void) { return TestStatus(QP_TEST_RESULT_LAST, ""); }
203 std::string m_description;
204 } DE_WARN_UNUSED_TYPE;
208 #endif // _TCUTESTCASE_HPP