• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef LOCATION_LBS_CONTEXTHUB_NANOAPPS_UTIL_NANO_ASSERT_H_
2 #define LOCATION_LBS_CONTEXTHUB_NANOAPPS_UTIL_NANO_ASSERT_H_
3 
4 #ifndef GOOGLE3
5 
6 // For external nanoapps (__NANOHUB__ defined), use SRC_FILENAME provided
7 // by the build system, which has the directory stripped. But allow the
8 // full filename for OS builds, where ASSERT should only be used for local
9 // development.
10 #if !defined(SRC_FILENAME) && defined(_OS_BUILD_)
11 #define SRC_FILENAME __FILENAME__
12 #endif
13 
14 #ifdef NANOHUB_NON_CHRE_API
15   #include <syscallDo.h>
16   #define ASSERT_LOG_FUNC(fmt, ...) eOsLog(LOG_ERROR, fmt, ##__VA_ARGS__)
17 #else
18   #include <chre.h>
19   #define ASSERT_LOG_FUNC(fmt, ...) chreLog(LOG_ERROR, fmt, ##__VA_ARGS__)
20 #endif
21 
22 // Note that this just logs and doesn't actually stop execution on Nanohub
23 #define ASSERT_IMPL(x) do {                                          \
24     if (!(x)) {                                                      \
25       ASSERT_LOG_FUNC("Assertion: %s:%d\n", SRC_FILENAME, __LINE__); \
26     }                                                                \
27   } while (0)
28 
29 #else  // Off-target testing, e.g. Google3
30 
31 #define NANO_ASSERT_ENABLED
32 #include <assert.h>
33 #define ASSERT_IMPL(x) assert(x)
34 
35 #endif  // GOOGLE3
36 
37 #ifndef ASSERT
38 #ifdef NANO_ASSERT_ENABLED
39 #define ASSERT(x) ASSERT_IMPL(x)
40 #else
41 #define ASSERT(x) ((void)(x))
42 #endif  // NANO_ASSERT_ENABLED
43 #endif  // ASSERT
44 
45 // Use NULL when compiling for C and nullptr for C++.
46 #ifdef __cplusplus
47 #define ASSERT_NOT_NULL(ptr) ASSERT((ptr) != nullptr)
48 #else
49 #define ASSERT_NOT_NULL(ptr) ASSERT((ptr) != NULL)
50 #endif
51 
52 #define UNUSED(x) ((void)(sizeof(x)))
53 
54 #endif  // LOCATION_LBS_CONTEXTHUB_NANOAPPS_UTIL_NANO_ASSERT_H_
55