Skip to content

Commit 22ab9aa

Browse files
committed
[docs][utest]:Add standardized utest documentation block for serialv2_tc
1 parent d80c211 commit 22ab9aa

19 files changed

+619
-14
lines changed

components/drivers/serial/utest/v2/posix/uart_posix_echo_block.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,39 @@
11
/*
2-
* Copyright (c) 2006-2024 RT-Thread Development Team
2+
* Copyright (c) 2006-2025 RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
66
* Change Logs:
77
* Date Author Notes
88
* 2021-06-16 KyleChan the first version
9+
* 2025-11-13 CYFS Add standardized utest documentation block
10+
*/
11+
12+
/**
13+
* Test Case Name: UART POSIX Blocking Echo Test
14+
*
15+
* Test Objectives:
16+
* - Validate POSIX blocking serial IO paths with multi-threaded send/receive verification
17+
* - Verify APIs: open/close, tcgetattr/tcsetattr, cfsetispeed/cfsetospeed, fcntl clearing O_NONBLOCK,
18+
* read, write, rt_thread_create/startup
19+
*
20+
* Test Scenarios:
21+
* - **Scenario 1 (Length Sweep Echo / tc_uart_api):**
22+
* 1. Open POSIX serial device, configure canonical settings, and enforce blocking mode.
23+
* 2. Launch sender/receiver threads; sender streams sequential byte patterns while receiver checks ordering until quota met.
24+
* 3. Iterate through deterministic and random lengths, mirroring behavior of kernel-space blocking tests, and monitor global flags for errors.
25+
*
26+
* Verification Metrics:
27+
* - Received data remains sequential; `uart_result` stays RT_TRUE; `uart_over_flag` raised after completion.
28+
* - No termios or fcntl calls fail; thread creation succeeds.
29+
*
30+
* Dependencies:
31+
* - Requires `RT_UTEST_SERIAL_V2` with POSIX serial device `RT_SERIAL_POSIX_TC_DEVICE_NAME` looped back.
32+
* - Host environment must provide POSIX termios/fcntl APIs; adequate heap for buffers and thread stacks.
33+
*
34+
* Expected Results:
35+
* - Test completes without assertions; logs reflect pass counts for each payload length.
36+
* - Utest harness prints `[ PASSED ] [ result ] testcase (components.drivers.serial.v2.uart_posix_echo_block)`.
937
*/
1038

1139
#include <rtthread.h>

components/drivers/serial/utest/v2/posix/uart_posix_nonblock.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,39 @@
11
/*
2-
* Copyright (c) 2006-2024 RT-Thread Development Team
2+
* Copyright (c) 2006-2025 RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
66
* Change Logs:
77
* Date Author Notes
88
* 2021-06-16 KyleChan the first version
9+
* 2025-11-13 CYFS Add standardized utest documentation block
10+
*/
11+
12+
/**
13+
* Test Case Name: UART POSIX Non-Blocking Test
14+
*
15+
* Test Objectives:
16+
* - Validate POSIX-layer non-blocking serial operations using termios configuration
17+
* - Verify APIs: open/close, tcgetattr/tcsetattr, cfsetispeed/cfsetospeed, fcntl(O_NONBLOCK),
18+
* read, write, rt_thread_mdelay
19+
*
20+
* Test Scenarios:
21+
* - **Scenario 1 (Non-Blocking Echo / tc_uart_api):**
22+
* 1. Open POSIX device `RT_SERIAL_POSIX_TC_DEVICE_NAME`, configure baud, frame format, and disable flow control.
23+
* 2. Enable O_NONBLOCK mode and allocate small TX/RX buffer.
24+
* 3. Loop `RT_SERIAL_TC_SEND_ITERATIONS` times, issuing fixed-size and random-length writes, followed by reads after short delays to confirm echo data availability.
25+
*
26+
* Verification Metrics:
27+
* - Each write/read pair returns the expected number of bytes.
28+
* - No system calls fail; routine returns RT_TRUE signalling success.
29+
*
30+
* Dependencies:
31+
* - Requires `RT_UTEST_SERIAL_V2` with POSIX device exposure (`RT_SERIAL_POSIX_TC_DEVICE_NAME`) and loopback wiring.
32+
* - Operating environment must provide termios/fcntl APIs (e.g., RT-Thread POSIX layer or Linux host).
33+
*
34+
* Expected Results:
35+
* - Test executes without assertions; logs remain quiet unless errors occur.
36+
* - Utest harness prints `[ PASSED ] [ result ] testcase (components.drivers.serial.v2.uart_posix_nonblock)`.
937
*/
1038

