/**************************************************************************** * CTC++, Test Coverage Analyzer for C/C++, Version 7.3.1 * * * * CTCBITS.H * * (header complement of ctc.h for bitcov addon) * * * * Copyright (c) 2006-2013 Testwell Oy * * Copyright (c) 2006-2014 Verifysoft Technology GmbH * ****************************************************************************/ /* * For the static (compile time) approach, we have to re-define some of the * dynamic (runtime) macros away * * Some of the regular defines, like CTC_SAFE have no effect any more... */ #ifndef CTC_CLIKE_TIMING #define CTC_CLIKE_TIMING #endif /* * Following for using Bytes as Bits * Requires to make CTC_array 8 times bigger, then displayed by any2mem */ #ifdef CTC_BYTECOV2 # ifndef CTC_BYTECOV # define CTC_BYTECOV # endif #endif #ifdef CTC_BYTECOV # ifndef CTC_NO_BITS # define CTC_NO_BITS # endif # ifndef CTC_COUNTER # define CTC_COUNTER unsigned char # endif #endif #include "ctc.h" #ifndef CTCBITS_H # define CTCBITS_H /* Offset calculations ctc_offset gets prepended to instrumented file */ #define ctc_s_pos ctc_offset #define ctc_j_pos (ctc_s_pos + CTC_F_SIZE) #define ctc_t_pos (ctc_j_pos + CTC_J_SIZE) #define ctc_f_pos (ctc_t_pos + CTC_TF_SIZE) #define ctc_c_pos (ctc_f_pos + CTC_TF_SIZE) #define ctc_time_pos (ctc_c_pos + CTC_C_SIZE) #define ctc_timemax_pos (ctc_time_pos + CTC_TIME_SIZE) #define ctc_maxtime_pos ctc_timemax_pos #ifdef CTC_TIMING # ifndef CTC_NO_BITS # error No timing support on bitwise bitcov # else # ifdef CTC_TIMER # define xxxCTC_TIMER CTC_COUNTER # endif # endif #endif # ifdef CTC_MODULE_HEAD # undef CTC_MODULE_HEAD # ifdef CTC_TIMING # if defined(__cplusplus) && !defined(CTC_CLIKE_TIMING) # ifdef CTC_INCLUSIVE_TIMING # define CTC_MODULE_HEAD(timer_func) \ CTC_TIMER_EXTERN CTC_TIMER_IMPORT CTC_TIMER CTC_TIMER_API \ timer_func(void) CTC_TIMER_THROW; \ CTC_CWRAP_START \ static CTC_COUNTER *ctc_s = 0; \ static CTC_COUNTER *ctc_j = 0; \ static CTC_COUNTER *ctc_t = 0; \ static CTC_COUNTER *ctc_f = 0; \ static CTC_COUNTER *ctc_c = 0; \ static CTC_TIMER *ctc_time = 0; \ static CTC_TIMER *ctc_maxtime = 0; \ static CTC_TIMER (CTC_TIMER_API *ctc_timer)(void) = timer_func; \ CTC_CWRAP_END \ class Ctc_timer_class { \ public: \ Ctc_timer_class () { \ ctc_start_temp = ctc_timer(); \ } \ void set_timer (CTC_TIMER* tp, CTC_TIMER* maxtp) { \ ctc_time_ptr = tp; \ ctc_maxtime_ptr = maxtp; \ } \ ~Ctc_timer_class() { \ ctc_elapsed_temp = ctc_timer() - ctc_start_temp; \ *ctc_time_ptr += ctc_elapsed_temp; \ if (ctc_elapsed_temp > *ctc_maxtime_ptr) \ *ctc_maxtime_ptr = ctc_elapsed_temp; \ } \ private: \ CTC_TIMER ctc_start_temp; \ CTC_TIMER* ctc_time_ptr; \ CTC_TIMER* ctc_maxtime_ptr; \ CTC_TIMER ctc_elapsed_temp; \ }; # else /* !defined(CTC_INCLUSIVE_TIMING) */ # define CTC_MODULE_HEAD(timer_func) \ CTC_TIMER_EXTERN CTC_TIMER_IMPORT CTC_TIMER CTC_TIMER_API \ timer_func(void) CTC_TIMER_THROW; \ CTC_CWRAP_START \ static CTC_COUNTER *ctc_s = 0; \ static CTC_COUNTER *ctc_j = 0; \ static CTC_COUNTER *ctc_t = 0; \ static CTC_COUNTER *ctc_f = 0; \ static CTC_COUNTER *ctc_c = 0; \ static CTC_TIMER *ctc_time = 0; \ static CTC_TIMER *ctc_maxtime = 0; \ static CTC_TIMER (CTC_TIMER_API *ctc_timer)(void) = timer_func; \ CTC_CWRAP_END \ class Ctc_timer_class { \ public: \ Ctc_timer_class () { \ ctc_start_temp = ctc_timer(); \ ctc_prev_tp = ctc_curf_tp; \ ctc_prev_maxtp = ctc_curf_maxtp; \ *ctc_prev_tp += ctc_start_temp - ctc_curf_start; \ ctc_prev_elapsed = \ ctc_curf_elapsed + (ctc_start_temp - ctc_curf_start); \ ctc_curf_start = ctc_start_temp; \ ctc_curf_elapsed = 0; \ } \ void set_timer (CTC_TIMER* tp, CTC_TIMER* maxtp) { \ ctc_curf_tp = tp; \ ctc_curf_maxtp = maxtp; \ } \ ~Ctc_timer_class () { \ ctc_start_temp = ctc_timer(); \ *ctc_curf_tp += ctc_start_temp - ctc_curf_start; \ ctc_curf_elapsed += ctc_start_temp - ctc_curf_start; \ if (ctc_curf_elapsed > *ctc_curf_maxtp) \ *ctc_curf_maxtp = ctc_curf_elapsed; \ ctc_curf_start = ctc_start_temp; \ ctc_curf_tp = ctc_prev_tp; \ ctc_curf_maxtp = ctc_prev_maxtp; \ ctc_curf_elapsed = ctc_prev_elapsed; \ } \ private: \ CTC_TIMER* ctc_prev_tp; \ CTC_TIMER* ctc_prev_maxtp; \ CTC_TIMER ctc_start_temp; \ CTC_TIMER ctc_prev_elapsed; \ }; # endif /* CTC_INCLUSIVE_TIMING */ # else /* !defined(__cplusplus) || defined(CTC_CLIKE_TIMING) */ # define CTC_MODULE_HEAD(timer_func) \ CTC_TIMER_EXTERN CTC_TIMER_IMPORT CTC_TIMER CTC_TIMER_API \ timer_func(void) CTC_TIMER_THROW; \ CTC_CWRAP_START \ static CTC_COUNTER *ctc_s = 0; \ static CTC_COUNTER *ctc_j = 0; \ static CTC_COUNTER *ctc_t = 0; \ static CTC_COUNTER *ctc_f = 0; \ static CTC_COUNTER *ctc_c = 0; \ static CTC_TIMER *ctc_time = 0; \ static CTC_TIMER *ctc_maxtime = 0; \ static CTC_TIMER (CTC_TIMER_API *ctc_timer)(void) = timer_func; \ CTC_CWRAP_END # endif /* __cplusplus */ #else /* !defined(CTC_TIMING) */ # define CTC_MODULE_HEAD(timer_func) #endif /* CTC_TIMING */ # endif /* CTC_MODULE_HEAD */ # ifdef CTC_MODULE_TAIL # undef CTC_MODULE_TAIL # define CTC_MODULE_TAIL( src, datfile, timestamp, s, j, tf, c, time ) # endif # ifdef CTC_FSTART # undef CTC_FSTART # define CTC_FSTART( name, sindex) CTC_TIMER_TMP CTC_IS(sindex); CTC_START(sindex) { # endif # ifdef CTC_FEND # undef CTC_FEND # define CTC_FEND( name, eindex, tindex) CTC_STOP(tindex) CTC_IE(eindex) } # endif #ifndef CTC_SPECIAL_FULL # ifdef CTC_MAIN_START # undef CTC_MAIN_START # define CTC_MAIN_START { # endif #endif #ifndef CTC_SPECIAL_FULL # ifdef CTC_FEND_MAIN # undef CTC_FEND_MAIN # define CTC_FEND_MAIN(name, eindex, tindex) CTC_STOP(tindex) CTC_IE(eindex); } # endif #endif CTC_SPECIAL_FULL /* * Dealing with the counter arrays */ # ifndef CTC_ARRAY /* You have to implement in one of your source files in global scope unsigned char CTC_array[ SIZE ]; where SIZE is reasonable enough to hold the measurement points. After a complete CTC++ instrumentation, look at the value of ctc_counter.txt divide by 8 add 1 to be on safe side (round-up) */ # ifndef CTC_NO_BITS extern unsigned char CTC_array[]; # else extern CTC_COUNTER CTC_array[]; # endif # define CTC_ARRAY CTC_array /* If you deterministic know a reasonable address range e.g. 0x4200 you can just define it in ctc.h by adding this define OPT_ADD_COMPILE=-DCTC_ARRAY=0x4200 */ # ifndef CTC_NO_BITS # define CTC_INC_BIT(i) (CTC_array[(i)>>3]|=1<<((i)%8) ) # define CTC_DEC_BIT(i) (CTC_array[(i)>>3]^=1<<((i)%8) ) # else #ifndef CTC_SAFE # ifdef CTC_BYTECOV # define CTC_INC_BIT(i) (CTC_array[i]=1) # define CTC_DEC_BIT(i) (CTC_array[i]=0) # else # define CTC_INC_BIT(i) (CTC_array[i]++) # define CTC_DEC_BIT(i) (CTC_array[i]--) # endif #else # define CTC_INC_BIT(i) (++CTC_array[i]?CTC_array[i]:--CTC_array[i]) # define CTC_DEC_BIT(i) (CTC_array[i]--) #endif # endif # else # ifndef CTC_NO_BITS # define CTC_INC_BIT(i) (*((unsigned char*)(CTC_ARRAY+((i)>>3))) |= 1<<((i)%8) ) # define CTC_DEC_BIT(i) (*((unsigned char*)(CTC_ARRAY+((i)>>3))) ^= 1<<((i)%8) ) # else # ifdef CTC_BYTECOV # define CTC_INC_BIT(i) ((*((CTC_COUNTER*)(CTC_ARRAY+(i*(sizeof(CTC_COUNTER))))))=1 ) # define CTC_DEC_BIT(i) ((*((CTC_COUNTER*)(CTC_ARRAY+(i*(sizeof(CTC_COUNTER))))))=0 ) # else # define CTC_INC_BIT(i) ((*((CTC_COUNTER*)(CTC_ARRAY+(i*(sizeof(CTC_COUNTER))))))++ ) # define CTC_DEC_BIT(i) ((*((CTC_COUNTER*)(CTC_ARRAY+(i*(sizeof(CTC_COUNTER))))))-- ) # endif # endif # endif /* CTC_ARRAY */ # ifdef CTC_IS # undef CTC_IS # define CTC_IS(i) CTC_INC_BIT(ctc_s_pos + i); # endif # ifdef CTC_IJ # undef CTC_IJ # define CTC_IJ(i) CTC_INC_BIT(ctc_j_pos + i); # endif # ifdef CTC_COND_START # undef CTC_COND_START # define CTC_COND_START(i) (( # endif # ifdef CTC_COND_END # undef CTC_COND_END #ifdef CTC_BYTECOV2 # define CTC_COND_END(i) ) && (CTC_INC_BIT(ctc_t_pos+i) != 0) || (CTC_INC_BIT(ctc_f_pos+i) == 0)) # else # define CTC_COND_END(i) ) ? (CTC_INC_BIT(ctc_t_pos+i), 1):(CTC_INC_BIT(ctc_f_pos+i), 0)) #endif # endif # ifdef CTC_M_START # undef CTC_M_START # define CTC_M_START ( ctc_m = 0, ( # ifdef CTC_M_IND # undef CTC_M_IND # endif # if defined(__cplusplus) && !defined(CTC_CLIKE_MCOND) # define CTC_M_IND(x, n) (static_cast(x) && (ctc_m += n)) # else # define CTC_M_IND(x, n) (x && (ctc_m += n)) # endif # ifdef CTC_M_END # undef CTC_M_END #ifdef CTC_BYTECOV2 # define CTC_M_END(c) ) && (CTC_INC_BIT(ctc_c_pos + (c + ctc_m)) != 0) || \ (CTC_INC_BIT(ctc_c_pos + (c + ctc_m)) == 0) ) #else # define CTC_M_END(c) ) ? (CTC_INC_BIT(ctc_c_pos + (c + ctc_m)), 1) : \ (CTC_INC_BIT(ctc_c_pos + (c + ctc_m)), 0) ) # endif # endif # endif # if !defined(CTC_DECL_COND_NO_INSTR) # ifdef CTC_DECL_COND_START # undef CTC_DECL_COND_START # define CTC_DECL_COND_START(i) CTC_INC_BIT(ctc_f_pos + i); # endif # ifdef CTC_DECL_COND_END # undef CTC_DECL_COND_END # define CTC_DECL_COND_END(i) CTC_DEC_BIT(ctc_f_pos + i); CTC_INC_BIT(ctc_t_pos + i); # endif # endif # if !defined(CTC_COND_OPER_NO_INSTR) # ifdef CTC_COND_OPER_START # undef CTC_COND_OPER_START # define CTC_COND_OPER_START(i) (( # endif # ifdef CTC_COND_OPER_END # undef CTC_COND_OPER_END # define CTC_COND_OPER_END(i) ) ? (CTC_INC_BIT(ctc_t_pos+i), 1):(CTC_INC_BIT(ctc_f_pos+i), 0)) # endif # endif # ifdef CTC_MULTICONDITION /* Could be also unsigned char, if not too complex conditions */ # ifdef CTC_MULTI_TMP # undef CTC_MULTI_TMP # endif # define CTC_MULTI_TMP unsigned short ctc_m; # endif #ifndef CTC_SPECIAL_FULL # ifdef CTC_PRAGMA_APPEND # undef CTC_PRAGMA_APPEND # define CTC_PRAGMA_APPEND # endif # if 0 # ifdef CTC_PRAGMA_INIT # undef CTC_PRAGMA_INIT # define CTC_PRAGMA_INIT # endif # endif # ifdef CTC_PRAGMA_QUIT # undef CTC_PRAGMA_QUIT # define CTC_PRAGMA_QUIT # endif #endif #ifdef CTC_TIMING # undef CTC_START # undef CTC_STOP # if defined(__cplusplus) && !defined(CTC_CLIKE_TIMING) # define CTC_START(i) ctc_timer_object.set_timer(i); # define CTC_STOP(i) # else /* !defined(__cplusplus) || defined(CTC_CLIKE_TIMING) */ # ifdef CTC_INCLUSIVE_TIMING # define CTC_TIMER_TMP CTC_TIMER ctc_start_temp; # define CTC_START(i) ctc_start_temp = ctc_timer(); # define CTC_STOP(i) \ { CTC_TIMER ctc_end_temp = ctc_timer(); \ CTC_TIMER ctc_elapsed_temp = ctc_end_temp - ctc_start_temp; \ CTC_ARRAY[ctc_time_pos+i] += ctc_elapsed_temp; \ if (ctc_elapsed_temp > CTC_ARRAY[ctc_maxtime_pos+i]) \ CTC_ARRAY[ctc_maxtime_pos+i]=ctc_elapsed_temp; \ ctc_start_temp = ctc_end_temp; } # else /* !defined(CTC_INCLUSIVE_TIMING) */ # define CTC_TIMER_TMP \ CTC_TIMER ctc_start_temp; \ CTC_TIMER* ctc_prev_tp; \ CTC_TIMER* ctc_prev_maxtp; \ CTC_TIMER ctc_prev_elapsed; # define CTC_START(i) \ ctc_start_temp = ctc_timer(); \ ctc_prev_tp = ctc_curf_tp; \ ctc_prev_maxtp = ctc_curf_maxtp; \ ctc_prev_elapsed = \ ctc_curf_elapsed + (ctc_start_temp - ctc_curf_start); \ ctc_curf_tp = &(CTC_ARRAY[ctc_time_pos+i]); \ ctc_curf_maxtp = &(CTC_ARRAY[ctc_maxtime_pos+i]); \ ctc_curf_start = ctc_start_temp; \ ctc_curf_elapsed = 0; # define CTC_STOP(i) \ ctc_start_temp = ctc_timer(); \ if (ctc_curf_tp == &(CTC_ARRAY[ctc_time_pos+i])) \ CTC_ARRAY[ctc_time_pos+i] += ctc_start_temp - ctc_curf_start; \ ctc_curf_elapsed += ctc_start_temp - ctc_curf_start; \ if (ctc_curf_elapsed > *ctc_curf_maxtp) \ *ctc_curf_maxtp = ctc_curf_elapsed; \ ctc_curf_tp = ctc_prev_tp; \ ctc_curf_maxtp = ctc_prev_maxtp; \ ctc_curf_start = ctc_start_temp; \ ctc_curf_elapsed = ctc_prev_elapsed; # endif /* CTC_INCLUSIVE_TIMING */ # endif /* __cplusplus */ #endif /* CTC_TIMING */ /* * ctcalt2.h gets included with e.g. gcc adding -DCTC_SPECIAL2 * to OPT_ADD_COMPILE * */ #ifdef CTC_SPECIAL2 # include "ctcalt2.h" #endif #endif