Skip to content
Merged
Changes from 1 commit
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
109 changes: 109 additions & 0 deletions src/utest/signal_tc.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,115 @@
* case 8:rt_signal_kill, kill illegal thread, return failed (unused);
* case 9:rt_signal_kill, kill illegal signo, return -RT_EINVAL;
*
*
* Test Case Name: [rt_signal_tc]
*
* Test Objectives:
* - [rt_signal_install_test]: Verify the correctness of the rt_signal_install function's
* - functionality. The registration of the signal handler should be completed correctly.
* - Include Case1 and Case2.
*
* - [rt_signal_mask_test]: Verify the correctness of the rt_signal_unmask functions's
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

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

Documentation Issue / 文档问题

English: Line 28 states this test verifies "rt_signal_unmask" but it should be "rt_signal_mask". The function name "rt_signal_mask_test" tests the unmask functionality (when signals are unmasked and should be received), not the mask functionality.

中文:第 28 行说明该测试验证 "rt_signal_unmask" 函数,但应该是 "rt_signal_mask"。函数名 "rt_signal_mask_test" 测试的是 unmask 功能(信号取消屏蔽后应该被接收),而非 mask 功能。

Suggested change
* - [rt_signal_mask_test]: Verify the correctness of the rt_signal_unmask functions's
* - [rt_signal_mask_test]: Verify the correctness of the rt_signal_mask function's

Copilot uses AI. Check for mistakes.
* - functionality. The signal handler will only be triggered when the signal is unmasked.
* - Include Case3.
*
* - [rt_signal_unmask_test]: Verify the correctness of the rt_signal_mask functions's
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

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

Documentation Issue / 文档问题

English: Line 32 states this test verifies "rt_signal_mask" but it should be "rt_signal_unmask". The function name "rt_signal_unmask_test" tests the mask functionality (when signals are masked and should NOT be received), not the unmask functionality.

中文:第 32 行说明该测试验证 "rt_signal_mask" 函数,但应该是 "rt_signal_unmask"。函数名 "rt_signal_unmask_test" 测试的是 mask 功能(信号被屏蔽后不应该被接收),而非 unmask 功能。

Suggested change
* - [rt_signal_unmask_test]: Verify the correctness of the rt_signal_mask functions's
* - [rt_signal_unmask_test]: Verify the correctness of the rt_signal_mask function's

Copilot uses AI. Check for mistakes.
* - functionality. The signal handler will not be triggered when the signal is masked.
* - Include Case4.
*
* - [rt_signal_kill_test]: Verify the correctness of the rt_signal_kill function's
* - functionality. Signals should be sent to the specified thread correctly. Include
* - Case7, Case8 and Case9. But Case8 is currently unused.
*
* - [rt_signal_wait_test]: Verify signal delivery to a waiting thread. Include Case5.
*
* - [rt_signal_wait_test2]: Verify timeout behavior when waiting for a signal.
*
* Test Scenarios:
*
* - [rt_signal_install_test]: When the signal signo is greater than 0 and less than RT_SIG_MAX,
* - the rt_signal_install function can register the signal handler normally (i.e., the return
* - value is not equal to SIG_ERR). However, if signo is not within the above range, the
* - rt_signal_install function returns SIG_ERR.
*
* - [rt_signal_mask_test]: When signo is valid, the signal handler will first be successfully
* - registered via rt_signal_install, where receive_sig is assigned the value of the triggered
* - signal signo. After successful registration, the specified signal mask is unmasked using
* - rt_signal_unmask, and a signal is sent to rt_thread_self via rt_thread_kill. After a 1ms
* - delay, the signal callback function is triggered successfully, and the value of recive_sig
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

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

Spelling Error / 拼写错误

English: The word "recive_sig" is misspelled. It should be "receive_sig" (missing the second 'e').

中文:单词 "recive_sig" 拼写错误,应为 "receive_sig"(缺少第二个 'e')。

Copilot uses AI. Check for mistakes.
* - equals the value of signo.
*
* - [rt_signal_unmask_test]: When signo is valid, the signal handler will first be successfully
* - registered via rt_signal_install, where receive_sig is assigned the value of the triggered
* - signal signo. After successful registration, the specified signal mask is unmasked using
* - rt_signal_unmask, then masked again using rt_signal_mask. A signal is then sent to rt_thread_self
* - via rt_thread_kill. After a 1ms delay, the signal callback function is not triggered, and the
* - value of recive_sig does not equal the value of signo.
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

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

Spelling Error / 拼写错误

English: The word "recive_sig" is misspelled. It should be "receive_sig" (missing the second 'e').

中文:单词 "recive_sig" 拼写错误,应为 "receive_sig"(缺少第二个 'e')。

Copilot uses AI. Check for mistakes.
*
* - [rt_signal_kill_test]: Case7(the for Loop) is the same as the loop in [rt_signal_mask_test].
* - Case9 Verifies that when an invalid signal is sent using rt_signal_kill, the function returns
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

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

Spelling Error / 拼写错误

English: The word "Verifieds" is grammatically incorrect. It should be "Verifies" (third person singular present tense).

中文:单词 "Verifieds" 语法错误,应为 "Verifies"(第三人称单数现在时)。

Suggested change
* - Case9 Verifies that when an invalid signal is sent using rt_signal_kill, the function returns
* - Case9 verifies that when an invalid signal is sent using rt_signal_kill, the function returns