1139
#include <rtthread.h>

components/drivers/serial/utest/v2/qemu/uart_qemu_echo.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,42 @@
1+
/*
2+
* Copyright (c) 2006-2025 RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2025-11-13 CYFS Add standardized utest documentation block
9+
*/
10+
11+
/**
12+
* Test Case Name: UART QEMU Echo Loopback Test
13+
*
14+
* Test Objectives:
15+
* - Validate dual-UART echo behavior under QEMU by cross-linking uart1 and uart2
16+
* - Verify APIs: rt_device_find, rt_device_open, rt_device_write, rt_device_read,
17+
* rt_device_control(RT_SERIAL_CTRL_GET_UNREAD_BYTES_COUNT), rt_thread_create/startup
18+
*
19+
* Test Scenarios:
20+
* - **Scenario 1 (Cross-Echo Stress / uart_test_nonblocking_tx):**
21+
* 1. Open uart1/uart2 in blocking mode and spawn threads to mirror RX→TX on uart2 while recording statistics.
22+
* 2. Simultaneously read uart1 in a dedicated thread to monitor inbound bytes.
23+
* 3. Send random-length payloads up to 1 KB for 1000 iterations, periodically comparing TX/RX counters across both devices.
24+
* 4. Signal threads to exit once validation completes and ensure device handles close cleanly.
25+
*
26+
* Verification Metrics:
27+
* - u1/u2 TX and RX counters remain equal; send total matches aggregated transmit length.
28+
* - No allocation failures; `echo_test()` returns RT_TRUE when counters align.
29+
*
30+
* Dependencies:
31+
* - Requires `RT_UTEST_SERIAL_V2` running under QEMU with uart1↔uart2 interconnected.
32+
* - UART driver must support unread-bytes query and blocking modes.
33+
* - Threads need 2 KB stacks; dynamic buffers sized at 1 KB per UART.
34+
*
35+
* Expected Results:
36+
* - Test completes without assertions; logs show synchronized counter updates.
37+
* - Utest harness prints `[ PASSED ] [ result ] testcase (components.drivers.serial.v2.uart_qemu_echo)`.
38+
*/
39+
140
#include <rtthread.h>
241
#include <rtdevice.h>
342
#include "utest.h"

components/drivers/serial/utest/v2/uart_blocking_rx.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,40 @@
1+
/*
2+
* Copyright (c) 2006-2025 RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2025-11-13 CYFS Add standardized utest documentation block
9+
*/
10+
11+
/**
12+
* Test Case Name: UART Blocking Receive Echo Test
13+
*
14+
* Test Objectives:
15+
* - Demonstrate blocking read semantics while capturing multiple user inputs
16+
* - Verify APIs: rt_device_find, rt_device_open with RT_DEVICE_FLAG_RX_BLOCKING,
17+
* rt_device_read, rt_device_write, rt_device_close
18+
*
19+
* Test Scenarios:
20+
* - **Scenario 1 (Interactive Echo / uart_test_blocking_rx):**
21+
* 1. Restart UART in fully blocking RX/TX mode.
22+
* 2. Prompt user (or loopback source) for data, then execute several blocking reads of identical size, echoing results to console.
23+
* 3. Track cumulative bytes received and log progress after each read.
24+
*
25+
* Verification Metrics:
26+
* - Each blocking read returns the requested buffer length; totals increment accordingly.
27+
* - Test helper returns RT_TRUE once sequence completes.
28+
*
29+
* Dependencies:
30+
* - Requires `RT_UTEST_SERIAL_V2` with loopback or external stimulus on `RT_SERIAL_TC_DEVICE_NAME`.
31+
* - UART driver must support blocking reads and repeated open/close operations.
32+
*
33+
* Expected Results:
34+
* - No assertions triggered; console displays prompts and echo logs.
35+
* - Utest harness prints `[ PASSED ] [ result ] testcase (components.drivers.serial.v2.uart_blocking_rx)`.
36+
*/
37+
138
#include <rtthread.h>
239
#include <rtdevice.h>
340
#include "utest.h"

