• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of version 2 of the GNU General Public License as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it would be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11  *
12  * You should have received a copy of the GNU General Public License along
13  * with this program; if not, write the Free Software Foundation, Inc.,
14  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15  *
16  */
17 /**************************************************************************
18  *
19  *    TEST IDENTIFIER	: mlockall01
20  *
21  *    EXECUTED BY	: root / superuser
22  *
23  *    TEST TITLE	: Basic test for mlockall(2)
24  *
25  *    TEST CASE TOTAL	: 3
26  *
27  *    AUTHOR		: Nirmala Devi Dhanasekar <nirmala.devi@wipro.com>
28  *
29  *    SIGNALS
30  * 	Uses SIGUSR1 to pause before test if option set.
31  * 	(See the parse_opts(3) man page).
32  *
33  *    DESCRIPTION
34  *	This is a Phase I test for the mlockall(2) system call.
35  *	It is intended to provide a limited exposure of the system call.
36  *
37  * 	Setup:
38  *	  Setup signal handling.
39  *	  Pause for SIGUSR1 if option specified.
40  *
41  * 	Test:
42  *	 Loop if the proper options are given.
43  *	  Execute system call
44  *	  Check return code, if system call failed (return=-1)
45  *		Log the errno and Issue a FAIL message.
46  *	  Otherwise, Issue a PASS message.
47  *
48  * 	Cleanup:
49  * 	  Print errno log and/or timing stats if options given
50  *
51  * USAGE:  <for command-line>
52  *  mlockall01 [-c n] [-e] [-i n] [-I x] [-p x] [-t]
53  *		where,$
54  *			-c n : Run n copies concurrently
55  *			-e   : Turn on errno logging.
56  *			-h   : Show this help screen
57  *			-i n : Execute test n times.
58  *			-I x : Execute test for x seconds.
59  *			-p   : Pause for SIGUSR1 before starting
60  *			-P x : Pause for x seconds between iterations.
61  *			-t   : Turn on syscall timing.
62  *
63  * RESTRICTIONS
64  *	Must run as root.
65  *****************************************************************************/
66 
67 #include <errno.h>
68 #include <unistd.h>
69 #include <sys/mman.h>
70 #include "test.h"
71 
72 void setup();
73 void cleanup();
74 
75 char *TCID = "mlockall01";
76 int TST_TOTAL = 3;
77 
78 #if !defined(UCLINUX)
79 
80 struct test_case_t {
81 	int flag;
82 	char *fdesc;
83 } TC[] = {
84 	/*
85 	 * Check for all possible flags of mlockall
86 	 */
87 	{
88 	MCL_CURRENT, "MCL_CURRENT"}, {
89 	MCL_FUTURE, "MCL_FUTURE"}, {
90 	MCL_CURRENT | MCL_FUTURE, "MCL_CURRENT|MCL_FUTURE"}
91 };
92 
main(int ac,char ** av)93 int main(int ac, char **av)
94 {
95 	int lc, i;
96 
97 	tst_parse_opts(ac, av, NULL, NULL);
98 
99 	setup();
100 
101 	for (lc = 0; TEST_LOOPING(lc); lc++) {
102 
103 		tst_count = 0;
104 
105 		for (i = 0; i < TST_TOTAL; i++) {
106 
107 			TEST(mlockall(TC[i].flag));
108 
109 			/* check return code */
110 
111 			if (TEST_RETURN == -1) {
112 				tst_resm(TFAIL | TTERRNO,
113 					 "mlockall(%s) Failed with "
114 					 "return=%ld", TC[i].fdesc,
115 					 TEST_RETURN);
116 			} else {
117 				tst_resm(TPASS, "mlockall test passed for %s",
118 					 TC[i].fdesc);
119 			}
120 		}
121 	}
122 
123 	/* cleanup and exit */
124 
125 	cleanup();
126 
127 	tst_exit();
128 }
129 
130 #else
131 
main(void)132 int main(void)
133 {
134 	tst_resm(TINFO, "test is not available on uClinux");
135 	tst_exit();
136 }
137 
138 #endif
139 
140 /*
141  * setup() - performs all ONE TIME setup for this test.
142  */
143 
setup(void)144 void setup(void)
145 {
146 	tst_require_root();
147 
148 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
149 
150 	TEST_PAUSE;
151 }
152 
153 /*
154  * cleanup() - performs all ONE TIME cleanup for this test at
155  *		completion or premature exit.
156  */
cleanup(void)157 void cleanup(void)
158 {
159 }
160