2 /* 01/02/2003 Port to LTP avenkat@us.ibm.com*/
3 /* 06/30/2001 Port to Linux nsharoff@us.ibm.com */
5 * Copyright (c) International Business Machines Corp., 2003
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
16 * the GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * This test mmaps a portion of a file, and then mmaps the next
25 * portion of the file in front of the virtual space containing the
26 * original mmap. It then mmaps the preceding portion of the file behind
27 * the original mmap. None of the mmaps can be concatenated.
29 #include <sys/types.h>
36 /* #include <sys/pte.h> */
38 /***** LTP Port *****/
43 #ifndef MMU_NARROWPTEPG
44 #define MMU_NARROWPTEPG 1024
47 /***** LTP Port *****/
51 int local_flag
= PASSED
;
52 char *TCID
= "mmapstress05";//mfile_insque
61 #define ERROR(M) (void)fprintf(stderr, "%s: errno = %d; " M "\n", \
63 #define CLEAN (void)close(fd); \
64 if (unlink(tmpname)) { \
65 ERROR("couldn't clean up temp file"); \
68 #define CERROR(M) CLEAN; ERROR(M)
70 #define CATCH_SIG(SIG) \
71 if (sigaction(SIG, &sa, 0) == -1) { \
72 ERROR("couldn't catch signal " #SIG); \
76 extern time_t time(time_t *);
77 extern char *ctime(const time_t *);
78 extern void exit(int);
81 //static char *tmpname; 12/31/02
82 static char tmpname
[] = "fileXXXXXX";
83 static char *progname
;
91 * Don't check error codes - we could be signaled before the file is
95 (void)unlink(tmpname
);
100 main(int argc
, char *argv
[])
102 size_t pagesize
= (size_t)sysconf(_SC_PAGE_SIZE
);
110 (void)fprintf(stderr
, "argc == 0\n");
116 // (void)printf("%s: Started %s", argv[0], ctime(&t)); LTP Port
117 if (sbrk(pagesize
-((ulong
)sbrk(0)&(pagesize
-1))) == (char *)-1) {
118 ERROR("couldn't round up brk");
121 if ((buf
= sbrk(pagesize
)) == (char *)-1) {
122 ERROR("couldn't allocate output buffer");
125 if ((mmapaddr
= (caddr_t
)sbrk(0)) == (caddr_t
)-1) {
126 ERROR("couldn't find top of brk");
130 /* i changed the second argument to NULL
131 from argv[0]. otherwise it causes the
136 if ((fd
= mkstemp(tmpname
))==-1) {
137 ERROR("mkstemp failed");
140 sa
.sa_handler
= cleanup
;
142 if (sigemptyset(&sa
.sa_mask
)) {
143 ERROR("sigemptyset failed");
149 for (i
= 0; i
< pagesize
; i
++)
151 if (write(fd
, buf
, pagesize
) != pagesize
) {
152 CERROR("couldn't write page case 1");
155 if (lseek(fd
, MMU_NARROWPTEPG
*pagesize
, SEEK_SET
) == -1) {
156 CERROR("lseek case 1 failed");
159 if (write(fd
, buf
, pagesize
) != pagesize
) {
160 CERROR("couldn't write page case 2");
163 if (lseek(fd
, 2*MMU_NARROWPTEPG
*pagesize
, SEEK_SET
) == -1) {
164 CERROR("lseek case 2 failed");
167 if (write(fd
, buf
, pagesize
) != pagesize
) {
168 CERROR("couldn't write page case 3");
171 /* fd now references a sparce file which has three pages widely spaced.
172 * Hopefully different mfile objects will be needed to reference each
175 if (mmap(mmapaddr
+pagesize
, pagesize
, PROT_READ
,
176 MAP_FILE
|MAP_PRIVATE
|MAP_FIXED
, fd
, MMU_NARROWPTEPG
*pagesize
)
179 CERROR("first mmap (of third page) failed");
182 if (mmap(mmapaddr
, pagesize
, PROT_READ
,
183 MAP_FILE
|MAP_PRIVATE
|MAP_FIXED
, fd
, 2*MMU_NARROWPTEPG
*pagesize
)
186 CERROR("second mmap (of fifth page) failed");
189 if (mmap(mmapaddr
+2*pagesize
, pagesize
, PROT_READ
,
190 MAP_FILE
|MAP_PRIVATE
|MAP_FIXED
, fd
, 0) == (caddr_t
)-1)
192 CERROR("third mmap (of first page) failed");
197 // (void)printf("%s: Finished %s", argv[0], ctime(&t)); LTP Port
204 tst_resm(TPASS
, "Test passed\n");
212 tst_resm(TFAIL
, "Test failed\n");