1 #include <setjmp.h> 2 #include <stdio.h> 3 #include "unity.h" 4 #include "esp_system.h" 5 6 7 typedef struct { 8 jmp_buf jmp_env; 9 uint32_t retval; 10 volatile bool inner_called; 11 } setjmp_test_ctx_t; 12 inner(setjmp_test_ctx_t * ctx)13static __attribute__((noreturn)) void inner(setjmp_test_ctx_t *ctx) 14 { 15 printf("inner, retval=0x%x\n", ctx->retval); 16 ctx->inner_called = true; 17 longjmp(ctx->jmp_env, ctx->retval); 18 TEST_FAIL_MESSAGE("Should not reach here"); 19 } 20 21 TEST_CASE("setjmp and longjmp", "[newlib]") 22 { 23 const uint32_t expected = 0x12345678; 24 setjmp_test_ctx_t ctx = { 25 .retval = expected 26 }; 27 uint32_t ret = setjmp(ctx.jmp_env); 28 if (!ctx.inner_called) { 29 TEST_ASSERT_EQUAL(0, ret); 30 inner(&ctx); 31 } else { 32 TEST_ASSERT_EQUAL(expected, ret); 33 } 34 TEST_ASSERT(ctx.inner_called); 35 } 36