Skip to content
Permalink
Browse files

tests: subsys: logging: Test for detection of missed log_strdup

Added test to validate algorithm for missed log_strdup() call.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
  • Loading branch information...
nordic-krch authored and carlescufi committed May 23, 2019
1 parent a211afb commit 93fb695244c64982b8855399a595e102883702bb
Showing with 43 additions and 1 deletion.
  1. +1 −0 tests/subsys/logging/log_core/prj.conf
  2. +42 −1 tests/subsys/logging/log_core/src/log_core_test.c
@@ -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
@@ -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)
{
@@ -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)
{
@@ -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));

0 comments on commit 93fb695

Please sign in to comment.
You can’t perform that action at this time.