Skip to content

Commit 3703120

Browse files
Ryan-CW-Codehydevcode
authored andcommitted
[utest][serial_v2] 更新测试用例
1 parent 5914592 commit 3703120

17 files changed

+122
-94
lines changed

examples/utest/testcases/drivers/serial_v2/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ RT-Thread Utestcases --->
140140

141141
其余同理,可在函数内部查看命令。
142142

143-
如果仅仅配置了 `Serial testcase` 相关的测试用例,则直接输入 `utest_run` 运行即可将上述测试用例按序测试。
143+
如果仅仅配置了 `Serial testcase` 相关的测试用例,则直接输入 `utest_run *` 运行即可将上述测试用例按序测试。
144144

145145
## 7、注意事项
146146

examples/utest/testcases/drivers/serial_v2/posix/uart_posix_echo_block.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include <fcntl.h>
1919
#include <unistd.h>
2020

21-
#define DBG_LVL DBG_LOG
2221

2322
#ifdef UTEST_SERIAL_TC
2423

examples/utest/testcases/drivers/serial_v2/posix/uart_posix_nonblock.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include <fcntl.h>
1919
#include <unistd.h>
2020

21-
#define DBG_LVL DBG_LOG
2221

2322
#ifdef UTEST_SERIAL_TC
2423

examples/utest/testcases/drivers/serial_v2/uart_blocking_rx.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#include <rtdevice.h>
33
#include "utest.h"
44

5-
#define DBG_LVL DBG_LOG
65
#ifdef UTEST_SERIAL_TC
76

87
static rt_bool_t block_read(rt_device_t uart_dev)

examples/utest/testcases/drivers/serial_v2/uart_blocking_tx.c

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,81 +2,86 @@
22
#include <rtdevice.h>
33
#include "utest.h"
44

5-
#define UART_SEND_TIMES 100
5+
#define UART_SEND_TIMES 100
66
#define UART_TEST_NUMBER 6
77

8-
#define DBG_LVL DBG_LOG
8+
99

1010
#ifdef UTEST_SERIAL_TC
1111

