3 * Copyright (c) International Business Machines Corp., 2004
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * Test Name: hugemmap03
23 * Test Description: Test that a normal page cannot be mapped into a high
26 * Usage: <for command-line>
27 * hugemmap03 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
28 * where, -c n : Run n copies concurrently.
29 * -f : Turn off functionality Testing.
30 * -i n : Execute test n times.
31 * -I x : Execute test for x seconds.
32 * -P x : Pause for x seconds between iterations.
33 * -t : Turn on syscall timing.
36 * 04/2004 Written by Robbie Williamson
39 * Must be compiled in 64-bit mode.
52 #include <sys/types.h>
57 #define PAGE_SIZE ((1UL) << 12) /* Normal page size */
58 #define HIGH_ADDR (void *)(0x1000000000000)
60 char* TEMPFILE
="mmapfile";
62 char *TCID
="hugemmap03"; /* Test program identifier. */
63 int TST_TOTAL
=1; /* Total number of test cases. */
64 extern int Tst_count
; /* Test Case counter for tst_* routines */
65 unsigned long *addr
; /* addr of memory mapped region */
66 int fildes
; /* file descriptor for tempfile */
67 char *Hopt
; /* location of hugetlbfs */
69 void setup(); /* Main setup function of test */
70 void cleanup(); /* cleanup function for the test */
74 printf(" -H /.. Location of hugetlbfs, i.e. -H /var/hugetlbfs \n");
78 main(int ac
, char **av
)
80 #if __WORDSIZE==32 /* 32-bit compiled */
81 tst_resm(TCONF
,"This test is only for 64bit");
85 #else /* 64-bit compiled */
86 int lc
; /* loop counter */
87 char *msg
; /* message returned from parse_opts */
88 int Hflag
=0; /* binary flag: opt or not */
90 option_t options
[] = {
91 { "H:", &Hflag
, &Hopt
}, /* Required for location of hugetlbfs */
92 { NULL
, NULL
, NULL
} /* NULL required to end array */
95 /* Parse standard options given to run the test. */
96 msg
= parse_opts(ac
, av
, options
, &help
);
97 if (msg
!= (char *) NULL
) {
98 tst_brkm(TBROK
, NULL
, "OPTION PARSING ERROR - %s, use -help", msg
);
103 tst_brkm(TBROK
, NULL
, "-H option is REQUIRED for this test, use -h for options help");
107 /* Perform global setup for test */
110 /* Check looping state if -i option given */
111 for (lc
= 0; TEST_LOOPING(lc
); lc
++) {
113 /* Creat a temporary file used for huge mapping */
114 if ((fildes
= open(TEMPFILE
, O_RDWR
| O_CREAT
, 0666)) < 0) {
115 tst_brkm(TFAIL
, cleanup
,
116 "open() on %s Failed, errno=%d : %s",
117 TEMPFILE
, errno
, strerror(errno
));
120 /* Reset Tst_count in case we are looping. */
123 /* Attempt to mmap using normal pages and a high memory address */
125 addr
= mmap(HIGH_ADDR
, PAGE_SIZE
, PROT_READ
,
126 MAP_SHARED
| MAP_FIXED
, fildes
, 0);
127 if (addr
!= MAP_FAILED
) {
128 tst_resm(TFAIL
, "Normal mmap() into high region unexpectedly succeeded on %s, errno=%d : %s",
129 TEMPFILE
, errno
, strerror(errno
));
132 tst_resm(TPASS
, "Normal mmap() into high region failed correctly");
137 } /* End for TEST_LOOPING */
139 /* Call cleanup() to undo setup done for the test. */
148 * setup() - performs all ONE TIME setup for this test.
150 * Get system page size, allocate and initialize the string dummy.
151 * Initialize addr such that it is more than one page below the break
152 * address of the process, and initialize one page region from addr
154 * Creat a temporary directory and a file under it.
155 * Write some known data into file and get the size of the file.
162 sprintf(mypid
,"/%d",getpid());
163 TEMPFILE
=strcat(mypid
,TEMPFILE
);
164 TEMPFILE
=strcat(Hopt
,TEMPFILE
);
166 /* capture signals */
167 tst_sig(FORK
, DEF_HANDLER
, cleanup
);
169 /* Pause if that option was specified */
176 * cleanup() - performs all ONE TIME cleanup for this test at
177 * completion or premature exit.
178 * Remove the temporary directory created.
184 * print timing stats if that option was specified.
190 /* exit with return code appropriate for results */