components/drivers/serial/utest/v2/uart_blocking_tx.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,41 @@
1+
/*
2+
* Copyright (c) 2006-2025 RT-Thread Development Team
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Change Logs:
7+
* Date Author Notes
8+
* 2025-11-13 CYFS Add standardized utest documentation block
9+
*/
10+
11+
/**
12+
* Test Case Name: UART Blocking Transmit Throughput Test
13+
*
14+
* Test Objectives:
15+
* - Measure blocking transmit throughput across varied burst sizes
16+
* - Verify APIs: rt_device_find, rt_device_open with RT_DEVICE_FLAG_TX_BLOCKING,
17+
* rt_device_write, rt_device_close, rt_tick_get
18+
*
19+
* Test Scenarios:
20+
* - **Scenario 1 (Burst Size Sweep / uart_test_blocking_tx):**
21+
* 1. Re-open the UART in blocking TX mode.
22+
* 2. Perform 100 iterations of 1024-byte writes followed by single bursts of 8, 32, 128, 512, and 1024 bytes,
23+
* capturing elapsed ticks and bytes transferred.
24+
* 3. Log throughput metrics for later comparison against non-blocking mode.
25+
*
26+
* Verification Metrics:
27+
* - Each write call returns the full requested length; accumulated counts match expectations.
28+
* - Timing data captured for every burst; helper returns RT_TRUE on success.
29+
*
30+
* Dependencies:
31+
* - Requires `RT_UTEST_SERIAL_V2` and loopback wiring on `RT_SERIAL_TC_DEVICE_NAME`.
32+
* - UART driver must support blocking writes and open/close sequences.
33+
*
34+
* Expected Results:
35+
* - Test finishes without assertions; logs show per-size timing statistics.
36+
* - Utest harness prints `[ PASSED ] [ result ] testcase (components.drivers.serial.v2.uart_blocking_tx)`.
37+
*/
38+
139
#include <rtthread.h>
240
#include <rtdevice.h>
341
#include "utest.h"

components/drivers/serial/utest/v2/uart_flush_rx.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,39 @@
11
/*
2-
* Copyright (c) 2006-2024 RT-Thread Development Team
2+
* Copyright (c) 2006-2025 RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
66
* Change Logs:
77
* Date Author Notes
8+
* 2025-11-13 CYFS Add standardized utest documentation block
9+
*/
10+
11+
/**
12+
* Test Case Name: UART RX Buffer Flush Test
13+
*
14+
* Test Objectives:
15+
* - Verify RX flush control clears buffered data and preserves integrity of subsequent transfers
16+
* - Confirm APIs: rt_device_find, rt_device_control(RT_DEVICE_CTRL_CONFIG / RT_SERIAL_CTRL_RX_FLUSH),
17+
* rt_device_open with RT_DEVICE_FLAG_RX_NON_BLOCKING | RT_DEVICE_FLAG_TX_BLOCKING,
18+
* rt_device_read, rt_device_write
19+
*
20+
* Test Scenarios:
21+
* - **Scenario 1 (Flush Validation / tc_uart_api):**
22+
* 1. Configure UART buffers and allocate test pattern spanning multiple RX buffer lengths.
23+
* 2. Send payload, consume a single byte, invoke RX flush, and ensure next read returns no residual data.
24+
* 3. Resend partial payloads of varying sizes to confirm data after flush matches original pattern.
25+
*
26+
* Verification Metrics:
27+
* - Initial read after flush returns zero bytes; subsequent reads match transmitted data byte-for-byte.
28+
* - All iterations across deterministic and random lengths complete with RT_EOK.
29+
*
30+
* Dependencies:
31+
* - Requires `RT_UTEST_SERIAL_V2`, loopback wiring, and RX flush support on `RT_SERIAL_TC_DEVICE_NAME`.
32+
* - Optional DMA ping buffer configuration honored when `RT_SERIAL_USING_DMA` enabled.
833
*
34+
* Expected Results:
35+
* - No assertions triggered; logs show flush operations with payload sizes.
36+
* - Utest harness prints `[ PASSED ] [ result ] testcase (components.drivers.serial.v2.uart_flush_rx)`.
937
*/
1038

