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 <[email protected]>
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 struct test_case_t {
79 int flag;
80 char *fdesc;
81 } TC[] = {
82 /*
83 * Check for all possible flags of mlockall
84 */
85 {
86 MCL_CURRENT, "MCL_CURRENT"}, {
87 MCL_FUTURE, "MCL_FUTURE"}, {
88 MCL_CURRENT | MCL_FUTURE, "MCL_CURRENT|MCL_FUTURE"}
89 };
90
main(int ac,char ** av)91 int main(int ac, char **av)
92 {
93 int lc, i;
94
95 tst_parse_opts(ac, av, NULL, NULL);
96
97 setup();
98
99 for (lc = 0; TEST_LOOPING(lc); lc++) {
100
101 tst_count = 0;
102
103 for (i = 0; i < TST_TOTAL; i++) {
104
105 TEST(mlockall(TC[i].flag));
106
107 /* check return code */
108
109 if (TEST_RETURN == -1) {
110 tst_resm(TFAIL | TTERRNO,
111 "mlockall(%s) Failed with "
112 "return=%ld", TC[i].fdesc,
113 TEST_RETURN);
114 } else {
115 tst_resm(TPASS, "mlockall test passed for %s",
116 TC[i].fdesc);
117 }
118 }
119 }
120
121 /* cleanup and exit */
122
123 cleanup();
124
125 tst_exit();
126 }
127
128 /*
129 * setup() - performs all ONE TIME setup for this test.
130 */
131
setup(void)132 void setup(void)
133 {
134 tst_require_root();
135
136 tst_sig(NOFORK, DEF_HANDLER, cleanup);
137
138 TEST_PAUSE;
139 }
140
141 /*
142 * cleanup() - performs all ONE TIME cleanup for this test at
143 * completion or premature exit.
144 */
cleanup(void)145 void cleanup(void)
146 {
147 }
148