Home | History | Annotate | Download | only in nanoapp
      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 #else
     49 // When compiling as a static nanoapp, use the platform implementation of
     50 // CHRE_ASSERT.
     51 #include "chre/platform/assert.h"
     52 #endif  // CHRE_IS_NANOAPP_BUILD
     53 
     54 #endif  // CHRE_UTIL_NANOAPP_ASSERT_H_
     55