Skip to content

Commit

Permalink
autotest: add enhanced DMA UAPI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pthierry-ledger committed Oct 9, 2024
1 parent 25bee75 commit 0843cd3
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 28 deletions.
83 changes: 66 additions & 17 deletions autotest/src/tests/test_dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,29 @@
// SPDX-License-Identifier: Apache-2.0

#include <inttypes.h>
#include <string.h>
#include <testlib/log.h>
#include <testlib/assert.h>
#include <uapi/uapi.h>
#include <uapi/dma.h>
#include <shms-dt.h>
#include "test_dma.h"

static taskh_t myself;

#if CONFIG_HAS_GPDMA
static void test_dma_get_handle(dmah_t* streamh)
static void test_dma_get_handle(dmah_t* d2mstreamh, dmah_t *m2mstreamh)
{
Status res;
TEST_START();
res = sys_get_dma_stream_handle(0x1);
copy_to_user((uint8_t*)streamh, sizeof(dmah_t));
copy_to_user((uint8_t*)d2mstreamh, sizeof(dmah_t));
ASSERT_EQ(res, STATUS_OK);
LOG("handle is %lx", *streamh);
LOG("handle is %lx", *d2mstreamh);
res = sys_get_dma_stream_handle(0x2);
copy_to_user((uint8_t*)m2mstreamh, sizeof(dmah_t));
ASSERT_EQ(res, STATUS_OK);
LOG("handle is %lx", *m2mstreamh);
TEST_END();
}

