Skip to content

Commit

Permalink
tests: Update tests to use new k_pipe API
Browse files Browse the repository at this point in the history
Update tests to use the reworked k_pipe API.

Signed-off-by: Måns Ansgariusson <[email protected]>
  • Loading branch information
Mattemagikern committed Jan 7, 2025
1 parent 52d6749 commit bc0eb3b
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 59 deletions.
3 changes: 0 additions & 3 deletions tests/benchmarks/app_kernel/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ CONFIG_CBPRINTF_FP_SUPPORT=y
# Can only run under 1 CPU
CONFIG_MP_MAX_NUM_CPUS=1

# Enable pipes
CONFIG_PIPES=y

CONFIG_APPLICATION_DEFINED_SYSCALL=y
CONFIG_TIMING_FUNCTIONS=y

Expand Down
3 changes: 0 additions & 3 deletions tests/benchmarks/app_kernel/prj_user.conf
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ CONFIG_CBPRINTF_FP_SUPPORT=y
# Can only run under 1 CPU
CONFIG_MP_MAX_NUM_CPUS=1

# Enable pipes
CONFIG_PIPES=y

CONFIG_APPLICATION_DEFINED_SYSCALL=y
CONFIG_TIMING_FUNCTIONS=y
CONFIG_USERSPACE=y
Expand Down
11 changes: 5 additions & 6 deletions tests/benchmarks/app_kernel/src/master.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
BENCH_BMEM char msg[MAX_MSG];
BENCH_BMEM char data_bench[MESSAGE_SIZE];

BENCH_DMEM struct k_pipe *test_pipes[] = {&PIPE_NOBUFF, &PIPE_SMALLBUFF, &PIPE_BIGBUFF};
BENCH_DMEM struct k_pipe *test_pipes[] = {&PIPE_SMALLBUFF, &PIPE_BIGBUFF};
BENCH_BMEM char sline[SLINE_LEN + 1];

