This is an automated email from the ASF dual-hosted git repository. xiaoxiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git
The following commit(s) were added to refs/heads/master by this push: new 30215c260 add test for longjump with 0 as return value 30215c260 is described below commit 30215c260bc087aa6675b4804ee600e43ea48839 Author: Gao Jiawei <gaojia...@xiaomi.com> AuthorDate: Tue Jul 23 18:13:14 2024 +0800 add test for longjump with 0 as return value Signed-off-by: Gao Jiawei <gaojia...@xiaomi.com> --- testing/ostest/setjmp.c | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/testing/ostest/setjmp.c b/testing/ostest/setjmp.c index 406756967..4d5461d36 100644 --- a/testing/ostest/setjmp.c +++ b/testing/ostest/setjmp.c @@ -32,17 +32,23 @@ * Public Functions ****************************************************************************/ -void setjmp_test(void) +void jump_with_retval(jmp_buf buf, int ret) { + volatile bool did_jump = false; int value; - jmp_buf buf; - - printf("setjmp_test: Initializing jmp_buf\n"); if ((value = setjmp(buf)) == 0) { printf("setjmp_test: Try jump\n"); - longjmp(buf, 123); + + if (did_jump) + { + ASSERT(!"setjmp retutns zero after calling longjmp"); + } + + did_jump = true; + printf("setjmp_test: About to jump, longjmp with ret val: %d\n", ret); + longjmp(buf, ret); /* Unreachable */ @@ -50,7 +56,32 @@ void setjmp_test(void) } else { - ASSERT(value == 123); + /* If we provide 0 as the return value to longjmp() + * we expect it substitute to 1 for us. + */ + + if (ret == 0) + { + ret = 1; + } + + ASSERT(value == ret); printf("setjmp_test: Jump succeed\n"); } } + +void setjmp_test(void) +{ + jmp_buf buf; + + printf("setjmp_test: Initializing jmp_buf\n"); + + jump_with_retval(buf, 123); + + /* Pls ref to: + * the longjmp should never make setjmp returns 0 + * https://pubs.opengroup.org/onlinepubs/009604599/functions/longjmp.html + */ + + jump_with_retval(buf, 0); +}