Skip to content

Commit 3b576fc

Browse files
hakehuangnashif
authored andcommitted
tests: dma: fix loopback suspend and resume issue
update dma loop test to resolve call sequence issue, and avoid randum failure due to dma finished fast than the dma status check. which cause suspend fails. fixing zephyrproject-rtos#43739 Signed-off-by: Hake Huang <hake.huang@oss.nxp.com>
1 parent a5234f3 commit 3b576fc

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

tests/drivers/dma/loop_transfer/src/test_dma_loop.c

+15-11
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,12 @@ static __aligned(16) char rx_data[TRANSFER_LOOPS][RX_BUFF_SIZE] = { { 0 } };
5151
volatile uint8_t transfer_count;
5252
static struct dma_config dma_cfg = {0};
5353
static struct dma_block_config dma_block_cfg = {0};
54+
static int test_case_id;
5455

5556
static void test_transfer(const struct device *dev, uint32_t id)
5657
{
58+
int res = 0;
59+
5760
transfer_count++;
5861
if (transfer_count < TRANSFER_LOOPS) {
5962
dma_block_cfg.block_size = strlen(tx_data);
@@ -66,6 +69,16 @@ static void test_transfer(const struct device *dev, uint32_t id)
6669
zassert_false(dma_start(dev, id),
6770
"Not able to start next transfer %d",
6871
transfer_count + 1);
72+
if (test_case_id == 1) {
73+
res = dma_suspend(dev, id);
74+
if (res == -ENOSYS) {
75+
TC_PRINT("dma suspend not supported\n");
76+
dma_stop(dev, id);
77+
} else if (res != 0) {
78+
TC_PRINT("ERROR: suspend failed, channel %d, result %d\n", id, res);
79+
}
80+
test_case_id = 2;
81+
}
6982
}
7083
}
7184

@@ -90,6 +103,7 @@ static int test_loop(void)
90103
const struct device *dma;
91104
static int chan_id;
92105

106+
test_case_id = 0;
93107
TC_PRINT("DMA memory to memory transfer started on %s\n",
94108
DMA_DEVICE_NAME);
95109
TC_PRINT("Preparing DMA Controller\n");
@@ -176,6 +190,7 @@ static int test_loop_suspend_resume(void)
176190
static int chan_id;
177191
int res = 0;
178192

193+
test_case_id = 1;
179194
TC_PRINT("DMA memory to memory transfer started on %s\n",
180195
DMA_DEVICE_NAME);
181196
TC_PRINT("Preparing DMA Controller\n");
@@ -235,17 +250,6 @@ static int test_loop_suspend_resume(void)
235250
while (transfer_count == 0) {
236251
}
237252

238-
res = dma_suspend(dma, chan_id);
239-
TC_PRINT("Suspended transfers\n");
240-
if (res == -ENOSYS) {
241-
TC_PRINT("dma suspend not supported\n");
242-
dma_stop(dma, chan_id);
243-
return TC_PASS;
244-
} else if (res != 0) {
245-
TC_PRINT("ERROR: suspend failed, channel %d, result %d\n", chan_id, res);
246-
return TC_FAIL;
247-
}
248-
249253
TC_PRINT("Sleeping while suspended\n");
250254
k_sleep(K_MSEC(SLEEPTIME));
251255

0 commit comments

Comments
 (0)