1 /** 2 * Copyright (c) 2019, The Linux Foundation. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * * Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * * Redistributions in binary form must reproduce the above 10 * copyright notice, this list of conditions and the following 11 * disclaimer in the documentation and/or other materials provided 12 * with the distribution. 13 * * Neither the name of The Linux Foundation nor the names of its 14 * contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 #ifndef VERIFY_H 31 #define VERIFY_H 32 33 #include "AEEstd.h" 34 35 //#define VERIFY_PRINT_ERROR 36 //#define VERIFY_PRINT_INFO 37 38 39 #ifndef _WIN32 40 #define C_ASSERT(test) \ 41 switch(0) {\ 42 case 0:\ 43 case test:;\ 44 } 45 #endif // _WIN32 46 47 #ifndef __V_STR__ 48 #define __V_STR__(x) #x ":" 49 #endif //__STR__ 50 #ifndef __V_TOSTR__ 51 #define __V_TOSTR__(x) __V_STR__(x) 52 #endif // __TOSTR__ 53 #ifndef __V_FILE_LINE__ 54 #define __V_FILE_LINE__ __FILE__ ":" __V_TOSTR__(__LINE__) 55 #endif /*__FILE_LINE__*/ 56 57 58 #ifdef __ANDROID__ 59 /*android */ 60 #if (defined VERIFY_PRINT_INFO) || (defined VERIFY_PRINT_ERROR) 61 #include <android/log.h> 62 #endif 63 64 extern const char* __progname; 65 #ifdef VERIFY_PRINT_INFO 66 #define VERIFY_IPRINTF(format, ...) __android_log_print(ANDROID_LOG_DEBUG , __progname, __V_FILE_LINE__ format, ##__VA_ARGS__) 67 #endif 68 69 #ifdef VERIFY_PRINT_ERROR 70 #define VERIFY_EPRINTF(format, ...) __android_log_print(ANDROID_LOG_ERROR , __progname, __V_FILE_LINE__ format, ##__VA_ARGS__) 71 #endif 72 73 /* end android */ 74 #elif (defined __hexagon__) || (defined __qdsp6__) 75 /* q6 */ 76 77 #ifdef VERIFY_PRINT_INFO 78 #define FARF_VERIFY_LOW 1 79 #define FARF_VERIFY_LOW_LEVEL HAP_LEVEL_LOW 80 #define VERIFY_IPRINTF(args...) FARF(VERIFY_LOW, args) 81 #endif 82 83 #ifdef VERIFY_PRINT_ERROR 84 #define FARF_VERIFY_ERROR 1 85 #define FARF_VERIFY_ERROR_LEVEL HAP_LEVEL_ERROR 86 #define VERIFY_EPRINTF(args...) FARF(VERIFY_ERROR, args) 87 #endif 88 89 #if (defined VERIFY_PRINT_INFO) || (defined VERIFY_PRINT_ERROR) 90 #include "HAP_farf.h" 91 #endif 92 93 /* end q6 */ 94 #else 95 /* generic */ 96 97 #if (defined VERIFY_PRINT_INFO) || (defined VERIFY_PRINT_ERROR) 98 #include <stdio.h> 99 #endif 100 101 #ifdef VERIFY_PRINT_INFO 102 #define VERIFY_IPRINTF(format, ...) printf(__V_FILE_LINE__ format, ##__VA_ARGS__) 103 #endif 104 105 #ifdef VERIFY_PRINT_ERROR 106 #define VERIFY_EPRINTF(format, ...) printf(__V_FILE_LINE__ format, ##__VA_ARGS__) 107 #endif 108 109 /* end generic */ 110 #endif 111 112 #ifndef VERIFY_PRINT_INFO 113 #define VERIFY_IPRINTF(format, ...) (void)0 114 #endif 115 116 #ifndef VERIFY_PRINT_ERROR 117 #define VERIFY_EPRINTF(format, ...) (void)0 118 #endif 119 120 #ifndef VERIFY 121 #define VERIFY(val) \ 122 do {\ 123 VERIFY_IPRINTF(":info: calling: " #val "\n");\ 124 if(0 == (val)) {\ 125 nErr = nErr == 0 ? -1 : nErr;\ 126 VERIFY_EPRINTF(":error: %d: " #val "\n", nErr);\ 127 goto bail;\ 128 } else {\ 129 VERIFY_IPRINTF(":info: passed: " #val "\n");\ 130 }\ 131 } while(0) 132 #endif //VERIFY 133 134 #ifndef VERIFYC 135 #define VERIFYC(val,err_code) \ 136 do {\ 137 VERIFY_IPRINTF(":info: calling: " #val "\n");\ 138 if(0 == (val)) {\ 139 nErr = err_code;\ 140 VERIFY_EPRINTF(":Error: %x: " #val "\n", nErr);\ 141 goto bail;\ 142 } else {\ 143 VERIFY_IPRINTF(":info: passed: " #val "\n");\ 144 }\ 145 } while(0) 146 #endif //VERIFYC 147 148 149 #endif //VERIFY_H 150 151