1f08c3bdfSopenharmony_ci/*
2f08c3bdfSopenharmony_ci * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
3f08c3bdfSopenharmony_ci *
4f08c3bdfSopenharmony_ci * This program is free software; you can redistribute it and/or modify it
5f08c3bdfSopenharmony_ci * under the terms of version 2 of the GNU General Public License as
6f08c3bdfSopenharmony_ci * published by the Free Software Foundation.
7f08c3bdfSopenharmony_ci *
8f08c3bdfSopenharmony_ci * This program is distributed in the hope that it would be useful, but
9f08c3bdfSopenharmony_ci * WITHOUT ANY WARRANTY; without even the implied warranty of
10f08c3bdfSopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11f08c3bdfSopenharmony_ci *
12f08c3bdfSopenharmony_ci * You should have received a copy of the GNU General Public License along
13f08c3bdfSopenharmony_ci * with this program; if not, write the Free Software Foundation, Inc.,
14f08c3bdfSopenharmony_ci * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15f08c3bdfSopenharmony_ci *
16f08c3bdfSopenharmony_ci */
17f08c3bdfSopenharmony_ci/**************************************************************************
18f08c3bdfSopenharmony_ci *
19f08c3bdfSopenharmony_ci *    TEST IDENTIFIER	: mlockall01
20f08c3bdfSopenharmony_ci *
21f08c3bdfSopenharmony_ci *    EXECUTED BY	: root / superuser
22f08c3bdfSopenharmony_ci *
23f08c3bdfSopenharmony_ci *    TEST TITLE	: Basic test for mlockall(2)
24f08c3bdfSopenharmony_ci *
25f08c3bdfSopenharmony_ci *    TEST CASE TOTAL	: 3
26f08c3bdfSopenharmony_ci *
27f08c3bdfSopenharmony_ci *    AUTHOR		: Nirmala Devi Dhanasekar <nirmala.devi@wipro.com>
28f08c3bdfSopenharmony_ci *
29f08c3bdfSopenharmony_ci *    SIGNALS
30f08c3bdfSopenharmony_ci * 	Uses SIGUSR1 to pause before test if option set.
31f08c3bdfSopenharmony_ci * 	(See the parse_opts(3) man page).
32f08c3bdfSopenharmony_ci *
33f08c3bdfSopenharmony_ci *    DESCRIPTION
34f08c3bdfSopenharmony_ci *	This is a Phase I test for the mlockall(2) system call.
35f08c3bdfSopenharmony_ci *	It is intended to provide a limited exposure of the system call.
36f08c3bdfSopenharmony_ci *
37f08c3bdfSopenharmony_ci * 	Setup:
38f08c3bdfSopenharmony_ci *	  Setup signal handling.
39f08c3bdfSopenharmony_ci *	  Pause for SIGUSR1 if option specified.
40f08c3bdfSopenharmony_ci *
41f08c3bdfSopenharmony_ci * 	Test:
42f08c3bdfSopenharmony_ci *	 Loop if the proper options are given.
43f08c3bdfSopenharmony_ci *	  Execute system call
44f08c3bdfSopenharmony_ci *	  Check return code, if system call failed (return=-1)
45f08c3bdfSopenharmony_ci *		Log the errno and Issue a FAIL message.
46f08c3bdfSopenharmony_ci *	  Otherwise, Issue a PASS message.
47f08c3bdfSopenharmony_ci *
48f08c3bdfSopenharmony_ci * 	Cleanup:
49f08c3bdfSopenharmony_ci * 	  Print errno log and/or timing stats if options given
50f08c3bdfSopenharmony_ci *
51f08c3bdfSopenharmony_ci * USAGE:  <for command-line>
52f08c3bdfSopenharmony_ci *  mlockall01 [-c n] [-e] [-i n] [-I x] [-p x] [-t]
53f08c3bdfSopenharmony_ci *		where,$
54f08c3bdfSopenharmony_ci *			-c n : Run n copies concurrently
55f08c3bdfSopenharmony_ci *			-e   : Turn on errno logging.
56f08c3bdfSopenharmony_ci *			-h   : Show this help screen
57f08c3bdfSopenharmony_ci *			-i n : Execute test n times.
58f08c3bdfSopenharmony_ci *			-I x : Execute test for x seconds.
59f08c3bdfSopenharmony_ci *			-p   : Pause for SIGUSR1 before starting
60f08c3bdfSopenharmony_ci *			-P x : Pause for x seconds between iterations.
61f08c3bdfSopenharmony_ci *			-t   : Turn on syscall timing.
62f08c3bdfSopenharmony_ci *
63f08c3bdfSopenharmony_ci * RESTRICTIONS
64f08c3bdfSopenharmony_ci *	Must run as root.
65f08c3bdfSopenharmony_ci *****************************************************************************/
66f08c3bdfSopenharmony_ci
67f08c3bdfSopenharmony_ci#include <errno.h>
68f08c3bdfSopenharmony_ci#include <unistd.h>
69f08c3bdfSopenharmony_ci#include <sys/mman.h>
70f08c3bdfSopenharmony_ci#include "test.h"
71f08c3bdfSopenharmony_ci
72f08c3bdfSopenharmony_civoid setup();
73f08c3bdfSopenharmony_civoid cleanup();
74f08c3bdfSopenharmony_ci
75f08c3bdfSopenharmony_cichar *TCID = "mlockall01";
76f08c3bdfSopenharmony_ciint TST_TOTAL = 3;
77f08c3bdfSopenharmony_ci
78f08c3bdfSopenharmony_ci#if !defined(UCLINUX)
79f08c3bdfSopenharmony_ci
80f08c3bdfSopenharmony_cistruct test_case_t {
81f08c3bdfSopenharmony_ci	int flag;
82f08c3bdfSopenharmony_ci	char *fdesc;
83f08c3bdfSopenharmony_ci} TC[] = {
84f08c3bdfSopenharmony_ci	/*
85f08c3bdfSopenharmony_ci	 * Check for all possible flags of mlockall
86f08c3bdfSopenharmony_ci	 */
87f08c3bdfSopenharmony_ci	{
88f08c3bdfSopenharmony_ci	MCL_CURRENT, "MCL_CURRENT"}, {
89f08c3bdfSopenharmony_ci	MCL_FUTURE, "MCL_FUTURE"}, {
90f08c3bdfSopenharmony_ci	MCL_CURRENT | MCL_FUTURE, "MCL_CURRENT|MCL_FUTURE"}
91f08c3bdfSopenharmony_ci};
92f08c3bdfSopenharmony_ci
93f08c3bdfSopenharmony_ciint main(int ac, char **av)
94f08c3bdfSopenharmony_ci{
95f08c3bdfSopenharmony_ci	int lc, i;
96f08c3bdfSopenharmony_ci
97f08c3bdfSopenharmony_ci	tst_parse_opts(ac, av, NULL, NULL);
98f08c3bdfSopenharmony_ci
99f08c3bdfSopenharmony_ci	setup();
100f08c3bdfSopenharmony_ci
101f08c3bdfSopenharmony_ci	for (lc = 0; TEST_LOOPING(lc); lc++) {
102f08c3bdfSopenharmony_ci
103f08c3bdfSopenharmony_ci		tst_count = 0;
104f08c3bdfSopenharmony_ci
105f08c3bdfSopenharmony_ci		for (i = 0; i < TST_TOTAL; i++) {
106f08c3bdfSopenharmony_ci
107f08c3bdfSopenharmony_ci			TEST(mlockall(TC[i].flag));
108f08c3bdfSopenharmony_ci
109f08c3bdfSopenharmony_ci			/* check return code */
110f08c3bdfSopenharmony_ci
111f08c3bdfSopenharmony_ci			if (TEST_RETURN == -1) {
112f08c3bdfSopenharmony_ci				tst_resm(TFAIL | TTERRNO,
113f08c3bdfSopenharmony_ci					 "mlockall(%s) Failed with "
114f08c3bdfSopenharmony_ci					 "return=%ld", TC[i].fdesc,
115f08c3bdfSopenharmony_ci					 TEST_RETURN);
116f08c3bdfSopenharmony_ci			} else {
117f08c3bdfSopenharmony_ci				tst_resm(TPASS, "mlockall test passed for %s",
118f08c3bdfSopenharmony_ci					 TC[i].fdesc);
119f08c3bdfSopenharmony_ci			}
120f08c3bdfSopenharmony_ci		}
121f08c3bdfSopenharmony_ci	}
122f08c3bdfSopenharmony_ci
123f08c3bdfSopenharmony_ci	/* cleanup and exit */
124f08c3bdfSopenharmony_ci
125f08c3bdfSopenharmony_ci	cleanup();
126f08c3bdfSopenharmony_ci
127f08c3bdfSopenharmony_ci	tst_exit();
128f08c3bdfSopenharmony_ci}
129f08c3bdfSopenharmony_ci
130f08c3bdfSopenharmony_ci#else
131f08c3bdfSopenharmony_ci
132f08c3bdfSopenharmony_ciint main(void)
133f08c3bdfSopenharmony_ci{
134f08c3bdfSopenharmony_ci	tst_resm(TINFO, "test is not available on uClinux");
135f08c3bdfSopenharmony_ci	tst_exit();
136f08c3bdfSopenharmony_ci}
137f08c3bdfSopenharmony_ci
138f08c3bdfSopenharmony_ci#endif
139f08c3bdfSopenharmony_ci
140f08c3bdfSopenharmony_ci/*
141f08c3bdfSopenharmony_ci * setup() - performs all ONE TIME setup for this test.
142f08c3bdfSopenharmony_ci */
143f08c3bdfSopenharmony_ci
144f08c3bdfSopenharmony_civoid setup(void)
145f08c3bdfSopenharmony_ci{
146f08c3bdfSopenharmony_ci	tst_require_root();
147f08c3bdfSopenharmony_ci
148f08c3bdfSopenharmony_ci	tst_sig(NOFORK, DEF_HANDLER, cleanup);
149f08c3bdfSopenharmony_ci
150f08c3bdfSopenharmony_ci	TEST_PAUSE;
151f08c3bdfSopenharmony_ci}
152f08c3bdfSopenharmony_ci
153f08c3bdfSopenharmony_ci/*
154f08c3bdfSopenharmony_ci * cleanup() - performs all ONE TIME cleanup for this test at
155f08c3bdfSopenharmony_ci *		completion or premature exit.
156f08c3bdfSopenharmony_ci */
157f08c3bdfSopenharmony_civoid cleanup(void)
158f08c3bdfSopenharmony_ci{
159f08c3bdfSopenharmony_ci}
160