1 /* 2 Copyright (c) 2005-2023 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 #include <cstdlib> 24 25 #define REPORT_FATAL_ERROR REPORT 26 27 namespace utils { 28 29 void ReportError( const char* filename, int line, const char* expression, const char * message ) { 30 print_call_stack(); 31 REPORT_FATAL_ERROR("%s:%d, assertion %s: %s\n", filename, line, expression, message ? message : "failed" ); 32 33 fflush(stdout); fflush(stderr); 34 35 #if _MSC_VER && _DEBUG 36 if(1 == _CrtDbgReport(_CRT_ASSERT, filename, line, nullptr, "%s\r\n%s", expression, message?message:"")) 37 _CrtDbgBreak(); 38 #else 39 abort(); 40 #endif 41 } 42 43 //! Compile-time error if x and y have different types 44 template<typename T> 45 void AssertSameType( const T& /*x*/, const T& /*y*/ ) {} 46 47 } // utils 48 49 #define ASSERT_CUSTOM(p,message,file,line) ((p)?(void)0:utils::ReportError(file,line,#p,message)) 50 #define ASSERT(p,message) ASSERT_CUSTOM(p,message,__FILE__,__LINE__) 51 52 #endif // __TBB_test_common_utils_assert_H 53