xref: /aosp_15_r20/external/deqp/framework/common/tcuDefs.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1*35238bceSAndroid Build Coastguard Worker #ifndef _TCUDEFS_HPP
2*35238bceSAndroid Build Coastguard Worker #define _TCUDEFS_HPP
3*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
4*35238bceSAndroid Build Coastguard Worker  * drawElements Quality Program Tester Core
5*35238bceSAndroid Build Coastguard Worker  * ----------------------------------------
6*35238bceSAndroid Build Coastguard Worker  *
7*35238bceSAndroid Build Coastguard Worker  * Copyright 2014 The Android Open Source Project
8*35238bceSAndroid Build Coastguard Worker  *
9*35238bceSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
10*35238bceSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
11*35238bceSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
12*35238bceSAndroid Build Coastguard Worker  *
13*35238bceSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
14*35238bceSAndroid Build Coastguard Worker  *
15*35238bceSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
16*35238bceSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
17*35238bceSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18*35238bceSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
19*35238bceSAndroid Build Coastguard Worker  * limitations under the License.
20*35238bceSAndroid Build Coastguard Worker  *
21*35238bceSAndroid Build Coastguard Worker  *//*!
22*35238bceSAndroid Build Coastguard Worker  * \file
23*35238bceSAndroid Build Coastguard Worker  * \brief Basic definitions.
24*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
25*35238bceSAndroid Build Coastguard Worker 
26*35238bceSAndroid Build Coastguard Worker #include "deDefs.hpp"
27*35238bceSAndroid Build Coastguard Worker #include "qpTestLog.h"
28*35238bceSAndroid Build Coastguard Worker 
29*35238bceSAndroid Build Coastguard Worker #include <string>
30*35238bceSAndroid Build Coastguard Worker #include <stdexcept>
31*35238bceSAndroid Build Coastguard Worker 
32*35238bceSAndroid Build Coastguard Worker /*--------------------------------------------------------------------*//*!
33*35238bceSAndroid Build Coastguard Worker  * \brief dEQP Common Test Framework
34*35238bceSAndroid Build Coastguard Worker  *
35*35238bceSAndroid Build Coastguard Worker  * Code in this namespace doesn't require support for any specific client
36*35238bceSAndroid Build Coastguard Worker  * APIs.
37*35238bceSAndroid Build Coastguard Worker  *//*--------------------------------------------------------------------*/
38*35238bceSAndroid Build Coastguard Worker namespace tcu
39*35238bceSAndroid Build Coastguard Worker {
40*35238bceSAndroid Build Coastguard Worker 
41*35238bceSAndroid Build Coastguard Worker //! Kill program. Called when a fatal error occurs.
42*35238bceSAndroid Build Coastguard Worker void die(const char *format, ...) DE_PRINTF_FUNC_ATTR(1, 2);
43*35238bceSAndroid Build Coastguard Worker 
44*35238bceSAndroid Build Coastguard Worker //! Print to debug console.
45*35238bceSAndroid Build Coastguard Worker void print(const char *format, ...) DE_PRINTF_FUNC_ATTR(1, 2);
46*35238bceSAndroid Build Coastguard Worker 
47*35238bceSAndroid Build Coastguard Worker //! Print nonfatal error.
48*35238bceSAndroid Build Coastguard Worker void printError(const char *format, ...) DE_PRINTF_FUNC_ATTR(1, 2);
49*35238bceSAndroid Build Coastguard Worker 
50*35238bceSAndroid Build Coastguard Worker //! Base exception class for dEQP test framework.
51*35238bceSAndroid Build Coastguard Worker class Exception : public std::runtime_error
52*35238bceSAndroid Build Coastguard Worker {
53*35238bceSAndroid Build Coastguard Worker public:
54*35238bceSAndroid Build Coastguard Worker     Exception(const char *message, const char *expr, const char *file, int line);
55*35238bceSAndroid Build Coastguard Worker     Exception(const std::string &message);
~Exception(void)56*35238bceSAndroid Build Coastguard Worker     virtual ~Exception(void) throw()
57*35238bceSAndroid Build Coastguard Worker     {
58*35238bceSAndroid Build Coastguard Worker     }
59*35238bceSAndroid Build Coastguard Worker 
getMessage(void) const60*35238bceSAndroid Build Coastguard Worker     const char *getMessage(void) const
61*35238bceSAndroid Build Coastguard Worker     {
62*35238bceSAndroid Build Coastguard Worker         return m_message.what();
63*35238bceSAndroid Build Coastguard Worker     }
64*35238bceSAndroid Build Coastguard Worker 
65*35238bceSAndroid Build Coastguard Worker private:
66*35238bceSAndroid Build Coastguard Worker     // std::runtime_error is used here as an immutable ref-counted string.
67*35238bceSAndroid Build Coastguard Worker     // This allows the copy constructor in the class to be noexcept.
68*35238bceSAndroid Build Coastguard Worker     const std::runtime_error m_message;
69*35238bceSAndroid Build Coastguard Worker };
70*35238bceSAndroid Build Coastguard Worker 
71*35238bceSAndroid Build Coastguard Worker //! Base exception class for test exceptions that affect test result
72*35238bceSAndroid Build Coastguard Worker class TestException : public Exception
73*35238bceSAndroid Build Coastguard Worker {
74*35238bceSAndroid Build Coastguard Worker public:
75*35238bceSAndroid Build Coastguard Worker     TestException(const char *message, const char *expr, const char *file, int line, qpTestResult result);
76*35238bceSAndroid Build Coastguard Worker     TestException(const std::string &message, qpTestResult result);
~TestException(void)77*35238bceSAndroid Build Coastguard Worker     virtual ~TestException(void) throw()
78*35238bceSAndroid Build Coastguard Worker     {
79*35238bceSAndroid Build Coastguard Worker     }
80*35238bceSAndroid Build Coastguard Worker 
getTestResult(void) const81*35238bceSAndroid Build Coastguard Worker     qpTestResult getTestResult(void) const
82*35238bceSAndroid Build Coastguard Worker     {
83*35238bceSAndroid Build Coastguard Worker         return m_result;
84*35238bceSAndroid Build Coastguard Worker     }
isFatal(void) const85*35238bceSAndroid Build Coastguard Worker     virtual bool isFatal(void) const
86*35238bceSAndroid Build Coastguard Worker     {
87*35238bceSAndroid Build Coastguard Worker         return false;
88*35238bceSAndroid Build Coastguard Worker     }
89*35238bceSAndroid Build Coastguard Worker 
90*35238bceSAndroid Build Coastguard Worker private:
91*35238bceSAndroid Build Coastguard Worker     const qpTestResult m_result;
92*35238bceSAndroid Build Coastguard Worker };
93*35238bceSAndroid Build Coastguard Worker 
94*35238bceSAndroid Build Coastguard Worker //! Exception for test errors.
95*35238bceSAndroid Build Coastguard Worker class TestError : public TestException
96*35238bceSAndroid Build Coastguard Worker {
97*35238bceSAndroid Build Coastguard Worker public:
98*35238bceSAndroid Build Coastguard Worker     TestError(const char *message, const char *expr, const char *file, int line, qpTestResult result);
99*35238bceSAndroid Build Coastguard Worker     TestError(const char *message, const char *expr, const char *file, int line);
100*35238bceSAndroid Build Coastguard Worker     TestError(const std::string &message, const char *expr, const char *file, int line);
101*35238bceSAndroid Build Coastguard Worker     TestError(const std::string &message);
~TestError(void)102*35238bceSAndroid Build Coastguard Worker     virtual ~TestError(void) throw()
103*35238bceSAndroid Build Coastguard Worker     {
104*35238bceSAndroid Build Coastguard Worker     }
105*35238bceSAndroid Build Coastguard Worker };
106*35238bceSAndroid Build Coastguard Worker 
107*35238bceSAndroid Build Coastguard Worker //! Exception for internal errors.
108*35238bceSAndroid Build Coastguard Worker class InternalError : public TestException
109*35238bceSAndroid Build Coastguard Worker {
110*35238bceSAndroid Build Coastguard Worker public:
111*35238bceSAndroid Build Coastguard Worker     InternalError(const char *message, const char *expr, const char *file, int line);
112*35238bceSAndroid Build Coastguard Worker     InternalError(const std::string &message, const char *expr, const char *file, int line);
113*35238bceSAndroid Build Coastguard Worker     InternalError(const std::string &message);
~InternalError(void)114*35238bceSAndroid Build Coastguard Worker     virtual ~InternalError(void) throw()
115*35238bceSAndroid Build Coastguard Worker     {
116*35238bceSAndroid Build Coastguard Worker     }
117*35238bceSAndroid Build Coastguard Worker };
118*35238bceSAndroid Build Coastguard Worker 
119*35238bceSAndroid Build Coastguard Worker //! Resource error. Tester will terminate if thrown out of test case.
120*35238bceSAndroid Build Coastguard Worker class ResourceError : public TestException
121*35238bceSAndroid Build Coastguard Worker {
122*35238bceSAndroid Build Coastguard Worker public:
123*35238bceSAndroid Build Coastguard Worker     ResourceError(const char *message, const char *expr, const char *file, int line);
124*35238bceSAndroid Build Coastguard Worker     ResourceError(const std::string &message);
~ResourceError(void)125*35238bceSAndroid Build Coastguard Worker     virtual ~ResourceError(void) throw()
126*35238bceSAndroid Build Coastguard Worker     {
127*35238bceSAndroid Build Coastguard Worker     }
128*35238bceSAndroid Build Coastguard Worker 
isFatal(void) const129*35238bceSAndroid Build Coastguard Worker     virtual bool isFatal(void) const
130*35238bceSAndroid Build Coastguard Worker     {
131*35238bceSAndroid Build Coastguard Worker         return true;
132*35238bceSAndroid Build Coastguard Worker     }
133*35238bceSAndroid Build Coastguard Worker };
134*35238bceSAndroid Build Coastguard Worker 
135*35238bceSAndroid Build Coastguard Worker //! Not supported error.
136*35238bceSAndroid Build Coastguard Worker class NotSupportedError : public TestException
137*35238bceSAndroid Build Coastguard Worker {
138*35238bceSAndroid Build Coastguard Worker public:
139*35238bceSAndroid Build Coastguard Worker     NotSupportedError(const char *message, const char *expr, const char *file, int line);
140*35238bceSAndroid Build Coastguard Worker     NotSupportedError(const std::string &message, const char *expr, const char *file, int line);
141*35238bceSAndroid Build Coastguard Worker     NotSupportedError(const std::string &message);
~NotSupportedError(void)142*35238bceSAndroid Build Coastguard Worker     virtual ~NotSupportedError(void) throw()
143*35238bceSAndroid Build Coastguard Worker     {
144*35238bceSAndroid Build Coastguard Worker     }
145*35238bceSAndroid Build Coastguard Worker };
146*35238bceSAndroid Build Coastguard Worker 
147*35238bceSAndroid Build Coastguard Worker //! Quality warning.
148*35238bceSAndroid Build Coastguard Worker class QualityWarning : public TestException
149*35238bceSAndroid Build Coastguard Worker {
150*35238bceSAndroid Build Coastguard Worker public:
151*35238bceSAndroid Build Coastguard Worker     QualityWarning(const char *message, const char *expr, const char *file, int line);
152*35238bceSAndroid Build Coastguard Worker     QualityWarning(const std::string &message, const char *expr, const char *file, int line);
153*35238bceSAndroid Build Coastguard Worker     QualityWarning(const std::string &message);
~QualityWarning(void)154*35238bceSAndroid Build Coastguard Worker     virtual ~QualityWarning(void) throw()
155*35238bceSAndroid Build Coastguard Worker     {
156*35238bceSAndroid Build Coastguard Worker     }
157*35238bceSAndroid Build Coastguard Worker };
158*35238bceSAndroid Build Coastguard Worker 
159*35238bceSAndroid Build Coastguard Worker } // namespace tcu
160*35238bceSAndroid Build Coastguard Worker 
161*35238bceSAndroid Build Coastguard Worker #define TCU_THROW_EXPR(ERRCLASS, MSG, EXPR) throw tcu::ERRCLASS(MSG, EXPR, __FILE__, __LINE__)
162*35238bceSAndroid Build Coastguard Worker 
163*35238bceSAndroid Build Coastguard Worker #define TCU_THROW(ERRCLASS, MSG) TCU_THROW_EXPR(ERRCLASS, MSG, DE_NULL)
164*35238bceSAndroid Build Coastguard Worker 
165*35238bceSAndroid Build Coastguard Worker #define TCU_CHECK_AND_THROW(ERRCLASS, X, MSG)  \
166*35238bceSAndroid Build Coastguard Worker     do                                         \
167*35238bceSAndroid Build Coastguard Worker     {                                          \
168*35238bceSAndroid Build Coastguard Worker         if (!(!false && (X)))                  \
169*35238bceSAndroid Build Coastguard Worker             TCU_THROW_EXPR(ERRCLASS, MSG, #X); \
170*35238bceSAndroid Build Coastguard Worker     } while (false)
171*35238bceSAndroid Build Coastguard Worker 
172*35238bceSAndroid Build Coastguard Worker //! Throw TestError.
173*35238bceSAndroid Build Coastguard Worker #define TCU_FAIL(MSG) TCU_THROW(TestError, MSG)
174*35238bceSAndroid Build Coastguard Worker 
175*35238bceSAndroid Build Coastguard Worker //! Throw TestError if condition X is not satisfied.
176*35238bceSAndroid Build Coastguard Worker #define TCU_CHECK(X)                                               \
177*35238bceSAndroid Build Coastguard Worker     do                                                             \
178*35238bceSAndroid Build Coastguard Worker     {                                                              \
179*35238bceSAndroid Build Coastguard Worker         if (!(!false && (X)))                                      \
180*35238bceSAndroid Build Coastguard Worker             throw tcu::TestError(DE_NULL, #X, __FILE__, __LINE__); \
181*35238bceSAndroid Build Coastguard Worker     } while (false)
182*35238bceSAndroid Build Coastguard Worker 
183*35238bceSAndroid Build Coastguard Worker //! Throw TestError if condition X is not satisfied.
184*35238bceSAndroid Build Coastguard Worker #define TCU_CHECK_MSG(X, MSG)                                    \
185*35238bceSAndroid Build Coastguard Worker     do                                                           \
186*35238bceSAndroid Build Coastguard Worker     {                                                            \
187*35238bceSAndroid Build Coastguard Worker         if (!(!false && (X)))                                    \
188*35238bceSAndroid Build Coastguard Worker             throw tcu::TestError((MSG), #X, __FILE__, __LINE__); \
189*35238bceSAndroid Build Coastguard Worker     } while (false)
190*35238bceSAndroid Build Coastguard Worker 
191*35238bceSAndroid Build Coastguard Worker //! Throw InternalError if condition X is not satisfied
192*35238bceSAndroid Build Coastguard Worker #define TCU_CHECK_INTERNAL(X)                                          \
193*35238bceSAndroid Build Coastguard Worker     do                                                                 \
194*35238bceSAndroid Build Coastguard Worker     {                                                                  \
195*35238bceSAndroid Build Coastguard Worker         if (!(!false && (X)))                                          \
196*35238bceSAndroid Build Coastguard Worker             throw tcu::InternalError(DE_NULL, #X, __FILE__, __LINE__); \
197*35238bceSAndroid Build Coastguard Worker     } while (false)
198*35238bceSAndroid Build Coastguard Worker 
199*35238bceSAndroid Build Coastguard Worker #endif // _TCUDEFS_HPP
200