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) \ 38 do { \ 39 if (!(condition)) { \ 40 chreLog(CHRE_LOG_ERROR, "CHRE_ASSERT at %s:%d", CHRE_FILENAME, \ 41 __LINE__); \ 42 chreAbort(UINT32_MAX); \ 43 } \ 44 } while (0) 45 #else 46 #define CHRE_ASSERT(condition) ((void)(condition)) 47 #endif // CHRE_ASSERTIONS_ENABLED 48 49 #ifdef __cplusplus 50 #define CHRE_ASSERT_NOT_NULL(ptr) CHRE_ASSERT((ptr) != nullptr) 51 #else 52 #define CHRE_ASSERT_NOT_NULL(ptr) CHRE_ASSERT((ptr) != NULL) 53 #endif 54 55 #ifdef GTEST 56 // Mocks are not supported in standalone mode. Just skip the statement entirely. 57 #define EXPECT_CHRE_ASSERT(statement) 58 #endif // GTEST 59 60 #else 61 // When compiling as a static nanoapp, use the platform implementation of 62 // CHRE_ASSERT. 63 #include "chre/platform/assert.h" 64 #endif // CHRE_IS_NANOAPP_BUILD 65 66 #endif // CHRE_UTIL_NANOAPP_ASSERT_H_ 67