xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/ssetmask/ssetmask01.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:        ssetmask01.c                                           */
22*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
23*49cdfc7eSAndroid Build Coastguard Worker /* Description: This tests the ssetmask() syscall                      */
24*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
25*49cdfc7eSAndroid Build Coastguard Worker /* Usage:  <for command-line>                                                 */
26*49cdfc7eSAndroid Build Coastguard Worker /* ssetmask01 [-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: 2                                                             */
35*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
36*49cdfc7eSAndroid Build Coastguard Worker /* Test Name:   ssetmask01                                             */
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 #include <stdio.h>
42*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
43*49cdfc7eSAndroid Build Coastguard Worker #include <stdlib.h>
44*49cdfc7eSAndroid Build Coastguard Worker #include <signal.h>
45*49cdfc7eSAndroid Build Coastguard Worker 
46*49cdfc7eSAndroid Build Coastguard Worker #include "test.h"
47*49cdfc7eSAndroid Build Coastguard Worker #include "lapi/syscalls.h"
48*49cdfc7eSAndroid Build Coastguard Worker 
49*49cdfc7eSAndroid Build Coastguard Worker char *TCID = "ssetmask01";
50*49cdfc7eSAndroid Build Coastguard Worker int testno;
51*49cdfc7eSAndroid Build Coastguard Worker int TST_TOTAL = 2;
52*49cdfc7eSAndroid Build Coastguard Worker 
53*49cdfc7eSAndroid Build Coastguard Worker /* Extern Global Functions */
54*49cdfc7eSAndroid Build Coastguard Worker /******************************************************************************/
55*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
56*49cdfc7eSAndroid Build Coastguard Worker /* Function:    cleanup                                                       */
57*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
58*49cdfc7eSAndroid Build Coastguard Worker /* Description: Performs all one time clean up for this test on successful    */
59*49cdfc7eSAndroid Build Coastguard Worker /*              completion,  premature exit or  failure. Closes all temporary */
60*49cdfc7eSAndroid Build Coastguard Worker /*              files, removes all temporary directories exits the test with  */
61*49cdfc7eSAndroid Build Coastguard Worker /*              appropriate return code by calling tst_exit() function.       */
62*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
63*49cdfc7eSAndroid Build Coastguard Worker /* Input:       None.                                                         */
64*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
65*49cdfc7eSAndroid Build Coastguard Worker /* Output:      None.                                                         */
66*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
67*49cdfc7eSAndroid Build Coastguard Worker /* Return:      On failure - Exits calling tst_exit(). Non '0' return code.   */
68*49cdfc7eSAndroid Build Coastguard Worker /*              On success - Exits calling tst_exit(). With '0' return code.  */
69*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
70*49cdfc7eSAndroid Build Coastguard Worker /******************************************************************************/
cleanup(void)71*49cdfc7eSAndroid Build Coastguard Worker void cleanup(void)
72*49cdfc7eSAndroid Build Coastguard Worker {
73*49cdfc7eSAndroid Build Coastguard Worker 
74*49cdfc7eSAndroid Build Coastguard Worker 	tst_rmdir();
75*49cdfc7eSAndroid Build Coastguard Worker 
76*49cdfc7eSAndroid Build Coastguard Worker }
77*49cdfc7eSAndroid Build Coastguard Worker 
78*49cdfc7eSAndroid Build Coastguard Worker /* Local  Functions */
79*49cdfc7eSAndroid Build Coastguard Worker /******************************************************************************/
80*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
81*49cdfc7eSAndroid Build Coastguard Worker /* Function:    setup                                                         */
82*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
83*49cdfc7eSAndroid Build Coastguard Worker /* Description: Performs all one time setup for this test. This function is   */
84*49cdfc7eSAndroid Build Coastguard Worker /*              typically used to capture signals, create temporary dirs      */
85*49cdfc7eSAndroid Build Coastguard Worker /*              and temporary files that may be used in the course of this    */
86*49cdfc7eSAndroid Build Coastguard Worker /*              test.                                                         */
87*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
88*49cdfc7eSAndroid Build Coastguard Worker /* Input:       None.                                                         */
89*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
90*49cdfc7eSAndroid Build Coastguard Worker /* Output:      None.                                                         */
91*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
92*49cdfc7eSAndroid Build Coastguard Worker /* Return:      On failure - Exits by calling cleanup().                      */
93*49cdfc7eSAndroid Build Coastguard Worker /*              On success - returns 0.                                       */
94*49cdfc7eSAndroid Build Coastguard Worker /*                                                                            */
95*49cdfc7eSAndroid Build Coastguard Worker /******************************************************************************/
setup(void)96*49cdfc7eSAndroid Build Coastguard Worker void setup(void)
97*49cdfc7eSAndroid Build Coastguard Worker {
98*49cdfc7eSAndroid Build Coastguard Worker 	/* Capture signals if any */
99*49cdfc7eSAndroid Build Coastguard Worker 	/* Create temporary directories */
100*49cdfc7eSAndroid Build Coastguard Worker 	TEST_PAUSE;
101*49cdfc7eSAndroid Build Coastguard Worker 	tst_tmpdir();
102*49cdfc7eSAndroid Build Coastguard Worker }
103*49cdfc7eSAndroid Build Coastguard Worker 
main(int ac,char ** av)104*49cdfc7eSAndroid Build Coastguard Worker int main(int ac, char **av)
105*49cdfc7eSAndroid Build Coastguard Worker {
106*49cdfc7eSAndroid Build Coastguard Worker 	int lc;
107*49cdfc7eSAndroid Build Coastguard Worker 
108*49cdfc7eSAndroid Build Coastguard Worker 	tst_parse_opts(ac, av, NULL, NULL);
109*49cdfc7eSAndroid Build Coastguard Worker 
110*49cdfc7eSAndroid Build Coastguard Worker 	setup();
111*49cdfc7eSAndroid Build Coastguard Worker 
112*49cdfc7eSAndroid Build Coastguard Worker 	for (lc = 0; TEST_LOOPING(lc); ++lc) {
113*49cdfc7eSAndroid Build Coastguard Worker 		tst_count = 0;
114*49cdfc7eSAndroid Build Coastguard Worker 		for (testno = 0; testno < TST_TOTAL; ++testno) {
115*49cdfc7eSAndroid Build Coastguard Worker 			tst_syscall(__NR_ssetmask, SIGALRM);
116*49cdfc7eSAndroid Build Coastguard Worker 			TEST(tst_syscall(__NR_sgetmask));
117*49cdfc7eSAndroid Build Coastguard Worker 			if (TEST_RETURN != SIGALRM) {
118*49cdfc7eSAndroid Build Coastguard Worker 				tst_brkm(TFAIL | TTERRNO, cleanup,
119*49cdfc7eSAndroid Build Coastguard Worker 					 "sgetmask() failed");
120*49cdfc7eSAndroid Build Coastguard Worker 			}
121*49cdfc7eSAndroid Build Coastguard Worker 			TEST(tst_syscall(__NR_ssetmask, SIGUSR1));
122*49cdfc7eSAndroid Build Coastguard Worker 			if (TEST_RETURN != SIGALRM) {
123*49cdfc7eSAndroid Build Coastguard Worker 				tst_brkm(TFAIL | TTERRNO, cleanup,
124*49cdfc7eSAndroid Build Coastguard Worker 					 "ssetmask() failed");
125*49cdfc7eSAndroid Build Coastguard Worker 			}
126*49cdfc7eSAndroid Build Coastguard Worker 			tst_resm(TPASS, "Got SIGALRM--Test PASS ");
127*49cdfc7eSAndroid Build Coastguard Worker 		}
128*49cdfc7eSAndroid Build Coastguard Worker 	}
129*49cdfc7eSAndroid Build Coastguard Worker 	cleanup();
130*49cdfc7eSAndroid Build Coastguard Worker 	tst_exit();
131*49cdfc7eSAndroid Build Coastguard Worker }
132