1 // SPDX-License-Identifier: GPL-2.0+
3 * Test setjmp(), longjmp()
10 #include <test/test.h>
12 #include <asm/setjmp.h>
20 * test_longjmp() - test longjmp function
22 * @i is passed to longjmp.
23 * @i << 8 is set in the environment structure.
26 * @i: value passed to longjmp()
28 static noinline void test_longjmp(struct test_jmp_buf *env, int i)
35 * test_setjmp() - test setjmp function
37 * setjmp() will return the value @i passed to longjmp() if @i is non-zero.
38 * For @i == 0 we expect return value 1.
40 * @i << 8 will be set by test_longjmp in the environment structure.
41 * This value can be used to check that the stack frame is restored.
43 * We return the XORed values to allow simply check both at once.
45 * @i: value passed to longjmp()
46 * Return: values return by longjmp()
48 static int test_setjmp(int i)
50 struct test_jmp_buf env;
54 ret = setjmp(env.env);
57 test_longjmp(&env, i);
58 /* We should not arrive here */
62 static int lib_test_longjmp(struct unit_test_state *uts)
66 for (i = -3; i < 0; ++i)
67 ut_asserteq(i ^ (i << 8), test_setjmp(i));
68 ut_asserteq(1, test_setjmp(0));
69 for (i = 1; i < 4; ++i)
70 ut_asserteq(i ^ (i << 8), test_setjmp(i));
73 LIB_TEST(lib_test_longjmp, 0);