Skip to content

Commit 3b29b9f

Browse files
cjwinklhoferkartben
authored andcommitted
tests: logging: restore userspace testing
Restore userspace testing that was removed with commit 'aa2b72d32af (tests: logging: remove userspace testing, 2024-04-10)' and reported in the issue #49213. For the tests running with threads in user space (with ZTEST_USER), the memory partitions are configured in the test-suite setup. Signed-off-by: Christoph Winklhofer <[email protected]>
1 parent 501f33e commit 3b29b9f

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

tests/subsys/logging/log_core_additional/log_user.conf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ CONFIG_TEST_LOGGING_DEFAULTS=n
55
CONFIG_LOG=y
66
CONFIG_LOG_OUTPUT=y
77
CONFIG_LOG_RUNTIME_FILTERING=y
8+
CONFIG_LOG_ALWAYS_RUNTIME=y
89
CONFIG_LOG_PROCESS_THREAD=n
910
CONFIG_LOG_PROCESS_TRIGGER_THRESHOLD=1
1011
CONFIG_THREAD_MONITOR=y
11-
CONFIG_LOG_PRINTK=y
12+
CONFIG_LOG_PRINTK=n
1213
CONFIG_LOG_BLOCK_IN_THREAD=y
1314
CONFIG_MAIN_STACK_SIZE=4096
15+
CONFIG_STACK_SENTINEL=n

tests/subsys/logging/log_core_additional/src/log_test.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <zephyr/logging/log.h>
2121
#include <zephyr/logging/log_output.h>
2222
#include <zephyr/sys/iterable_sections.h>
23+
#include <zephyr/sys/libc-hooks.h>
2324

2425
#define TEST_MESSAGE "test msg"
2526

@@ -33,6 +34,18 @@ ZTEST_BMEM uint32_t source_id;
3334
ZTEST_BMEM uint8_t domain, level;
3435
ZTEST_DMEM uint32_t msg_data = 0x1234;
3536

37+
/* Memory domain for tests with threads in user space (ZTEST_USER) */
38+
#if CONFIG_USERSPACE
39+
static struct k_mem_domain mem_domain;
40+
static struct k_mem_partition *mem_parts[] = {
41+
#if Z_LIBC_PARTITION_EXISTS
42+
&z_libc_partition,
43+
#endif
44+
&ztest_mem_partition,
45+
&k_log_partition
46+
};
47+
#endif
48+
3649
static uint8_t buf;
3750
static int char_out(uint8_t *data, size_t length, void *ctx)
3851
{
@@ -571,6 +584,12 @@ static void *test_log_core_additional_setup(void)
571584
#ifdef CONFIG_LOG_PROCESS_THREAD
572585
k_thread_foreach(promote_log_thread, NULL);
573586
#endif
587+
588+
#if CONFIG_USERSPACE
589+
/* Set memory domain for threads in user space */
590+
k_mem_domain_init(&mem_domain, ARRAY_SIZE(mem_parts), mem_parts);
591+
k_mem_domain_add_thread(&mem_domain, k_current_get());
592+
#endif
574593
return NULL;
575594
}
576595

tests/subsys/logging/log_core_additional/testcase.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,11 @@ tests:
1414
extra_args: CONF_FILE=log_thread.conf
1515
integration_platforms:
1616
- native_sim
17+
logging.log_user:
18+
tags: logging
19+
filter: CONFIG_USERSPACE
20+
extra_args:
21+
- CONF_FILE=log_user.conf
22+
- USERSPACE_TEST=1
23+
integration_platforms:
24+
- qemu_x86

0 commit comments

Comments
 (0)