tests: Update tests to use new k_pipe API

Update tests to use the reworked k_pipe API.

Signed-off-by: Måns Ansgariusson <Mansgariusson@gmail.com>
This commit is contained in:
Måns Ansgariusson 2024-12-31 20:31:43 +01:00 committed by Benjamin Cabé
commit 0572f1f098
14 changed files with 29 additions and 61 deletions

View file

@ -16,9 +16,6 @@ CONFIG_CBPRINTF_FP_SUPPORT=y
# Can only run under 1 CPU # Can only run under 1 CPU
CONFIG_MP_MAX_NUM_CPUS=1 CONFIG_MP_MAX_NUM_CPUS=1
# Enable pipes
CONFIG_PIPES=y
CONFIG_APPLICATION_DEFINED_SYSCALL=y CONFIG_APPLICATION_DEFINED_SYSCALL=y
CONFIG_TIMING_FUNCTIONS=y CONFIG_TIMING_FUNCTIONS=y

View file

@ -16,9 +16,6 @@ CONFIG_CBPRINTF_FP_SUPPORT=y
# Can only run under 1 CPU # Can only run under 1 CPU
CONFIG_MP_MAX_NUM_CPUS=1 CONFIG_MP_MAX_NUM_CPUS=1
# Enable pipes
CONFIG_PIPES=y
CONFIG_APPLICATION_DEFINED_SYSCALL=y CONFIG_APPLICATION_DEFINED_SYSCALL=y
CONFIG_TIMING_FUNCTIONS=y CONFIG_TIMING_FUNCTIONS=y
CONFIG_USERSPACE=y CONFIG_USERSPACE=y

View file

@ -23,7 +23,7 @@
BENCH_BMEM char msg[MAX_MSG]; BENCH_BMEM char msg[MAX_MSG];
BENCH_BMEM char data_bench[MESSAGE_SIZE]; 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]; BENCH_BMEM char sline[SLINE_LEN + 1];
/* /*
@ -70,7 +70,6 @@ K_MBOX_DEFINE(MAILB1);
K_MUTEX_DEFINE(DEMO_MUTEX); K_MUTEX_DEFINE(DEMO_MUTEX);
K_PIPE_DEFINE(PIPE_NOBUFF, 0, 4);
K_PIPE_DEFINE(PIPE_SMALLBUFF, 256, 4); K_PIPE_DEFINE(PIPE_SMALLBUFF, 256, 4);
K_PIPE_DEFINE(PIPE_BIGBUFF, 4096, 4); K_PIPE_DEFINE(PIPE_BIGBUFF, 4096, 4);
@ -188,7 +187,7 @@ int main(void)
k_thread_access_grant(&recv_thread, &DEMOQX1, &DEMOQX4, &DEMOQX192, k_thread_access_grant(&recv_thread, &DEMOQX1, &DEMOQX4, &DEMOQX192,
&MB_COMM, &CH_COMM, &SEM0, &SEM1, &SEM2, &SEM3, &MB_COMM, &CH_COMM, &SEM0, &SEM1, &SEM2, &SEM3,
&SEM4, &STARTRCV, &DEMO_MUTEX, &SEM4, &STARTRCV, &DEMO_MUTEX,
&PIPE_NOBUFF, &PIPE_SMALLBUFF, &PIPE_BIGBUFF); &PIPE_SMALLBUFF, &PIPE_BIGBUFF);
k_thread_start(&recv_thread); k_thread_start(&recv_thread);
k_thread_start(&test_thread); k_thread_start(&test_thread);
@ -212,7 +211,7 @@ int main(void)
k_thread_access_grant(&test_thread, &DEMOQX1, &DEMOQX4, &DEMOQX192, k_thread_access_grant(&test_thread, &DEMOQX1, &DEMOQX4, &DEMOQX192,
&MB_COMM, &CH_COMM, &SEM0, &SEM1, &SEM2, &SEM3, &MB_COMM, &CH_COMM, &SEM0, &SEM1, &SEM2, &SEM3,
&SEM4, &STARTRCV, &DEMO_MUTEX, &SEM4, &STARTRCV, &DEMO_MUTEX,
&PIPE_NOBUFF, &PIPE_SMALLBUFF, &PIPE_BIGBUFF); &PIPE_SMALLBUFF, &PIPE_BIGBUFF);
k_thread_start(&recv_thread); k_thread_start(&recv_thread);
k_thread_start(&test_thread); k_thread_start(&test_thread);
@ -236,11 +235,11 @@ int main(void)
k_thread_access_grant(&test_thread, &DEMOQX1, &DEMOQX4, &DEMOQX192, k_thread_access_grant(&test_thread, &DEMOQX1, &DEMOQX4, &DEMOQX192,
&MB_COMM, &CH_COMM, &SEM0, &SEM1, &SEM2, &SEM3, &MB_COMM, &CH_COMM, &SEM0, &SEM1, &SEM2, &SEM3,
&SEM4, &STARTRCV, &DEMO_MUTEX, &SEM4, &STARTRCV, &DEMO_MUTEX,
&PIPE_NOBUFF, &PIPE_SMALLBUFF, &PIPE_BIGBUFF); &PIPE_SMALLBUFF, &PIPE_BIGBUFF);
k_thread_access_grant(&recv_thread, &DEMOQX1, &DEMOQX4, &DEMOQX192, k_thread_access_grant(&recv_thread, &DEMOQX1, &DEMOQX4, &DEMOQX192,
&MB_COMM, &CH_COMM, &SEM0, &SEM1, &SEM2, &SEM3, &MB_COMM, &CH_COMM, &SEM0, &SEM1, &SEM2, &SEM3,
&SEM4, &STARTRCV, &DEMO_MUTEX, &SEM4, &STARTRCV, &DEMO_MUTEX,
&PIPE_NOBUFF, &PIPE_SMALLBUFF, &PIPE_BIGBUFF); &PIPE_SMALLBUFF, &PIPE_BIGBUFF);
k_thread_start(&recv_thread); k_thread_start(&recv_thread);
k_thread_start(&test_thread); k_thread_start(&test_thread);

View file

@ -90,7 +90,7 @@ void pipe_test(void)
PRINT_STRING(dashline); PRINT_STRING(dashline);
for (putsize = 8U; putsize <= MESSAGE_SIZE_PIPE; putsize <<= 1) { 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; putcount = NR_OF_PIPE_RUNS;
pipeput(test_pipes[pipe], _ALL_N, putsize, putcount, pipeput(test_pipes[pipe], _ALL_N, putsize, putcount,
&puttime[pipe]); &puttime[pipe]);
@ -125,7 +125,7 @@ void pipe_test(void)
for (putsize = 8U; putsize <= (MESSAGE_SIZE_PIPE); putsize <<= 1) { for (putsize = 8U; putsize <= (MESSAGE_SIZE_PIPE); putsize <<= 1) {
putcount = MESSAGE_SIZE_PIPE / putsize; 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, pipeput(test_pipes[pipe], _1_TO_N, putsize,
putcount, &puttime[pipe]); putcount, &puttime[pipe]);
/* size*count == MESSAGE_SIZE_PIPE */ /* size*count == MESSAGE_SIZE_PIPE */
@ -171,16 +171,10 @@ int pipeput(struct k_pipe *pipe,
for (i = 0; option == _1_TO_N || (i < count); i++) { for (i = 0; option == _1_TO_N || (i < count); i++) {
size_t sizexferd = 0; size_t sizexferd = 0;
size_t size2xfer = MIN(size, size2xfer_total - sizexferd_total); size_t size2xfer = MIN(size, size2xfer_total - sizexferd_total);
int ret;
size_t mim_num_of_bytes = 0;
if (option == _ALL_N) { sizexferd = k_pipe_write(pipe, data_bench, size2xfer, K_FOREVER);
mim_num_of_bytes = size2xfer;
}
ret = k_pipe_put(pipe, data_bench, size2xfer,
&sizexferd, mim_num_of_bytes, K_FOREVER);
if (ret != 0) { if (sizexferd < 0) {
return 1; return 1;
} }
if (option == _ALL_N && sizexferd != size2xfer) { if (option == _ALL_N && sizexferd != size2xfer) {

View file

@ -36,7 +36,7 @@ void piperecvtask(void)
/* matching (ALL_N) */ /* matching (ALL_N) */
for (getsize = 8; getsize <= MESSAGE_SIZE_PIPE; getsize <<= 1) { 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; getcount = NR_OF_PIPE_RUNS;
pipeget(test_pipes[pipe], _ALL_N, getsize, pipeget(test_pipes[pipe], _ALL_N, getsize,
getcount, &gettime); getcount, &gettime);
@ -52,7 +52,7 @@ void piperecvtask(void)
/* non-matching (1_TO_N) */ /* non-matching (1_TO_N) */
for (getsize = (MESSAGE_SIZE_PIPE); getsize >= 8; getsize >>= 1) { for (getsize = (MESSAGE_SIZE_PIPE); getsize >= 8; getsize >>= 1) {
getcount = MESSAGE_SIZE_PIPE / getsize; getcount = MESSAGE_SIZE_PIPE / getsize;
for (pipe = 0; pipe < 3; pipe++) { for (pipe = 0; pipe < 2; pipe++) {
/* size*count == MESSAGE_SIZE_PIPE */ /* size*count == MESSAGE_SIZE_PIPE */
pipeget(test_pipes[pipe], _1_TO_N, pipeget(test_pipes[pipe], _1_TO_N,
getsize, getcount, &gettime); getsize, getcount, &gettime);
@ -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++) { for (i = 0; option == _1_TO_N || (i < count); i++) {
size_t sizexferd = 0; size_t sizexferd = 0;
size_t size2xfer = MIN(size, size2xfer_total - sizexferd_total); size_t size2xfer = MIN(size, size2xfer_total - sizexferd_total);
int ret;
ret = k_pipe_get(pipe, data_recv, size2xfer, sizexferd = k_pipe_read(pipe, data_recv, size2xfer, K_FOREVER);
&sizexferd, option, K_FOREVER); if (sizexferd < 0) {
if (ret != 0) {
return 1; return 1;
} }

View file

@ -4,4 +4,3 @@ CONFIG_ZTEST_STACK_SIZE=2048
CONFIG_MAX_THREAD_BYTES=4 CONFIG_MAX_THREAD_BYTES=4
CONFIG_TEST_USERSPACE=y CONFIG_TEST_USERSPACE=y
CONFIG_APPLICATION_DEFINED_SYSCALL=y CONFIG_APPLICATION_DEFINED_SYSCALL=y
CONFIG_PIPES=y

View file

@ -3,4 +3,3 @@ CONFIG_ZTEST=y
CONFIG_INIT_STACKS=y CONFIG_INIT_STACKS=y
CONFIG_APPLICATION_DEFINED_SYSCALL=y CONFIG_APPLICATION_DEFINED_SYSCALL=y
CONFIG_TEST_USERSPACE=y CONFIG_TEST_USERSPACE=y
CONFIG_PIPES=y

View file

@ -664,8 +664,6 @@ ZTEST(userspace, test_user_mode_enter)
/* Define and initialize pipe. */ /* Define and initialize pipe. */
K_PIPE_DEFINE(kpipe, PIPE_LEN, BYTES_TO_READ_WRITE); 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 * @brief Test to write to kobject using pipe
* *
@ -679,8 +677,7 @@ ZTEST_USER(userspace, test_write_kobject_user_pipe)
*/ */
set_fault(K_ERR_KERNEL_OOPS); set_fault(K_ERR_KERNEL_OOPS);
k_pipe_get(&kpipe, &test_revoke_sem, BYTES_TO_READ_WRITE, k_pipe_read(&kpipe, (uint8_t *)&test_revoke_sem, BYTES_TO_READ_WRITE, K_NO_WAIT);
&bytes_written_read, 1, K_NO_WAIT);
zassert_unreachable("System call memory write validation " zassert_unreachable("System call memory write validation "
"did not fault"); "did not fault");
@ -699,8 +696,7 @@ ZTEST_USER(userspace, test_read_kobject_user_pipe)
*/ */
set_fault(K_ERR_KERNEL_OOPS); set_fault(K_ERR_KERNEL_OOPS);
k_pipe_put(&kpipe, &test_revoke_sem, BYTES_TO_READ_WRITE, k_pipe_write(&kpipe, (uint8_t *)&test_revoke_sem, BYTES_TO_READ_WRITE, K_NO_WAIT);
&bytes_written_read, 1, K_NO_WAIT);
zassert_unreachable("System call memory read validation " zassert_unreachable("System call memory read validation "
"did not fault"); "did not fault");

View file

@ -3,4 +3,3 @@ CONFIG_IRQ_OFFLOAD=y
CONFIG_TEST_USERSPACE=y CONFIG_TEST_USERSPACE=y
CONFIG_MP_MAX_NUM_CPUS=1 CONFIG_MP_MAX_NUM_CPUS=1
CONFIG_ZTEST_FATAL_HOOK=y CONFIG_ZTEST_FATAL_HOOK=y
CONFIG_PIPES=y

View file

@ -1,5 +1,4 @@
CONFIG_ZTEST=y CONFIG_ZTEST=y
CONFIG_OBJ_CORE=y CONFIG_OBJ_CORE=y
CONFIG_EVENTS=y CONFIG_EVENTS=y
CONFIG_PIPES=y
CONFIG_SYS_MEM_BLOCKS=y CONFIG_SYS_MEM_BLOCKS=y

View file

@ -1,6 +1,5 @@
CONFIG_ZTEST=y CONFIG_ZTEST=y
CONFIG_OBJ_CORE=y CONFIG_OBJ_CORE=y
CONFIG_OBJ_CORE_STATS=y CONFIG_OBJ_CORE_STATS=y
CONFIG_PIPES=y
CONFIG_SCHED_THREAD_USAGE=y CONFIG_SCHED_THREAD_USAGE=y
CONFIG_SCHED_THREAD_USAGE_ANALYSIS=y CONFIG_SCHED_THREAD_USAGE_ANALYSIS=y

View file

@ -3,5 +3,4 @@ CONFIG_IRQ_OFFLOAD=y
CONFIG_TRACING=y CONFIG_TRACING=y
CONFIG_TRACING_OBJECT_TRACKING=y CONFIG_TRACING_OBJECT_TRACKING=y
CONFIG_TRACING_NONE=y CONFIG_TRACING_NONE=y
CONFIG_PIPES=y
CONFIG_EVENTS=y CONFIG_EVENTS=y

View file

@ -2,5 +2,4 @@ CONFIG_ZTEST=y
CONFIG_IRQ_OFFLOAD=y CONFIG_IRQ_OFFLOAD=y
CONFIG_TEST_USERSPACE=y CONFIG_TEST_USERSPACE=y
CONFIG_ZTEST_FATAL_HOOK=y CONFIG_ZTEST_FATAL_HOOK=y
CONFIG_PIPES=y
CONFIG_MAX_THREAD_BYTES=3 CONFIG_MAX_THREAD_BYTES=3

View file

@ -980,7 +980,6 @@ void sem_multiple_take_and_timeouts_helper(void *p1, void *p2, void *p3)
{ {
int timeout = POINTER_TO_INT(p1); int timeout = POINTER_TO_INT(p1);
int64_t start_ticks, end_ticks, diff_ticks; int64_t start_ticks, end_ticks, diff_ticks;
size_t bytes_written;
start_ticks = k_uptime_get(); start_ticks = k_uptime_get();
@ -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", "time mismatch - expected at least %d, got %lld",
timeout, diff_ticks); timeout, diff_ticks);
k_pipe_put(&timeout_info_pipe, &timeout, sizeof(int), k_pipe_write(&timeout_info_pipe, (uint8_t *)&timeout, sizeof(int), K_FOREVER);
&bytes_written, sizeof(int), K_FOREVER);
} }
@ -1011,10 +1009,9 @@ ZTEST(semaphore_1cpu, test_sem_multiple_take_and_timeouts)
} }
static uint32_t timeout; static uint32_t timeout;
size_t bytes_read;
k_sem_reset(&simple_sem); k_sem_reset(&simple_sem);
k_pipe_flush(&timeout_info_pipe); k_pipe_reset(&timeout_info_pipe);
/* Multiple threads timeout and the sequence in which it times out /* Multiple threads timeout and the sequence in which it times out
* is pushed into a pipe and checked later on. * is pushed into a pipe and checked later on.
@ -1028,8 +1025,7 @@ ZTEST(semaphore_1cpu, test_sem_multiple_take_and_timeouts)
} }
for (int i = 0; i < TOTAL_THREADS_WAITING; i++) { for (int i = 0; i < TOTAL_THREADS_WAITING; i++) {
k_pipe_get(&timeout_info_pipe, &timeout, sizeof(int), k_pipe_read(&timeout_info_pipe, (uint8_t *)&timeout, sizeof(int), K_FOREVER);
&bytes_read, sizeof(int), K_FOREVER);
zassert_equal(timeout, QSEC2MS(i + 1), zassert_equal(timeout, QSEC2MS(i + 1),
"timeout did not occur properly: %d != %d", "timeout did not occur properly: %d != %d",
timeout, QSEC2MS(i + 1)); timeout, QSEC2MS(i + 1));
@ -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) void sem_multi_take_timeout_diff_sem_helper(void *p1, void *p2, void *p3)
{ {
int rc;
int timeout = POINTER_TO_INT(p1); int timeout = POINTER_TO_INT(p1);
struct k_sem *sema = p2; struct k_sem *sema = p2;
int64_t start_ticks, end_ticks, diff_ticks; int64_t start_ticks, end_ticks, diff_ticks;
size_t bytes_written;
struct timeout_info info = { struct timeout_info info = {
.timeout = timeout, .timeout = timeout,
.sema = sema .sema = sema
@ -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", "time mismatch - expected at least %d, got %lld",
timeout, diff_ticks); timeout, diff_ticks);
k_pipe_put(&timeout_info_pipe, &info, sizeof(struct timeout_info), rc = k_pipe_write(&timeout_info_pipe, (uint8_t *)&info, sizeof(struct timeout_info),
&bytes_written, sizeof(struct timeout_info), K_FOREVER); K_FOREVER);
zassert_true(rc == sizeof(struct timeout_info),
"k_pipe_write failed: %d", rc);
} }
/** /**
@ -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) ZTEST(semaphore, test_sem_multi_take_timeout_diff_sem)
{ {
int rc;
if (IS_ENABLED(CONFIG_KERNEL_COHERENCE)) { if (IS_ENABLED(CONFIG_KERNEL_COHERENCE)) {
ztest_test_skip(); ztest_test_skip();
} }
size_t bytes_read;
struct timeout_info seq_info[] = { struct timeout_info seq_info[] = {
{ SEC2MS(2), &simple_sem }, { SEC2MS(2), &simple_sem },
{ SEC2MS(1), &multiple_thread_sem }, { SEC2MS(1), &multiple_thread_sem },
@ -1092,7 +1090,7 @@ ZTEST(semaphore, test_sem_multi_take_timeout_diff_sem)
k_sem_reset(&simple_sem); k_sem_reset(&simple_sem);
k_sem_reset(&multiple_thread_sem); k_sem_reset(&multiple_thread_sem);
k_pipe_flush(&timeout_info_pipe); k_pipe_reset(&timeout_info_pipe);
memset(&retrieved_info, 0, sizeof(struct timeout_info)); memset(&retrieved_info, 0, sizeof(struct timeout_info));
/* Multiple threads timeout on different semaphores and the sequence /* Multiple threads timeout on different semaphores and the sequence
@ -1108,13 +1106,10 @@ ZTEST(semaphore, test_sem_multi_take_timeout_diff_sem)
} }
for (int i = 0; i < TOTAL_THREADS_WAITING; i++) { for (int i = 0; i < TOTAL_THREADS_WAITING; i++) {
k_pipe_get(&timeout_info_pipe, rc = k_pipe_read(&timeout_info_pipe, (uint8_t *)&retrieved_info,
&retrieved_info, sizeof(struct timeout_info), K_FOREVER);
sizeof(struct timeout_info), zassert_true(rc == sizeof(struct timeout_info),
&bytes_read, "k_pipe_read failed: %d", rc);
sizeof(struct timeout_info),
K_FOREVER);
zassert_true(retrieved_info.timeout == SEC2MS(i + 1), zassert_true(retrieved_info.timeout == SEC2MS(i + 1),
"timeout did not occur properly"); "timeout did not occur properly");