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