Skip to content

Commit 604d123

Browse files
ChuanN-sudoRbb666
authored andcommitted
[utest][serial bypass]:Add standardized documentation for Serial Bypass Test
1 parent 9c2279a commit 604d123

File tree

4 files changed

+149
-0
lines changed

4 files changed

+149
-0
lines changed

components/drivers/serial/utest/bypass/bypass_conflict.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,46 @@
66
* Change Logs:
77
* Date Author Notes
88
* 2024-11-20 zhujiale the first version
9+
* 2025-11-24 ChuanN-sudo add standardized utest documentation block
910
*/
11+
12+
/**
13+
* Test Case Name: Serial Bypass Conflict Test
14+
*
15+
* Test Objectives:
16+
* - Validate serial device bypass mechanism under high-concurrency RX interrupt scenarios.
17+
* - Verify thread-safe registration/unregistration of upper and lower bypass handlers.
18+
* - Ensure correct data reception counting across concurrent ISR triggers and workqueue processing.
19+
* - Test core APIs: rt_bypass_upper_register(), rt_bypass_upper_unregister(),
20+
* rt_bypass_lower_register(), rt_bypass_lower_unregister(), rt_hw_serial_isr().
21+
*
22+
* Test Scenarios:
23+
* - bypass_rx_stress_001: Two threads simultaneously trigger RX ISRs with upper bypass handler registered.
24+
* Each thread generates 10 ISR events, expecting 200 total character receptions (10 chars per ISR × 10 ISRs × 2 threads).
25+
* - bypass_rx_stress_002: Concurrent ISR triggering and workqueue processing with lower bypass handler.
26+
* Tests interaction between interrupt context and work queue context, expecting 100 total receptions.
27+
* - bypass_rx_stress_003: High-priority thread (priority 15, numerically lower = higher priority) dynamically
28+
* registers/unregisters bypass handlers while low-priority thread (priority 20) continuously triggers RX ISRs.
29+
*
30+
* Verification Metrics:
31+
* - Character reception counter matches expected values (200 for test_001, 100 for test_002, 200 for test_003).
32+
* - No data loss occurs during concurrent handler registration/unregistration operations.
33+
* - Atomic operations ensure thread-safe counter increments without race conditions.
34+
* - Mock UART getc function correctly limits character generation to 10 per call sequence.
35+
* - System remains stable during priority inversion scenarios (priority 15 vs 20 threads).
36+
*
37+
* Dependencies:
38+
* - Hardware requirements: Platform with serial console device (UART) support.
39+
* - Software configuration:
40+
* - RT_USING_UTESTCASES must be enabled (select "RT-Thread Utestcases" in menuconfig).
41+
* - RT_UTEST_SERIAL_BYPASS must be enabled (enable via: RT-Thread Utestcases -> Kernel Components -> Drivers -> Serial Test -> Serial Bypass Test).
42+
* - Environmental Assumptions: Serial device initialized and operational before test execution.
43+
*
44+
* Expected Results:
45+
* - Final output: "[ PASSED ] [ result ] testcase (components.drivers.serial.bypass_rx_stress)"
46+
* - All atomic counter assertions pass with exact expected values.
47+
*/
48+
1049
#include <rtthread.h>
1150
#include <rtdevice.h>
1251
#include "utest.h"

components/drivers/serial/utest/bypass/bypass_lower_run.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,42 @@
66
* Change Logs:
77
* Date Author Notes
88
* 2024-11-20 zhujiale the first version
9+
* 2025-11-24 ChuanN-sudo add standardized utest documentation block
910
*/
11+
12+
/**
13+
* Test Case Name: Serial Bypass Lower Run Test
14+
*
15+
* Test Objectives:
16+
* - Validate serial device bypass lower layer registration and data processing mechanisms.
17+
* - Verify correct character reception and callback execution in bypass mode.
18+
* - Test core APIs: rt_bypass_lower_register(), rt_bypass_lower_unregister(), rt_hw_serial_isr()
19+
*
20+
* Test Scenarios:
21+
* - Register bypass lower layer callback to intercept serial RX data before normal processing.
22+
* - Simulate hardware interrupt with custom getc function returning predefined character sequences.
23+
* - Verify repeated character reception, counting mechanism and sequential character reception with incremental validation.
24+
* - Temporarily replace serial device operations with mock implementations for controlled testing.
25+
*
26+
* Verification Metrics:
27+
* - Bypass callback executes for each received character with correct character value.
28+
* - Character validation assertions pass: bypass_lower_001 validates 10 'a' characters, bypass_lower_002 validates sequential characters 'b' to 'u'.
29+
* - Mock getc function returns -1 after 10 iterations (bypass_lower_001) or 20 iterations (bypass_lower_002) to terminate reception.
30+
* - Serial device operations restore to original state after test completion.
31+
* - Bypass lower layer unregisters successfully without resource leaks.
32+
*
33+
* Dependencies:
34+
* - Hardware requirements: Platform with serial console device (UART) support.
35+
* - Software configuration:
36+
* - RT_USING_UTESTCASES must be enabled (select "RT-Thread Utestcases" in menuconfig).
37+
* - RT_UTEST_SERIAL_BYPASS must be enabled (enable via: RT-Thread Utestcases -> Kernel Components -> Drivers -> Serial Test -> Serial Bypass Test).
38+
* - Environmental Assumptions: Serial device initialized and operational before test execution.
39+
*
40+
* Expected Results:
41+
* - Final output: "[ PASSED ] [ result ] testcase (components.drivers.serial.bypass_lower)"
42+
* - Character validation assertions pass for all test iterations.
43+
*/
44+
1045
#include <rtthread.h>
1146
#include <rtdevice.h>
1247
#include "utest.h"

