tcuTestCase.hpp revision 3c827367444ee418f129b2c238299f49d3264554
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 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyryinline bool isTestNodeTypeExecutable (TestNodeType type) 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry return type == NODETYPE_SELF_VALIDATE || 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry type == NODETYPE_PERFORMANCE || 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry type == NODETYPE_CAPABILITY || 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry type == NODETYPE_ACCURACY; 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*! 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Test case hierarchy node 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Test node forms the backbone of the test case hierarchy. All objects 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * in the hierarchy are derived from this class. 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Each test node has a type and all except the root node have name and 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * description. Root and test group nodes have a list of children. 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * During test execution TestExecutor iterates the hierarchy. Upon entering 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * the node (both groups and test cases) init() is called. When exiting the 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * node deinit() is called respectively. 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass TestNode 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry enum IterateResult 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry STOP = 0, 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry CONTINUE = 1 743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // Methods. 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestNode (TestContext& testCtx, TestNodeType nodeType, const char* name, const char* description); 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestNode (TestContext& testCtx, TestNodeType nodeType, const char* name, const char* description, const std::vector<TestNode*>& children); 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual ~TestNode (void); 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestNodeType getNodeType (void) const { return m_nodeType; } 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestContext& getTestContext (void) const { return m_testCtx; } 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* getName (void) const { return m_name.c_str(); } 843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* getDescription (void) const { return m_description.c_str(); } 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void getChildren (std::vector<TestNode*>& children) const; 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void addChild (TestNode* node); 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual void init (void); 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual void deinit (void); 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual IterateResult iterate (void) = 0; 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprotected: 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestContext& m_testCtx; 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestNodeType m_nodeType; 953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::string m_name; 963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::string m_description; 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<TestNode*> m_children; 1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*! 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Test case group node 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Test case group implementations must inherit this class. To save resources 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * during test execution the group must delay creation of any child groups 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * until init() is called. 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Default deinit() for test group will destroy all child nodes. 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass TestCaseGroup : public TestNode 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestCaseGroup (TestContext& testCtx, const char* name, const char* description); 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestCaseGroup (TestContext& testCtx, const char* name, const char* description, const std::vector<TestNode*>& children); 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual ~TestCaseGroup (void); 1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual IterateResult iterate (void); 1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*! 1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Test case class 1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Test case implementations must inherit this class. 1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Test case objects are usually constructed when TestExecutor enters parent 1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * group. Allocating any non-parameter resources, especially target API objects 1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * must be delayed to init(). 1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Upon entering the test case TestExecutor calls init(). If initialization 1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * is successful (no exception is thrown) the executor will then call iterate() 1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * until test case returns STOP. After that deinit() will be called. 1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Before exiting the execution phase (i.e. at returning STOP from iterate()) 1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * the test case must set valid status code to test context (m_testCtx). 1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Test case can also signal error condition by throwing an exception. In 1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * that case the framework will set result code and details based on the 1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * exception. 1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass TestCase : public TestNode 1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestCase (TestContext& testCtx, const char* name, const char* description); 1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestCase (TestContext& testCtx, TestNodeType nodeType, const char* name, const char* description); 1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual ~TestCase (void); 1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // tcu 1503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#endif // _TCUTESTCASE_HPP 152