Skip to content

Commit

Permalink
tests: subsys: logging: Test for detection of missed log_strdup
Browse files Browse the repository at this point in the history
Added test to validate algorithm for missed log_strdup() call.

Signed-off-by: Krzysztof Chruscinski <[email protected]>
  • Loading branch information
nordic-krch authored and carlescufi committed May 29, 2019
1 parent a211afb commit 93fb695
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
1 change: 1 addition & 0 deletions tests/subsys/logging/log_core/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ CONFIG_SOC_LOG_LEVEL_OFF=y
CONFIG_ARCH_LOG_LEVEL_OFF=y
CONFIG_LOG_FUNC_NAME_PREFIX_DBG=n
CONFIG_LOG_PROCESS_THREAD=n
CONFIG_ASSERT=n
43 changes: 42 additions & 1 deletion tests/subsys/logging/log_core/src/log_core_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,47 @@ static void test_log_strdup_gc(void)

}

#define DETECT_STRDUP_MISSED(str, do_strdup, ...) \
{\
char tmp[] = "tmp";\
u32_t exp_cnt = backend1_cb.counter + 1 + (do_strdup ? 0 : 1); \
LOG_ERR(str, ##__VA_ARGS__, do_strdup ? log_strdup(tmp) : tmp); \
\
while (log_process(false)) { \
} \
\
zassert_equal(exp_cnt, backend1_cb.counter,\
"Unexpected amount of messages received by the backend (%d).", \
backend1_cb.counter); \
}

static void test_log_strdup_detect_miss(void)
{
if (IS_ENABLED(CONFIG_LOG_DETECT_MISSED_STRDUP)) {
return;
}

log_setup(false);

DETECT_STRDUP_MISSED("%s", true);
DETECT_STRDUP_MISSED("%s", false);

DETECT_STRDUP_MISSED("%-20s", true);
DETECT_STRDUP_MISSED("%-20s", false);

DETECT_STRDUP_MISSED("%20s", true);
DETECT_STRDUP_MISSED("%20s", false);

DETECT_STRDUP_MISSED("%20.4s", true);
DETECT_STRDUP_MISSED("%20.4s", false);

DETECT_STRDUP_MISSED("%% %s %%", true);
DETECT_STRDUP_MISSED("%% %s %%", false);

DETECT_STRDUP_MISSED("%% %08X %s", true, 4);
DETECT_STRDUP_MISSED("%% %08X %s", false, 4);
}

static void strdup_trim_callback(struct log_backend const *const backend,
struct log_msg *msg, size_t counter)
{
Expand Down Expand Up @@ -463,7 +504,6 @@ static void test_log_panic(void)
"Unexpected amount of messages received by the backend.");
}


/*test case main entry*/
void test_main(void)
{
Expand All @@ -473,6 +513,7 @@ void test_main(void)
ztest_unit_test(test_log_arguments),
ztest_unit_test(test_log_from_declared_module),
ztest_unit_test(test_log_strdup_gc),
ztest_unit_test(test_log_strdup_detect_miss),
ztest_unit_test(test_strdup_trimming),
ztest_unit_test(test_log_msg_dropped_notification),
ztest_unit_test(test_log_panic));
Expand Down

0 comments on commit 93fb695

Please sign in to comment.