components/drivers/serial/utest/bypass/bypass_register.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,46 @@
66
* Change Logs:
77
* Date Author Notes
88
* 2024-11-20 zhujiale the first version
9+
* 2025-11-24 ChuanN-sudo add standardized utest documentation block
910
*/
11+
12+
/**
13+
* Test Case Name: Serial Bypass Register Test
14+
*
15+
* Test Objectives:
16+
* - Validate serial bypass function registration and unregistration mechanisms.
17+
* - Verify correct ordering of bypass functions by priority level in concurrent scenarios.
18+
* - Ensure thread-safe registration of upper and lower bypass handlers.
19+
* - Test core APIs: rt_bypass_upper_register(), rt_bypass_lower_register(),
20+
* rt_bypass_upper_unregister(), rt_bypass_lower_unregister()
21+
*
22+
* Test Scenarios:
23+
* - bypass_register_001: Main thread and worker thread concurrently register upper bypass
24+
* functions with even/odd priority levels to test insertion ordering and thread safety.
25+
* - bypass_register_002: Two worker threads simultaneously register upper and lower bypass
26+
* functions with levels 1-9 to verify independent queue management.
27+
* - Tests validate that registered functions maintain strict ascending order by level.
28+
* - Unregistration operations verify complete cleanup of bypass function chains.
29+
*
30+
* Verification Metrics:
31+
* - Bypass functions are inserted in correct priority order (level 0-9 ascending).
32+
* - Concurrent registrations from multiple threads maintain list integrity.
33+
* - Upper and lower bypass chains operate independently without interference.
34+
* - All registered bypass functions can be successfully unregistered by level.
35+
* - No memory leaks or list corruption after registration/unregistration cycles.
36+
*
37+
* Dependencies:
38+
* - Hardware requirements: Platform with serial console device (UART) support.
39+
* - Software configuration:
40+
* - RT_USING_UTESTCASES must be enabled (select "RT-Thread Utestcases" in menuconfig).
41+
* - RT_UTEST_SERIAL_BYPASS must be enabled (enable via: RT-Thread Utestcases -> Kernel Components -> Drivers -> Serial Test -> Serial Bypass Test).
42+
* - Environmental Assumptions: Serial device initialized and operational before test execution.
43+
*
44+
* Expected Results:
45+
* - Final output: "[ PASSED ] [ result ] testcase (components.drivers.serial.bypass_register)"
46+
* - All uassert_true() checks pass, confirming correct level ordering.
47+
*/
48+
1049
#include <rtthread.h>
1150
#include <rtdevice.h>
1251
#include "utest.h"

components/drivers/serial/utest/bypass/bypass_upper_run.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,43 @@
66
* Change Logs:
77
* Date Author Notes
88
* 2024-11-20 zhujiale the first version
9+
* 2025-11-24 ChuanN-sudo add standardized utest documentation block
910
*/
11+
12+
/**
13+
* Test Case Name: Serial Bypass Upper Run Test
14+
*
15+
* Test Objectives:
16+
* - Validate serial device bypass upper layer registration and data processing mechanisms.
17+
* - Verify correct character reception and filtering through bypass callback functions.
18+
* - Ensure proper handling of bypass level priorities and callback execution order.
19+
* - Test core APIs: rt_bypass_upper_register(), rt_bypass_upper_unregister(), rt_hw_serial_isr()
20+
*
21+
* Test Scenarios:
22+
* - Register bypass callback at RT_BYPASS_LEVEL_1 to intercept incoming serial data.
23+
* - Verify bypass callback receives expected character values and executes correct number of times.
24+
* - Register bypass callback at RT_BYPASS_MAX_LEVEL with different character sequence.
25+
* - Test bypass unregistration and verify proper cleanup of callback handlers.
26+
*
27+
* Verification Metrics:
28+
* - Bypass callback executes exactly 10 times for first test case with character 'a'.
29+
* - Second test case processes 20 characters in ascending sequence ('b' to 'u').
30+
* - Character values received in callback match expected values from mock getc function.
31+
* - Bypass registration and unregistration complete without memory leaks or errors.
32+
* - Serial device operations restore to original state after test completion.
33+
*
34+
* Dependencies:
35+
* - Hardware requirements: Platform with serial console device (UART) support.
36+
* - Software configuration:
37+
* - RT_USING_UTESTCASES must be enabled (select "RT-Thread Utestcases" in menuconfig).
38+
* - RT_UTEST_SERIAL_BYPASS must be enabled (enable via: RT-Thread Utestcases -> Kernel Components -> Drivers -> Serial Test -> Serial Bypass Test).
39+
* - Environmental Assumptions: Serial device initialized and operational before test execution.
40+
*
41+
* Expected Results:
42+
* - Final output: "[ PASSED ] [ result ] testcase (components.drivers.serial.bypass_upper)"
43+
* - No assertions triggered during character validation or callback execution.
44+
*/
45+
1046
#include <rtthread.h>
1147
#include <rtdevice.h>
1248
#include "utest.h"

0 commit comments

Comments
 (0)