Skip to content

Commit 8209c7f

Browse files
committed
Add server DMA allow list for pthread client-server test using file-scope DMA buffers
1 parent d75109a commit 8209c7f

1 file changed

Lines changed: 58 additions & 21 deletions

File tree

test/wh_test_clientserver.c

Lines changed: 58 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,31 @@ int whTest_ClientServerSequential(whTestNvmBackendType nvmType)
11621162
#endif /* WOLFHSM_CFG_ENABLE_CLIENT && WOLFHSM_CFG_ENABLE_SERVER */
11631163

11641164
#ifdef WOLFHSM_CFG_ENABLE_CLIENT
1165+
1166+
#ifdef WOLFHSM_CFG_DMA
1167+
/* File-scope buffers for the client-config DMA tests so the server thread's
1168+
* allow list can reference them */
1169+
static char _ccfg_send[WOLFHSM_CFG_COMM_DATA_LEN];
1170+
static char _ccfg_recv[WOLFHSM_CFG_COMM_DATA_LEN];
1171+
static whNvmMetadata _ccfg_meta;
1172+
static whServerDmaAddrAllowList _ccfg_dmaAllowList;
1173+
static whServerDmaConfig _ccfg_serverDmaConfig;
1174+
1175+
static void _initClientCfgDma(void)
1176+
{
1177+
memset(&_ccfg_dmaAllowList, 0, sizeof(_ccfg_dmaAllowList));
1178+
_ccfg_dmaAllowList.readList[0].addr = _ccfg_send;
1179+
_ccfg_dmaAllowList.readList[0].size = sizeof(_ccfg_send);
1180+
_ccfg_dmaAllowList.readList[1].addr = &_ccfg_meta;
1181+
_ccfg_dmaAllowList.readList[1].size = sizeof(_ccfg_meta);
1182+
_ccfg_dmaAllowList.writeList[0].addr = _ccfg_recv;
1183+
_ccfg_dmaAllowList.writeList[0].size = sizeof(_ccfg_recv);
1184+
1185+
memset(&_ccfg_serverDmaConfig, 0, sizeof(_ccfg_serverDmaConfig));
1186+
_ccfg_serverDmaConfig.dmaAddrAllowList = &_ccfg_dmaAllowList;
1187+
}
1188+
#endif /* WOLFHSM_CFG_DMA */
1189+
11651190
int whTest_ClientServerClientConfig(whClientConfig* clientCfg)
11661191
{
11671192
int ret = 0;
@@ -1170,8 +1195,15 @@ int whTest_ClientServerClientConfig(whClientConfig* clientCfg)
11701195
WH_TEST_RETURN_ON_FAIL(wh_Client_Init(client, clientCfg));
11711196

11721197
int counter = 1;
1173-
char recv_buffer[WOLFHSM_CFG_COMM_DATA_LEN] = {0};
1174-
char send_buffer[WOLFHSM_CFG_COMM_DATA_LEN] = {0};
1198+
#ifdef WOLFHSM_CFG_DMA
1199+
char* recv_buffer = _ccfg_recv;
1200+
char* send_buffer = _ccfg_send;
1201+
#else
1202+
char recv_buffer[WOLFHSM_CFG_COMM_DATA_LEN];
1203+
char send_buffer[WOLFHSM_CFG_COMM_DATA_LEN];
1204+
#endif
1205+
memset(recv_buffer, 0, WOLFHSM_CFG_COMM_DATA_LEN);
1206+
memset(send_buffer, 0, WOLFHSM_CFG_COMM_DATA_LEN);
11751207
uint16_t send_len = 0;
11761208
uint16_t recv_len = 0;
11771209

@@ -1354,17 +1386,15 @@ int whTest_ClientServerClientConfig(whClientConfig* clientCfg)
13541386

13551387
#ifdef WOLFHSM_CFG_DMA
13561388
/* Same writeback test, but with DMA.
1357-
* Note: this is a client-only test where the server runs separately,
1358-
* so we cannot register a DMA allow list here. The server must have
1359-
* its allow list configured externally. */
1389+
* Uses file-scope buffers so the server thread's DMA allow list can
1390+
* reference them (configured in wh_ClientServer_MemThreadTest). */
13601391
for (counter = 0; counter < 5; counter++) {
1361-
whNvmMetadata meta = {
1362-
.id = counter + 40,
1363-
.access = WH_NVM_ACCESS_ANY,
1364-
.flags = WH_NVM_FLAGS_NONE,
1365-
.len = 0,
1366-
.label = {0},
1367-
};
1392+
whNvmMetadata* meta = &_ccfg_meta;
1393+
memset(meta, 0, sizeof(*meta));
1394+
meta->id = counter + 40;
1395+
meta->access = WH_NVM_ACCESS_ANY;
1396+
meta->flags = WH_NVM_FLAGS_NONE;
1397+
meta->len = 0;
13681398
whNvmSize len = 0;
13691399

13701400
whNvmId gid = 0;
@@ -1375,16 +1405,16 @@ int whTest_ClientServerClientConfig(whClientConfig* clientCfg)
13751405

13761406
whNvmId lastAvailObjects = 0;
13771407

1378-
snprintf((char*)(meta.label), sizeof(meta.label), "Label:%d", meta.id);
1379-
len = snprintf(send_buffer, sizeof(send_buffer), "Data:%d Counter:%d",
1380-
meta.id, counter);
1408+
snprintf((char*)(meta->label), sizeof(meta->label), "Label:%d", meta->id);
1409+
len = snprintf(send_buffer, WOLFHSM_CFG_COMM_DATA_LEN,
1410+
"Data:%d Counter:%d", meta->id, counter);
13811411

13821412
lastAvailObjects = avail_objects;
13831413

1384-
WH_TEST_RETURN_ON_FAIL(ret = wh_Client_NvmAddObjectDma(client, &meta, len, (uint8_t*)send_buffer, &server_rc));
1414+
WH_TEST_RETURN_ON_FAIL(ret = wh_Client_NvmAddObjectDma(client, meta, len, (uint8_t*)send_buffer, &server_rc));
13851415

13861416
WH_TEST_PRINT("Client NvmAddObjectDma:%d, server_rc:%d, meta.len:%u\n",
1387-
ret, (int)server_rc, meta.len);
1417+
ret, (int)server_rc, meta->len);
13881418
WH_TEST_ASSERT_RETURN(server_rc == WH_ERROR_OK);
13891419

13901420
WH_TEST_RETURN_ON_FAIL(ret = wh_Client_NvmGetAvailable(client, &server_rc, &avail_size, &avail_objects, &reclaim_size, &reclaim_objects));
@@ -1395,20 +1425,20 @@ int whTest_ClientServerClientConfig(whClientConfig* clientCfg)
13951425
(int)reclaim_size, (int)reclaim_objects);
13961426
WH_TEST_ASSERT_RETURN(lastAvailObjects - 1 == avail_objects);
13971427

