Fix missing dependency on sparse binds
[platform/upstream/VK-GL-CTS.git] / framework / common / tcuDefs.hpp
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);
56         virtual                         ~Exception                      (void) throw() {}
57
58         const char*                     getMessage                      (void) const { return m_message.what(); }
59
60 private:
61         // std::runtime_error is used here as an immutable ref-counted string.
62         // This allows the copy constructor in the class to be noexcept.
63         const std::runtime_error m_message;
64 };
65
66 //! Base exception class for test exceptions that affect test result
67 class TestException : public Exception
68 {
69 public:
70                                                 TestException           (const char* message, const char* expr, const char* file, int line, qpTestResult result);
71                                                 TestException           (const std::string& message, qpTestResult result);
72         virtual                         ~TestException          (void) throw() {}
73
74         qpTestResult            getTestResult           (void) const { return m_result; }
75         virtual bool            isFatal                         (void) const { return false; }
76
77 private:
78         const qpTestResult      m_result;
79 };
80
81 //! Exception for test errors.
82 class TestError : public TestException
83 {
84 public:
85                                         TestError                       (const char* message, const char* expr, const char* file, int line);
86                                         TestError                       (const std::string& message, const char* expr, const char* file, int line);
87                                         TestError                       (const std::string& message);
88         virtual                 ~TestError                      (void) throw() {}
89 };
90
91 //! Exception for internal errors.
92 class InternalError : public TestException
93 {
94 public:
95                                         InternalError           (const char* message, const char* expr, const char* file, int line);
96                                         InternalError           (const std::string& message, const char* expr, const char* file, int line);
97                                         InternalError           (const std::string& message);
98         virtual                 ~InternalError          (void) throw() {}
99 };
100
101 //! Resource error. Tester will terminate if thrown out of test case.
102 class ResourceError : public TestException
103 {
104 public:
105                                         ResourceError           (const char* message, const char* expr, const char* file, int line);
106                                         ResourceError           (const std::string& message);
107         virtual                 ~ResourceError          (void) throw() {}
108
109         virtual bool    isFatal                         (void) const { return true; }
110 };
111
112 //! Not supported error.
113 class NotSupportedError : public TestException
114 {
115 public:
116                                         NotSupportedError       (const char* message, const char* expr, const char* file, int line);
117                                         NotSupportedError       (const std::string& message, const char* expr, const char* file, int line);
118                                         NotSupportedError       (const std::string& message);
119         virtual                 ~NotSupportedError      (void) throw() {}
120 };
121
122 } // tcu
123
124 #define TCU_THROW_EXPR(ERRCLASS, MSG, EXPR)                                             \
125                         throw tcu::ERRCLASS(MSG, EXPR, __FILE__, __LINE__)
126
127 #define TCU_THROW(ERRCLASS, MSG)                                                                \
128                         TCU_THROW_EXPR(ERRCLASS, MSG, DE_NULL)
129
130 #define TCU_CHECK_AND_THROW(ERRCLASS, X, MSG)                                   \
131         do {                                                                                                            \
132                 if (!(!deGetFalse() && (X)))                                                    \
133                         TCU_THROW_EXPR(ERRCLASS, MSG, #X);                                      \
134         } while(deGetFalse())
135
136 //! Throw TestError.
137 #define TCU_FAIL(MSG)                           TCU_THROW(TestError, MSG)
138
139 //! Throw TestError if condition X is not satisfied.
140 #define TCU_CHECK(X)                    do { if (!(!deGetFalse() && (X))) throw tcu::TestError(DE_NULL, #X, __FILE__, __LINE__); } while(deGetFalse())
141
142 //! Throw TestError if condition X is not satisfied.
143 #define TCU_CHECK_MSG(X, MSG)   do { if (!(!deGetFalse() && (X))) throw tcu::TestError((MSG), #X, __FILE__, __LINE__); } while(deGetFalse())
144
145 //! Throw InternalError if condition X is not satisfied
146 #define TCU_CHECK_INTERNAL(X)   do { if (!(!deGetFalse() && (X))) throw tcu::InternalError(DE_NULL, #X, __FILE__, __LINE__); } while(deGetFalse())
147
148 #endif // _TCUDEFS_HPP