xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/sgetmask/sgetmask01.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1*49cdfc7eSAndroid Build Coastguard Worker /******************************************************************************/
2*49cdfc7eSAndroid Build Coastguard Worker /* Copyright (c) Crackerjack Project., 2007                                   */
3*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
4*49cdfc7eSAndroid Build Coastguard Worker /* This program is free software;  you can redistribute it and/or modify      */
5*49cdfc7eSAndroid Build Coastguard Worker /* it under the terms of the GNU General Public License as published by       */
6*49cdfc7eSAndroid Build Coastguard Worker /* the Free Software Foundation; either version 2 of the License, or          */
7*49cdfc7eSAndroid Build Coastguard Worker /* (at your option) any later version.                                        */
8*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
9*49cdfc7eSAndroid Build Coastguard Worker /* This program is distributed in the hope that it will be useful,            */
10*49cdfc7eSAndroid Build Coastguard Worker /* but WITHOUT ANY WARRANTY;  without even the implied warranty of            */
11*49cdfc7eSAndroid Build Coastguard Worker /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                  */
12*49cdfc7eSAndroid Build Coastguard Worker /* the GNU General Public License for more details.                           */
13*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
14*49cdfc7eSAndroid Build Coastguard Worker /* You should have received a copy of the GNU General Public License          */
15*49cdfc7eSAndroid Build Coastguard Worker /* along with this program;  if not, write to the Free Software               */
16*49cdfc7eSAndroid Build Coastguard Worker /* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    */
17*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
18*49cdfc7eSAndroid Build Coastguard Worker /******************************************************************************/
19*49cdfc7eSAndroid Build Coastguard Worker /******************************************************************************/
20*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
21*49cdfc7eSAndroid Build Coastguard Worker /* File:        sgetmask01.c                                           */
22*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
23*49cdfc7eSAndroid Build Coastguard Worker /* Description: This tests the sgetmask() syscall                      */
24*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
25*49cdfc7eSAndroid Build Coastguard Worker /* Usage:  <for command-line>                                                 */
26*49cdfc7eSAndroid Build Coastguard Worker /* sgetmask01 [-c n] [-e][-i n] [-I x] [-p x] [-t]                     */
27*49cdfc7eSAndroid Build Coastguard Worker /*      where,  -c n : Run n copies concurrently.                             */
28*49cdfc7eSAndroid Build Coastguard Worker /*              -e   : Turn on errno logging.                                 */
29*49cdfc7eSAndroid Build Coastguard Worker /*              -i n : Execute test n times.                                  */
30*49cdfc7eSAndroid Build Coastguard Worker /*              -I x : Execute test for x seconds.                            */
31*49cdfc7eSAndroid Build Coastguard Worker /*              -P x : Pause for x seconds between iterations.                */
32*49cdfc7eSAndroid Build Coastguard Worker /*              -t   : Turn on syscall timing.                                */
33*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
34*49cdfc7eSAndroid Build Coastguard Worker /* Total Tests: 1                                                             */
35*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
36*49cdfc7eSAndroid Build Coastguard Worker /* Test Name:   sgetmask01                                             */
37*49cdfc7eSAndroid Build Coastguard Worker /* History:     Porting from Crackerjack to LTP is done by                    */
38*49cdfc7eSAndroid Build Coastguard Worker /*              Manas Kumar Nayak [email protected]>                        */
39*49cdfc7eSAndroid Build Coastguard Worker /******************************************************************************/
40*49cdfc7eSAndroid Build Coastguard Worker 
41*49cdfc7eSAndroid Build Coastguard Worker /* NOTE:  This case test the behavior of sgetmask
42*49cdfc7eSAndroid Build Coastguard Worker # Sometime the returned "Oops"in this case don't mean anything for
43*49cdfc7eSAndroid Build Coastguard Worker # correct or error, we check the result between different kernel and
44*49cdfc7eSAndroid Build Coastguard Worker # try to find if there exist different returned code in different kernel
45*49cdfc7eSAndroid Build Coastguard Worker #
46*49cdfc7eSAndroid Build Coastguard Worker */
47*49cdfc7eSAndroid Build Coastguard Worker 
48*49cdfc7eSAndroid Build Coastguard Worker #include <stdio.h>
49*49cdfc7eSAndroid Build Coastguard Worker #include <signal.h>
50*49cdfc7eSAndroid Build Coastguard Worker #include <sys/syscall.h>
51*49cdfc7eSAndroid Build Coastguard Worker #include <unistd.h>
52*49cdfc7eSAndroid Build Coastguard Worker #include <stdio.h>
53*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
54*49cdfc7eSAndroid Build Coastguard Worker 
55*49cdfc7eSAndroid Build Coastguard Worker #include "test.h"
56*49cdfc7eSAndroid Build Coastguard Worker #include "lapi/syscalls.h"
57*49cdfc7eSAndroid Build Coastguard Worker 
58*49cdfc7eSAndroid Build Coastguard Worker char *TCID = "sgetmask01";
59*49cdfc7eSAndroid Build Coastguard Worker int testno;
60*49cdfc7eSAndroid Build Coastguard Worker int TST_TOTAL = 2;
61*49cdfc7eSAndroid Build Coastguard Worker 
62*49cdfc7eSAndroid Build Coastguard Worker /* Extern Global Functions */
63*49cdfc7eSAndroid Build Coastguard Worker /******************************************************************************/
64*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
65*49cdfc7eSAndroid Build Coastguard Worker /* Function:    cleanup                                                       */
66*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
67*49cdfc7eSAndroid Build Coastguard Worker /* Description: Performs all one time clean up for this test on successful    */
68*49cdfc7eSAndroid Build Coastguard Worker /*              completion,  premature exit or  failure. Closes all temporary */
69*49cdfc7eSAndroid Build Coastguard Worker /*              files, removes all temporary directories exits the test with  */
70*49cdfc7eSAndroid Build Coastguard Worker /*              appropriate return code by calling tst_exit() function.       */
71*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
72*49cdfc7eSAndroid Build Coastguard Worker /* Input:       None.                                                         */
73*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
74*49cdfc7eSAndroid Build Coastguard Worker /* Output:      None.                                                         */
75*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
76*49cdfc7eSAndroid Build Coastguard Worker /* Return:      On failure - Exits calling tst_exit(). Non '0' return code.   */
77*49cdfc7eSAndroid Build Coastguard Worker /*              On success - Exits calling tst_exit(). With '0' return code.  */
78*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
79*49cdfc7eSAndroid Build Coastguard Worker /******************************************************************************/
cleanup(void)80*49cdfc7eSAndroid Build Coastguard Worker void cleanup(void)
81*49cdfc7eSAndroid Build Coastguard Worker {
82*49cdfc7eSAndroid Build Coastguard Worker 
83*49cdfc7eSAndroid Build Coastguard Worker 	tst_rmdir();
84*49cdfc7eSAndroid Build Coastguard Worker 
85*49cdfc7eSAndroid Build Coastguard Worker 	tst_exit();
86*49cdfc7eSAndroid Build Coastguard Worker }
87*49cdfc7eSAndroid Build Coastguard Worker 
88*49cdfc7eSAndroid Build Coastguard Worker /* Local  Functions */
89*49cdfc7eSAndroid Build Coastguard Worker /******************************************************************************/
90*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
91*49cdfc7eSAndroid Build Coastguard Worker /* Function:    setup                                                         */
92*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
93*49cdfc7eSAndroid Build Coastguard Worker /* Description: Performs all one time setup for this test. This function is   */
94*49cdfc7eSAndroid Build Coastguard Worker /*              typically used to capture signals, create temporary dirs      */
95*49cdfc7eSAndroid Build Coastguard Worker /*              and temporary files that may be used in the course of this    */
96*49cdfc7eSAndroid Build Coastguard Worker /*              test.                                                         */
97*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
98*49cdfc7eSAndroid Build Coastguard Worker /* Input:       None.                                                         */
99*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
100*49cdfc7eSAndroid Build Coastguard Worker /* Output:      None.                                                         */
101*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
102*49cdfc7eSAndroid Build Coastguard Worker /* Return:      On failure - Exits by calling cleanup().                      */
103*49cdfc7eSAndroid Build Coastguard Worker /*              On success - returns 0.                                       */
104*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
105*49cdfc7eSAndroid Build Coastguard Worker /******************************************************************************/
setup(void)106*49cdfc7eSAndroid Build Coastguard Worker void setup(void)
107*49cdfc7eSAndroid Build Coastguard Worker {
108*49cdfc7eSAndroid Build Coastguard Worker 	/* Capture signals if any */
109*49cdfc7eSAndroid Build Coastguard Worker 	/* Create temporary directories */
110*49cdfc7eSAndroid Build Coastguard Worker 	TEST_PAUSE;
111*49cdfc7eSAndroid Build Coastguard Worker 	tst_tmpdir();
112*49cdfc7eSAndroid Build Coastguard Worker }
113*49cdfc7eSAndroid Build Coastguard Worker 
main(int ac,char ** av)114*49cdfc7eSAndroid Build Coastguard Worker int main(int ac, char **av)
115*49cdfc7eSAndroid Build Coastguard Worker {
116*49cdfc7eSAndroid Build Coastguard Worker 	int sig;
117*49cdfc7eSAndroid Build Coastguard Worker 	int lc;
118*49cdfc7eSAndroid Build Coastguard Worker 
119*49cdfc7eSAndroid Build Coastguard Worker 	tst_parse_opts(ac, av, NULL, NULL);
120*49cdfc7eSAndroid Build Coastguard Worker 
121*49cdfc7eSAndroid Build Coastguard Worker 	setup();
122*49cdfc7eSAndroid Build Coastguard Worker 
123*49cdfc7eSAndroid Build Coastguard Worker 	for (lc = 0; TEST_LOOPING(lc); ++lc) {
124*49cdfc7eSAndroid Build Coastguard Worker 		tst_count = 0;
125*49cdfc7eSAndroid Build Coastguard Worker 		for (testno = 0; testno < TST_TOTAL; ++testno) {
126*49cdfc7eSAndroid Build Coastguard Worker 
127*49cdfc7eSAndroid Build Coastguard Worker 			for (sig = -3; sig <= SIGRTMAX + 1; sig++) {
128*49cdfc7eSAndroid Build Coastguard Worker 				TEST(tst_syscall(__NR_ssetmask, sig));
129*49cdfc7eSAndroid Build Coastguard Worker 				tst_resm(TINFO, "Setting signal : %d -- "
130*49cdfc7eSAndroid Build Coastguard Worker 					"return of setmask : %ld",
131*49cdfc7eSAndroid Build Coastguard Worker 					sig, TEST_RETURN);
132*49cdfc7eSAndroid Build Coastguard Worker 				TEST(tst_syscall(__NR_sgetmask));
133*49cdfc7eSAndroid Build Coastguard Worker 				if (TEST_RETURN != sig) {
134*49cdfc7eSAndroid Build Coastguard Worker 					tst_resm(TINFO,
135*49cdfc7eSAndroid Build Coastguard Worker 						 "Oops,setting sig %d, got %ld",
136*49cdfc7eSAndroid Build Coastguard Worker 						 sig, TEST_RETURN);
137*49cdfc7eSAndroid Build Coastguard Worker 				} else
138*49cdfc7eSAndroid Build Coastguard Worker 					tst_resm(TPASS,
139*49cdfc7eSAndroid Build Coastguard Worker 						 "OK,setting sig %d, got %ld",
140*49cdfc7eSAndroid Build Coastguard Worker 						 sig, TEST_RETURN);
141*49cdfc7eSAndroid Build Coastguard Worker 				if (sig == SIGRTMAX + 1) {
142*49cdfc7eSAndroid Build Coastguard Worker 					cleanup();
143*49cdfc7eSAndroid Build Coastguard Worker 					tst_exit();
144*49cdfc7eSAndroid Build Coastguard Worker 				}
145*49cdfc7eSAndroid Build Coastguard Worker 			}
146*49cdfc7eSAndroid Build Coastguard Worker 		}
147*49cdfc7eSAndroid Build Coastguard Worker 	}
148*49cdfc7eSAndroid Build Coastguard Worker 	cleanup();
149*49cdfc7eSAndroid Build Coastguard Worker 	tst_exit();
150*49cdfc7eSAndroid Build Coastguard Worker }
151