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 : munlock01
20 *
21 * EXECUTED BY : root / superuser
22 *
23 * TEST TITLE : Basic test for munlock(2)
24 *
25 * TEST CASE TOTAL : 4
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 munlock(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 * munlock01 [-c n] [-e] [-i n] [-I x] [-p x] [-t]
53 * where, -c n : Run n copies concurrently
54 * -e : Turn on errno logging.
55 * -h : Show this help screen
56 * -i n : Execute test n times.
57 * -I x : Execute test for x seconds.
58 * -p : Pause for SIGUSR1 before starting
59 * -P x : Pause for x seconds between iterations.
60 * -t : Turn on syscall timing.
61 *
62 * RESTRICTIONS
63 * Must be root/superuser to run it.
64 *****************************************************************************/
65
66 #include <errno.h>
67 #include <unistd.h>
68 #include <sys/mman.h>
69 #include "test.h"
70
71 void setup();
72 void setup1(int);
73 void cleanup();
74
75 char *TCID = "munlock01";
76 int TST_TOTAL = 4;
77
78 void *addr1;
79
80 struct test_case_t {
81 void **addr;
82 int len;
83 void (*setupfunc) ();
84 } TC[] = {
85 {
86 &addr1, 1, setup1}, {
87 &addr1, 1024, setup1}, {
88 &addr1, 1024 * 1024, setup1}, {
89 &addr1, 1024 * 1024 * 10, setup1}
90 };
91
main(int ac,char ** av)92 int main(int ac, char **av)
93 {
94 int lc, i;
95
96 tst_parse_opts(ac, av, NULL, NULL);
97
98 setup();
99
100 /* check looping state */
101 for (lc = 0; TEST_LOOPING(lc); lc++) {
102
103 tst_count = 0;
104
105 for (i = 0; i < TST_TOTAL; i++) {
106
107 if (TC[i].setupfunc != NULL)
108 TC[i].setupfunc(i);
109
110 TEST(munlock(*(TC[i].addr), TC[i].len));
111
112 /* check return code */
113 if (TEST_RETURN == -1) {
114 tst_resm(TFAIL | TTERRNO,
115 "mlock(%p, %d) Failed with "
116 "return=%ld", TC[i].addr, TC[i].len,
117 TEST_RETURN);
118 } else {
119 tst_resm(TPASS, "test %d passed length = %d",
120 i, TC[i].len);
121 }
122 }
123 }
124
125 /* cleanup and exit */
126 cleanup();
127
128 tst_exit();
129 }
130
setup1(int i)131 void setup1(int i)
132 {
133 addr1 = malloc(TC[i].len);
134 if (addr1 == NULL)
135 tst_brkm(TFAIL, cleanup, "malloc failed");
136 TEST(mlock(*(TC[i].addr), TC[i].len));
137
138 /* check return code */
139 if (TEST_RETURN == -1) {
140 tst_brkm(TFAIL | TTERRNO, cleanup,
141 "mlock(%p, %d) Failed with return=%ld", TC[i].addr,
142 TC[i].len, TEST_RETURN);
143 }
144 }
145
146 /* setup() - performs all ONE TIME setup for this test. */
setup(void)147 void setup(void)
148 {
149 tst_require_root();
150
151 tst_sig(NOFORK, DEF_HANDLER, cleanup);
152
153 TEST_PAUSE;
154 }
155
156 /*
157 * cleanup() - performs all ONE TIME cleanup for this test at
158 * completion or premature exit.
159 */
cleanup(void)160 void cleanup(void)
161 {
162 }
163