1139
#include <rtthread.h>

components/drivers/serial/utest/v2/uart_flush_txb.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,39 @@
11
/*
2-
* Copyright (c) 2006-2024 RT-Thread Development Team
2+
* Copyright (c) 2006-2025 RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
66
* Change Logs:
77
* Date Author Notes
8+
* 2025-11-13 CYFS Add standardized utest documentation block
9+
*/
10+
11+
/**
12+
* Test Case Name: UART TX Blocking Flush Test
13+
*
14+
* Test Objectives:
15+
* - Validate TX flush completion timing in blocking mode and ensure subsequent RX integrity
16+
* - Verify APIs: rt_device_find, rt_device_control(RT_DEVICE_CTRL_CONFIG / RT_SERIAL_CTRL_TX_FLUSH / _SET_TX_TIMEOUT / RT_SERIAL_CTRL_RX_FLUSH),
17+
* rt_device_open with RT_DEVICE_FLAG_RX_BLOCKING | RT_DEVICE_FLAG_TX_BLOCKING,
18+
* rt_device_write, rt_device_read
19+
*
20+
* Test Scenarios:
21+
* - **Scenario 1 (Flush Timing & Data Integrity / tc_uart_api):**
22+
* 1. Configure enlarged TX buffer and set TX timeout guard.
23+
* 2. Perform multiple iterations with varied payload sizes (aligned and unaligned), recording ticks needed to flush queued bytes and verifying they fall within `[expect_time, expect_time + 10]`.
24+
* 3. After each flush, resend small samples and confirm received data matches transmitted pattern.
25+
*
26+
* Verification Metrics:
27+
* - `rt_device_write` returns full payload length; measured tick difference respects expected window.
28+
* - Post-flush RX comparisons succeed for all sample sizes.
29+
*
30+
* Dependencies:
31+
* - Requires `RT_UTEST_SERIAL_V2` with hardware loopback and TX flush capability on `RT_SERIAL_TC_DEVICE_NAME`.
32+
* - Optional DMA ping buffer configuration supported.
833
*
34+
* Expected Results:
35+
* - Test completes without assertions; logs show flush durations per payload.
36+
* - Utest harness prints `[ PASSED ] [ result ] testcase (components.drivers.serial.v2.uart_flush_txb)`.
937
*/
1038

1139
#include <rtthread.h>

