Skip to content

Commit

Permalink
Add call site size tests for conditionals
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-mice committed Apr 27, 2016
1 parent c264a39 commit 24aec99
Show file tree
Hide file tree
Showing 4 changed files with 299 additions and 54 deletions.
4 changes: 4 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,7 @@ endfunction()

add_code_size_test(test_call_site_size_msg_only SOURCES test_call_site_size_msg_only.c)
add_code_size_test(test_call_site_size_fmt_args SOURCES test_call_site_size_fmt_args.c)
add_code_size_test(test_call_site_size_conditional_true SOURCES test_call_site_size_conditional.c DEFINES TEST_CONDITION=1)
add_code_size_test(test_call_site_size_conditional_false SOURCES test_call_site_size_conditional.c DEFINES TEST_CONDITION=0)
add_code_size_test(test_call_site_size_censoring_on SOURCES test_call_site_size_censoring.c DEFINES ZF_LOG_CENSORING=ZF_LOG_CENSORED)
add_code_size_test(test_call_site_size_censoring_off SOURCES test_call_site_size_censoring.c DEFINES ZF_LOG_CENSORING=ZF_LOG_UNCENSORED)
34 changes: 34 additions & 0 deletions tests/test_call_site_size_censoring.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#define ZF_LOG_LEVEL ZF_LOG_INFO
#include <zf_log.h>
#include <time.h>

#define LOG_SOME_ONCE \
ZF_LOG_SECRET(ZF_LOGI("Lorem ipsum dolor sit amet")); \
time(0); \

static void log_some()
{
LOG_SOME_ONCE
LOG_SOME_ONCE
LOG_SOME_ONCE
LOG_SOME_ONCE
LOG_SOME_ONCE
LOG_SOME_ONCE
LOG_SOME_ONCE
LOG_SOME_ONCE
LOG_SOME_ONCE
LOG_SOME_ONCE
LOG_SOME_ONCE
LOG_SOME_ONCE
LOG_SOME_ONCE
LOG_SOME_ONCE
LOG_SOME_ONCE
LOG_SOME_ONCE
}

int main(int argc, char *argv[])
{
(void)argc; (void)argv;
log_some();
return 0;
}
40 changes: 40 additions & 0 deletions tests/test_call_site_size_conditional.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#define ZF_LOG_LEVEL ZF_LOG_INFO
#include <zf_log.h>
#include <time.h>

#if TEST_CONDITION
#define CONDITION 1 < 2
#else
#define CONDITION 1 > 2
#endif

#define LOG_SOME_ONCE \
ZF_LOG_IF(CONDITION, ZF_LOGI("Lorem ipsum dolor sit amet")); \
time(0); \

static void log_some()
{
LOG_SOME_ONCE
LOG_SOME_ONCE
LOG_SOME_ONCE
LOG_SOME_ONCE
LOG_SOME_ONCE
LOG_SOME_ONCE
LOG_SOME_ONCE
LOG_SOME_ONCE
LOG_SOME_ONCE
LOG_SOME_ONCE
LOG_SOME_ONCE
LOG_SOME_ONCE
LOG_SOME_ONCE
LOG_SOME_ONCE
LOG_SOME_ONCE
LOG_SOME_ONCE
}

int main(int argc, char *argv[])
{
(void)argc; (void)argv;
log_some();
return 0;
}
Loading

0 comments on commit 24aec99

Please sign in to comment.