blob: bf95e6c1a5b461e48f1304250559b58c71070249 [file] [log] [blame]
vapierd13d74b2006-02-11 07:24:00 +00001/*
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
Wanlong Gaofed96412012-10-24 10:10:29 +080013 * with this program; if not, write the Free Software Foundation, Inc.,
14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
vapierd13d74b2006-02-11 07:24:00 +000015 *
16 */
17/**************************************************************************
subrata_modak4bb656a2009-02-26 12:02:09 +000018 *
vapierd13d74b2006-02-11 07:24:00 +000019 * TEST IDENTIFIER : munlock01
subrata_modak4bb656a2009-02-26 12:02:09 +000020 *
vapierd13d74b2006-02-11 07:24:00 +000021 * EXECUTED BY : root / superuser
subrata_modak4bb656a2009-02-26 12:02:09 +000022 *
vapierd13d74b2006-02-11 07:24:00 +000023 * TEST TITLE : Basic test for munlock(2)
subrata_modak4bb656a2009-02-26 12:02:09 +000024 *
vapierd13d74b2006-02-11 07:24:00 +000025 * TEST CASE TOTAL : 4
subrata_modak4bb656a2009-02-26 12:02:09 +000026 *
vapierd13d74b2006-02-11 07:24:00 +000027 * AUTHOR : Nirmala Devi Dhanasekar <nirmala.devi@wipro.com>
subrata_modak4bb656a2009-02-26 12:02:09 +000028 *
vapierd13d74b2006-02-11 07:24:00 +000029 * 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.
subrata_modak4bb656a2009-02-26 12:02:09 +000036 *
vapierd13d74b2006-02-11 07:24:00 +000037 * Setup:
38 * Setup signal handling.
39 * Pause for SIGUSR1 if option specified.
subrata_modak4bb656a2009-02-26 12:02:09 +000040 *
vapierd13d74b2006-02-11 07:24:00 +000041 * 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.
subrata_modak4bb656a2009-02-26 12:02:09 +000047 *
vapierd13d74b2006-02-11 07:24:00 +000048 * Cleanup:
49 * Print errno log and/or timing stats if options given
subrata_modak4bb656a2009-02-26 12:02:09 +000050 *
vapierd13d74b2006-02-11 07:24:00 +000051 * 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#include "usctest.h"
71
72void setup();
73void setup1(int);
74void cleanup();
75
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020076char *TCID = "munlock01";
77int TST_TOTAL = 4;
vapierd13d74b2006-02-11 07:24:00 +000078
79int exp_enos[] = { 0 };
80
81void *addr1;
82
83struct test_case_t {
84 void **addr;
85 int len;
86 void (*setupfunc) ();
87} TC[] = {
subrata_modak56207ce2009-03-23 13:35:39 +000088 {
89 &addr1, 1, setup1}, {
90 &addr1, 1024, setup1}, {
91 &addr1, 1024 * 1024, setup1}, {
92 &addr1, 1024 * 1024 * 10, setup1}
vapierd13d74b2006-02-11 07:24:00 +000093};
94
95int main(int ac, char **av)
96{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020097 int lc, i;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020098 const char *msg;
vapierd13d74b2006-02-11 07:24:00 +000099
Garrett Cooper45e285d2010-11-22 12:19:25 -0800100 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
vapierd13d74b2006-02-11 07:24:00 +0000101 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
102 tst_exit();
103 }
104
vapierd13d74b2006-02-11 07:24:00 +0000105 setup();
106
107 /* check looping state */
108 for (lc = 0; TEST_LOOPING(lc); lc++) {
109
Caspar Zhangd59a6592013-03-07 14:59:12 +0800110 tst_count = 0;
vapierd13d74b2006-02-11 07:24:00 +0000111
112 for (i = 0; i < TST_TOTAL; i++) {
113
114 if (TC[i].setupfunc != NULL)
115 TC[i].setupfunc(i);
116
117 TEST(munlock(*(TC[i].addr), TC[i].len));
118
119 /* check return code */
120 if (TEST_RETURN == -1) {
121 TEST_ERROR_LOG(TEST_ERRNO);
Wanlong Gao354ebb42012-12-07 10:10:04 +0800122 tst_resm(TFAIL | TTERRNO,
123 "mlock(%p, %d) Failed with "
124 "return=%ld", TC[i].addr, TC[i].len,
subrata_modak923b23f2009-11-02 13:57:16 +0000125 TEST_RETURN);
vapierd13d74b2006-02-11 07:24:00 +0000126 } else {
127 tst_resm(TPASS, "test %d passed length = %d",
128 i, TC[i].len);
129 }
130 }
Garrett Cooper2c282152010-12-16 00:55:50 -0800131 }
vapierd13d74b2006-02-11 07:24:00 +0000132
133 /* cleanup and exit */
134 cleanup();
135
Garrett Cooper2c282152010-12-16 00:55:50 -0800136 tst_exit();
137}
vapierd13d74b2006-02-11 07:24:00 +0000138
139void setup1(int i)
140{
subrata_modak56207ce2009-03-23 13:35:39 +0000141 addr1 = (char *)malloc(TC[i].len);
vapierd13d74b2006-02-11 07:24:00 +0000142 if (addr1 == NULL)
143 tst_brkm(TFAIL, cleanup, "malloc failed");
144 TEST(mlock(*(TC[i].addr), TC[i].len));
145
146 /* check return code */
147 if (TEST_RETURN == -1) {
148 TEST_ERROR_LOG(TEST_ERRNO);
Wanlong Gao354ebb42012-12-07 10:10:04 +0800149 tst_brkm(TFAIL | TTERRNO, cleanup,
150 "mlock(%p, %d) Failed with return=%ld", TC[i].addr,
151 TC[i].len, TEST_RETURN);
subrata_modak4bb656a2009-02-26 12:02:09 +0000152 }
vapierd13d74b2006-02-11 07:24:00 +0000153}
154
155/* setup() - performs all ONE TIME setup for this test. */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400156void setup(void)
vapierd13d74b2006-02-11 07:24:00 +0000157{
Garrett Cooper2c282152010-12-16 00:55:50 -0800158
vapierd13d74b2006-02-11 07:24:00 +0000159 tst_sig(NOFORK, DEF_HANDLER, cleanup);
160
subrata_modak56207ce2009-03-23 13:35:39 +0000161 /* Check whether we are root */
vapierd13d74b2006-02-11 07:24:00 +0000162 if (geteuid() != 0) {
Garrett Cooper53740502010-12-16 00:04:01 -0800163 tst_brkm(TBROK, NULL, "Test must be run as root");
vapierd13d74b2006-02-11 07:24:00 +0000164 }
165
166 /* set the expected errnos... */
167 TEST_EXP_ENOS(exp_enos);
168
vapierd13d74b2006-02-11 07:24:00 +0000169 TEST_PAUSE;
170}
171
172/*
173 * cleanup() - performs all ONE TIME cleanup for this test at
174 * completion or premature exit.
175 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400176void cleanup(void)
vapierd13d74b2006-02-11 07:24:00 +0000177{
178 TEST_CLEANUP;
179
Chris Dearmanec6edca2012-10-17 19:54:01 -0700180}