[serial_v2]串口设备框架serial_v2在utest下的testcases补充 (#8079)
This commit is contained in:
parent
ad9cbf3e51
commit
f79ae29c70
|
@ -10,6 +10,10 @@
|
|||
| uart_rxb_txnb.c | 串口接收阻塞和发送非阻塞模式 的测试用例 |
|
||||
| uart_rxnb_txb.c | 串口接收非阻塞和发送阻塞模式 的测试用例 |
|
||||
| uart_rxnb_txnb.c | 串口接收非阻塞和发送非阻塞模式 的测试用例 |
|
||||
| uart_blocking_tx.c| 串口阻塞发送模式 的测试 |
|
||||
| uart_blocking_rx.c| 串口阻塞接收模式 的测试 |
|
||||
| uart_nonblocking_tx.c| 串口非阻塞发送模式 的测试 |
|
||||
| uart_nonblocking_rx.c | 串口非阻塞接收模式 的测试 |
|
||||
|
||||
## 3、软硬件环境
|
||||
|
||||
|
@ -75,11 +79,37 @@
|
|||
|
||||
### 4.2 测试思路
|
||||
|
||||
这四个测试用例的测试思路基本一致。
|
||||
前四个测试用例的测试思路:
|
||||
|
||||
硬件上:**短接串口的发送TX引脚和接收RX引脚,完成自发自收的回路**。
|
||||
>硬件上:**短接串口的发送TX引脚和接收RX引脚,完成自发自收的回路**。
|
||||
>
|
||||
>软件上:创建两个线程A和B,A为接收线程,B为发送线程,设置A线程优先级比B线程优先级高。发送线程发送随机长度(长度范围是 0 到 1000)的数据,接收线程接收到数据进行校验,数据正确则测试通过,默认测试100次。
|
||||
|
||||
软件上:创建两个线程A和B,A为接收线程,B为发送线程,设置A线程优先级比B线程优先级高。发送线程发送随机长度(长度范围是 0 到 1000)的数据,接收线程接收到数据进行校验,数据正确则测试通过,默认测试100次。
|
||||
后四个测试用例的测试思路:
|
||||
|
||||
>硬件上: **不需要将TX,RX引脚进行短接**,每次只针对发送或接收中的一种进行测试,更为简单与直接
|
||||
>
|
||||
>软件上: 四个样例每次仅测试TX/RX中的一种引脚与一种对应的阻塞/非阻塞模式
|
||||
>四种测试模式具体分为:
|
||||
>>阻塞接收模式----(硬件工作模式可选: 轮询, 中断, DMA)
|
||||
>>阻塞发送模式----(硬件工作模式可选: 轮询, 中断, DMA)
|
||||
>>非阻塞接收模式--(硬件工作模式可选: 中断, DMA)
|
||||
>>非阻塞发送模式--(硬件工作模式可选: 中断, DMA)
|
||||
>
|
||||
>其中阻塞或非阻塞背后的具体硬件工作模式选择(如 轮询, 中断, DMA)需要对`rtconfig.h`文件做出配置,具体配置流程可见文章中关于
|
||||
[seril_v2硬件工作模式的选择](https://club.rt-thread.org/ask/article/b4c536303c8e2335.html "serial_v2源码分析")一节.
|
||||
>
|
||||
>发送测试流程 :
|
||||
>>1. 先关闭串口,再以需要测试的模式打开.
|
||||
>>2. 然后依次发送 UART_SEND_TIMES(默认为400) * 1024, 8, 32, 128, 512, 1024个数据.
|
||||
>>3. 发送的同时记录每次发送所耗费的时钟周期与成功发送的数据数量.
|
||||
>>3. 打印记录的数据,通过时钟周期来反应发送效率, 通过成功发送的数据量来反应是否产生丢包问题.
|
||||
>
|
||||
>接收测试流程 :
|
||||
>>1. 先关闭串口,再以需要测试的模式打开.
|
||||
>>2. 然后以此接收 256, 256, 256, 128, 128, 共计1024个数据
|
||||
>>3. 接收的同时记录成功接收的数据数量
|
||||
>>4. 打印记录的数据, 通过现实成功接收的数据量与串口发送的数据量做对比,来验证是否出现丢包问题
|
||||
|
||||
## 5、配置
|
||||
|
||||
|
@ -104,6 +134,14 @@ RT-Thread Utestcases --->
|
|||
|
||||
\- 在 MSH 中输入 `utest_run testcases.drivers.uart_rxb_txb` 运行串口接收阻塞和发送阻塞测试用例。
|
||||
|
||||
\- 在 MSH 中输入 `utest_run testcases.drivers.uart_blocking_tx` 运行串口阻塞发送测试
|
||||
|
||||
\- 在 MSH 中输入 `utest_run testcases.drivers.uart_blocking_rx` 运行串口阻塞接收测试
|
||||
|
||||
\- 在 MSH 中输入 `utest_run testcases.drivers.uart_nonblocking_tx` 运行串口非阻塞发送测试
|
||||
|
||||
\- 在 MSH 中输入 `utest_run testcases.drivers.uart_nonblocking_rx` 运行串口非阻塞接收测试
|
||||
|
||||
如果仅仅配置了 `Serial testcase` 相关的测试用例,则直接输入 `utest_run` 运行即可将上述测试用例按序测试。
|
||||
|
||||
## 7、注意事项
|
||||
|
|
|
@ -7,6 +7,10 @@ uart_rxb_txnb.c
|
|||
uart_rxb_txb.c
|
||||
uart_rxnb_txb.c
|
||||
uart_rxnb_txnb.c
|
||||
uart_blocking_rx.c
|
||||
uart_blocking_tx.c
|
||||
uart_nonblocking_rx.c
|
||||
uart_nonblocking_tx.c
|
||||
''')
|
||||
|
||||
CPPPATH = [cwd]
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
#include "utest.h"
|
||||
|
||||
#define SERIAL_UART_NAME "uart2"
|
||||
|
||||
#ifdef UTEST_SERIAL_TC
|
||||
|
||||
static rt_bool_t block_read(rt_device_t uart_dev)
|
||||
{
|
||||
rt_size_t total_length, recv_length;
|
||||
rt_uint8_t uart_read_buffer[1024], log_buffer[64];
|
||||
|
||||
/* make sure device is closed and reopen it */
|
||||
while(rt_device_close(uart_dev) != -RT_ERROR);
|
||||
rt_device_open(uart_dev, RT_DEVICE_FLAG_TX_BLOCKING | RT_DEVICE_FLAG_RX_BLOCKING);
|
||||
|
||||
rt_sprintf(log_buffer, "\nBLOCKING READ BEGIN, PLEASE SEND SOME DATAS\n");
|
||||
rt_device_write(uart_dev, 0, log_buffer, rt_strlen(log_buffer));
|
||||
|
||||
total_length = 0;
|
||||
recv_length = 0;
|
||||
recv_length = rt_device_read(uart_dev, -1, uart_read_buffer, 256);
|
||||
total_length += recv_length;
|
||||
|
||||
rt_sprintf(log_buffer, "\nblock : %d bytes read, total: %d \n", recv_length, total_length);
|
||||
rt_device_write(uart_dev, 0, log_buffer, rt_strlen(log_buffer));
|
||||
|
||||
recv_length = 0;
|
||||
recv_length = rt_device_read(uart_dev, -1, uart_read_buffer, 256);
|
||||
total_length += recv_length;
|
||||
|
||||
rt_sprintf(log_buffer, "\nblock : %d bytes read , total: %d \n", recv_length, total_length);
|
||||
rt_device_write(uart_dev, 0, log_buffer, rt_strlen(log_buffer));
|
||||
|
||||
recv_length = 0;
|
||||
recv_length = rt_device_read(uart_dev, -1, uart_read_buffer, 256);
|
||||
total_length += recv_length;
|
||||
|
||||
rt_sprintf(log_buffer, "\nblock : %d bytes read , total: %d \n", recv_length, total_length);
|
||||
rt_device_write(uart_dev, 0, log_buffer, rt_strlen(log_buffer));
|
||||
|
||||
recv_length = 0;
|
||||
recv_length = rt_device_read(uart_dev, -1, uart_read_buffer, 128);
|
||||
total_length += recv_length;
|
||||
|
||||
rt_sprintf(log_buffer, "\nblock : %d bytes read , total: %d \n", recv_length, total_length);
|
||||
rt_device_write(uart_dev, 0, log_buffer, rt_strlen(log_buffer));
|
||||
|
||||
recv_length = 0;
|
||||
recv_length = rt_device_read(uart_dev, -1, uart_read_buffer, 128);
|
||||
total_length += recv_length;
|
||||
|
||||
rt_sprintf(log_buffer, "\nblock : %d bytes read , total: %d \n", recv_length, total_length);
|
||||
rt_device_write(uart_dev, 0, log_buffer, rt_strlen(log_buffer));
|
||||
rt_thread_mdelay(1000);
|
||||
|
||||
rt_sprintf(log_buffer, "BLOCKING READ END");
|
||||
rt_device_write(uart_dev, 0, log_buffer, rt_strlen(log_buffer));
|
||||
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
static void uart_test_blocking_rx(void)
|
||||
{
|
||||
rt_device_t uart_dev;
|
||||
uart_dev = rt_device_find(SERIAL_UART_NAME);
|
||||
uassert_not_null(uart_dev);
|
||||
|
||||
uassert_true (block_read(uart_dev));
|
||||
}
|
||||
|
||||
static rt_err_t utest_tc_init(void)
|
||||
{
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_err_t utest_tc_cleanup(void)
|
||||
{
|
||||
rt_device_t uart_dev;
|
||||
uart_dev = rt_device_find(SERIAL_UART_NAME);
|
||||
while(rt_device_close(uart_dev) != -RT_ERROR);
|
||||
rt_device_open(uart_dev, RT_DEVICE_FLAG_TX_BLOCKING | RT_DEVICE_FLAG_TX_BLOCKING);
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(uart_test_blocking_rx);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "uart_blocking_rx", utest_tc_init, utest_tc_cleanup, 10);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,118 @@
|
|||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
#include "utest.h"
|
||||
|
||||
#define SERIAL_UART_NAME "uart2"
|
||||
#define UART_SEND_TIMES 400
|
||||
#define UART_TEST_NUMBER 6
|
||||
|
||||
#ifdef UTEST_SERIAL_TC
|
||||
|
||||
static rt_bool_t block_write(rt_device_t uart_dev)
|
||||
{
|
||||
rt_size_t i, wr_sz, index, write_num_array[UART_TEST_NUMBER], total_write_num[UART_TEST_NUMBER];
|
||||
rt_tick_t tick1, tick2, tick_array[UART_TEST_NUMBER];
|
||||
rt_uint8_t uart_write_buffer[1024];
|
||||
|
||||
for (i = 0; i < 1024; i++)
|
||||
uart_write_buffer[i] = '0' + (i % 49);
|
||||
|
||||
/* make sure device is closed and reopen it */
|
||||
while(rt_device_close(uart_dev) != -RT_ERROR);
|
||||
rt_device_open(uart_dev, RT_DEVICE_FLAG_TX_BLOCKING);
|
||||
|
||||
LOG_D("\nBLOCKING WRITE BEGIN\n");
|
||||
rt_thread_mdelay(2000);
|
||||
|
||||
index = 0;
|
||||
wr_sz = 0;
|
||||
tick1 = rt_tick_get();
|
||||
for(i = 0; i < UART_SEND_TIMES; i++)
|
||||
wr_sz += rt_device_write(uart_dev, 0, uart_write_buffer, 1024);
|
||||
|
||||
tick2 = rt_tick_get();
|
||||
total_write_num[index] = UART_SEND_TIMES * 1024;
|
||||
tick_array[index] = tick2 - tick1;
|
||||
write_num_array[index++] = wr_sz;
|
||||
|
||||
wr_sz = 0;
|
||||
tick1 = rt_tick_get();
|
||||
wr_sz += rt_device_write(uart_dev, 0, uart_write_buffer, 8);
|
||||
tick2 = rt_tick_get();
|
||||
total_write_num[index] = 8;
|
||||
tick_array[index] = tick2 - tick1;
|
||||
write_num_array[index++] = wr_sz;
|
||||
|
||||
wr_sz = 0;
|
||||
tick1 = rt_tick_get();
|
||||
wr_sz += rt_device_write(uart_dev, 0, uart_write_buffer, 32);
|
||||
tick2 = rt_tick_get();
|
||||
total_write_num[index] = 32;
|
||||
tick_array[index] = tick2 - tick1;
|
||||
write_num_array[index++] = wr_sz;
|
||||
|
||||
wr_sz = 0;
|
||||
tick1 = rt_tick_get();
|
||||
wr_sz += rt_device_write(uart_dev, 0, uart_write_buffer, 128);
|
||||
tick2 = rt_tick_get();
|
||||
total_write_num[index] = 128;
|
||||
tick_array[index] = tick2 - tick1;
|
||||
write_num_array[index++] = wr_sz;
|
||||
|
||||
wr_sz = 0;
|
||||
tick1 = rt_tick_get();
|
||||
wr_sz += rt_device_write(uart_dev, 0, uart_write_buffer, 512);
|
||||
tick2 = rt_tick_get();
|
||||
total_write_num[index] = 512;
|
||||
tick_array[index] = tick2 - tick1;
|
||||
write_num_array[index++] = wr_sz;
|
||||
|
||||
wr_sz = 0;
|
||||
tick1 = rt_tick_get();
|
||||
wr_sz += rt_device_write(uart_dev, 0, uart_write_buffer, 1024);
|
||||
tick2 = rt_tick_get();
|
||||
total_write_num[index] = 1024;
|
||||
tick_array[index] = tick2 - tick1;
|
||||
write_num_array[index++] = wr_sz;
|
||||
|
||||
rt_thread_mdelay(1000);
|
||||
LOG_D("\nBLOCKING_TX END\n");
|
||||
for(i = 0; i < index; i++)
|
||||
{
|
||||
LOG_D("\nBLOCKING_MODE : write %d / %d bytes in %d ticks\n", write_num_array[i], total_write_num[i], tick_array[i]);
|
||||
rt_thread_mdelay(1000);
|
||||
}
|
||||
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
static void uart_test_blocking_tx(void)
|
||||
{
|
||||
rt_device_t uart_dev;
|
||||
uart_dev = rt_device_find(SERIAL_UART_NAME);
|
||||
uassert_not_null(uart_dev);
|
||||
|
||||
uassert_true (block_write(uart_dev));
|
||||
}
|
||||
|
||||
static rt_err_t utest_tc_init(void)
|
||||
{
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_err_t utest_tc_cleanup(void)
|
||||
{
|
||||
rt_device_t uart_dev;
|
||||
uart_dev = rt_device_find(SERIAL_UART_NAME);
|
||||
while(rt_device_close(uart_dev) != -RT_ERROR);
|
||||
rt_device_open(uart_dev, RT_DEVICE_FLAG_TX_BLOCKING | RT_DEVICE_FLAG_TX_BLOCKING);
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(uart_test_blocking_tx);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "uart_blocking_tx", utest_tc_init, utest_tc_cleanup, 10);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,107 @@
|
|||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
#include "utest.h"
|
||||
|
||||
#define SERIAL_UART_NAME "uart2"
|
||||
|
||||
#ifdef UTEST_SERIAL_TC
|
||||
|
||||
static rt_bool_t nonblock_read(rt_device_t uart_dev)
|
||||
{
|
||||
rt_size_t total_length, recv_length;
|
||||
rt_uint8_t uart_read_buffer[1024], log_buffer[64];
|
||||
|
||||
/* make sure device is closed and reopen it */
|
||||
while(rt_device_close(uart_dev) != -RT_ERROR);
|
||||
rt_device_open(uart_dev, RT_DEVICE_FLAG_TX_BLOCKING | RT_DEVICE_FLAG_RX_NON_BLOCKING);
|
||||
|
||||
rt_sprintf(log_buffer, "\nNONBLOCKING READ BEGIN, PLEASE SEND SOME DATAS\n");
|
||||
rt_device_write(uart_dev, 0, log_buffer, rt_strlen(log_buffer));
|
||||
|
||||
total_length = 0;
|
||||
rt_device_write(uart_dev, 0, "5\n", 2);
|
||||
recv_length = 0;
|
||||
recv_length = rt_device_read(uart_dev, -1, uart_read_buffer, 256);
|
||||
rt_device_write(uart_dev, 0, uart_read_buffer, 256);
|
||||
total_length += recv_length;
|
||||
rt_thread_mdelay(1000);
|
||||
|
||||
rt_sprintf(log_buffer, "\nnonblock : %d bytes read, total: %d \n", recv_length, total_length);
|
||||
rt_device_write(uart_dev, 0, log_buffer, rt_strlen(log_buffer));
|
||||
|
||||
rt_device_write(uart_dev, 0, "4\n", 2);
|
||||
recv_length = 0;
|
||||
recv_length = rt_device_read(uart_dev, -1, uart_read_buffer, 256);
|
||||
rt_device_write(uart_dev, 0, uart_read_buffer, 256);
|
||||
total_length += recv_length;
|
||||
rt_thread_mdelay(1000);
|
||||
|
||||
rt_sprintf(log_buffer,"\nnonblock : %d bytes read , total: %d \n", recv_length, total_length);
|
||||
rt_device_write(uart_dev,0,log_buffer, rt_strlen(log_buffer));
|
||||
|
||||
rt_device_write(uart_dev, 0, "3\n", 2);
|
||||
recv_length = 0;
|
||||
recv_length = rt_device_read(uart_dev, -1, uart_read_buffer, 256);
|
||||
rt_device_write(uart_dev, 0, uart_read_buffer, 256);
|
||||
total_length += recv_length;
|
||||
rt_thread_mdelay(1000);
|
||||
|
||||
rt_sprintf(log_buffer, "\nnonblock : %d bytes read, total: %d \n", recv_length, total_length);
|
||||
rt_device_write(uart_dev,0,log_buffer, rt_strlen(log_buffer));
|
||||
|
||||
rt_device_write(uart_dev, 0, "2\n", 2);
|
||||
recv_length = 0;
|
||||
recv_length = rt_device_read(uart_dev, -1, uart_read_buffer, 128);
|
||||
rt_device_write(uart_dev, 0, uart_read_buffer, 128);
|
||||
total_length += recv_length;
|
||||
rt_thread_mdelay(1000);
|
||||
|
||||
rt_sprintf(log_buffer,"\nnonblock : %d bytes read , total: %d \n", recv_length, total_length);
|
||||
rt_device_write(uart_dev, 0, log_buffer, rt_strlen(log_buffer));
|
||||
|
||||
rt_device_write(uart_dev, 0, "1\n", 2);
|
||||
recv_length = 0;
|
||||
recv_length = rt_device_read(uart_dev, -1, uart_read_buffer, 128);
|
||||
rt_device_write(uart_dev, 0, uart_read_buffer, 128);
|
||||
total_length += recv_length;
|
||||
rt_thread_mdelay(1000);
|
||||
|
||||
rt_sprintf(log_buffer, "\nnonblock : %d bytes read , total: %d \n", recv_length, total_length);
|
||||
rt_device_write(uart_dev, 0, log_buffer, rt_strlen(log_buffer));
|
||||
|
||||
rt_sprintf(log_buffer, "BLOCKING READ END");
|
||||
rt_device_write(uart_dev, 0, log_buffer, rt_strlen(log_buffer));
|
||||
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
static void uart_test_nonblocking_rx(void)
|
||||
{
|
||||
rt_device_t uart_dev;
|
||||
uart_dev = rt_device_find(SERIAL_UART_NAME);
|
||||
uassert_not_null(uart_dev);
|
||||
|
||||
uassert_true (nonblock_read(uart_dev));
|
||||
}
|
||||
|
||||
static rt_err_t utest_tc_init(void)
|
||||
{
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_err_t utest_tc_cleanup(void)
|
||||
{
|
||||
rt_device_t uart_dev;
|
||||
uart_dev = rt_device_find(SERIAL_UART_NAME);
|
||||
while(rt_device_close(uart_dev) != -RT_ERROR);
|
||||
rt_device_open(uart_dev, RT_DEVICE_FLAG_TX_BLOCKING | RT_DEVICE_FLAG_TX_BLOCKING);
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(uart_test_nonblocking_rx);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "uart_nonblocking_rx", utest_tc_init, utest_tc_cleanup, 10);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,128 @@
|
|||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
#include "utest.h"
|
||||
|
||||
#define SERIAL_UART_NAME "uart2"
|
||||
#define UART_SEND_TIMES 400
|
||||
#define UART_TEST_NUMBER 6
|
||||
|
||||
#ifdef UTEST_SERIAL_TC
|
||||
|
||||
static rt_bool_t nonblock_write(rt_device_t uart_dev)
|
||||
{
|
||||
rt_size_t wr_sz = 0, tmp = 0, i, write_num_array[UART_TEST_NUMBER], total_write_num[UART_TEST_NUMBER], index;
|
||||
rt_tick_t tick1, tick2, tick_array[UART_TEST_NUMBER];
|
||||
rt_uint8_t uart_write_buffer[1024];
|
||||
|
||||
for (i = 0; i < 1024; i++)
|
||||
uart_write_buffer[i] = '0' + (i % 50);
|
||||
|
||||
/* make sure device is closed and reopen it */
|
||||
while(rt_device_close(uart_dev) != -RT_ERROR);
|
||||
uart_dev = rt_device_find(SERIAL_UART_NAME);
|
||||
rt_device_open(uart_dev, RT_DEVICE_FLAG_TX_NON_BLOCKING | RT_DEVICE_FLAG_RX_NON_BLOCKING);
|
||||
|
||||
LOG_D("\nNONBLOCKING WRITE BEGIN\n");
|
||||
rt_thread_mdelay(2000);
|
||||
|
||||
index = 0;
|
||||
tmp = 0;
|
||||
tick1 = rt_tick_get();
|
||||
for (i = 0; i < UART_SEND_TIMES; i++)
|
||||
{
|
||||
wr_sz = 0;
|
||||
while(wr_sz < 1024)
|
||||
wr_sz += rt_device_write(uart_dev, 0, &uart_write_buffer[wr_sz], 1024-wr_sz);
|
||||
tmp += wr_sz;
|
||||
}
|
||||
tick2 = rt_tick_get();
|
||||
total_write_num[index] = UART_SEND_TIMES * 1024;
|
||||
tick_array[index] = tick2 - tick1;
|
||||
write_num_array[index++] = tmp;
|
||||
|
||||
wr_sz = 0;
|
||||
tick1 = rt_tick_get();
|
||||
while(wr_sz < 8)
|
||||
wr_sz += rt_device_write(uart_dev, 0, &uart_write_buffer[wr_sz], 8-wr_sz);
|
||||
tick2 = rt_tick_get();
|
||||
total_write_num[index] = 8;
|
||||
tick_array[index] = tick2 - tick1;
|
||||
write_num_array[index++] = wr_sz;
|
||||
|
||||
wr_sz = 0;
|
||||
tick1 = rt_tick_get();
|
||||
while(wr_sz < 32)
|
||||
wr_sz += rt_device_write(uart_dev, 0, &uart_write_buffer[wr_sz], 32-wr_sz);
|
||||
tick2 = rt_tick_get();
|
||||
total_write_num[index] = 32;
|
||||
tick_array[index] = tick2 - tick1;
|
||||
write_num_array[index++] = wr_sz;
|
||||
|
||||
wr_sz = 0;
|
||||
tick1 = rt_tick_get();
|
||||
while(wr_sz < 128)
|
||||
wr_sz += rt_device_write(uart_dev, 0, &uart_write_buffer[wr_sz], 128-wr_sz);
|
||||
tick2 = rt_tick_get();
|
||||
total_write_num[index] = 128;
|
||||
tick_array[index] = tick2 - tick1;
|
||||
write_num_array[index++] = wr_sz;
|
||||
|
||||
wr_sz = 0;
|
||||
tick1 = rt_tick_get();
|
||||
while(wr_sz < 512)
|
||||
wr_sz += rt_device_write(uart_dev, 0, &uart_write_buffer[wr_sz], 512-wr_sz);
|
||||
tick2 = rt_tick_get();
|
||||
total_write_num[index] = 512;
|
||||
tick_array[index] = tick2 - tick1;
|
||||
write_num_array[index++] = wr_sz;
|
||||
|
||||
wr_sz = 0;
|
||||
tick1 = rt_tick_get();
|
||||
while(wr_sz < 1024)
|
||||
wr_sz += rt_device_write(uart_dev, 0, &uart_write_buffer[wr_sz], 1024-wr_sz);
|
||||
tick2 = rt_tick_get();
|
||||
total_write_num[index] = 1024;
|
||||
tick_array[index] = tick2 - tick1;
|
||||
write_num_array[index++] = wr_sz;
|
||||
|
||||
rt_thread_mdelay(1000);
|
||||
LOG_D("\nNONBLOCKING_TX END\n");
|
||||
for(i = 0; i < index; i++)
|
||||
{
|
||||
LOG_D("\nNONBLOCKING_MODE : write %d / %d bytes in %d ticks\n", write_num_array[i], total_write_num[i], tick_array[i]);
|
||||
rt_thread_mdelay(1000);
|
||||
}
|
||||
|
||||
return RT_TRUE;
|
||||
}
|
||||
|
||||
static void uart_test_nonblocking_tx(void)
|
||||
{
|
||||
rt_device_t uart_dev;
|
||||
uart_dev = rt_device_find(SERIAL_UART_NAME);
|
||||
uassert_not_null(uart_dev);
|
||||
|
||||
uassert_true (nonblock_write(uart_dev));
|
||||
}
|
||||
|
||||
static rt_err_t utest_tc_init(void)
|
||||
{
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_err_t utest_tc_cleanup(void)
|
||||
{
|
||||
rt_device_t uart_dev;
|
||||
uart_dev = rt_device_find(SERIAL_UART_NAME);
|
||||
while(rt_device_close(uart_dev) != -RT_ERROR);
|
||||
rt_device_open(uart_dev, RT_DEVICE_FLAG_TX_BLOCKING | RT_DEVICE_FLAG_TX_BLOCKING);
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static void testcase(void)
|
||||
{
|
||||
UTEST_UNIT_RUN(uart_test_nonblocking_tx);
|
||||
}
|
||||
UTEST_TC_EXPORT(testcase, "uart_nonblocking_tx", utest_tc_init, utest_tc_cleanup, 10);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue