2
0

Fix overriding of ftl behaviour for tests.

This commit is contained in:
Maarten Billemont 2018-03-24 15:22:37 -04:00
parent a1f5e0ba1c
commit 6650382e19
2 changed files with 22 additions and 11 deletions

View File

@ -26,36 +26,41 @@
//// Logging. //// Logging.
#ifndef log #ifndef mpw_log_do
#define mpw_log_do(level, format, ...) \
fprintf( stderr, format "\n", ##__VA_ARGS__ )
#endif
#ifndef mpw_log
extern int mpw_verbosity; extern int mpw_verbosity;
#define log(level, format, ...) ({ \ #define mpw_log(level, ...) ({ \
if (mpw_verbosity >= level) { \ if (mpw_verbosity >= level) { \
fprintf( stderr, format "\n", ##__VA_ARGS__ ); \ mpw_log_do( level, ##__VA_ARGS__ ); \
}; }) }; })
/** Logging internal state. */ /** Logging internal state. */
#define trc_level 3 #define trc_level 3
#define trc(...) log( trc_level, ##__VA_ARGS__ ) #define trc(...) mpw_log( trc_level, ##__VA_ARGS__ )
/** Logging state and events interesting when investigating issues. */ /** Logging state and events interesting when investigating issues. */
#define dbg_level 2 #define dbg_level 2
#define dbg(...) log( dbg_level, ##__VA_ARGS__ ) #define dbg(...) mpw_log( dbg_level, ##__VA_ARGS__ )
/** User messages. */ /** User messages. */
#define inf_level 1 #define inf_level 1
#define inf(...) log( inf_level, ##__VA_ARGS__ ) #define inf(...) mpw_log( inf_level, ##__VA_ARGS__ )
/** Recoverable issues and user suggestions. */ /** Recoverable issues and user suggestions. */
#define wrn_level 0 #define wrn_level 0
#define wrn(...) log( wrn_level, ##__VA_ARGS__ ) #define wrn(...) mpw_log( wrn_level, ##__VA_ARGS__ )
/** Unrecoverable issues. */ /** Unrecoverable issues. */
#define err_level -1 #define err_level -1
#define err(...) log( err_level, ##__VA_ARGS__ ) #define err(...) mpw_log( err_level, ##__VA_ARGS__ )
/** Issues that lead to abortion. */ /** Issues that lead to abortion. */
#define ftl_level -2 #define ftl_level -2
#define ftl(...) log( ftl_level, ##__VA_ARGS__ ) #define ftl(...) mpw_log( ftl_level, ##__VA_ARGS__ )
#endif #endif
#ifndef min #ifndef min

View File

@ -19,7 +19,13 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#define ftl(...) do { fprintf( stderr, __VA_ARGS__ ); exit(2); } while (0) #ifndef mpw_log_do
#define mpw_log_do(level, format, ...) ({ \
fprintf( stderr, format "\n", ##__VA_ARGS__ ); \
if (level == ftl_level) \
abort(); \
})
#endif
#include "mpw-algorithm.h" #include "mpw-algorithm.h"
#include "mpw-util.h" #include "mpw-util.h"