components/drivers/serial/utest/v2/uart_flush_txnb.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,39 @@
11
/*
2-
* Copyright (c) 2006-2024 RT-Thread Development Team
2+
* Copyright (c) 2006-2025 RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
66
* Change Logs:
77
* Date Author Notes
8+
* 2025-11-13 CYFS Add standardized utest documentation block
9+
*/
10+
11+
/**
12+
* Test Case Name: UART TX Non-Blocking Flush Test
13+
*
14+
* Test Objectives:
15+
* - Validate flush completion timing for non-blocking transmit mode and verify subsequent RX integrity
16+
* - Verify APIs: rt_device_find, rt_device_control(RT_DEVICE_CTRL_CONFIG / RT_SERIAL_CTRL_TX_FLUSH / _SET_TX_TIMEOUT / RT_SERIAL_CTRL_RX_FLUSH),
17+
* rt_device_open with RT_DEVICE_FLAG_RX_BLOCKING | RT_DEVICE_FLAG_TX_NON_BLOCKING,
18+
* rt_device_write, rt_device_read
19+
*
20+
* Test Scenarios:
21+
* - **Scenario 1 (Flush Timing & Data Integrity / tc_uart_api):**
22+
* 1. Configure UART with expanded buffer sizes and minimal TX timeout to emulate non-blocking semantics.
23+
* 2. Iterate across varied payload lengths (including random lengths), measuring ticks between write and flush completion; ensure timing lies within expected band.
24+
* 3. After each flush, resend small samples and check received bytes for equality.
25+
*
26+
* Verification Metrics:
27+
* - Flushed transmissions complete within `[expect_time, expect_time + 10]` tick window.
28+
* - Post-flush RX comparisons succeed for all sample sizes.
29+
*
30+
* Dependencies:
31+
* - Requires `RT_UTEST_SERIAL_V2`, loopback wiring, and TX flush support for non-blocking mode on `RT_SERIAL_TC_DEVICE_NAME`.
32+
* - Optional DMA ping buffer configuration honored.
833
*
34+
* Expected Results:
35+
* - Test runs without assertions; logs report flush timing per payload.
36+
* - Utest harness prints `[ PASSED ] [ result ] testcase (components.drivers.serial.v2.uart_flush_txnb)`.
937
*/
1038

1139
#include <rtthread.h>

components/drivers/serial/utest/v2/uart_get_unread_bytes_count.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,39 @@
11
/*
2-
* Copyright (c) 2006-2024 RT-Thread Development Team
2+
* Copyright (c) 2006-2025 RT-Thread Development Team
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*
66
* Change Logs:
77
* Date Author Notes
8+
* 2025-11-13 CYFS Add standardized utest documentation block
9+
*/
10+
11+
/**
12+
* Test Case Name: UART Unread Bytes Count Test
13+
*
14+
* Test Objectives:
15+
* - Validate query of unread RX bytes and flush interaction in non-blocking receive mode
16+
* - Verify APIs: rt_device_find, rt_device_control(RT_DEVICE_CTRL_CONFIG / RT_SERIAL_CTRL_GET_UNREAD_BYTES_COUNT / RT_SERIAL_CTRL_RX_FLUSH),
17+
* rt_device_open with RT_DEVICE_FLAG_RX_NON_BLOCKING | RT_DEVICE_FLAG_TX_BLOCKING,
18+
* rt_device_write
19+
*
20+
* Test Scenarios:
21+
* - **Scenario 1 (Unread Count Verification / tc_uart_api):**
22+
* 1. Configure UART buffers and send varying payload lengths, some exceeding RX buffer capacity.
23+
* 2. After each transfer, query unread byte count and ensure it saturates at `min(send_size, RT_SERIAL_TC_RXBUF_SIZE)`.
24+
* 3. Flush RX buffer and verify unread count resets to zero before next iteration.
25+
*
26+
* Verification Metrics:
27+
* - `RT_SERIAL_CTRL_GET_UNREAD_BYTES_COUNT` returns expected length; subsequent flush yields zero.
28+
* - All iterations covering large and random payloads complete with RT_EOK.
29+
*
30+
* Dependencies:
31+
* - Requires `RT_UTEST_SERIAL_V2`, RX count control support, and loopback wiring on `RT_SERIAL_TC_DEVICE_NAME`.
32+
* - Optional DMA ping buffer configuration honored.
833
*
34+
* Expected Results:
35+
* - Test ends without assertions; logs may remain silent unless failures occur.
36+
* - Utest harness prints `[ PASSED ] [ result ] testcase (components.drivers.serial.v2.uart_get_unread_bytes_count)`.
937
*/
1038

1139
#include <rtthread.h>

0 commit comments

Comments
 (0)