How to exclude lcov branches inside a macro

I have several logging protocols in my code in lines:

#define LOG_MSG (pri, msg, ... ) \
    if (pri > PriorityLevel ) \
        printf( msg, ##\__VA_ARGS__);

I know that I can use LCOV_EXCL_START, LCOV_EXCL_STOP or LCOV_EXCL_LINE to suppress a branch. But this only works if I add it to every place that I call LOG_MSG:

LOG_MSG(ERROR, "An Error has occurred\n");//LCOV_EXCL_LINE

I would like to include this comment in the macro, but LCOV will not recognize it if I put it there. For example, this code still creates branches.

#define LOG_MSG (pri, msg, ... ) \
    if (pri > PriorityLevel ) \
        printf( msg, ##\__VA_ARGS__);//LCOV_EXCL_LINE

Is there a good way to suppress these branches in the macro itself?

+4
source share
4 answers

Why not turn a macro into a function?

as:

template <typename ... Ts>
void LOG_MSG(int priority, const std::string& message, Ts&&...ts)
{
    if (priority > PriorityLevel)
        printf(message.c_str(), std::forward<Ts>(ts)...);
    // Or more appropriate stuff
}
+1
source

lcov 1.11 ( 1.12) LCOV_EXCL_BR_LINE. , :

LOG_MSG(ERROR, "An Error has occurred\n"); //LCOV_EXCL_BR_LINE

:

LOG_MSG(ERROR, "An Error has occurred\n"); (void)("LCOV_EXCL_BR_LINE");

.

+1

, , @Jarod42. ++ 0x, :

void LogMsgFunc( U32 pri, const char* msg, ... )
{
    //LCOV_EXCL_START
    va_list variableArgumentList;
    va_start( variableArgumentList, msg );
    if ( pri <= PriorityLevel ) 
    { 
        vfprintf( stderr, msg, variableArgumentList );
    }    
    va_end( variableArgumentList );
    //LCOV_EXCL_STOP
}

#define LOG_MSG (pri, msg, ... ) \
    LogMsgFunc(pri, msg, ##__VA_ARGS__);
0

#define LOG_MSG__LCOV_EXCL_BR_LINE LOG_MSG

LOG_MSG, LOG_MSG__LCOV_EXCL_BR_LINE. ?

0

All Articles