tcuDefs.hpp revision 9296957fdb746e7558a00fec7f9a519f092168d8
13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#ifndef _TCUDEFS_HPP 23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define _TCUDEFS_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 Basic definitions. 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "deDefs.hpp" 279296957fdb746e7558a00fec7f9a519f092168d8Jarkko Pöyry#include "qpTestLog.h" 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <string> 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <stdexcept> 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*! 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief dEQP Common Test Framework 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Code in this namespace doesn't require support for any specific client 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * APIs. 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace tcu 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//! Kill program. Called when a fatal error occurs. 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid die (const char* format, ...) DE_PRINTF_FUNC_ATTR(1, 2); 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//! Print to debug console. 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyryvoid print (const char* format, ...) DE_PRINTF_FUNC_ATTR(1, 2); 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//! Base exception class for dEQP test framework. 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass Exception : public std::runtime_error 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 519296957fdb746e7558a00fec7f9a519f092168d8Jarkko Pöyry Exception (const char* message, const char* expr, const char* file, int line); 529296957fdb746e7558a00fec7f9a519f092168d8Jarkko Pöyry Exception (const std::string& message); 539296957fdb746e7558a00fec7f9a519f092168d8Jarkko Pöyry virtual ~Exception (void) throw() {} 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 559296957fdb746e7558a00fec7f9a519f092168d8Jarkko Pöyry const char* getMessage (void) const { return m_message.c_str(); } 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 589296957fdb746e7558a00fec7f9a519f092168d8Jarkko Pöyry const std::string m_message; 599296957fdb746e7558a00fec7f9a519f092168d8Jarkko Pöyry}; 609296957fdb746e7558a00fec7f9a519f092168d8Jarkko Pöyry 619296957fdb746e7558a00fec7f9a519f092168d8Jarkko Pöyry//! Base exception class for test exceptions that affect test result 629296957fdb746e7558a00fec7f9a519f092168d8Jarkko Pöyryclass TestException : public Exception 639296957fdb746e7558a00fec7f9a519f092168d8Jarkko Pöyry{ 649296957fdb746e7558a00fec7f9a519f092168d8Jarkko Pöyrypublic: 659296957fdb746e7558a00fec7f9a519f092168d8Jarkko Pöyry TestException (const char* message, const char* expr, const char* file, int line, qpTestResult result); 669296957fdb746e7558a00fec7f9a519f092168d8Jarkko Pöyry TestException (const std::string& message, qpTestResult result); 679296957fdb746e7558a00fec7f9a519f092168d8Jarkko Pöyry virtual ~TestException (void) throw() {} 689296957fdb746e7558a00fec7f9a519f092168d8Jarkko Pöyry 699296957fdb746e7558a00fec7f9a519f092168d8Jarkko Pöyry qpTestResult getTestResult (void) const { return m_result; } 709296957fdb746e7558a00fec7f9a519f092168d8Jarkko Pöyry virtual bool isFatal (void) const { return false; } 719296957fdb746e7558a00fec7f9a519f092168d8Jarkko Pöyry 729296957fdb746e7558a00fec7f9a519f092168d8Jarkko Pöyryprivate: 739296957fdb746e7558a00fec7f9a519f092168d8Jarkko Pöyry const qpTestResult m_result; 743c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//! Exception for test errors. 779296957fdb746e7558a00fec7f9a519f092168d8Jarkko Pöyryclass TestError : public TestException 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestError (const char* message, const char* expr, const char* file, int line); 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TestError (const std::string& message); 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual ~TestError (void) throw() {} 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//! Exception for internal errors. 869296957fdb746e7558a00fec7f9a519f092168d8Jarkko Pöyryclass InternalError : public TestException 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry InternalError (const char* message, const char* expr, const char* file, int line); 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry InternalError (const std::string& message); 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual ~InternalError (void) throw() {} 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//! Resource error. Tester will terminate if thrown out of test case. 959296957fdb746e7558a00fec7f9a519f092168d8Jarkko Pöyryclass ResourceError : public TestException 963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ResourceError (const char* message, const char* expr, const char* file, int line); 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ResourceError (const std::string& message); 1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual ~ResourceError (void) throw() {} 1019296957fdb746e7558a00fec7f9a519f092168d8Jarkko Pöyry 1029296957fdb746e7558a00fec7f9a519f092168d8Jarkko Pöyry virtual bool isFatal (void) const { return true; } 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//! Not supported error. 1069296957fdb746e7558a00fec7f9a519f092168d8Jarkko Pöyryclass NotSupportedError : public TestException 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry NotSupportedError (const char* message, const char* expr, const char* file, int line); 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry NotSupportedError (const std::string& message); 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry virtual ~NotSupportedError (void) throw() {} 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // tcu 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define TCU_THROW_EXPR(ERRCLASS, MSG, EXPR) \ 1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry throw tcu::ERRCLASS(MSG, EXPR, __FILE__, __LINE__) 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define TCU_THROW(ERRCLASS, MSG) \ 1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_THROW_EXPR(ERRCLASS, MSG, DE_NULL) 1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define TCU_CHECK_AND_THROW(ERRCLASS, X, MSG) \ 1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry do { \ 1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry if (!(!deGetFalse() && (X))) \ 1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TCU_THROW_EXPR(ERRCLASS, MSG, #X); \ 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry } while(deGetFalse()) 1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//! Throw TestError. 1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define TCU_FAIL(MSG) TCU_THROW(TestError, MSG) 1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//! Throw TestError if condition X is not satisfied. 1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define TCU_CHECK(X) do { if (!(!deGetFalse() && (X))) throw tcu::TestError(DE_NULL, #X, __FILE__, __LINE__); } while(deGetFalse()) 1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//! Throw TestError if condition X is not satisfied. 1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define TCU_CHECK_MSG(X, MSG) do { if (!(!deGetFalse() && (X))) throw tcu::TestError((MSG), #X, __FILE__, __LINE__); } while(deGetFalse()) 1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry//! Throw InternalError if condition X is not satisfied 1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define TCU_CHECK_INTERNAL(X) do { if (!(!deGetFalse() && (X))) throw tcu::InternalError(DE_NULL, #X, __FILE__, __LINE__); } while(deGetFalse()) 1393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#endif // _TCUDEFS_HPP 141