Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Kconfig.utestcases
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ menu "RT-Thread Utestcases"
bool "RT-Thread Utestcases"
default n
select RT_USING_UTEST
select RT_USING_DEBUG if !RT_USING_ULOG

if RT_USING_UTESTCASES

Expand Down
4 changes: 4 additions & 0 deletions components/drivers/serial/utest/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ menu "Serial Test"
string "Device Name for Serial Test"
default "uart2"

config RT_SERIAL_TC_DEVICE_USING_TX_DMA
bool "Selected serial device is using TX DMA"
default n

config RT_SERIAL_TC_RXBUF_SIZE
int "RX Buffer Size for Serial Test"
default 128
Expand Down
3 changes: 2 additions & 1 deletion components/drivers/serial/utest/v2/uart_flush_txb.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ static rt_err_t test_item(rt_uint8_t *uart_write_buffer, rt_uint32_t send_size)
rt_device_control(&serial->parent, RT_SERIAL_CTRL_TX_FLUSH, RT_NULL);
tick_diff = rt_tick_get() - old_tick;

if (tick_diff < expect_time || tick_diff > (expect_time + 10))
rt_uint32_t lower_bound = (expect_time > 2) ? (expect_time - 2) : 0;
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic number alert / 魔术数字警告: The constant value 2 used in the lower bound calculation is a magic number that lacks explanation. Consider defining it as a named constant (e.g., TIMING_TOLERANCE_MARGIN) to improve code readability and maintainability.

English: The hardcoded value 2 should be extracted to a constant with a meaningful name explaining why this specific tolerance is needed for the lower bound calculation.

中文: 硬编码的值 2 应该提取为一个有意义名称的常量,解释为什么下限计算需要这个特定的容差值。

Example/示例:

#define TIMING_TOLERANCE_MARGIN 2
rt_uint32_t lower_bound = (expect_time > TIMING_TOLERANCE_MARGIN) ? (expect_time - TIMING_TOLERANCE_MARGIN) : 0;

Copilot uses AI. Check for mistakes.
if (tick_diff < lower_bound || tick_diff > (expect_time + 10))
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic number inconsistency / 魔术数字不一致: The upper bound uses a hardcoded value 10 for tolerance, which is inconsistent with the lower bound tolerance of 2. Both tolerance values should be defined as named constants for consistency and maintainability.

English: The upper bound tolerance (10) and lower bound tolerance (2) should both be defined as named constants to ensure consistency and make the timing validation logic more maintainable.

中文: 上限容差(10)和下限容差(2)都应该定义为命名常量,以确保一致性并使时间验证逻辑更易于维护。

Example/示例:

#define TIMING_LOWER_TOLERANCE 2
#define TIMING_UPPER_TOLERANCE 10
rt_uint32_t lower_bound = (expect_time > TIMING_LOWER_TOLERANCE) ? (expect_time - TIMING_LOWER_TOLERANCE) : 0;
if (tick_diff < lower_bound || tick_diff > (expect_time + TIMING_UPPER_TOLERANCE))

Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ryan-CW-Code AI的这个提示好像还可以,可以给两个宏说明下

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉意义不大,是计算发送 n 个字节大约需要多少毫秒,然后在这个值的基础上再加一些冗余。
因为上面计算的时候默认向下取整的,如果过于严格,很容易导致测试不通过,这个测试主要测试flush有没有生效。

您再评估一下,依然感觉有必要的话我就加上。

{
LOG_E("send_size [%4d], time required for TXB mode transmission to complete [%3d], expect_time [%3d]", send_size, tick_diff, expect_time);
return -RT_ERROR;
Expand Down
3 changes: 2 additions & 1 deletion components/drivers/serial/utest/v2/uart_flush_txnb.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ static rt_err_t test_item(rt_uint8_t *uart_write_buffer, rt_uint32_t send_size)
rt_device_control(&serial->parent, RT_SERIAL_CTRL_TX_FLUSH, RT_NULL);
tick_diff = rt_tick_get() - old_tick;

if (tick_diff < expect_time || tick_diff > (expect_time + 10))
rt_uint32_t lower_bound = (expect_time > 2) ? (expect_time - 2) : 0;
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic number alert / 魔术数字警告: The constant value 2 used in the lower bound calculation is a magic number that lacks explanation. Consider defining it as a named constant (e.g., TIMING_TOLERANCE_MARGIN) to improve code readability and maintainability.

English: The hardcoded value 2 should be extracted to a constant with a meaningful name explaining why this specific tolerance is needed for the lower bound calculation.

中文: 硬编码的值 2 应该提取为一个有意义名称的常量,解释为什么下限计算需要这个特定的容差值。

Example/示例:

#define TIMING_TOLERANCE_MARGIN 2
rt_uint32_t lower_bound = (expect_time > TIMING_TOLERANCE_MARGIN) ? (expect_time - TIMING_TOLERANCE_MARGIN) : 0;

Copilot uses AI. Check for mistakes.
if (tick_diff < lower_bound || tick_diff > (expect_time + 10))
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic number inconsistency / 魔术数字不一致: The upper bound uses a hardcoded value 10 for tolerance, which is inconsistent with the lower bound tolerance of 2. Both tolerance values should be defined as named constants for consistency and maintainability.

English: The upper bound tolerance (10) and lower bound tolerance (2) should both be defined as named constants to ensure consistency and make the timing validation logic more maintainable.

中文: 上限容差(10)和下限容差(2)都应该定义为命名常量,以确保一致性并使时间验证逻辑更易于维护。

Example/示例:

#define TIMING_LOWER_TOLERANCE 2
#define TIMING_UPPER_TOLERANCE 10
rt_uint32_t lower_bound = (expect_time > TIMING_LOWER_TOLERANCE) ? (expect_time - TIMING_LOWER_TOLERANCE) : 0;
if (tick_diff < lower_bound || tick_diff > (expect_time + TIMING_UPPER_TOLERANCE))

Copilot uses AI. Check for mistakes.
{
LOG_E("send_size [%4d], time required for TXNB mode transmission to complete [%3d], expect_time [%3d]", send_size, tick_diff, expect_time);
return -RT_ERROR;
Expand Down
2 changes: 1 addition & 1 deletion components/drivers/serial/utest/v2/uart_timeout_txb.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <stdlib.h>

#ifdef RT_UTEST_SERIAL_V2
#ifndef BSP_UART2_TX_USING_DMA
#ifndef RT_SERIAL_TC_DEVICE_USING_TX_DMA

static struct rt_serial_device *serial;

Expand Down