1398-
WH_TEST_RETURN_ON_FAIL(ret = wh_Client_NvmGetMetadata(client, meta.id, &server_rc, &gid, &gaccess, &gflags, &glen, sizeof(glabel), (uint8_t*)glabel));
1428+
WH_TEST_RETURN_ON_FAIL(ret = wh_Client_NvmGetMetadata(client, meta->id, &server_rc, &gid, &gaccess, &gflags, &glen, sizeof(glabel), (uint8_t*)glabel));
13991429

14001430
WH_TEST_PRINT("Client NvmGetMetadata:%d, id:%u, access:0x%x, "
14011431
"flags:0x%x, len:%u label:%s\n",
14021432
ret, (unsigned int)gid, (unsigned int)gaccess,
14031433
(unsigned int)gflags, (unsigned int)glen, glabel);
14041434

14051435
/* Ensure metadata matches that of the object we just wrote */
1406-
WH_TEST_ASSERT_RETURN(gid == meta.id);
1436+
WH_TEST_ASSERT_RETURN(gid == meta->id);
14071437

14081438

1409-
memset(recv_buffer, 0, sizeof(recv_buffer));
1439+
memset(recv_buffer, 0, WOLFHSM_CFG_COMM_DATA_LEN);
14101440
WH_TEST_RETURN_ON_FAIL(
1411-
ret = wh_Client_NvmReadDma(client, meta.id, 0, glen,
1441+
ret = wh_Client_NvmReadDma(client, meta->id, 0, glen,
14121442
(uint8_t*)recv_buffer, &server_rc));
14131443
WH_TEST_PRINT("Client NvmReadDma:%d, server_rc:%d id:%u, len:%u "
14141444
"data:%s\n",
@@ -1645,12 +1675,19 @@ static int wh_ClientServer_MemThreadTest(whTestNvmBackendType nvmType)
16451675
#endif
16461676

16471677

1678+
#ifdef WOLFHSM_CFG_DMA
1679+
_initClientCfgDma();
1680+
#endif
1681+
16481682
whServerConfig s_conf[1] = {{
16491683
.comm_config = cs_conf,
16501684
.nvm = nvm,
16511685
#ifndef WOLFHSM_CFG_NO_CRYPTO
16521686
.crypto = crypto,
16531687
.devId = INVALID_DEVID,
1688+
#endif
1689+
#ifdef WOLFHSM_CFG_DMA
1690+
.dmaConfig = &_ccfg_serverDmaConfig,
16541691
#endif
16551692
}};
16561693

0 commit comments

Comments
 (0)