1 /*
2  * Copyright (C) 2018 The Android Open Source Project
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 CHRE_UTIL_NANOAPP_ASSERT_H_
18 #define CHRE_UTIL_NANOAPP_ASSERT_H_
19 
20 /**
21  * @file
22  *
23  * Suppplies a CHRE_ASSERT macro for Nanoapps to use.
24  */
25 
26 #ifdef CHRE_IS_NANOAPP_BUILD
27 
28 #include <chre.h>
29 
30 /**
31  * Provides the CHRE_ASSERT macro that uses chreAbort to abort the nanoapp upon
32  * failure.
33  *
34  * @param the condition to check for non-zero.
35  */
36 #ifdef CHRE_ASSERTIONS_ENABLED
37 #define CHRE_ASSERT(condition) do {                                    \
38       if (!(condition)) {                                              \
39         chreLog(CHRE_LOG_ERROR, "CHRE_ASSERT at %s:%d", CHRE_FILENAME, \
40                 __LINE__);                                             \
41         chreAbort(UINT32_MAX);                                         \
42       }                                                                \
43     } while (0)
44 #else
45 #define CHRE_ASSERT(condition) ((void) (condition))
46 #endif  // CHRE_ASSERTIONS_ENABLED
47 
48 #ifdef GTEST
49 // Mocks are not supported in standalone mode. Just skip the statement entirely.
50 #define EXPECT_CHRE_ASSERT(statement)
51 #endif  // GTEST
52 
53 #else
54 // When compiling as a static nanoapp, use the platform implementation of
55 // CHRE_ASSERT.
56 #include "chre/platform/assert.h"
57 #endif  // CHRE_IS_NANOAPP_BUILD
58 
59 #endif  // CHRE_UTIL_NANOAPP_ASSERT_H_
60