blob: 201e967f76cb331e6051e85c18defc03dac47198 [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 : mlockall01
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 mlockall(2)
subrata_modak4bb656a2009-02-26 12:02:09 +000024 *
vapierd13d74b2006-02-11 07:24:00 +000025 * TEST CASE TOTAL : 3
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 mlockall(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 * mlockall01 [-c n] [-e] [-i n] [-I x] [-p x] [-t]
subrata_modak56207ce2009-03-23 13:35:39 +000053 * where,$
vapierd13d74b2006-02-11 07:24:00 +000054 * -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"
vapierd13d74b2006-02-11 07:24:00 +000071
72void setup();
73void cleanup();
74
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020075char *TCID = "mlockall01";
76int TST_TOTAL = 3;
vapierd13d74b2006-02-11 07:24:00 +000077
vapierd13d74b2006-02-11 07:24:00 +000078#if !defined(UCLINUX)
79
80struct test_case_t {
81 int flag;
82 char *fdesc;
83} TC[] = {
84 /*
85 * Check for all possible flags of mlockall
86 */
subrata_modak56207ce2009-03-23 13:35:39 +000087 {
88 MCL_CURRENT, "MCL_CURRENT"}, {
89 MCL_FUTURE, "MCL_FUTURE"}, {
90 MCL_CURRENT | MCL_FUTURE, "MCL_CURRENT|MCL_FUTURE"}
vapierd13d74b2006-02-11 07:24:00 +000091};
92
93int main(int ac, char **av)
94{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020095 int lc, i;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020096 const char *msg;
vapierd13d74b2006-02-11 07:24:00 +000097
Garrett Cooper45e285d2010-11-22 12:19:25 -080098 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
vapierd13d74b2006-02-11 07:24:00 +000099 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
vapierd13d74b2006-02-11 07:24:00 +0000100 }
101
vapierd13d74b2006-02-11 07:24:00 +0000102 setup();
103
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 TEST(mlockall(TC[i].flag));
111
112 /* check return code */
113
114 if (TEST_RETURN == -1) {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800115 tst_resm(TFAIL | TTERRNO,
116 "mlockall(%s) Failed with "
117 "return=%ld", TC[i].fdesc,
118 TEST_RETURN);
vapierd13d74b2006-02-11 07:24:00 +0000119 } else {
120 tst_resm(TPASS, "mlockall test passed for %s",
121 TC[i].fdesc);
122 }
123 }
Garrett Cooper2c282152010-12-16 00:55:50 -0800124 }
vapierd13d74b2006-02-11 07:24:00 +0000125
126 /* cleanup and exit */
127
128 cleanup();
129
Garrett Cooper2c282152010-12-16 00:55:50 -0800130 tst_exit();
131}
vapierd13d74b2006-02-11 07:24:00 +0000132
133#else
134
Mike Frysingerc57fba52014-04-09 18:56:30 -0400135int main(void)
vapierd13d74b2006-02-11 07:24:00 +0000136{
vapier81a63072006-02-27 04:29:21 +0000137 tst_resm(TINFO, "test is not available on uClinux");
Garrett Cooper2c282152010-12-16 00:55:50 -0800138 tst_exit();
vapierd13d74b2006-02-11 07:24:00 +0000139}
140
141#endif
142
143/*
144 * setup() - performs all ONE TIME setup for this test.
145 */
146
Mike Frysingerc57fba52014-04-09 18:56:30 -0400147void setup(void)
vapierd13d74b2006-02-11 07:24:00 +0000148{
Nicolas Jolyd4ceb372014-06-22 17:03:57 +0200149 tst_require_root(NULL);
Garrett Cooper2c282152010-12-16 00:55:50 -0800150
vapierd13d74b2006-02-11 07:24:00 +0000151 tst_sig(NOFORK, DEF_HANDLER, cleanup);
152
vapierd13d74b2006-02-11 07:24:00 +0000153 TEST_PAUSE;
154}
155
vapierd13d74b2006-02-11 07:24:00 +0000156/*
157 * cleanup() - performs all ONE TIME cleanup for this test at
158 * completion or premature exit.
159 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400160void cleanup(void)
vapierd13d74b2006-02-11 07:24:00 +0000161{
Chris Dearmanec6edca2012-10-17 19:54:01 -0700162}