xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/getcontext/getcontext01.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) Wipro Technologies Ltd, 2005.  All Rights Reserved.
4  *               Author: Prashant P Yendigeri <[email protected]>
5  * Copyright (C) 2022 SUSE LLC Andrea Cervesato <[email protected]>
6  */
7 
8 /*\
9  * [Description]
10  *
11  * Basic test for getcontext().
12  *
13  * Calls a getcontext() then jumps back with a setcontext().
14  */
15 
16 #include "config.h"
17 #include "tst_test.h"
18 
19 #ifdef HAVE_GETCONTEXT
20 
21 #include <ucontext.h>
22 
23 static volatile int flag;
24 
run(void)25 static void run(void)
26 {
27 	ucontext_t ptr;
28 
29 	flag = 0;
30 
31 	TST_EXP_PASS(getcontext(&ptr), "getcontext() flag=%i", flag);
32 
33 	if (flag)
34 		return;
35 
36 	flag = 1;
37 	setcontext(&ptr);
38 
39 	tst_res(TFAIL, "setcontext() did return");
40 }
41 
42 static struct tst_test test = {
43 	.test_all = run,
44 };
45 
46 #else
47 TST_TEST_TCONF("system doesn't have getcontext support");
48 #endif
49