Skip to content

Commit a70314c

Browse files
author
Andrew Boie
committed
tests: convert to use app shared memory
CONFIG_APPLICATION_MEMORY was a stopgap feature that is being removed from the kernel. Convert tests and samples to use the application shared memory feature instead, in most cases using the domain set up by ztest. Signed-off-by: Andrew Boie <[email protected]>
1 parent 91d3064 commit a70314c

File tree

28 files changed

+87
-64
lines changed

28 files changed

+87
-64
lines changed

samples/userspace/shared_mem/prj.conf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
CONFIG_USERSPACE=y
2-
CONFIG_APPLICATION_MEMORY=n
32
CONFIG_APP_SHARED_MEM=y

tests/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ config TEST_USERSPACE
6262
depends on ARCH_HAS_USERSPACE
6363
depends on TEST
6464
select USERSPACE
65-
select APPLICATION_MEMORY
65+
select APP_SHARED_MEM
6666
select DYNAMIC_OBJECTS
6767
default y
6868
help

tests/benchmarks/timing_info/src/userspace_bench.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
#include <tc_util.h>
1515
#include <ksched.h>
1616
#include "timing_info.h"
17+
#include <app_memory/app_memdomain.h>
1718

19+
K_APPMEM_PARTITION_DEFINE(bench_ptn);
20+
struct k_mem_domain bench_domain;
1821

1922
extern char sline[256];
2023
extern u64_t __end_drop_to_usermode_time;
@@ -50,14 +53,20 @@ void validation_overhead(void);
5053

5154
void userspace_bench(void)
5255
{
56+
struct k_mem_partition *parts[] = {
57+
&bench_ptn
58+
};
59+
60+
k_mem_domain_init(&bench_domain, ARRAY_SIZE(parts), parts);
61+
k_mem_domain_add_thread(&bench_domain, k_current_get());
62+
5363
drop_to_user_mode();
5464

5565
user_thread_creation();
5666

5767
syscall_overhead();
5868

5969
validation_overhead();
60-
6170
}
6271
/******************************************************************************/
6372

@@ -146,7 +155,8 @@ void user_thread_creation(void)
146155

147156
/******************************************************************************/
148157
/* dummy syscalls creation */
149-
u32_t syscall_overhead_start_time, syscall_overhead_end_time;
158+
K_APP_BMEM(bench_ptn) u32_t syscall_overhead_start_time,
159+
syscall_overhead_end_time;
150160

