blob: 5e31e4782643ac6e648c712dafca05802d38062b [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"
vapierd13d74b2006-02-11 07:24:00 +000070
71void setup();
72void setup1(int);
73void cleanup();
74
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020075char *TCID = "munlock01";
76int TST_TOTAL = 4;
vapierd13d74b2006-02-11 07:24:00 +000077
vapierd13d74b2006-02-11 07:24:00 +000078void *addr1;
79
80struct test_case_t {
81 void **addr;
82 int len;
83 void (*setupfunc) ();
84} TC[] = {
subrata_modak56207ce2009-03-23 13:35:39 +000085 {
86 &addr1, 1, setup1}, {
87 &addr1, 1024, setup1}, {
88 &addr1, 1024 * 1024, setup1}, {
89 &addr1, 1024 * 1024 * 10, setup1}
vapierd13d74b2006-02-11 07:24:00 +000090};
91
92int main(int ac, char **av)
93{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020094 int lc, i;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020095 const char *msg;
vapierd13d74b2006-02-11 07:24:00 +000096
Garrett Cooper45e285d2010-11-22 12:19:25 -080097 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
vapierd13d74b2006-02-11 07:24:00 +000098 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
vapierd13d74b2006-02-11 07:24:00 +000099 }
100
vapierd13d74b2006-02-11 07:24:00 +0000101 setup();
102
103 /* check looping state */
104 for (lc = 0; TEST_LOOPING(lc); lc++) {
105
Caspar Zhangd59a6592013-03-07 14:59:12 +0800106 tst_count = 0;
vapierd13d74b2006-02-11 07:24:00 +0000107
108 for (i = 0; i < TST_TOTAL; i++) {
109
110 if (TC[i].setupfunc != NULL)
111 TC[i].setupfunc(i);
112
113 TEST(munlock(*(TC[i].addr), TC[i].len));
114
115 /* check return code */
116 if (TEST_RETURN == -1) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800117 tst_resm(TFAIL | TTERRNO,
118 "mlock(%p, %d) Failed with "
119 "return=%ld", TC[i].addr, TC[i].len,
subrata_modak923b23f2009-11-02 13:57:16 +0000120 TEST_RETURN);
vapierd13d74b2006-02-11 07:24:00 +0000121 } else {
122 tst_resm(TPASS, "test %d passed length = %d",
123 i, TC[i].len);
124 }
125 }
Garrett Cooper2c282152010-12-16 00:55:50 -0800126 }
vapierd13d74b2006-02-11 07:24:00 +0000127
128 /* cleanup and exit */
129 cleanup();
130
Garrett Cooper2c282152010-12-16 00:55:50 -0800131 tst_exit();
132}
vapierd13d74b2006-02-11 07:24:00 +0000133
134void setup1(int i)
135{
Cyril Hrubisd218f342014-09-23 13:14:56 +0200136 addr1 = malloc(TC[i].len);
vapierd13d74b2006-02-11 07:24:00 +0000137 if (addr1 == NULL)
138 tst_brkm(TFAIL, cleanup, "malloc failed");
139 TEST(mlock(*(TC[i].addr), TC[i].len));
140
141 /* check return code */
142 if (TEST_RETURN == -1) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800143 tst_brkm(TFAIL | TTERRNO, cleanup,
144 "mlock(%p, %d) Failed with return=%ld", TC[i].addr,
145 TC[i].len, TEST_RETURN);
subrata_modak4bb656a2009-02-26 12:02:09 +0000146 }
vapierd13d74b2006-02-11 07:24:00 +0000147}
148
149/* setup() - performs all ONE TIME setup for this test. */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400150void setup(void)
vapierd13d74b2006-02-11 07:24:00 +0000151{
Nicolas Jolyd4ceb372014-06-22 17:03:57 +0200152 tst_require_root(NULL);
Garrett Cooper2c282152010-12-16 00:55:50 -0800153
vapierd13d74b2006-02-11 07:24:00 +0000154 tst_sig(NOFORK, DEF_HANDLER, cleanup);
155
vapierd13d74b2006-02-11 07:24:00 +0000156 TEST_PAUSE;
157}
158
159/*
160 * cleanup() - performs all ONE TIME cleanup for this test at
161 * completion or premature exit.
162 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400163void cleanup(void)
vapierd13d74b2006-02-11 07:24:00 +0000164{
Chris Dearmanec6edca2012-10-17 19:54:01 -0700165}