1/*
2 Copyright (c) 2005-2019 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// Declarations for checking __TBB_ASSERT checks inside TBB.
18// This header is an optional part of the test harness.
19// It assumes that "harness.h" has already been included.
20
21#define TRY_BAD_EXPR_ENABLED (TBB_USE_ASSERT && TBB_USE_EXCEPTIONS && !__TBB_THROW_ACROSS_MODULE_BOUNDARY_BROKEN)
22
23#if TRY_BAD_EXPR_ENABLED
24
25//! Check that expression x raises assertion failure with message containing given substring.
26/** Assumes that tbb::set_assertion_handler( AssertionFailureHandler ) was called earlier. */
27#define TRY_BAD_EXPR(x,substr) \
28 { \
29 const char* message = NULL; \
30 bool okay = false; \
31 try { \
32 x; \
33 } catch( AssertionFailure a ) { \
34 okay = true; \
35 message = a.message; \
36 } \
37 CheckAssertionFailure(__LINE__,#x,okay,message,substr); \
38 }
39
40//! Exception object that holds a message.
41struct AssertionFailure {
42 const char* message;
43 AssertionFailure( const char* filename, int line, const char* expression, const char* comment );
44};
45
46AssertionFailure::AssertionFailure( const char* filename, int line, const char* expression, const char* comment ) :
47 message(comment)
48{
49 ASSERT(filename,"missing filename");
50 ASSERT(0<line,"line number must be positive");
51 // All of our current files have fewer than 4000 lines.
52 ASSERT(line<5000,"dubiously high line number");
53 ASSERT(expression,"missing expression");
54}
55
56void AssertionFailureHandler( const char* filename, int line, const char* expression, const char* comment ) {
57 throw AssertionFailure(filename,line,expression,comment);
58}
59
60void CheckAssertionFailure( int line, const char* expression, bool okay, const char* message, const char* substr ) {
61 if( !okay ) {
62 REPORT("Line %d, %s failed to fail\n", line, expression );
63 abort();
64 } else if( !message ) {
65 REPORT("Line %d, %s failed without a message\n", line, expression );
66 abort();
67 } else if( strstr(message,substr)==0 ) {
68 REPORT("Line %d, %s failed with message '%s' missing substring '%s'\n", __LINE__, expression, message, substr );
69 abort();
70 }
71}
72
73#endif /* TRY_BAD_EXPR_ENABLED */
74