1 #ifndef _TCUDEFS_HPP 2 #define _TCUDEFS_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 Basic definitions. 24 *//*--------------------------------------------------------------------*/ 25 26 #include "deDefs.hpp" 27 #include "qpTestLog.h" 28 29 #include <string> 30 #include <stdexcept> 31 32 /*--------------------------------------------------------------------*//*! 33 * \brief dEQP Common Test Framework 34 * 35 * Code in this namespace doesn't require support for any specific client 36 * APIs. 37 *//*--------------------------------------------------------------------*/ 38 namespace tcu 39 { 40 41 //! Kill program. Called when a fatal error occurs. 42 void die(const char *format, ...) DE_PRINTF_FUNC_ATTR(1, 2); 43 44 //! Print to debug console. 45 void print(const char *format, ...) DE_PRINTF_FUNC_ATTR(1, 2); 46 47 //! Print nonfatal error. 48 void printError(const char *format, ...) DE_PRINTF_FUNC_ATTR(1, 2); 49 50 //! Base exception class for dEQP test framework. 51 class Exception : public std::runtime_error 52 { 53 public: 54 Exception(const char *message, const char *expr, const char *file, int line); 55 Exception(const std::string &message); ~Exception(void)56 virtual ~Exception(void) throw() 57 { 58 } 59 getMessage(void) const60 const char *getMessage(void) const 61 { 62 return m_message.what(); 63 } 64 65 private: 66 // std::runtime_error is used here as an immutable ref-counted string. 67 // This allows the copy constructor in the class to be noexcept. 68 const std::runtime_error m_message; 69 }; 70 71 //! Base exception class for test exceptions that affect test result 72 class TestException : public Exception 73 { 74 public: 75 TestException(const char *message, const char *expr, const char *file, int line, qpTestResult result); 76 TestException(const std::string &message, qpTestResult result); ~TestException(void)77 virtual ~TestException(void) throw() 78 { 79 } 80 getTestResult(void) const81 qpTestResult getTestResult(void) const 82 { 83 return m_result; 84 } isFatal(void) const85 virtual bool isFatal(void) const 86 { 87 return false; 88 } 89 90 private: 91 const qpTestResult m_result; 92 }; 93 94 //! Exception for test errors. 95 class TestError : public TestException 96 { 97 public: 98 TestError(const char *message, const char *expr, const char *file, int line, qpTestResult result); 99 TestError(const char *message, const char *expr, const char *file, int line); 100 TestError(const std::string &message, const char *expr, const char *file, int line); 101 TestError(const std::string &message); ~TestError(void)102 virtual ~TestError(void) throw() 103 { 104 } 105 }; 106 107 //! Exception for internal errors. 108 class InternalError : public TestException 109 { 110 public: 111 InternalError(const char *message, const char *expr, const char *file, int line); 112 InternalError(const std::string &message, const char *expr, const char *file, int line); 113 InternalError(const std::string &message); ~InternalError(void)114 virtual ~InternalError(void) throw() 115 { 116 } 117 }; 118 119 //! Resource error. Tester will terminate if thrown out of test case. 120 class ResourceError : public TestException 121 { 122 public: 123 ResourceError(const char *message, const char *expr, const char *file, int line); 124 ResourceError(const std::string &message); ~ResourceError(void)125 virtual ~ResourceError(void) throw() 126 { 127 } 128 isFatal(void) const129 virtual bool isFatal(void) const 130 { 131 return true; 132 } 133 }; 134 135 //! Not supported error. 136 class NotSupportedError : public TestException 137 { 138 public: 139 NotSupportedError(const char *message, const char *expr, const char *file, int line); 140 NotSupportedError(const std::string &message, const char *expr, const char *file, int line); 141 NotSupportedError(const std::string &message); ~NotSupportedError(void)142 virtual ~NotSupportedError(void) throw() 143 { 144 } 145 }; 146 147 //! Quality warning. 148 class QualityWarning : public TestException 149 { 150 public: 151 QualityWarning(const char *message, const char *expr, const char *file, int line); 152 QualityWarning(const std::string &message, const char *expr, const char *file, int line); 153 QualityWarning(const std::string &message); ~QualityWarning(void)154 virtual ~QualityWarning(void) throw() 155 { 156 } 157 }; 158 159 } // namespace tcu 160 161 #define TCU_THROW_EXPR(ERRCLASS, MSG, EXPR) throw tcu::ERRCLASS(MSG, EXPR, __FILE__, __LINE__) 162 163 #define TCU_THROW(ERRCLASS, MSG) TCU_THROW_EXPR(ERRCLASS, MSG, DE_NULL) 164 165 #define TCU_CHECK_AND_THROW(ERRCLASS, X, MSG) \ 166 do \ 167 { \ 168 if (!(!false && (X))) \ 169 TCU_THROW_EXPR(ERRCLASS, MSG, #X); \ 170 } while (false) 171 172 //! Throw TestError. 173 #define TCU_FAIL(MSG) TCU_THROW(TestError, MSG) 174 175 //! Throw TestError if condition X is not satisfied. 176 #define TCU_CHECK(X) \ 177 do \ 178 { \ 179 if (!(!false && (X))) \ 180 throw tcu::TestError(DE_NULL, #X, __FILE__, __LINE__); \ 181 } while (false) 182 183 //! Throw TestError if condition X is not satisfied. 184 #define TCU_CHECK_MSG(X, MSG) \ 185 do \ 186 { \ 187 if (!(!false && (X))) \ 188 throw tcu::TestError((MSG), #X, __FILE__, __LINE__); \ 189 } while (false) 190 191 //! Throw InternalError if condition X is not satisfied 192 #define TCU_CHECK_INTERNAL(X) \ 193 do \ 194 { \ 195 if (!(!false && (X))) \ 196 throw tcu::InternalError(DE_NULL, #X, __FILE__, __LINE__); \ 197 } while (false) 198 199 #endif // _TCUDEFS_HPP 200