This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
commit 496535eb437ad9d6af8c366622abdc5e70575efd Author: Marco Casaroli <[email protected]> AuthorDate: Fri Oct 23 20:53:13 2026 +0200 testing/ostest: Check WIFEXITED() before WEXITSTATUS() in waitpid.c. The waitpid tests compared WEXITSTATUS() of each child with the expected exit code, without WIFEXITED(). POSIX defines WEXITSTATUS() only when WIFEXITED() is true, so a child that a signal ended would not be seen as an error if the value matched. Check WIFEXITED() first, and print the whole status on an error. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- testing/ostest/waitpid.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/testing/ostest/waitpid.c b/testing/ostest/waitpid.c index b7a84db45..aac8263b2 100644 --- a/testing/ostest/waitpid.c +++ b/testing/ostest/waitpid.c @@ -152,13 +152,11 @@ static void waitpid_last(void) ASSERT(false); } } - else if (WEXITSTATUS(stat_loc) != RETURN_STATUS) + else if (!WIFEXITED(stat_loc) || WEXITSTATUS(stat_loc) != RETURN_STATUS) { printf("waitpid_last: ERROR: " - "PID %d return status is %d, expected %d\n", - g_waitpids[NCHILDREN - 1], - WEXITSTATUS(stat_loc), - RETURN_STATUS); + "PID %d stat_loc=%04x, expected exit status %d\n", + g_waitpids[NCHILDREN - 1], stat_loc, RETURN_STATUS); ASSERT(false); } else @@ -220,11 +218,11 @@ int waitpid_test(void) g_waitpids[0], ret); ASSERT(false); } - else if (WEXITSTATUS(stat_loc) != RETURN_STATUS) + else if (!WIFEXITED(stat_loc) || WEXITSTATUS(stat_loc) != RETURN_STATUS) { printf("waitpid_test: ERROR: " - "PID %d return status is %d, expected %d\n", - g_waitpids[0], WEXITSTATUS(stat_loc), RETURN_STATUS); + "PID %d stat_loc=%04x, expected exit status %d\n", + g_waitpids[0], stat_loc, RETURN_STATUS); ASSERT(false); } else @@ -376,11 +374,11 @@ int waitpid_test(void) ASSERT(false); } } - else if (WEXITSTATUS(stat_loc) != RETURN_STATUS) + else if (!WIFEXITED(stat_loc) || WEXITSTATUS(stat_loc) != RETURN_STATUS) { printf("waitpid_test: ERROR: " - "PID %d return status is %d, expected %d\n", - ret, WEXITSTATUS(stat_loc), RETURN_STATUS); + "PID %d stat_loc=%04x, expected exit status %d\n", + ret, stat_loc, RETURN_STATUS); ASSERT(false); } else
