1 // SPDX-License-Identifier: GPL-2.0+
3 * Test setjmp(), longjmp()
11 #include <asm/setjmp.h>
19 * test_longjmp() - test longjmp function
21 * @i is passed to longjmp.
22 * @i << 8 is set in the environment structure.
25 * @i: value passed to longjmp()
27 static noinline void test_longjmp(struct test_jmp_buf *env, int i)
34 * test_setjmp() - test setjmp function
36 * setjmp() will return the value @i passed to longjmp() if @i is non-zero.
37 * For @i == 0 we expect return value 1.
39 * @i << 8 will be set by test_longjmp in the environment structure.
40 * This value can be used to check that the stack frame is restored.
42 * We return the XORed values to allow simply check both at once.
44 * @i: value passed to longjmp()
45 * Return: values return by longjmp()
47 static int test_setjmp(int i)
49 struct test_jmp_buf env;
53 ret = setjmp(env.env);
56 test_longjmp(&env, i);
57 /* We should not arrive here */
61 static int lib_test_longjmp(struct unit_test_state *uts)
65 for (i = -3; i < 0; ++i)
66 ut_asserteq(i ^ (i << 8), test_setjmp(i));
67 ut_asserteq(1, test_setjmp(0));
68 for (i = 1; i < 4; ++i)
69 ut_asserteq(i ^ (i << 8), test_setjmp(i));
72 LIB_TEST(lib_test_longjmp, 0);