/* *Author : DavidLin *Date : 2014-12-26pm *Email : linpeng1577@163.com or linpeng1577@gmail.com *world : the city of SZ, in China *Ver : 000.000.001 *For : threads for rxtx! *history : editor time do * 1)LinPeng 2014-12-26 created this file! * 2) */ /* assert_self.h */ #ifndef __ASSERT_SELF_H__ #define __ASSERT_SELF_H__ #include<stdio.h> #define ASSERT_ENABLE (1) #define xprintf printf /* xprintf can be tty print or uart print, etc */ #if ASSERT_ENABLE #define assert_error() / do / { / xprintf("[ERROR] Assert FILE: %s: LINE %d/n", __FILE__, __LINE__); / }while(0) #define ASSERT1(para) / do / { / if(!para) / { / assert_error(); / } / }while(0) / #else /* if ! ASSERT_ENABLE */ #define ASSERT1(para) / do / { / if(para) / { / } / }while(0) #endif /* end of ASSERT_ENABLE */ #endif /* end of __ASSERT_SELF_H__*/
测试用例
/* test case : test.c */ #include<stdio.h> #include"assert_self.h" int main(int argc, char* argv[]) { switch(argc) { case 2: ASSERT1(atoi(argv[1])); break; default: printf("ARG ACCEPT 1/n"); break; } exit(0); }
软件Bug定位,很多时候,比如利用Assert宏,可以把48小时的调试大餐压缩成1口可以吃掉的饭后甜点,每个软件小组都在重新演化,过去的经验总是得不到很好的传承,这就是我们!
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/192979.html