tests/drivers/dma: loop_transfer: Use ztest harness
loop_transfer test was not using ztest framework as test harness. Fix it. Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
This commit is contained in:
parent
f729f82171
commit
d74dae2eaf
@ -1,4 +1,4 @@
|
||||
CONFIG_TEST=y
|
||||
CONFIG_ZTEST=y
|
||||
CONFIG_DMA=y
|
||||
CONFIG_LOG=y
|
||||
CONFIG_DMA_LOG_LEVEL_INF=y
|
||||
|
||||
18
tests/drivers/dma/loop_transfer/src/main.c
Normal file
18
tests/drivers/dma/loop_transfer/src/main.c
Normal file
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Linaro Limited
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
|
||||
#include <zephyr.h>
|
||||
#include <ztest.h>
|
||||
|
||||
extern void test_dma_m2m_loop(void);
|
||||
|
||||
void test_main(void)
|
||||
{
|
||||
ztest_test_suite(dma_m2m_loop_test,
|
||||
ztest_unit_test(test_dma_m2m_loop));
|
||||
ztest_run_test_suite(dma_m2m_loop_test);
|
||||
}
|
||||
@ -2,16 +2,30 @@
|
||||
|
||||
/*
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
* Copyright (c) 2021 Linaro Limited.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Verify zephyr dma memory to memory transfer loops
|
||||
* @details
|
||||
* - Test Steps
|
||||
* -# Set dma channel configuration including source/dest addr, burstlen
|
||||
* -# Set direction memory-to-memory
|
||||
* -# Start transfer
|
||||
* -# Move to next dest addr
|
||||
* -# Back to first step
|
||||
* - Expected Results
|
||||
* -# Data is transferred correctly from src to dest, for each loop
|
||||
*/
|
||||
|
||||
#include <zephyr.h>
|
||||
|
||||
#include <device.h>
|
||||
#include <drivers/dma.h>
|
||||
#include <sys/printk.h>
|
||||
#include <string.h>
|
||||
#include <ztest.h>
|
||||
|
||||
/* in millisecond */
|
||||
#define SLEEPTIME 1000
|
||||
@ -40,49 +54,45 @@ static struct dma_block_config dma_block_cfg = {0};
|
||||
|
||||
static void test_transfer(const struct device *dev, uint32_t id)
|
||||
{
|
||||
int ret;
|
||||
transfer_count++;
|
||||
if (transfer_count < TRANSFER_LOOPS) {
|
||||
dma_block_cfg.block_size = strlen(tx_data);
|
||||
dma_block_cfg.source_address = (uint32_t)tx_data;
|
||||
dma_block_cfg.dest_address = (uint32_t)rx_data[transfer_count];
|
||||
ret = dma_config(dev, id, &dma_cfg);
|
||||
if (ret == 0) {
|
||||
dma_start(dev, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void test_error(void)
|
||||
{
|
||||
printk("DMA could not proceed, an error occurred\n");
|
||||
zassert_false(dma_config(dev, id, &dma_cfg),
|
||||
"Not able to config transfer %d",
|
||||
transfer_count + 1);
|
||||
zassert_false(dma_start(dev, id),
|
||||
"Not able to start next transfer %d",
|
||||
transfer_count + 1);
|
||||
}
|
||||
}
|
||||
|
||||
static void dma_user_callback(const struct device *dma_dev, void *arg,
|
||||
uint32_t id, int error_code)
|
||||
{
|
||||
if (error_code == 0) {
|
||||
zassert_false(error_code, "DMA could not proceed, an error occurred\n");
|
||||
|
||||
#ifdef CONFIG_DMAMUX_STM32
|
||||
/* the channel is the DMAMUX's one
|
||||
* the device is the DMAMUX, given through
|
||||
* the stream->user_data by the dma_stm32_irq_handler */
|
||||
test_transfer((struct device *)arg, id);
|
||||
/* the channel is the DMAMUX's one
|
||||
* the device is the DMAMUX, given through
|
||||
* the stream->user_data by the dma_stm32_irq_handler
|
||||
*/
|
||||
test_transfer((struct device *)arg, id);
|
||||
#else
|
||||
test_transfer(dma_dev, id);
|
||||
test_transfer(dma_dev, id);
|
||||
#endif /* CONFIG_DMAMUX_STM32 */
|
||||
} else {
|
||||
test_error();
|
||||
}
|
||||
}
|
||||
|
||||
void main(void)
|
||||
static int test_loop(void)
|
||||
{
|
||||
const struct device *dma;
|
||||
static uint32_t chan_id;
|
||||
|
||||
printk("DMA memory to memory transfer started on %s\n",
|
||||
TC_PRINT("DMA memory to memory transfer started on %s\n",
|
||||
DMA_DEVICE_NAME);
|
||||
printk("Preparing DMA Controller\n");
|
||||
TC_PRINT("Preparing DMA Controller\n");
|
||||
|
||||
#if CONFIG_NOCACHE_MEMORY
|
||||
memset(tx_data, 0, sizeof(tx_data));
|
||||
@ -93,8 +103,8 @@ void main(void)
|
||||
|
||||
dma = device_get_binding(DMA_DEVICE_NAME);
|
||||
if (!dma) {
|
||||
printk("Cannot get dma controller\n");
|
||||
return;
|
||||
TC_PRINT("Cannot get dma controller\n");
|
||||
return TC_FAIL;
|
||||
}
|
||||
|
||||
dma_cfg.channel_direction = MEMORY_TO_MEMORY;
|
||||
@ -116,37 +126,48 @@ void main(void)
|
||||
#endif
|
||||
chan_id = CONFIG_DMA_LOOP_TRANSFER_CHANNEL_NR;
|
||||
transfer_count = 0;
|
||||
printk("Starting the transfer and waiting for 1 second\n");
|
||||
TC_PRINT("Starting the transfer and waiting for 1 second\n");
|
||||
dma_block_cfg.block_size = strlen(tx_data);
|
||||
dma_block_cfg.source_address = (uint32_t)tx_data;
|
||||
dma_block_cfg.dest_address = (uint32_t)rx_data[transfer_count];
|
||||
|
||||
if (dma_config(dma, chan_id, &dma_cfg)) {
|
||||
printk("ERROR: transfer config (%d)\n", chan_id);
|
||||
return;
|
||||
TC_PRINT("ERROR: transfer config (%d)\n", chan_id);
|
||||
return TC_FAIL;
|
||||
}
|
||||
|
||||
if (dma_start(dma, chan_id)) {
|
||||
printk("ERROR: transfer start (%d)\n", chan_id);
|
||||
return;
|
||||
TC_PRINT("ERROR: transfer start (%d)\n", chan_id);
|
||||
return TC_FAIL;
|
||||
}
|
||||
|
||||
k_sleep(K_MSEC(SLEEPTIME));
|
||||
|
||||
if (transfer_count < TRANSFER_LOOPS) {
|
||||
transfer_count = TRANSFER_LOOPS;
|
||||
printk("ERROR: unfinished transfer\n");
|
||||
TC_PRINT("ERROR: unfinished transfer\n");
|
||||
return TC_FAIL;
|
||||
if (dma_stop(dma, chan_id)) {
|
||||
printk("ERROR: transfer stop\n");
|
||||
TC_PRINT("ERROR: transfer stop\n");
|
||||
return TC_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
printk("Each RX buffer should contain the full TX buffer string.\n");
|
||||
printk("TX data: %s\n", tx_data);
|
||||
TC_PRINT("Each RX buffer should contain the full TX buffer string.\n");
|
||||
|
||||
for (int i = 0; i < TRANSFER_LOOPS; i++) {
|
||||
printk("RX data Loop %d: %s\n", i, rx_data[i]);
|
||||
TC_PRINT("RX data Loop %d: %s\n", i, rx_data[i]);
|
||||
if (strncmp(tx_data, rx_data[i], sizeof(rx_data[i])) != 0) {
|
||||
return TC_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
printk("Finished: DMA\n");
|
||||
TC_PRINT("Finished: DMA\n");
|
||||
return TC_PASS;
|
||||
}
|
||||
|
||||
/* export test cases */
|
||||
void test_dma_m2m_loop(void)
|
||||
{
|
||||
zassert_true((test_loop() == TC_PASS), NULL);
|
||||
}
|
||||
@ -2,18 +2,3 @@ tests:
|
||||
drivers.dma.loop_transfer:
|
||||
depends_on: dma
|
||||
tags: drivers dma
|
||||
harness: console
|
||||
harness_config:
|
||||
type: multi_line
|
||||
regex:
|
||||
- "DMA memory to memory transfer started on DMA_\\d"
|
||||
- "Preparing DMA Controller"
|
||||
- "Starting the transfer and waiting for 1 second"
|
||||
- "Each RX buffer should contain the full TX buffer string."
|
||||
- "TX data: The quick brown fox jumps over the lazy dog"
|
||||
- "RX data Loop 0: The quick brown fox jumps over the lazy dog"
|
||||
- "RX data Loop 1: The quick brown fox jumps over the lazy dog"
|
||||
- "RX data Loop 2: The quick brown fox jumps over the lazy dog"
|
||||
- "RX data Loop 3: The quick brown fox jumps over the lazy dog"
|
||||
- "RX data Loop 4: The quick brown fox jumps over the lazy dog"
|
||||
- "Finished: DMA"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user