Copilot uses AI. Check for mistakes.
* - -RT_EINVAL.
*
* - [rt_signal_wait_test]: In this test case, a new thread("sig_t1") is created to execute the
* - rt_signal_wait_thread function. Inside the new thread, the SIGUSR1 signal handler is
* - installed and unmasked. The thread then waits for the SIGUSR1 signal with a timeout of
* - RT_TICK_PER_SECOND ticks. Meanwhile, the main test case thread sleeps for 1ms to ensure that
* - "sig_t1" is waiting for the signal, and then sends the SIGUSR1 signal to "sig_t1" using
* - rt_thread_kill. The main thread then waits on the _received_signal semaphore, which will be
* - released by "sig_t1" upon receiving the signal. Finally, the test case verifies that the
* - recive_sig variable is set to SIGUSR1, confirming that the signal was successfully
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

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

Spelling Error / 拼写错误

English: The word "recive_sig" is misspelled. It should be "receive_sig" (missing the second 'e').

中文:单词 "recive_sig" 拼写错误,应为 "receive_sig"(缺少第二个 'e')。

Copilot uses AI. Check for mistakes.
* - received by the waiting thread.
*
* - [rt_signal_wait_test2]: Similar to [rt_signal_wait_test], a new thread("sig_t1") is created
* - to execute the rt_signal_wait_thread function. But in this case, after creating the thread,
* - the main test case thread sleeps for 2000ms, which is longer than the 1-second timeout
* - specified in rt_signal_wait_thread. After waking up, the main thread sends the SIGUSR1 signal
* - to "sig_t1" using rt_thread_kill. Since "sig_t1" has already timed out waiting for the signal,
* - it will not receive the signal. The main thread then attempts to take the _received_signal
* - semaphore with a timeout of 1 tick, which should fail since "sig_t1" did not receive the signal
* - and thus did not release the semaphore. Finally, the test case verifieds that the receive_sig
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

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

Spelling Error / 拼写错误

English: The word "verifieds" is grammatically incorrect. It should be "verifies" (third person singular present tense).

中文:单词 "verifieds" 语法错误,应为 "verifies"(第三人称单数现在时)。

Suggested change
* - and thus did not release the semaphore. Finally, the test case verifieds that the receive_sig
* - and thus did not release the semaphore. Finally, the test case verifies that the receive_sig

Copilot uses AI. Check for mistakes.
* - variable is not equal to SIGUSR1, confirming that the signal was not received by the waiting thread
* - due to the timeout.
*
* Verification Metrics:
*
* - [rt_signal_install_test]: Case 1 (i.e., the rt_signal_install inside the for loop)
* - will not return SIG_ERR. Case 2 (i.e., the rt_signal_install outside the for loop)
* - will return SIG_ERR.
*
* - [rt_signal_mask_test]: Every signo shall correctly trigger the signal handler, such
* - that recive_sig equals signo.
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

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

Spelling Error / 拼写错误

English: The word "recive_sig" is misspelled. It should be "receive_sig" (missing the second 'e').

中文:单词 "recive_sig" 拼写错误,应为 "receive_sig"(缺少第二个 'e')。

Copilot uses AI. Check for mistakes.
*
* - [rt_signal_unmask_test]: Every signo shall not trigger the signal handler after masking,
* - such that recive_sig does not equal signo.
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

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

Spelling Error / 拼写错误

English: The word "recive_sig" is misspelled. It should be "receive_sig" (missing the second 'e').

中文:单词 "recive_sig" 拼写错误,应为 "receive_sig"(缺少第二个 'e')。

Copilot uses AI. Check for mistakes.
*
* - [rt_signal_kill_test]: In Case7, every signo shall correctly trigger the signal handler,
* - such that recive_sig equals signo. In Case9, rt_signal_kill shall return -RT_EINVAL.
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

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

Spelling Error / 拼写错误

English: The word "recive_sig" is misspelled. It should be "receive_sig" (missing the second 'e').

中文:单词 "recive_sig" 拼写错误,应为 "receive_sig"(缺少第二个 'e')。

Copilot uses AI. Check for mistakes.
*
* - [rt_signal_wait_test]: In Case5, recive_sig shall equal SIGUSR1, indicating that the waiting
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

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

Spelling Error / 拼写错误

English: The word "recive_sig" is misspelled. It should be "receive_sig" (missing the second 'e').

中文:单词 "recive_sig" 拼写错误,应为 "receive_sig"(缺少第二个 'e')。

Copilot uses AI. Check for mistakes.
* - thread successfully received the signal. And main thread can take the semaphore.
*
* - [rt_signal_wait_test2]: In Case6, recive_sig shall not equal SIGUSR1, indicating that the waiting
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

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

Spelling Error / 拼写错误

English: The word "recive_sig" is misspelled. It should be "receive_sig" (missing the second 'e').

中文:单词 "recive_sig" 拼写错误,应为 "receive_sig"(缺少第二个 'e')。

Copilot uses AI. Check for mistakes.
* - thread did not receive the signal due to timeout. And main thread fails to take the semaphore.
*
* Dependencies:
* - Case1-9: Enable RT_USING_SIGNALS and RT_USING_HEAP.
*
* Expected Results:
* - [rt_signal_install_test]: Handlers installed successfully for all valid signals,
* - installation fails for invalid signal.
*
* - [rt_signal_mask_test]: Signals are received when unmasked.
*
* - [rt_signal_unmask_test]: Signals are not received when masked.
*
* - [rt_signal_kill_test]: Signals are sent and received correctly for valid cases,
* - errors returned for invalid cases.
*
* - [rt_signal_wait_test]: Signals are correctly received by waiting threads and semaphore
* - is released as expected.
*
* - [rt_signal_wait_test2]: Signals are not received after timeout and semaphore take fails.
*/

#include <rtthread.h>
Expand Down