Skip to content

Commit 13a57ca

Browse files
committed
[utest]: [signal]:Standardized function comment blocks have been added.
Added comments to the utest for the signal module, including: test purpose, usage scenarios, dependency configurations, expected outcomes, and expected behaviors. Signed-off-by: Mengchen Teng <[email protected]>
1 parent 934c819 commit 13a57ca

File tree

1 file changed

+109
-0
lines changed

1 file changed

+109
-0
lines changed

src/utest/signal_tc.c

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,115 @@
1717
* case 8:rt_signal_kill, kill illegal thread, return failed (unused);
1818
* case 9:rt_signal_kill, kill illegal signo, return -RT_EINVAL;
1919
*
20+
*
21+
* Test Case Name: [rt_signal_tc]
22+
*
23+
* Test Objectives:
24+
* - [rt_signal_install_test]: Verify the correctness of the rt_signal_install function's
25+
* - functionality. The registration of the signal handler should be completed correctly.
26+
* - Include Case1 and Case2.
27+
*
28+
* - [rt_signal_mask_test]: Verify the correctness of the rt_signal_unmask functions's
29+
* - functionality. The signal handler will only be triggered when the signal is unmasked.
30+
* - Include Case3.
31+
*
32+
* - [rt_signal_unmask_test]: Verify the correctness of the rt_signal_mask functions's
33+
* - functionality. The signal handler will not be triggered when the signal is masked.
34+
* - Include Case4.
35+
*
36+
* - [rt_signal_kill_test]: Verify the correctness of the rt_signal_kill function's
37+
* - functionality. Signals should be sent to the specified thread correctly. Include
38+
* - Case7, Case8 and Case9. But Case8 is currently unused.
39+
*
40+
* - [rt_signal_wait_test]: Verify signal delivery to a waiting thread. Include Case5.
41+
*
42+
* - [rt_signal_wait_test2]: Verify timeout behavior when waiting for a signal.
43+
*
44+
* Test Scenarios:
45+
*
46+
* - [rt_signal_install_test]: When the signal signo is greater than 0 and less than RT_SIG_MAX,
47+
* - the rt_signal_install function can register the signal handler normally (i.e., the return
48+
* - value is not equal to SIG_ERR). However, if signo is not within the above range, the
49+
* - rt_signal_install function returns SIG_ERR.
50+
*
51+
* - [rt_signal_mask_test]: When signo is valid, the signal handler will first be successfully
52+
* - registered via rt_signal_install, where receive_sig is assigned the value of the triggered
53+
* - signal signo. After successful registration, the specified signal mask is unmasked using
54+
* - rt_signal_unmask, and a signal is sent to rt_thread_self via rt_thread_kill. After a 1ms
55+
* - delay, the signal callback function is triggered successfully, and the value of recive_sig
56+
* - equals the value of signo.
57+
*
58+
* - [rt_signal_unmask_test]: When signo is valid, the signal handler will first be successfully
59+
* - registered via rt_signal_install, where receive_sig is assigned the value of the triggered
60+
* - signal signo. After successful registration, the specified signal mask is unmasked using
61+
* - rt_signal_unmask, then masked again using rt_signal_mask. A signal is then sent to rt_thread_self
62+
* - via rt_thread_kill. After a 1ms delay, the signal callback function is not triggered, and the
63+
* - value of recive_sig does not equal the value of signo.
64+
*
65+
* - [rt_signal_kill_test]: Case7(the for Loop) is the same as the loop in [rt_signal_mask_test].
66+
* - Case9 Verifies that when an invalid signal is sent using rt_signal_kill, the function returns
67+
* - -RT_EINVAL.
68+
*
69+
* - [rt_signal_wait_test]: In this test case, a new thread("sig_t1") is created to execute the
70+
* - rt_signal_wait_thread function. Inside the new thread, the SIGUSR1 signal handler is
71+
* - installed and unmasked. The thread then waits for the SIGUSR1 signal with a timeout of
72+
* - RT_TICK_PER_SECOND ticks. Meanwhile, the main test case thread sleeps for 1ms to ensure that
73+
* - "sig_t1" is waiting for the signal, and then sends the SIGUSR1 signal to "sig_t1" using
74+
* - rt_thread_kill. The main thread then waits on the _received_signal semaphore, which will be
75+
* - released by "sig_t1" upon receiving the signal. Finally, the test case verifies that the
76+
* - recive_sig variable is set to SIGUSR1, confirming that the signal was successfully
77+
* - received by the waiting thread.
78+
*
79+
* - [rt_signal_wait_test2]: Similar to [rt_signal_wait_test], a new thread("sig_t1") is created
80+
* - to execute the rt_signal_wait_thread function. But in this case, after creating the thread,
81+
* - the main test case thread sleeps for 2000ms, which is longer than the 1-second timeout
82+
* - specified in rt_signal_wait_thread. After waking up, the main thread sends the SIGUSR1 signal
83+
* - to "sig_t1" using rt_thread_kill. Since "sig_t1" has already timed out waiting for the signal,
84+
* - it will not receive the signal. The main thread then attempts to take the _received_signal
85+
* - semaphore with a timeout of 1 tick, which should fail since "sig_t1" did not receive the signal
86+
* - and thus did not release the semaphore. Finally, the test case verifieds that the receive_sig
87+
* - variable is not equal to SIGUSR1, confirming that the signal was not received by the waiting thread
88+
* - due to the timeout.
89+
*
90+
* Verification Metrics:
91+
*
92+
* - [rt_signal_install_test]: Case 1 (i.e., the rt_signal_install inside the for loop)
93+
* - will not return SIG_ERR. Case 2 (i.e., the rt_signal_install outside the for loop)
94+
* - will return SIG_ERR.
95+
*
96+
* - [rt_signal_mask_test]: Every signo shall correctly trigger the signal handler, such
97+
* - that recive_sig equals signo.
98+
*
99+
* - [rt_signal_unmask_test]: Every signo shall not trigger the signal handler after masking,
100+
* - such that recive_sig does not equal signo.
101+
*
102+
* - [rt_signal_kill_test]: In Case7, every signo shall correctly trigger the signal handler,
103+
* - such that recive_sig equals signo. In Case9, rt_signal_kill shall return -RT_EINVAL.
104+
*
105+
* - [rt_signal_wait_test]: In Case5, recive_sig shall equal SIGUSR1, indicating that the waiting
106+
* - thread successfully received the signal. And main thread can take the semaphore.
107+
*
108+
* - [rt_signal_wait_test2]: In Case6, recive_sig shall not equal SIGUSR1, indicating that the waiting
109+
* - thread did not receive the signal due to timeout. And main thread fails to take the semaphore.
110+
*
111+
* Dependencies:
112+
* - Case1-9: Enable RT_USING_SIGNALS and RT_USING_HEAP.
113+
*
114+
* Expected Results:
115+
* - [rt_signal_install_test]: Handlers installed successfully for all valid signals,
116+
* - installation fails for invalid signal.
117+
*
118+
* - [rt_signal_mask_test]: Signals are received when unmasked.
119+
*
120+
* - [rt_signal_unmask_test]: Signals are not received when masked.
121+
*
122+
* - [rt_signal_kill_test]: Signals are sent and received correctly for valid cases,
123+
* - errors returned for invalid cases.
124+
*
125+
* - [rt_signal_wait_test]: Signals are correctly received by waiting threads and semaphore
126+
* - is released as expected.
127+
*
128+
* - [rt_signal_wait_test2]: Signals are not received after timeout and semaphore take fails.
20129
*/
21130

22131
#include <rtthread.h>

0 commit comments

Comments
 (0)