Skip to content

Commit f647201

Browse files
nordic-krchnashif
authored andcommitted
tests: logging: log_api: Add test for argument evaluation
Added test which checks that log argument is evaluated only once when log message is created. Signed-off-by: Krzysztof Chruscinski <[email protected]>
1 parent 3f56567 commit f647201

File tree

1 file changed

+26
-0
lines changed
  • tests/subsys/logging/log_api/src

1 file changed

+26
-0
lines changed

tests/subsys/logging/log_api/src/test.inc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,31 @@ static void test_log_printk(void)
666666
process_and_validate(false, true);
667667
}
668668

669+
static void test_log_arg_evaluation(void)
670+
{
671+
uint32_t cnt0 = 0;
672+
uint32_t cnt1 = 0;
673+
uint32_t exp0 = 1;
674+
uint32_t exp1 = 1;
675+
676+
if (IS_ENABLED(CONFIG_SAMPLE_MODULE_LOG_LEVEL_DBG)) {
677+
/* Debug message arguments are only evaluated when this level
678+
* is enabled.
679+
*/
680+
exp0++;
681+
exp1++;
682+
}
683+
684+
/* Arguments used for logging shall be evaluated only once. They should
685+
* be evaluated also when given log level is disabled.
686+
*/
687+
LOG_INF("%u %u", cnt0++, cnt1++);
688+
LOG_DBG("%u %u", cnt0++, cnt1++);
689+
690+
zassert_equal(cnt0, exp0, "Got:%u, Expected:%u", cnt0, exp0);
691+
zassert_equal(cnt1, exp1, "Got:%u, Expected:%u", cnt1, exp1);
692+
}
693+
669694
/* Disable backends because same suite may be executed again but compiled by C++ */
670695
static void log_api_suite_teardown(void *data)
671696
{
@@ -754,6 +779,7 @@ WRAP_TEST(test_log_arguments, test_log_api)
754779
WRAP_TEST(test_log_from_declared_module, test_log_api)
755780
WRAP_TEST(test_log_panic, test_log_api)
756781
WRAP_TEST(test_log_printk, test_log_api)
782+
WRAP_TEST(test_log_arg_evaluation, test_log_api)
757783

758784
/* With multiple cpus you may not get consistent message dropping
759785
* as other core may process logs. Executing on 1 cpu only.

0 commit comments

Comments
 (0)