1212
static rt_bool_t block_write(rt_device_t uart_dev)
1313
{
1414
rt_size_t i, wr_sz, index, write_num_array[UART_TEST_NUMBER], total_write_num[UART_TEST_NUMBER];
1515
rt_tick_t tick1, tick2, tick_array[UART_TEST_NUMBER];
16-
char uart_write_buffer[1024];
16+
char uart_write_buffer[1024];
1717

1818
for (i = 0; i < 1024; i++)
1919
uart_write_buffer[i] = '0' + (i % 49);
2020

2121
/* make sure device is closed and reopen it */
22-
while(rt_device_close(uart_dev) != -RT_ERROR);
22+
while (rt_device_close(uart_dev) != -RT_ERROR);
2323
rt_device_open(uart_dev, RT_DEVICE_FLAG_TX_BLOCKING);
2424

2525
LOG_D("\nBLOCKING WRITE BEGIN\n");
2626

2727
index = 0;
2828
wr_sz = 0;
2929
tick1 = rt_tick_get();
30-
for(i = 0; i < UART_SEND_TIMES; i++)
30+
for (i = 0; i < UART_SEND_TIMES; i++)
3131
wr_sz += rt_device_write(uart_dev, 0, uart_write_buffer, 1024);
3232

33-
tick2 = rt_tick_get();
34-
total_write_num[index] = UART_SEND_TIMES * 1024;
35-
tick_array[index] = tick2 - tick1;
33+
tick2 = rt_tick_get();
34+
total_write_num[index] = UART_SEND_TIMES * 1024;
35+
tick_array[index] = tick2 - tick1;
3636
write_num_array[index++] = wr_sz;
3737

38-
wr_sz = 0;
39-
tick1 = rt_tick_get();
38+
wr_sz = 0;
39+
tick1 = rt_tick_get();
4040
wr_sz += rt_device_write(uart_dev, 0, uart_write_buffer, 8);
41-
tick2 = rt_tick_get();
42-
total_write_num[index] = 8;
43-
tick_array[index] = tick2 - tick1;
41+
tick2 = rt_tick_get();
42+
43+
total_write_num[index] = 8;
44+
tick_array[index] = tick2 - tick1;
4445
write_num_array[index++] = wr_sz;
4546

46-
wr_sz = 0;
47-
tick1 = rt_tick_get();
47+
wr_sz = 0;
48+
tick1 = rt_tick_get();
4849
wr_sz += rt_device_write(uart_dev, 0, uart_write_buffer, 32);
49-
tick2 = rt_tick_get();
50-
total_write_num[index] = 32;
51-
tick_array[index] = tick2 - tick1;
50+
tick2 = rt_tick_get();
51+
52+
total_write_num[index] = 32;
53+
tick_array[index] = tick2 - tick1;
5254
write_num_array[index++] = wr_sz;
5355

54-
wr_sz = 0;
55-
tick1 = rt_tick_get();
56+
wr_sz = 0;
57+
tick1 = rt_tick_get();
5658
wr_sz += rt_device_write(uart_dev, 0, uart_write_buffer, 128);
57-
tick2 = rt_tick_get();
58-
total_write_num[index] = 128;
59-
tick_array[index] = tick2 - tick1;
59+
tick2 = rt_tick_get();
60+
61+
total_write_num[index] = 128;
62+
tick_array[index] = tick2 - tick1;
6063
write_num_array[index++] = wr_sz;
6164

62-
wr_sz = 0;
63-
tick1 = rt_tick_get();
65+
wr_sz = 0;
66+
tick1 = rt_tick_get();
6467
wr_sz += rt_device_write(uart_dev, 0, uart_write_buffer, 512);
65-
tick2 = rt_tick_get();
66-
total_write_num[index] = 512;
67-
tick_array[index] = tick2 - tick1;
68+
tick2 = rt_tick_get();
69+
70+
total_write_num[index] = 512;
71+
tick_array[index] = tick2 - tick1;
6872
write_num_array[index++] = wr_sz;
6973

70-
wr_sz = 0;
71-
tick1 = rt_tick_get();
74+
wr_sz = 0;
75+
tick1 = rt_tick_get();
7276
wr_sz += rt_device_write(uart_dev, 0, uart_write_buffer, 1024);
73-
tick2 = rt_tick_get();
74-
total_write_num[index] = 1024;
75-
tick_array[index] = tick2 - tick1;
77+
tick2 = rt_tick_get();
78+
79+
total_write_num[index] = 1024;
80+
tick_array[index] = tick2 - tick1;
7681
write_num_array[index++] = wr_sz;
7782

7883
LOG_D("\nBLOCKING_TX END\n");
79-
for(i = 0; i < index; i++)
84+
for (i = 0; i < index; i++)
8085
{
8186
LOG_D("\nBLOCKING_MODE : write %d / %d bytes in %d ticks\n", write_num_array[i], total_write_num[i], tick_array[i]);
8287
rt_thread_mdelay(1000);
@@ -91,7 +96,7 @@ static void uart_test_blocking_tx(void)
9196
uart_dev = rt_device_find(RT_SERIAL_TC_DEVICE_NAME);
9297
uassert_not_null(uart_dev);
9398

94-
uassert_true (block_write(uart_dev));
99+
uassert_true(block_write(uart_dev));
95100
}
96101

97102
static rt_err_t utest_tc_init(void)

examples/utest/testcases/drivers/serial_v2/uart_flush_rx.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <rtdevice.h>
1414
#include <stdlib.h>
1515

16-
#define DBG_LVL DBG_LOG
16+
1717

1818
#ifdef UTEST_SERIAL_TC
1919

@@ -83,6 +83,7 @@ static rt_bool_t uart_api()
8383
rt_uint32_t i;
8484
uart_write_buffer = (rt_uint8_t *)rt_malloc(sizeof(rt_uint8_t) * (RT_SERIAL_TC_TXBUF_SIZE * 5 + 1));
8585

86+
srand(rt_tick_get());
8687
for (i = 0; i < RT_SERIAL_TC_SEND_ITERATIONS; i++)
8788
{
8889
if (RT_EOK != test_item(uart_write_buffer, RT_SERIAL_TC_RXBUF_SIZE + RT_SERIAL_TC_RXBUF_SIZE * (rand() % 5)))
@@ -103,6 +104,7 @@ static rt_bool_t uart_api()
103104
__exit:
104105
rt_free(uart_write_buffer);
105106
rt_device_close(&serial->parent);
107+
rt_thread_mdelay(5);
106108
return result == RT_EOK ? RT_TRUE : RT_FALSE;
107109
}
108110

examples/utest/testcases/drivers/serial_v2/uart_flush_txb.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <rtdevice.h>
1414
#include <stdlib.h>
1515

16-
#define DBG_LVL DBG_LOG
1716

1817
#ifdef UTEST_SERIAL_TC
1918

@@ -49,7 +48,7 @@ static rt_err_t test_item(rt_uint8_t *uart_write_buffer, rt_uint32_t send_size)
4948
rt_device_control(&serial->parent, RT_SERIAL_CTRL_TX_FLUSH, RT_NULL);
5049
tick_diff = rt_tick_get() - old_tick;
5150

52-
if (tick_diff < expect_time)
51+
if (tick_diff < expect_time || tick_diff > expect_time + 10)
5352
{
5453
LOG_E("send_size [%4d], time required for TXB mode transmission to complete [%3d], expect_time [%3d]", send_size, tick_diff, expect_time);
5554
return -RT_ERROR;
@@ -96,6 +95,7 @@ static rt_bool_t uart_api()
9695

9796
rt_device_control(&serial->parent, RT_SERIAL_CTRL_SET_TX_TIMEOUT, (void *)&tx_timeout);
9897

98+
srand(rt_tick_get());
9999
for (i = 0; i < RT_SERIAL_TC_SEND_ITERATIONS; i++)
100100
{
101101
if (RT_EOK != test_item(uart_write_buffer, RT_SERIAL_TC_TXBUF_SIZE * (rand() % 6)))
@@ -119,6 +119,7 @@ static rt_bool_t uart_api()
119119
__exit:
120120
rt_free(uart_write_buffer);
121121
rt_device_close(&serial->parent);
122+
rt_thread_mdelay(5);
122123
return result == RT_EOK ? RT_TRUE : RT_FALSE;
123124
}
124125

examples/utest/testcases/drivers/serial_v2/uart_flush_txnb.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <rtdevice.h>
1414
#include <stdlib.h>
1515

16-
#define DBG_LVL DBG_LOG
16+
1717

1818
#ifdef UTEST_SERIAL_TC
1919

@@ -95,6 +95,7 @@ static rt_bool_t uart_api()
9595

9696
rt_device_control(&serial->parent, RT_SERIAL_CTRL_SET_TX_TIMEOUT, (void *)&tx_timeout);
9797

98+
srand(rt_tick_get());
9899
for (i = 0; i < RT_SERIAL_TC_SEND_ITERATIONS; i++)
99100
{
100101
if (RT_EOK != test_item(uart_write_buffer, RT_SERIAL_TC_RXBUF_SIZE * (rand() % 6)))
@@ -119,6 +120,7 @@ static rt_bool_t uart_api()
119120
__exit:
120121
rt_free(uart_write_buffer);
121122
rt_device_close(&serial->parent);
123+
rt_thread_mdelay(5);
122124
return result == RT_EOK ? RT_TRUE : RT_FALSE;
123125
}
124126

examples/utest/testcases/drivers/serial_v2/uart_get_unread_bytes_count.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <rtdevice.h>
1414
#include <stdlib.h>
1515

16-
/* #define DBG_LVL DBG_LOG*/
16+
/* */
1717

1818
#ifdef UTEST_SERIAL_TC
1919

@@ -94,6 +94,7 @@ static rt_bool_t uart_api()
9494
rt_uint32_t i;
9595
uart_write_buffer = (rt_uint8_t *)rt_malloc(sizeof(rt_uint8_t) * (RT_SERIAL_TC_TXBUF_SIZE * 5 + 1));
9696

97+
srand(rt_tick_get());
9798
for (i = 0; i < RT_SERIAL_TC_SEND_ITERATIONS; i++)
9899
{
99100
if (RT_EOK != test_item(uart_write_buffer, RT_SERIAL_TC_RXBUF_SIZE + RT_SERIAL_TC_RXBUF_SIZE * (rand() % 5)))
@@ -113,6 +114,7 @@ static rt_bool_t uart_api()
113114
__exit:
114115
rt_free(uart_write_buffer);
115116
rt_device_close(&serial->parent);
117+
rt_thread_mdelay(5);
116118
return result == RT_EOK ? RT_TRUE : RT_FALSE;
117119
}
118120

examples/utest/testcases/drivers/serial_v2/uart_nonblocking_rx.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#include <rtdevice.h>
33
#include "utest.h"
44

5-
#define DBG_LVL DBG_LOG
65
#ifdef UTEST_SERIAL_TC
76

87
static rt_bool_t nonblock_read(rt_device_t uart_dev)

0 commit comments

Comments
 (0)