Expand All @@ -36,7 +42,6 @@ static void test_dma_start_stream(dmah_t stream)
{
Status res;
TEST_START();
/* not assigned */
res = sys_dma_start_stream(stream);
ASSERT_EQ(res, STATUS_INVALID);
res = sys_dma_assign_stream(stream);
Expand All @@ -57,7 +62,7 @@ static void test_dma_manipulate_stream_badhandle(void)
TEST_START();
res = sys_dma_start_stream(0);
ASSERT_EQ(res, STATUS_INVALID);
res = sys_dma_stop_stream(0);
res = sys_dma_suspend_stream(0);
ASSERT_EQ(res, STATUS_INVALID);
res = sys_dma_get_stream_status(0);
ASSERT_EQ(res, STATUS_INVALID);
Expand All @@ -77,10 +82,10 @@ static void test_dma_stop_stream(dmah_t stream)
{
Status res;
TEST_START();
res = sys_dma_stop_stream(stream);
res = sys_dma_suspend_stream(stream);
ASSERT_EQ(res, STATUS_OK);
res = sys_dma_unassign_stream(stream);
ASSERT_EQ(res, STATUS_OK);
res = sys_dma_stop_stream(stream);
ASSERT_EQ(res, STATUS_INVALID);
TEST_END();
}

Expand All @@ -102,13 +107,55 @@ static void test_dma_assign_unassign_stream(dmah_t stream)
static void test_dma_start_n_wait_stream(dmah_t stream)
{
Status res;
shmh_t shm1;
shm_infos_t shminfos1;
shmh_t shm2;
shm_infos_t shminfos2;
uint32_t perms = 0;
perms |= SHM_PERMISSION_WRITE;
perms |= SHM_PERMISSION_MAP;
int ret_builtin;
TEST_START();
res = sys_get_process_handle(0xbabeUL);
copy_to_user((uint8_t*)&myself, sizeof(taskh_t));
// preparing shm1 with content
res = sys_get_shm_handle(shms[0].id);
copy_to_user((uint8_t*)&shm1, sizeof(shmh_t));
ASSERT_EQ(res, STATUS_OK);
res = sys_shm_set_credential(shm1, myself, perms);
ASSERT_EQ(res, STATUS_OK);
res = sys_map_shm(shm1);
ASSERT_EQ(res, STATUS_OK);
res = sys_shm_get_infos(shm1);
copy_to_user((uint8_t*)&shminfos1, sizeof(shm_infos_t));
ASSERT_EQ(res, STATUS_OK);
memset((void*)shminfos1.base, 0xa5, 0x100UL);
// garbaging shm2
res = sys_get_shm_handle(shms[1].id);
copy_to_user((uint8_t*)&shm2, sizeof(shmh_t));
ASSERT_EQ(res, STATUS_OK);
res = sys_shm_set_credential(shm2, myself, perms);
ASSERT_EQ(res, STATUS_OK);
res = sys_map_shm(shm2);
ASSERT_EQ(res, STATUS_OK);
res = sys_shm_get_infos(shm2);
copy_to_user((uint8_t*)&shminfos2, sizeof(shm_infos_t));
ASSERT_EQ(res, STATUS_OK);
memset((void*)shminfos2.base, 0x42, 0x100UL);
// start stream
res = sys_dma_assign_stream(stream);
ASSERT_EQ(res, STATUS_OK);
res = sys_dma_start_stream(stream);
ASSERT_EQ(res, STATUS_OK);
/* wait 50ms for DMA event, should rise in the meantime */
res = sys_wait_for_event(EVENT_TYPE_DMA, 50);
res = sys_wait_for_event(EVENT_TYPE_DMA, -1);
ASSERT_EQ(res, STATUS_OK);
// compare shm1 with shm2
ret_builtin = memcmp((void*)shminfos1.base, (void*)shminfos2.base, 0x100);
ASSERT_EQ((uint32_t)ret_builtin, 0);
res = sys_dma_suspend_stream(stream);
ASSERT_EQ(res, STATUS_OK);
res = sys_dma_unassign_stream(stream);
ASSERT_EQ(res, STATUS_OK);
TEST_END();
}
Expand Down Expand Up @@ -149,18 +196,20 @@ static void test_dma_get_info(dmah_t stream)

void test_dma(void)
{
dmah_t stream = 0;
dmah_t d2mstream = 0;
dmah_t m2mstream = 0;
Status res;
TEST_SUITE_START("sys_dma");
#if CONFIG_HAS_GPDMA
test_dma_get_handle(&stream);
test_dma_get_handle(&d2mstream, &m2mstream);
test_dma_get_handle_inval();
test_dma_get_info(stream);
test_dma_get_info(d2mstream);
test_dma_manipulate_stream_badhandle();
test_dma_assign_unassign_stream(stream);
test_dma_start_n_wait_stream(stream);
test_dma_start_stream(stream);
test_dma_get_stream_status(stream);
test_dma_stop_stream(stream);
test_dma_assign_unassign_stream(m2mstream);
test_dma_start_n_wait_stream(m2mstream);
test_dma_start_stream(m2mstream);
test_dma_get_stream_status(m2mstream);
test_dma_stop_stream(m2mstream);
#endif
TEST_SUITE_END("sys_dma");
}
4 changes: 2 additions & 2 deletions autotest/src/tests/test_ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void test_ipc_sendrecv(void)
Status ret;
taskh_t handle = 0;
uint8_t data[CONFIG_SVC_EXCHANGE_AREA_LEN] = {0};
uint32_t timeout = 100UL; /* milisecond timeout */
int32_t timeout = 100L; /* milisecond timeout */
exchange_event_t *header;

ret = sys_get_process_handle(0xbabeUL);
Expand Down Expand Up @@ -75,7 +75,7 @@ void test_ipc_deadlock(void)
Status ret;
taskh_t handle = 0;
uint8_t data[CONFIG_SVC_EXCHANGE_AREA_LEN] = {0};
uint32_t timeout = 100UL; /* milisecond timeout */
int32_t timeout = 100L; /* milisecond timeout */
exchange_event_t *header;

ret = sys_get_process_handle(0xbabeUL);
Expand Down
22 changes: 20 additions & 2 deletions autotest/src/tests/test_shm.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
*/
#include <shms-dt.h>

static_assert(SHM_LIST_SIZE == 3, "invalid autotest SHM list");
static_assert(SHM_LIST_SIZE == 4, "invalid autotest SHM list");

#define SHM_MAP_DMAPOOL shms[0].id
#define SHM_NOMAP_DMAPOOL shms[1].id
#define SHM_MAP_NODMAPOOL shms[2].id
#define SHM_NOMAP_DMAPOOL shms[3].id

/* TODO: use generated instead */
#define SHM_MAP_DMAPOOL_BASEADDR shms[0].baseaddr
Expand Down Expand Up @@ -66,6 +66,23 @@ void test_shm_invalidmap(void) {
TEST_END();
}

void test_shm_mapdenied(void) {
Status res;
shmh_t shm;
uint32_t perms = 0;
perms |= SHM_PERMISSION_WRITE;
perms |= SHM_PERMISSION_MAP;
TEST_START();
res = sys_get_shm_handle(SHM_NOMAP_DMAPOOL);
copy_to_user((uint8_t*)&shm, sizeof(shmh_t));
ASSERT_EQ(res, STATUS_OK);
res = sys_shm_set_credential(shm, myself, perms);
ASSERT_EQ(res, STATUS_OK);
res = sys_map_shm(shm);
ASSERT_EQ(res, STATUS_DENIED);
TEST_END();
}

void test_shm_infos(void) {
Status res;
shmh_t shm;
Expand Down Expand Up @@ -204,6 +221,7 @@ void test_shm(void) {
test_shm_unmap_notmapped();
test_shm_mapunmap();
test_shm_map_unmappable();
test_shm_mapdenied();
test_shm_creds_on_mapped();
test_shm_infos();
test_shm_allows_idle();
Expand Down
2 changes: 1 addition & 1 deletion autotest/src/tests/test_signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void test_signal_sendrecv(void)
{
Status ret;
taskh_t handle = 0;
uint32_t timeout = 20UL;
int32_t timeout = 20UL;
uint8_t data[CONFIG_SVC_EXCHANGE_AREA_LEN] = {0};
exchange_event_t *header;

Expand Down
21 changes: 15 additions & 6 deletions dts/examples/nucleo_u5a5_autotest.dts
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,17 @@
shm_autotest_1: memory@2000a000 {
// mappable, dma allowed
reg = <0x2000a000 0x256>;
dma-pool;
outpost,shm;
dma-pool;
outpost,label = <0xf00>;
outpost,owner = <0xbabe>;
};

shm_autotest_2: memory@2000b000 {
// not mappable, dma allowed
// mappable, dma allowed
reg = <0x2000b000 0x100>;
outpost,shm;
dma-pool;
outpost,no-map;
outpost,label = <0xf01>;
outpost,owner = <0xbabe>;
};
Expand All @@ -67,6 +66,16 @@
outpost,label = <0xf02>;
outpost,owner = <0xbabe>;
};

shm_autotest_4: memory@2000b200 {
// not mappable, dma allowed
reg = <0x2000b200 0x100>;
outpost,shm;
dma-pool;
outpost,no-map;
outpost,label = <0xf03>;
outpost,owner = <0xbabe>;
};
};
dma-streams {
// device-to-memory DMA stream
Expand All @@ -79,7 +88,7 @@
dest = <&shm_autotest_1>;
length = <42>;
circular = <1 0>; // circular source, linear dest
outpost,label = <0x1>; // task-level unique identifier
outpost,label = <0x1>; // task-level unique DMA identifier
};
// memory-to-memory DMA stream
stream2 {
Expand All @@ -88,9 +97,9 @@
prio = <STM32_DMA_PRIORITY_HIGH>;
source = <&shm_autotest_1>;
dest = <&shm_autotest_2>;
length = <64>;
length = <0x100>;
// no circular, linear for both source and dest
outpost,label = <0x2>; // task-level unique identifier
outpost,label = <0x2>; // task-level unique DMA identifier
};
};
};
Expand Down

0 comments on commit 0843cd3

Please sign in to comment.