Home | History | Annotate | Download | only in common
      1 #ifndef _TCUTESTEXECUTOR_HPP
      2 #define _TCUTESTEXECUTOR_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 "deDefs.h"
     27 #include "tcuTestContext.hpp"
     28 #include "tcuTestCase.hpp"
     29 #include "tcuTestPackage.hpp"
     30 #include "qpXmlWriter.h"
     31 
     32 #include <vector>
     33 
     34 namespace tcu
     35 {
     36 
     37 class CommandLine;
     38 
     39 //! Test run summary.
     40 class TestRunResult
     41 {
     42 public:
     43 	TestRunResult (void) { clear(); }
     44 
     45 	void clear (void)
     46 	{
     47 		numExecuted		= 0;
     48 		numPassed		= 0;
     49 		numFailed		= 0;
     50 		numNotSupported	= 0;
     51 		numWarnings		= 0;
     52 		isComplete		= false;
     53 	}
     54 
     55 	int		numExecuted;		//!< Total number of cases executed.
     56 	int		numPassed;			//!< Number of cases passed.
     57 	int		numFailed;			//!< Number of cases failed.
     58 	int		numNotSupported;	//!< Number of cases not supported.
     59 	int		numWarnings;		//!< Number of QualityWarning / CompatibilityWarning results.
     60 	bool	isComplete;			//!< Is run complete.
     61 };
     62 
     63 /*--------------------------------------------------------------------*//*!
     64  * \brief Test executor
     65  *
     66  * Test executor traverses TestNode hierarchy and executes the cases
     67  * included in current test case set. If no test case set is provided
     68  * all test cases in hierarchy are executed.
     69  *//*--------------------------------------------------------------------*/
     70 class TestExecutor
     71 {
     72 public:
     73 							TestExecutor		(TestContext& testCtx, const CommandLine& cmdLine);
     74 							~TestExecutor		(void);
     75 
     76 	bool					iterate				(void);
     77 
     78 	const TestRunResult&	getResult			(void) const { return m_result;			}
     79 
     80 	bool					isInTestCase		(void) const { return m_isInTestCase;	}
     81 
     82 private:
     83 	struct NodeIter
     84 	{
     85 		enum State
     86 		{
     87 			STATE_BEGIN = 0,
     88 			STATE_TRAVERSE_CHILDREN,
     89 			STATE_EXECUTE_TEST,
     90 			STATE_FINISH,
     91 
     92 			STATE_LAST
     93 		};
     94 
     95 		NodeIter (void)
     96 			: node			(DE_NULL)
     97 			, curChildNdx	(-1)
     98 			, m_state		(STATE_LAST)
     99 		{
    100 		}
    101 
    102 		NodeIter (TestNode* node_)
    103 			: node			(node_)
    104 			, curChildNdx	(-1)
    105 			, m_state		(STATE_BEGIN)
    106 		{
    107 		}
    108 
    109 		State getState (void) const
    110 		{
    111 			return m_state;
    112 		}
    113 
    114 		void setState (State newState)
    115 		{
    116 			switch (newState)
    117 			{
    118 				case STATE_TRAVERSE_CHILDREN:
    119 					node->getChildren(children);
    120 					curChildNdx = -1;
    121 					break;
    122 
    123 				default:
    124 					// nada
    125 					break;
    126 			}
    127 
    128 			m_state = newState;
    129 		}
    130 
    131 		TestNode*				node;
    132 		std::vector<TestNode*>	children;
    133 		int						curChildNdx;
    134 
    135 	private:
    136 		State					m_state;
    137 	};
    138 
    139 							TestExecutor		(const TestExecutor&);		// not allowed!
    140 	TestExecutor&			operator=			(const TestExecutor&);		// not allowed!
    141 
    142 	bool					matchFolderName		(const char* folderName) const;
    143 	bool					matchCaseName		(const char* caseName) const;
    144 
    145 	void					enterTestPackage	(TestPackage* testPackage, const char* packageName);
    146 	void					leaveTestPackage	(TestPackage* testPackage);
    147 
    148 	void					enterGroupNode		(TestCaseGroup* testGroup, const char* casePath);
    149 	void					leaveGroupNode		(TestCaseGroup* testGroup);
    150 
    151 	bool					enterTestCase		(TestCase* testCase, const char* casePath);
    152 	void					leaveTestCase		(TestCase* testCase);
    153 
    154 	// Member variables.
    155 	TestContext&			m_testCtx;
    156 	const CommandLine&		m_cmdLine;
    157 	TestPackageRoot*		m_rootNode;
    158 
    159 	TestCaseWrapper*		m_testCaseWrapper;
    160 
    161 	FILE*					m_testCaseListFile;
    162 	qpXmlWriter*			m_testCaseListWriter;
    163 
    164 	// Current session state.
    165 	std::vector<NodeIter>	m_sessionStack;
    166 	bool					m_abortSession;
    167 	bool					m_isInTestCase;
    168 
    169 	TestRunResult			m_result;
    170 };
    171 
    172 } // tcu
    173 
    174 #endif // _TCUTESTEXECUTOR_HPP
    175