@@ -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++ */
670695static void log_api_suite_teardown (void *data)
671696{
@@ -754,6 +779,7 @@ WRAP_TEST(test_log_arguments, test_log_api)
754779WRAP_TEST(test_log_from_declared_module, test_log_api)
755780WRAP_TEST(test_log_panic, test_log_api)
756781WRAP_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