/*
Expand Down Expand Up @@ -70,7 +70,6 @@ K_MBOX_DEFINE(MAILB1);

K_MUTEX_DEFINE(DEMO_MUTEX);

K_PIPE_DEFINE(PIPE_NOBUFF, 0, 4);
K_PIPE_DEFINE(PIPE_SMALLBUFF, 256, 4);
K_PIPE_DEFINE(PIPE_BIGBUFF, 4096, 4);

Expand Down Expand Up @@ -188,7 +187,7 @@ int main(void)
k_thread_access_grant(&recv_thread, &DEMOQX1, &DEMOQX4, &DEMOQX192,
&MB_COMM, &CH_COMM, &SEM0, &SEM1, &SEM2, &SEM3,
&SEM4, &STARTRCV, &DEMO_MUTEX,
&PIPE_NOBUFF, &PIPE_SMALLBUFF, &PIPE_BIGBUFF);
&PIPE_SMALLBUFF, &PIPE_BIGBUFF);

k_thread_start(&recv_thread);
k_thread_start(&test_thread);
Expand All @@ -212,7 +211,7 @@ int main(void)
k_thread_access_grant(&test_thread, &DEMOQX1, &DEMOQX4, &DEMOQX192,
&MB_COMM, &CH_COMM, &SEM0, &SEM1, &SEM2, &SEM3,
&SEM4, &STARTRCV, &DEMO_MUTEX,
&PIPE_NOBUFF, &PIPE_SMALLBUFF, &PIPE_BIGBUFF);
&PIPE_SMALLBUFF, &PIPE_BIGBUFF);

k_thread_start(&recv_thread);
k_thread_start(&test_thread);
Expand All @@ -236,11 +235,11 @@ int main(void)
k_thread_access_grant(&test_thread, &DEMOQX1, &DEMOQX4, &DEMOQX192,
&MB_COMM, &CH_COMM, &SEM0, &SEM1, &SEM2, &SEM3,
&SEM4, &STARTRCV, &DEMO_MUTEX,
&PIPE_NOBUFF, &PIPE_SMALLBUFF, &PIPE_BIGBUFF);
&PIPE_SMALLBUFF, &PIPE_BIGBUFF);
k_thread_access_grant(&recv_thread, &DEMOQX1, &DEMOQX4, &DEMOQX192,
&MB_COMM, &CH_COMM, &SEM0, &SEM1, &SEM2, &SEM3,
&SEM4, &STARTRCV, &DEMO_MUTEX,
&PIPE_NOBUFF, &PIPE_SMALLBUFF, &PIPE_BIGBUFF);
&PIPE_SMALLBUFF, &PIPE_BIGBUFF);

k_thread_start(&recv_thread);
k_thread_start(&test_thread);
Expand Down
14 changes: 4 additions & 10 deletions tests/benchmarks/app_kernel/src/pipe_b.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void pipe_test(void)
PRINT_STRING(dashline);

for (putsize = 8U; putsize <= MESSAGE_SIZE_PIPE; putsize <<= 1) {
for (pipe = 0; pipe < 3; pipe++) {
for (pipe = 0; pipe < 2; pipe++) {
putcount = NR_OF_PIPE_RUNS;
pipeput(test_pipes[pipe], _ALL_N, putsize, putcount,
&puttime[pipe]);
Expand Down Expand Up @@ -125,7 +125,7 @@ void pipe_test(void)

for (putsize = 8U; putsize <= (MESSAGE_SIZE_PIPE); putsize <<= 1) {
putcount = MESSAGE_SIZE_PIPE / putsize;
for (pipe = 0; pipe < 3; pipe++) {
for (pipe = 0; pipe < 2; pipe++) {
pipeput(test_pipes[pipe], _1_TO_N, putsize,
putcount, &puttime[pipe]);
/* size*count == MESSAGE_SIZE_PIPE */
Expand Down Expand Up @@ -171,16 +171,10 @@ int pipeput(struct k_pipe *pipe,
for (i = 0; option == _1_TO_N || (i < count); i++) {
size_t sizexferd = 0;
size_t size2xfer = MIN(size, size2xfer_total - sizexferd_total);
int ret;
size_t mim_num_of_bytes = 0;

if (option == _ALL_N) {
mim_num_of_bytes = size2xfer;
}
ret = k_pipe_put(pipe, data_bench, size2xfer,
&sizexferd, mim_num_of_bytes, K_FOREVER);
sizexferd = k_pipe_write(pipe, data_bench, size2xfer, K_FOREVER);

if (ret != 0) {
if (sizexferd < 0) {
return 1;
}
if (option == _ALL_N && sizexferd != size2xfer) {
Expand Down
11 changes: 4 additions & 7 deletions tests/benchmarks/app_kernel/src/pipe_r.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void piperecvtask(void)
/* matching (ALL_N) */

for (getsize = 8; getsize <= MESSAGE_SIZE_PIPE; getsize <<= 1) {
for (pipe = 0; pipe < 3; pipe++) {
for (pipe = 0; pipe < 2; pipe++) {
getcount = NR_OF_PIPE_RUNS;
pipeget(test_pipes[pipe], _ALL_N, getsize,
getcount, &gettime);
Expand All @@ -52,7 +52,7 @@ void piperecvtask(void)
/* non-matching (1_TO_N) */
for (getsize = (MESSAGE_SIZE_PIPE); getsize >= 8; getsize >>= 1) {
getcount = MESSAGE_SIZE_PIPE / getsize;
for (pipe = 0; pipe < 3; pipe++) {
for (pipe = 0; pipe < 2; pipe++) {
/* size*count == MESSAGE_SIZE_PIPE */
pipeget(test_pipes[pipe], _1_TO_N,
getsize, getcount, &gettime);
Expand Down Expand Up @@ -95,12 +95,9 @@ int pipeget(struct k_pipe *pipe, enum pipe_options option, int size, int count,
for (i = 0; option == _1_TO_N || (i < count); i++) {
size_t sizexferd = 0;
size_t size2xfer = MIN(size, size2xfer_total - sizexferd_total);
int ret;

ret = k_pipe_get(pipe, data_recv, size2xfer,
&sizexferd, option, K_FOREVER);

if (ret != 0) {
sizexferd = k_pipe_read(pipe, data_recv, size2xfer, K_FOREVER);
if (sizexferd < 0) {
return 1;
}

Expand Down
1 change: 0 additions & 1 deletion tests/kernel/mem_protect/mem_protect/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ CONFIG_ZTEST_STACK_SIZE=2048
CONFIG_MAX_THREAD_BYTES=4
CONFIG_TEST_USERSPACE=y
CONFIG_APPLICATION_DEFINED_SYSCALL=y
CONFIG_PIPES=y
1 change: 0 additions & 1 deletion tests/kernel/mem_protect/userspace/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ CONFIG_ZTEST=y
CONFIG_INIT_STACKS=y
CONFIG_APPLICATION_DEFINED_SYSCALL=y
CONFIG_TEST_USERSPACE=y
CONFIG_PIPES=y
8 changes: 2 additions & 6 deletions tests/kernel/mem_protect/userspace/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -664,8 +664,6 @@ ZTEST(userspace, test_user_mode_enter)

/* Define and initialize pipe. */
K_PIPE_DEFINE(kpipe, PIPE_LEN, BYTES_TO_READ_WRITE);
K_APP_BMEM(default_part) static size_t bytes_written_read;

/**
* @brief Test to write to kobject using pipe
*
Expand All @@ -679,8 +677,7 @@ ZTEST_USER(userspace, test_write_kobject_user_pipe)
*/
set_fault(K_ERR_KERNEL_OOPS);

k_pipe_get(&kpipe, &test_revoke_sem, BYTES_TO_READ_WRITE,
&bytes_written_read, 1, K_NO_WAIT);
k_pipe_read(&kpipe, (uint8_t *)&test_revoke_sem, BYTES_TO_READ_WRITE, K_NO_WAIT);

zassert_unreachable("System call memory write validation "
"did not fault");
Expand All @@ -699,8 +696,7 @@ ZTEST_USER(userspace, test_read_kobject_user_pipe)
*/
set_fault(K_ERR_KERNEL_OOPS);

k_pipe_put(&kpipe, &test_revoke_sem, BYTES_TO_READ_WRITE,
&bytes_written_read, 1, K_NO_WAIT);
k_pipe_write(&kpipe, (uint8_t *)&test_revoke_sem, BYTES_TO_READ_WRITE, K_NO_WAIT);

zassert_unreachable("System call memory read validation "
"did not fault");
Expand Down
1 change: 0 additions & 1 deletion tests/kernel/mutex/mutex_error_case/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ CONFIG_IRQ_OFFLOAD=y
CONFIG_TEST_USERSPACE=y
CONFIG_MP_MAX_NUM_CPUS=1
CONFIG_ZTEST_FATAL_HOOK=y
CONFIG_PIPES=y
1 change: 0 additions & 1 deletion tests/kernel/obj_core/obj_core/prj.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
CONFIG_ZTEST=y
CONFIG_OBJ_CORE=y
CONFIG_EVENTS=y
CONFIG_PIPES=y
CONFIG_SYS_MEM_BLOCKS=y
1 change: 0 additions & 1 deletion tests/kernel/obj_core/obj_core_stats_api/prj.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
CONFIG_ZTEST=y
CONFIG_OBJ_CORE=y
CONFIG_OBJ_CORE_STATS=y
CONFIG_PIPES=y
CONFIG_SCHED_THREAD_USAGE=y
CONFIG_SCHED_THREAD_USAGE_ANALYSIS=y
1 change: 0 additions & 1 deletion tests/kernel/obj_tracking/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ CONFIG_IRQ_OFFLOAD=y
CONFIG_TRACING=y
CONFIG_TRACING_OBJECT_TRACKING=y
CONFIG_TRACING_NONE=y
CONFIG_PIPES=y
CONFIG_EVENTS=y
1 change: 0 additions & 1 deletion tests/kernel/semaphore/semaphore/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ CONFIG_ZTEST=y
CONFIG_IRQ_OFFLOAD=y
CONFIG_TEST_USERSPACE=y
CONFIG_ZTEST_FATAL_HOOK=y
CONFIG_PIPES=y
CONFIG_MAX_THREAD_BYTES=3
29 changes: 12 additions & 17 deletions tests/kernel/semaphore/semaphore/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,6 @@ void sem_multiple_take_and_timeouts_helper(void *p1, void *p2, void *p3)
{
int timeout = POINTER_TO_INT(p1);
int64_t start_ticks, end_ticks, diff_ticks;
size_t bytes_written;

start_ticks = k_uptime_get();

Expand All @@ -994,8 +993,7 @@ void sem_multiple_take_and_timeouts_helper(void *p1, void *p2, void *p3)
"time mismatch - expected at least %d, got %lld",
timeout, diff_ticks);

k_pipe_put(&timeout_info_pipe, &timeout, sizeof(int),
&bytes_written, sizeof(int), K_FOREVER);
k_pipe_write(&timeout_info_pipe, (uint8_t *)&timeout, sizeof(int), K_FOREVER);

}

Expand All @@ -1011,7 +1009,6 @@ ZTEST(semaphore_1cpu, test_sem_multiple_take_and_timeouts)
}

static uint32_t timeout;
size_t bytes_read;

k_sem_reset(&simple_sem);
k_pipe_flush(&timeout_info_pipe);
Expand All @@ -1028,8 +1025,7 @@ ZTEST(semaphore_1cpu, test_sem_multiple_take_and_timeouts)
}

for (int i = 0; i < TOTAL_THREADS_WAITING; i++) {
k_pipe_get(&timeout_info_pipe, &timeout, sizeof(int),
&bytes_read, sizeof(int), K_FOREVER);
k_pipe_read(&timeout_info_pipe, (uint8_t *)&timeout, sizeof(int), K_FOREVER);
zassert_equal(timeout, QSEC2MS(i + 1),
"timeout did not occur properly: %d != %d",
timeout, QSEC2MS(i + 1));
Expand All @@ -1043,10 +1039,10 @@ ZTEST(semaphore_1cpu, test_sem_multiple_take_and_timeouts)

void sem_multi_take_timeout_diff_sem_helper(void *p1, void *p2, void *p3)
{
int rc;
int timeout = POINTER_TO_INT(p1);
struct k_sem *sema = p2;
int64_t start_ticks, end_ticks, diff_ticks;
size_t bytes_written;
struct timeout_info info = {
.timeout = timeout,
.sema = sema
Expand All @@ -1064,8 +1060,10 @@ void sem_multi_take_timeout_diff_sem_helper(void *p1, void *p2, void *p3)
"time mismatch - expected at least %d, got %lld",
timeout, diff_ticks);

k_pipe_put(&timeout_info_pipe, &info, sizeof(struct timeout_info),
&bytes_written, sizeof(struct timeout_info), K_FOREVER);
rc = k_pipe_write(&timeout_info_pipe, (uint8_t *)&info, sizeof(struct timeout_info),
K_FOREVER);
zassert_true(rc == sizeof(struct timeout_info),
"k_pipe_write failed: %d", rc);
}

/**
Expand All @@ -1075,11 +1073,11 @@ void sem_multi_take_timeout_diff_sem_helper(void *p1, void *p2, void *p3)
*/
ZTEST(semaphore, test_sem_multi_take_timeout_diff_sem)
{
int rc;
if (IS_ENABLED(CONFIG_KERNEL_COHERENCE)) {
ztest_test_skip();
}

size_t bytes_read;
struct timeout_info seq_info[] = {
{ SEC2MS(2), &simple_sem },
{ SEC2MS(1), &multiple_thread_sem },
Expand Down Expand Up @@ -1108,13 +1106,10 @@ ZTEST(semaphore, test_sem_multi_take_timeout_diff_sem)
}

for (int i = 0; i < TOTAL_THREADS_WAITING; i++) {
k_pipe_get(&timeout_info_pipe,
&retrieved_info,
sizeof(struct timeout_info),
&bytes_read,
sizeof(struct timeout_info),
K_FOREVER);

rc = k_pipe_read(&timeout_info_pipe, (uint8_t *)&retrieved_info,
sizeof(struct timeout_info), K_FOREVER);
zassert_true(rc == sizeof(struct timeout_info),
"k_pipe_read failed: %d", rc);

zassert_true(retrieved_info.timeout == SEC2MS(i + 1),
"timeout did not occur properly");
Expand Down

0 comments on commit bc0eb3b

Please sign in to comment.