• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *
3  *   Copyright (c) International Business Machines  Corp., 2002
4  *
5  *   This program is free software;  you can redistribute it and/or modify
6  *   it under the terms of the GNU General Public License as published by
7  *   the Free Software Foundation; either version 2 of the License, or
8  *   (at your option) any later version.
9  *
10  *   This program is distributed in the hope that it will be useful,
11  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
13  *   the GNU General Public License for more details.
14  *
15  *   You should have received a copy of the GNU General Public License
16  *   along with this program;  if not, write to the Free Software
17  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 /*
21  * NAME
22  * 	mlock01.c
23  *
24  * DESCRIPTION
25  * 	Test to see that mlock works
26  *$
27  * ALGORITHM
28  * 	test 1:
29  *		Call mlock with various valid addresses and lengths.  No
30  *		error should be returned
31  *
32  * USAGE:  <for command-line>
33  *         -c n    Run n copies concurrently
34  *         -e      Turn on errno logging
35  *         -f      Turn off functional testing
36  *         -h      Show this help screen
37  *         -i n    Execute test n times
38  *         -I x    Execute test for x seconds
39  *         -p      Pause for SIGUSR1 before starting
40  *         -P x    Pause for x seconds between iterations
41  *         -t      Turn on syscall timing
42  *
43  * HISTORY
44  *	06/2002 Written by Paul Larson
45  *
46  * RESTRICTIONS
47  * 	None
48  */
49 #include <errno.h>
50 #include <unistd.h>
51 #include <sys/mman.h>
52 #include "test.h"
53 
54 void setup();
55 void setup1(int);
56 void cleanup();
57 
58 char *TCID = "mlock01";
59 int TST_TOTAL = 4;
60 
61 void *addr1;
62 
63 struct test_case_t {
64 	void **addr;
65 	int len;
66 	void (*setupfunc) ();
67 } TC[] = {
68 	/* mlock should return ENOMEM when some or all of the address
69 	 * range pointed to by addr and len are not valid mapped pages
70 	 * in the address space of the process
71 	 */
72 	{
73 	&addr1, 1, setup1}, {
74 	&addr1, 1024, setup1}, {
75 	&addr1, 1024 * 1024, setup1}, {
76 	&addr1, 1024 * 1024 * 10, setup1}
77 };
78 
79 #if !defined(UCLINUX)
80 
main(int ac,char ** av)81 int main(int ac, char **av)
82 {
83 	int lc, i;
84 
85 	tst_parse_opts(ac, av, NULL, NULL);
86 
87 	setup();
88 
89 	/*
90 	 * FIXME (garrcoop): this should really test out whether or not the
91 	 * process's mappable address space is indeed accessible by the
92 	 * current user, instead of needing to be run by root all the time.
93 	 */
94 	tst_require_root();
95 
96 	for (lc = 0; TEST_LOOPING(lc); lc++) {
97 
98 		tst_count = 0;
99 
100 		for (i = 0; i < TST_TOTAL; i++) {
101 
102 			if (TC[i].setupfunc != NULL)
103 				TC[i].setupfunc(TC[i].len);
104 
105 			TEST(mlock(*(TC[i].addr), TC[i].len));
106 
107 			/* I'm confused -- given the description above this
108 			 * should fail as designed, but this application
109 			 * */
110 			if (TEST_RETURN == -1)
111 				tst_resm(TFAIL | TTERRNO, "mlock failed");
112 			else
113 				tst_resm(TPASS, "mlock passed");
114 		}
115 	}
116 
117 	cleanup();
118 
119 	tst_exit();
120 }
121 
122 #else
123 
main(void)124 int main(void)
125 {
126 	tst_brkm(TCONF, NULL, "test is not available on uClinux");
127 }
128 
129 #endif /* if !defined(UCLINUX) */
130 
setup(void)131 void setup(void)
132 {
133 	TEST_PAUSE;
134 }
135 
setup1(int len)136 void setup1(int len)
137 {
138 	addr1 = malloc(len);
139 	if (addr1 == NULL)
140 		tst_brkm(TFAIL, cleanup, "malloc failed");
141 }
142 
cleanup(void)143 void cleanup(void)
144 {
145 }
146