151161
int _impl_k_dummy_syscall(void)
152162
{
@@ -235,7 +245,6 @@ void validation_overhead_user_thread(void *p1, void *p2, void *p3)
235245

236246
void validation_overhead(void)
237247
{
238-
239248
k_thread_access_grant(k_current_get(), &test_sema);
240249

241250

tests/kernel/mem_pool/sys_mem_pool/src/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
#define BLK_SIZE_EXCLUDE_DESC (BLK_SIZE_MIN - 16)
2020
#define BLK_ALIGN BLK_SIZE_MIN
2121

22-
2322
K_MUTEX_DEFINE(pool_mutex);
23+
2424
SYS_MEM_POOL_DEFINE(pool, &pool_mutex, BLK_SIZE_MIN, BLK_SIZE_MAX,
25-
BLK_NUM_MAX, BLK_ALIGN, .data);
25+
BLK_NUM_MAX, BLK_ALIGN, ZTEST_SECTION);
2626

2727
/**
2828
* @brief Verify sys_mem_pool allocation and free

tests/kernel/mem_protect/mem_protect/src/common.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ K_SEM_DEFINE(barrier_sem,
1717
SYNC_BARRIER_SEMAPHORE_INIT_COUNT,
1818
SYNC_BARRIER_SEMAPHORE_MAX_COUNT);
1919

20-
bool valid_fault;
20+
ZTEST_BMEM bool valid_fault;
2121

2222
void _SysFatalErrorHandler(unsigned int reason, const NANO_ESF *pEsf)
2323
{
24-
printk("Caught system error -- reason %d\n", reason);
24+
printk("Caught system error -- reason %d %d\n", reason, valid_fault);
2525
if (valid_fault) {
2626
valid_fault = false; /* reset back to normal */
2727
ztest_test_pass();

tests/kernel/mem_protect/mem_protect/src/inherit.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ K_MEM_PARTITION_DEFINE(inherit_memory_partition,
3232
K_MEM_PARTITION_P_RW_U_RW);
3333

3434
struct k_mem_partition *inherit_memory_partition_array[] = {
35-
&inherit_memory_partition
35+
&inherit_memory_partition,
36+
&ztest_mem_partition
3637
};
3738

3839
__kernel struct k_mem_domain inherit_mem_domain;
@@ -78,11 +79,11 @@ void test_thread_1_for_SU(void *p1, void *p2, void *p3)
7879
*/
7980
void test_permission_inheritance(void *p1, void *p2, void *p3)
8081
{
81-
8282
k_mem_domain_init(&inherit_mem_domain,
83-
1,
83+
ARRAY_SIZE(inherit_memory_partition_array),
8484
inherit_memory_partition_array);
8585

86+
k_mem_domain_remove_thread(k_current_get());
8687
k_mem_domain_add_thread(&inherit_mem_domain, k_current_get());
8788

8889
k_thread_access_grant(k_current_get(),

tests/kernel/mem_protect/mem_protect/src/kobject.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
#include "mem_protect.h"
8+
#include <syscall_handler.h>
89

910
/* Kernel objects */
1011
K_THREAD_STACK_DEFINE(kobject_stack_1, KOBJECT_STACK_SIZE);
@@ -434,11 +435,8 @@ void test_kobject_access_grant_to_invalid_thread(void *p1, void *p2, void *p3)
434435
k_object_access_revoke(&kobject_sem,
435436
&kobject_test_10_tid_uninitialized);
436437

437-
/* Test if this has actually taken the required branch */
438-
extern void *_k_object_find(void *object);
439-
void *ret_value = _k_object_find(&kobject_test_10_tid_uninitialized);
440-
441-
if (ret_value == NULL) {
438+
if (Z_SYSCALL_OBJ(&kobject_test_10_tid_uninitialized, K_OBJ_THREAD)
439+
!= 0) {
442440
ztest_test_pass();
443441
} else {
444442
zassert_unreachable(ERROR_STR_TEST_10);

tests/kernel/mem_protect/mem_protect/src/mem_domain.c

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@ K_MEM_PARTITION_DEFINE(mem_domain_memory_partition1,
5151
#endif
5252

5353
struct k_mem_partition *mem_domain_memory_partition_array[] = {
54-
&mem_domain_memory_partition
54+
&mem_domain_memory_partition,
55+
&ztest_mem_partition
5556
};
5657

5758
struct k_mem_partition *mem_domain_memory_partition_array1[] = {
58-
&mem_domain_memory_partition1
59+
&mem_domain_memory_partition1,
60+
&ztest_mem_partition
5961
};
6062
__kernel struct k_mem_domain mem_domain_mem_domain;
6163
__kernel struct k_mem_domain mem_domain1;
@@ -65,7 +67,7 @@ __kernel struct k_mem_domain mem_domain1;
6567
static inline void mem_domain_init(void)
6668
{
6769
k_mem_domain_init(&mem_domain_mem_domain,
68-
MEM_PARTITION_INIT_NUM,
70+
ARRAY_SIZE(mem_domain_memory_partition_array),
6971
mem_domain_memory_partition_array);
7072
}
7173

@@ -104,6 +106,7 @@ void mem_domain_test_1(void *tc_number, void *p2, void *p3)
104106
{
105107
if ((u32_t)tc_number == 1) {
106108
mem_domain_buf[0] = 10U;
109+
k_mem_domain_remove_thread(k_current_get());
107110
k_mem_domain_add_thread(&mem_domain_mem_domain,
108111
k_current_get());
109112
}
@@ -187,9 +190,10 @@ void test_mem_domain_partitions_user_rw(void)
187190
{
188191
/* Initialize the memory domain */
189192
k_mem_domain_init(&mem_domain_mem_domain,
190-
MEM_PARTITION_INIT_NUM,
193+
ARRAY_SIZE(mem_domain_memory_partition_array),
191194
mem_domain_memory_partition_array);
192195

196+
k_mem_domain_remove_thread(k_current_get());
193197
k_mem_domain_add_thread(&mem_domain_mem_domain,
194198
k_current_get());
195199

@@ -229,8 +233,9 @@ void test_mem_domain_partitions_user_ro(void)
229233
* with read only access privilege
230234
*/
231235
k_mem_domain_init(&mem_domain1,
232-
MEM_PARTITION_INIT_NUM,
236+
ARRAY_SIZE(mem_domain_memory_partition_array1),
233237
mem_domain_memory_partition_array1);
238+
k_mem_domain_remove_thread(k_current_get());
234239

235240
k_mem_domain_add_thread(&mem_domain1, k_current_get());
236241

@@ -246,8 +251,9 @@ void test_mem_domain_partitions_user_ro(void)
246251
void test_mem_domain_partitions_supervisor_rw(void)
247252
{
248253
k_mem_domain_init(&mem_domain_mem_domain,
249-
MEM_PARTITION_INIT_NUM,
254+
ARRAY_SIZE(mem_domain_memory_partition_array1),
250255
mem_domain_memory_partition_array1);
256+
k_mem_domain_remove_thread(k_current_get());
251257

252258
k_mem_domain_add_thread(&mem_domain_mem_domain, k_current_get());
253259

@@ -304,6 +310,7 @@ K_MEM_PARTITION_DEFINE(mem_domain_tc3_part8_struct,
304310

305311

306312
struct k_mem_partition *mem_domain_tc3_partition_array[] = {
313+
&ztest_mem_partition,
307314
&mem_domain_tc3_part1_struct,
308315
&mem_domain_tc3_part2_struct,
309316
&mem_domain_tc3_part3_struct,
@@ -352,6 +359,8 @@ void test_mem_domain_add_partitions_invalid(void *p1, void *p2, void *p3)
352359
u8_t max_partitions = (u8_t)_arch_mem_domain_max_partitions_get() - 1;
353360
u8_t index;
354361

362+
k_mem_domain_remove_thread(k_current_get());
363+
355364
mem_domain_init();
356365
k_mem_domain_init(&mem_domain_tc3_mem_domain,
357366
1,
@@ -425,6 +434,7 @@ void test_mem_domain_add_partitions_simple(void *p1, void *p2, void *p3)
425434

426435
}
427436

437+
k_mem_domain_remove_thread(k_current_get());
428438
k_mem_domain_add_thread(&mem_domain_tc3_mem_domain,
429439
k_current_get());
430440

@@ -456,6 +466,7 @@ void mem_domain_for_user_tc5(void *p1, void *p2, void *p3)
456466
*/
457467
void test_mem_domain_remove_partitions_simple(void *p1, void *p2, void *p3)
458468
{
469+
k_mem_domain_remove_thread(k_current_get());
459470
k_mem_domain_add_thread(&mem_domain_tc3_mem_domain,
460471
k_current_get());
461472

@@ -499,7 +510,7 @@ void mem_domain_test_6_2(void *p1, void *p2, void *p3)
499510
*/
500511
void test_mem_domain_remove_partitions(void *p1, void *p2, void *p3)
501512
{
502-
513+
k_mem_domain_remove_thread(k_current_get());
503514
k_mem_domain_add_thread(&mem_domain_tc3_mem_domain,
504515
k_current_get());
505516

@@ -552,13 +563,14 @@ void mem_domain_for_user_tc7(void *p1, void *p2, void *p3)
552563
*/
553564
void test_mem_domain_remove_thread(void *p1, void *p2, void *p3)
554565
{
566+
k_mem_domain_remove_thread(k_current_get());
555567

556568
k_mem_domain_add_thread(&mem_domain_tc3_mem_domain,
557569
k_current_get());
558570

559571

560572
k_mem_domain_remove_thread(k_current_get());
561-
573+
k_mem_domain_add_thread(&ztest_mem_domain, k_current_get());
562574

563575
k_thread_user_mode_enter(mem_domain_for_user_tc7,
564576
NULL, NULL, NULL);
@@ -575,8 +587,9 @@ void test_mem_domain_remove_thread(void *p1, void *p2, void *p3)
575587
void test_mem_domain_destroy(void)
576588
{
577589
k_mem_domain_init(&mem_domain1,
578-
MEM_PARTITION_INIT_NUM,
590+
ARRAY_SIZE(mem_domain_memory_partition_array1),
579591
mem_domain_memory_partition_array1);
592+
k_mem_domain_remove_thread(k_current_get());
580593

581594
k_mem_domain_add_thread(&mem_domain1, k_current_get());
582595

tests/kernel/mem_protect/syscalls/src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
__kernel char kernel_string[BUF_SIZE];
1515
__kernel char kernel_buf[BUF_SIZE];
16-
char user_string[BUF_SIZE];
16+
ZTEST_BMEM char user_string[BUF_SIZE];
1717

1818
size_t _impl_string_nlen(char *src, size_t maxlen, int *err)
1919
{
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
11
CONFIG_ZTEST=y
2-
CONFIG_TEST_USERSPACE=n
3-
CONFIG_USERSPACE=y
4-
CONFIG_APPLICATION_MEMORY=n
5-
CONFIG_APP_SHARED_MEM=y

tests/kernel/mem_protect/userspace/src/main.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,9 +687,11 @@ extern k_thread_stack_t ztest_thread_stack[];
687687

688688
void test_main(void)
689689
{
690-
struct k_mem_partition *parts[] = {&part0, &part1};
690+
struct k_mem_partition *parts[] = {&part0, &part1,
691+
&ztest_mem_partition};
691692

692-
k_mem_domain_init(&dom0, 2, parts);
693+
k_mem_domain_remove_thread(k_current_get());
694+
k_mem_domain_init(&dom0, ARRAY_SIZE(parts), parts);
693695
k_mem_domain_add_thread(&dom0, k_current_get());
694696

695697
#if defined(CONFIG_ARM)

tests/kernel/msgq/msgq_api/src/test_msgq_attrs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
#include "test_msgq.h"
88
extern struct k_msgq msgq;
9-
static char __aligned(4) tbuffer[MSG_SIZE * MSGQ_LEN];
10-
static u32_t send_buf[MSGQ_LEN] = { MSG0, MSG1 };
11-
static u32_t rec_buf[MSGQ_LEN] = { MSG0, MSG1 };
9+
static ZTEST_BMEM char __aligned(4) tbuffer[MSG_SIZE * MSGQ_LEN];
10+
static ZTEST_DMEM u32_t send_buf[MSGQ_LEN] = { MSG0, MSG1 };
11+
static ZTEST_DMEM u32_t rec_buf[MSGQ_LEN] = { MSG0, MSG1 };
1212

1313
static void attrs_get(struct k_msgq *q)
1414
{

tests/kernel/msgq/msgq_api/src/test_msgq_contexts.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ K_THREAD_STACK_DEFINE(tstack2, STACK_SIZE);
1717
__kernel struct k_thread tdata;
1818
__kernel struct k_thread tdata1;
1919
__kernel struct k_thread tdata2;
20-
static char __aligned(4) tbuffer[MSG_SIZE * MSGQ_LEN];
21-
static char __aligned(4) tbuffer1[MSG_SIZE];
22-
static u32_t data[MSGQ_LEN] = { MSG0, MSG1 };
20+
static ZTEST_BMEM char __aligned(4) tbuffer[MSG_SIZE * MSGQ_LEN];
21+
static ZTEST_DMEM char __aligned(4) tbuffer1[MSG_SIZE];
22+
static ZTEST_DMEM u32_t data[MSGQ_LEN] = { MSG0, MSG1 };
2323
__kernel struct k_sem end_sema;
2424

2525
static void put_msgq(struct k_msgq *pmsgq)

tests/kernel/msgq/msgq_api/src/test_msgq_fail.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
*/
66
#include "test_msgq.h"
77

8-
static char __aligned(4) tbuffer[MSG_SIZE * MSGQ_LEN];
9-
static u32_t data[MSGQ_LEN] = { MSG0, MSG1 };
8+
static ZTEST_BMEM char __aligned(4) tbuffer[MSG_SIZE * MSGQ_LEN];
9+
static ZTEST_DMEM u32_t data[MSGQ_LEN] = { MSG0, MSG1 };
1010
extern struct k_msgq msgq;
1111

1212
static void put_fail(struct k_msgq *q)

tests/kernel/msgq/msgq_api/src/test_msgq_purge.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
K_THREAD_STACK_EXTERN(tstack);
1010
extern struct k_thread tdata;
1111
extern struct k_msgq msgq;
12-
static char __aligned(4) tbuffer[MSG_SIZE * MSGQ_LEN];
13-
static u32_t data[MSGQ_LEN] = { MSG0, MSG1 };
12+
static ZTEST_BMEM char __aligned(4) tbuffer[MSG_SIZE * MSGQ_LEN];
13+
static ZTEST_DMEM u32_t data[MSGQ_LEN] = { MSG0, MSG1 };
1414

1515
static void tThread_entry(void *p1, void *p2, void *p3)
1616
{

tests/kernel/mutex/mutex/src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151

5252
#define STACKSIZE 512
5353

54-
static int tc_rc = TC_PASS; /* test case return code */
54+
static ZTEST_DMEM int tc_rc = TC_PASS; /* test case return code */
5555

5656
K_MUTEX_DEFINE(private_mutex);
5757

tests/kernel/pipe/pipe/src/test_pipe.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ K_SEM_DEFINE(sync_sem, 0, 1);
1919
K_SEM_DEFINE(multiple_send_sem, 0, 1);
2020

2121

22-
u8_t tx_buffer[PIPE_SIZE];
23-
u8_t rx_buffer[PIPE_SIZE];
22+
ZTEST_BMEM u8_t tx_buffer[PIPE_SIZE];
23+
ZTEST_BMEM u8_t rx_buffer[PIPE_SIZE];
2424

2525
#define TOTAL_ELEMENTS (sizeof(single_elements) / sizeof(struct pipe_sequence))
2626
#define TOTAL_WAIT_ELEMENTS (sizeof(wait_elements) / \
@@ -674,7 +674,7 @@ void pipe_put_get_timeout(void)
674674
}
675675

676676
/******************************************************************************/
677-
bool valid_fault;
677+
ZTEST_BMEM bool valid_fault;
678678
void _SysFatalErrorHandler(unsigned int reason, const NANO_ESF *pEsf)
679679
{
680680
printk("Caught system error -- reason %d\n", reason);

tests/kernel/pipe/pipe_api/src/test_pipe_contexts.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#define BYTES_TO_READ BYTES_TO_WRITE
1313
K_MEM_POOL_DEFINE(mpool, BYTES_TO_WRITE, PIPE_LEN, 1, BYTES_TO_WRITE);
1414

15-
static unsigned char __aligned(4) data[] = "abcd1234$%^&PIPE";
15+
static ZTEST_DMEM unsigned char __aligned(4) data[] = "abcd1234$%^&PIPE";
1616
/**TESTPOINT: init via K_PIPE_DEFINE*/
1717
K_PIPE_DEFINE(kpipe, PIPE_LEN, 4);
1818
K_PIPE_DEFINE(khalfpipe, (PIPE_LEN / 2), 4);

tests/kernel/pipe/pipe_api/src/test_pipe_fail.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#define TIMEOUT 100
1111
#define PIPE_LEN 8
1212

13-
static unsigned char __aligned(4) data[] = "abcd1234";
13+
static ZTEST_DMEM unsigned char __aligned(4) data[] = "abcd1234";
1414

1515
__kernel struct k_pipe put_get_pipe;
1616

0 commit comments

Comments
 (0)