Skip to content

Commit 10232b5

Browse files
mengxianglinxcfriedt
authored andcommitted
test: logging: improve test coverage for logging subsystem
Add some test point in existing test cases. Add some test cases for usersapce. Signed-off-by: Meng xianglin <xianglinx.meng@intel.com>
1 parent 905c430 commit 10232b5

File tree

12 files changed

+260
-49
lines changed

12 files changed

+260
-49
lines changed

subsys/logging/log_core.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,13 +943,15 @@ void log_free(void *str)
943943
}
944944

945945
#if defined(CONFIG_USERSPACE)
946+
/* LCOV_EXCL_START */
946947
void z_impl_z_log_string_from_user(uint32_t src_level_val, const char *str)
947948
{
948949
ARG_UNUSED(src_level_val);
949950
ARG_UNUSED(str);
950951

951952
__ASSERT(false, "This function can be called from user mode only.");
952953
}
954+
/* LCOV_EXCL_STOP */
953955

954956
void z_vrfy_z_log_string_from_user(uint32_t src_level_val, const char *str)
955957
{
@@ -1037,6 +1039,7 @@ void log_from_user(struct log_msg_ids src_level, const char *fmt, ...)
10371039
va_end(ap);
10381040
}
10391041

1042+
/* LCOV_EXCL_START */
10401043
void z_impl_z_log_hexdump_from_user(uint32_t src_level_val, const char *metadata,
10411044
const uint8_t *data, uint32_t len)
10421045
{
@@ -1047,6 +1050,7 @@ void z_impl_z_log_hexdump_from_user(uint32_t src_level_val, const char *metadata
10471050

10481051
__ASSERT(false, "This function can be called from user mode only.");
10491052
}
1053+
/* LCOV_EXCL_STOP */
10501054

10511055
void z_vrfy_z_log_hexdump_from_user(uint32_t src_level_val, const char *metadata,
10521056
const uint8_t *data, uint32_t len)
@@ -1112,6 +1116,7 @@ void log_hexdump_from_user(struct log_msg_ids src_level, const char *metadata,
11121116
(const uint8_t *)data, len);
11131117
}
11141118
#else
1119+
/* LCOV_EXCL_START */
11151120
void z_impl_z_log_string_from_user(uint32_t src_level_val, const char *str)
11161121
{
11171122
ARG_UNUSED(src_level_val);
@@ -1159,6 +1164,7 @@ void log_hexdump_from_user(struct log_msg_ids src_level, const char *metadata,
11591164

11601165
__ASSERT_NO_MSG(false);
11611166
}
1167+
/* LCOV_EXCL_STOP */
11621168
#endif /* !defined(CONFIG_USERSPACE) */
11631169

11641170
void z_log_msg2_init(void)

tests/subsys/logging/log_api/prj.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ CONFIG_TEST_USERSPACE=y
44
CONFIG_TEST_LOGGING_DEFAULTS=n
55
CONFIG_LOG=y
66
CONFIG_LOG_PRINTK=n
7-
CONFIG_LOG_BACKEND_UART=n
7+
CONFIG_LOG_BACKEND_UART=y
88
CONFIG_LOG_BUFFER_SIZE=768
99
CONFIG_LOG_STRDUP_BUF_COUNT=1
1010
CONFIG_LOG_STRDUP_MAX_STRING=8

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

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -402,38 +402,59 @@ static void test_log_overflow(void)
402402
* Log messages with supported number of messages are called. Test backend
403403
* validates number of arguments and values.
404404
*/
405+
#define MOCK_LOG_BACKEND_RECORD(str) mock_log_backend_record( \
406+
&backend1, LOG_CURRENT_MODULE_ID(), \
407+
CONFIG_LOG_DOMAIN_ID, LOG_LEVEL_INF, \
408+
exp_timestamp++, \
409+
str);
410+
405411
static void test_log_arguments(void)
406412
{
407413
log_timestamp_t exp_timestamp = TIMESTAMP_INIT_VAL;
408414

409415
log_setup(false);
410416

411-
mock_log_backend_record(&backend1, LOG_CURRENT_MODULE_ID(),
412-
CONFIG_LOG_DOMAIN_ID, LOG_LEVEL_INF,
413-
exp_timestamp++, "test");
414-
mock_log_backend_record(&backend1, LOG_CURRENT_MODULE_ID(),
415-
CONFIG_LOG_DOMAIN_ID, LOG_LEVEL_INF,
416-
exp_timestamp++,
417-
"test 1 2 3");
418-
mock_log_backend_record(&backend1, LOG_CURRENT_MODULE_ID(),
419-
CONFIG_LOG_DOMAIN_ID, LOG_LEVEL_INF,
420-
exp_timestamp++,
421-
"test 1 2 3 4 5 6 7");
422-
mock_log_backend_record(&backend1, LOG_CURRENT_MODULE_ID(),
423-
CONFIG_LOG_DOMAIN_ID, LOG_LEVEL_INF,
424-
exp_timestamp++,
425-
"test 1 2 3 4 5 6 7 8 9 10 11");
426-
mock_log_backend_record(&backend1, LOG_CURRENT_MODULE_ID(),
427-
CONFIG_LOG_DOMAIN_ID, LOG_LEVEL_INF,
428-
exp_timestamp++,
429-
"test 1 2 3 4 5 6 7 8 9 10 11 12 13 14");
417+
MOCK_LOG_BACKEND_RECORD("test");
418+
MOCK_LOG_BACKEND_RECORD("test 1 2 3");
419+
MOCK_LOG_BACKEND_RECORD("test 1 2 3 4");
420+
MOCK_LOG_BACKEND_RECORD("test 1 2 3 4 5");
421+
MOCK_LOG_BACKEND_RECORD("test 1 2 3 4 5 6");
422+
MOCK_LOG_BACKEND_RECORD("test 1 2 3 4 5 6 7");
423+
MOCK_LOG_BACKEND_RECORD("test 1 2 3 4 5 6 7 8");
424+
MOCK_LOG_BACKEND_RECORD("test 1 2 3 4 5 6 7 8 9");
425+
MOCK_LOG_BACKEND_RECORD("test 1 2 3 4 5 6 7 8 9 10");
426+
MOCK_LOG_BACKEND_RECORD("test 1 2 3 4 5 6 7 8 9 10 11");
427+
MOCK_LOG_BACKEND_RECORD("test 1 2 3 4 5 6 7 8 9 10 11 12");
428+
MOCK_LOG_BACKEND_RECORD("test 1 2 3 4 5 6 7 8 9 10 11 12 13");
429+
MOCK_LOG_BACKEND_RECORD("test 1 2 3 4 5 6 7 8 9 10 11 12 13 14");
430+
430431
LOG_INF("test");
431432
LOG_INF("test %d %d %d", 1, 2, 3);
433+
LOG_INF("test %d %d %d %d", 1, 2, 3, 4);
434+
LOG_INF("test %d %d %d %d %d", 1, 2, 3, 4, 5);
435+
while (LOG_PROCESS()) {
436+
}
437+
438+
LOG_INF("test %d %d %d %d %d %d", 1, 2, 3, 4, 5, 6);
432439
LOG_INF("test %d %d %d %d %d %d %d", 1, 2, 3, 4, 5, 6, 7);
440+
LOG_INF("test %d %d %d %d %d %d %d %d", 1, 2, 3, 4, 5, 6, 7,8);
441+
LOG_INF("test %d %d %d %d %d %d %d %d %d", 1, 2, 3, 4, 5, 6, 7,8, 9);
442+
while (LOG_PROCESS()) {
443+
}
444+
445+
LOG_INF("test %d %d %d %d %d %d %d %d %d %d",
446+
1, 2, 3, 4, 5, 6, 7,8, 9, 10);
433447
LOG_INF("test %d %d %d %d %d %d %d %d %d %d %d",
434-
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
448+
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
449+
LOG_INF("test %d %d %d %d %d %d %d %d %d %d %d %d",
450+
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
451+
while (LOG_PROCESS()) {
452+
}
453+
454+
LOG_INF("test %d %d %d %d %d %d %d %d %d %d %d %d %d",
455+
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13);
435456
LOG_INF("test %d %d %d %d %d %d %d %d %d %d %d %d %d %d",
436-
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14);
457+
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14);
437458
while (LOG_PROCESS()) {
438459
}
439460

tests/subsys/logging/log_core/src/log_core_test.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ struct backend_cb {
3636
uint32_t exp_id[100];
3737
bool check_timestamp;
3838
uint32_t exp_timestamps[100];
39-
bool check_args;
40-
uint32_t exp_nargs[100];
4139
bool check_strdup;
4240
bool exp_strdup[100];
4341
custom_put_callback_t callback;
@@ -48,7 +46,6 @@ static void put(struct log_backend const *const backend,
4846
struct log_msg *msg)
4947
{
5048
log_msg_get(msg);
51-
uint32_t nargs = log_msg_nargs_get(msg);
5249
struct backend_cb *cb = (struct backend_cb *)backend->cb->ctx;
5350

5451
if (cb->check_id) {
@@ -67,16 +64,6 @@ static void put(struct log_backend const *const backend,
6764
"Unexpected message index");
6865
}
6966

70-
/* Arguments in the test are fixed, 1,2,3,4,5,... */
71-
if (cb->check_args && log_msg_is_std(msg) && nargs > 0) {
72-
for (int i = 0; i < nargs; i++) {
73-
uint32_t arg = log_msg_arg_get(msg, i);
74-
75-
zassert_equal(i+1, arg,
76-
"Unexpected argument in the message");
77-
}
78-
}
79-
8067
if (cb->check_strdup) {
8168
zassert_false(cb->exp_strdup[cb->counter]
8269
^ log_is_strdup((void *)log_msg_arg_get(msg, 0)),
@@ -177,7 +164,7 @@ static void test_log_strdup_gc(void)
177164
{
178165
char test_str[] = "test string";
179166
char *dstr;
180-
uint32_t size_u0, size_u1, size_l0, size_l1;
167+
uint32_t size_u0, size_u1, size_cu0, size_cu1, size_l0, size_l1;
181168

182169
log_setup(false);
183170

@@ -189,6 +176,7 @@ static void test_log_strdup_gc(void)
189176

190177
size_l0 = log_get_strdup_longest_string();
191178
size_u0 = log_get_strdup_pool_utilization();
179+
size_cu0 = log_get_strdup_pool_current_utilization();
192180

193181
dstr = log_strdup(test_str);
194182
/* test if message freeing is not fooled by using value within strdup
@@ -207,6 +195,8 @@ static void test_log_strdup_gc(void)
207195
backend1_cb.exp_strdup[2] = true;
208196
LOG_INF("%s", log_strdup(test_str));
209197

198+
size_cu1 = log_get_strdup_pool_current_utilization();
199+
210200
while (log_process(false)) {
211201
}
212202

@@ -216,6 +206,8 @@ static void test_log_strdup_gc(void)
216206
size_u1 = log_get_strdup_pool_utilization();
217207
zassert_true(size_l1 > size_l0, "longest string size never changed");
218208
zassert_true(size_u1 > size_u0, "strdup pool utilization never changed");
209+
zassert_true(size_cu1 > size_cu0,
210+
"strdup pool current utilization never changed");
219211
}
220212

221213
#define DETECT_STRDUP_MISSED(str, do_strdup, ...) \

tests/subsys/logging/log_core_additional/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.20.0)
44
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
55
project(log_core_additional)
66

7-
if(CONFIG_TEST_USERSPACE)
7+
if(${USERSPACE_TEST})
88
target_sources(app PRIVATE src/log_test_user.c)
99
else()
1010
target_sources(app PRIVATE src/log_test.c)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CONFIG_MAIN_THREAD_PRIORITY=5
2+
CONFIG_ZTEST=y
3+
CONFIG_TEST_USERSPACE=y
4+
CONFIG_TEST_LOGGING_DEFAULTS=n
5+
CONFIG_LOG=y
6+
CONFIG_LOG2_MODE_DEFERRED=y
7+
CONFIG_LOG_PRINTK=n
8+
CONFIG_LOG_SPEED=y
9+
CONFIG_LOG_BUFFER_SIZE=1024
10+
CONFIG_CBPRINTF_FP_SUPPORT=y
11+
CONFIG_CBPRINTF_LIBC_SUBSTS=y
12+
CONFIG_ZTEST_STACKSIZE=4096
13+
CONFIG_LOG_PROCESS_THREAD=n
14+
15+
CONFIG_MPSC_CLEAR_ALLOCATED=y
16+
CONFIG_LOG_BACKEND_UART=y

tests/subsys/logging/log_core_additional/log_user.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ CONFIG_THREAD_MONITOR=y
1010
CONFIG_LOG_PRINTK=y
1111
CONFIG_LOG_BLOCK_IN_THREAD=y
1212
CONFIG_MAIN_STACK_SIZE=1024
13+
CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=1000000

tests/subsys/logging/log_core_additional/prj.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ CONFIG_LOG_RUNTIME_FILTERING=y
66
CONFIG_LOG_BACKEND_UART=y
77
CONFIG_LOG_PROCESS_TRIGGER_THRESHOLD=0
88
CONFIG_THREAD_MONITOR=y
9+
CONFIG_LOG_MODE_DEFERRED=y
10+
CONFIG_MEM_SLAB_TRACE_MAX_UTILIZATION=y

0 commit comments

Comments
 (0)