Home | History | Annotate | Download | only in common
      1 #ifndef _TCUTESTCONTEXT_HPP
      2 #define _TCUTESTCONTEXT_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 Context shared between test cases.
     24  *//*--------------------------------------------------------------------*/
     25 
     26 #include "tcuDefs.hpp"
     27 #include "qpWatchDog.h"
     28 #include "qpTestLog.h"
     29 
     30 #include <string>
     31 
     32 namespace tcu
     33 {
     34 
     35 class Archive;
     36 class Platform;
     37 class CommandLine;
     38 class TestLog;
     39 
     40 /*--------------------------------------------------------------------*//*!
     41  * \brief Test context
     42  *
     43  * Test context holds common resources that are available to test cases.
     44  * This includes test log and resource archive.
     45  *
     46  * Test case can write to test log and must set test result to test context.
     47  *//*--------------------------------------------------------------------*/
     48 class TestContext
     49 {
     50 public:
     51 							TestContext			(Platform& platform, Archive& rootArchive, TestLog& log, const CommandLine& cmdLine, qpWatchDog* watchDog);
     52 							~TestContext		(void) {}
     53 
     54 	// API for test cases
     55 	TestLog&				getLog				(void)			{ return m_log;			}
     56 	Archive&				getArchive			(void)			{ return *m_curArchive;	} //!< \note Do not access in TestNode constructors.
     57 	Platform&				getPlatform			(void)			{ return m_platform;	}
     58 	void					setTestResult		(qpTestResult result, const char* description);
     59 	void					touchWatchdog		(void);
     60 	const CommandLine&		getCommandLine		(void) const	{ return m_cmdLine;		}
     61 
     62 	// API for test framework
     63 	qpTestResult			getTestResult		(void) const	{ return m_testResult;				}
     64 	const char*				getTestResultDesc	(void) const	{ return m_testResultDesc.c_str();	}
     65 	qpWatchDog*				getWatchDog			(void)			{ return m_watchDog;				}
     66 
     67 	Archive&				getRootArchive		(void) const		{ return m_rootArchive;		}
     68 	void					setCurrentArchive	(Archive& archive)	{ m_curArchive = &archive;	}
     69 
     70 	void					setTerminateAfter	(bool terminate)	{ m_terminateAfter = terminate;	}
     71 	bool					getTerminateAfter	(void) const		{ return m_terminateAfter; 		}
     72 protected:
     73 	Platform&				m_platform;			//!< Platform port implementation.
     74 	Archive&				m_rootArchive;		//!< Root archive.
     75 	TestLog&				m_log;				//!< Test log.
     76 	const CommandLine&		m_cmdLine;			//!< Command line.
     77 	qpWatchDog*				m_watchDog;			//!< Watchdog (can be null).
     78 
     79 	Archive*				m_curArchive;		//!< Current archive for test cases.
     80 	qpTestResult			m_testResult;		//!< Latest test result.
     81 	std::string				m_testResultDesc;	//!< Latest test result description.
     82 	bool					m_terminateAfter;	//!< Should tester terminate after execution of the current test
     83 };
     84 
     85 /*--------------------------------------------------------------------*//*!
     86  * \brief Test result collector
     87  *
     88  * This utility class collects test results with associated messages,
     89  * optionally logs them, and finally sets the test result of a TestContext to
     90  * the most severe collected result. This allows multiple problems to be
     91  * easily reported from a single test run.
     92  *//*--------------------------------------------------------------------*/
     93 class ResultCollector
     94 {
     95 public:
     96 					ResultCollector			(void);
     97 					ResultCollector			(TestLog& log, const std::string& prefix = "");
     98 
     99 	qpTestResult	getResult				(void) const  { return m_result; }
    100 
    101 	void			fail					(const std::string& msg);
    102 	bool			check					(bool condition, const std::string& msg);
    103 
    104 	void			addResult				(qpTestResult result, const std::string& msg);
    105 	bool			checkResult				(bool condition, qpTestResult result, const std::string& msg);
    106 
    107 	void			setTestContextResult	(TestContext& testCtx);
    108 
    109 private:
    110 	TestLog*		m_log;
    111 	std::string		m_prefix;
    112 	qpTestResult	m_result;
    113 	std::string		m_message;
    114 };
    115 
    116 } // tcu
    117 
    118 #endif // _TCUTESTCONTEXT_HPP
    119