xref: /oneTBB/test/common/utils_assert.h (revision 6caecf96)
1 /*
2     Copyright (c) 2005-2021 Intel Corporation
3 
4     Licensed under the Apache License, Version 2.0 (the "License");
5     you may not use this file except in compliance with the License.
6     You may obtain a copy of the License at
7 
8         http://www.apache.org/licenses/LICENSE-2.0
9 
10     Unless required by applicable law or agreed to in writing, software
11     distributed under the License is distributed on an "AS IS" BASIS,
12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13     See the License for the specific language governing permissions and
14     limitations under the License.
15 */
16 
17 #ifndef __TBB_test_common_utils_assert_H
18 #define __TBB_test_common_utils_assert_H
19 
20 #include "config.h"
21 #include "utils_report.h"
22 
23 #define REPORT_FATAL_ERROR REPORT
24 
25 namespace utils {
26 
27 void ReportError( const char* filename, int line, const char* expression, const char * message ) {
28     print_call_stack();
29     REPORT_FATAL_ERROR("%s:%d, assertion %s: %s\n", filename, line, expression, message ? message : "failed" );
30 
31     fflush(stdout); fflush(stderr);
32 
33 #if _MSC_VER && _DEBUG
34     if(1 == _CrtDbgReport(_CRT_ASSERT, filename, line, NULL, "%s\r\n%s", expression, message?message:""))
35         _CrtDbgBreak();
36 #else
37     abort();
38 #endif
39 }
40 
41 //! Compile-time error if x and y have different types
42 template<typename T>
43 void AssertSameType( const T& /*x*/, const T& /*y*/ ) {}
44 
45 } // utils
46 
47 #define ASSERT_CUSTOM(p,message,file,line)  ((p)?(void)0:utils::ReportError(file,line,#p,message))
48 #define ASSERT(p,message)                   ASSERT_CUSTOM(p,message,__FILE__,__LINE__)
49 
50 #endif // __TBB_test_common_utils_assert_H
51