From a97830e49315d3c11244bb1e8ab9959bc3dd948f Mon Sep 17 00:00:00 2001 From: Giacomo Tesio Date: Sun, 3 Sep 2017 17:41:55 +0200 Subject: [PATCH] newlib: add qa test for setjmp/longjmp --- qa/lib/newlib/031-setjmp.c | 35 +++++++++++++++++++++++++++++++++++ qa/lib/newlib/build.json | 1 + 2 files changed, 36 insertions(+) create mode 100644 qa/lib/newlib/031-setjmp.c diff --git a/qa/lib/newlib/031-setjmp.c b/qa/lib/newlib/031-setjmp.c new file mode 100644 index 0000000..474b6c7 --- /dev/null +++ b/qa/lib/newlib/031-setjmp.c @@ -0,0 +1,35 @@ +#include +#include +#include + +/* declare variable of type jmp_buf */ +jmp_buf resume_here; + +void hello(void); + +int main(void) +{ + int ret_val; + printf("sizeof(jmp_buf) = %lu\n", sizeof(jmp_buf)); + + /* Initialize 'resume_here' by calling setjmp() */ + if (ret_val = setjmp(resume_here)) { + printf("After \'longjump()\', back in \'main()\'\n"); + printf("\'jump buffer variable \'resume_here\'\' becomes " + "INVALID!\n"); + return 0; + } else { + printf("\'setjmp()\' returns first time\n"); + hello(); + return 1; + } +} + +void hello(void) +{ + printf("Hey, I'm in \'hello()\'\n"); + longjmp(resume_here, 1); + + /* other code */ + printf("can't be reached here because I did longjmp!\n"); +} diff --git a/qa/lib/newlib/build.json b/qa/lib/newlib/build.json index ea341f4..67356f2 100644 --- a/qa/lib/newlib/build.json +++ b/qa/lib/newlib/build.json @@ -35,6 +35,7 @@ "010-fork.c", "020-waitpid.c", "030-pause.c", + "031-setjmp.c", "040-gettimeofday.c", "100-files.c", "101-files.c",