1 /* IBM Corporation */
2 /* 01/02/2003 Port to LTP avenkat@us.ibm.com */
3 /* 06/30/2001 Port to Linux nsharoff@us.ibm.com */
4 /*
5 * Copyright (c) International Business Machines Corp., 2003
6 *
7 *
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.
12 *
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.
17 *
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 /*
24 * mfile_swap:
25 * Mmap a large (> ANON_GRAN_PAGES_MAX) shared, anonymous region before
26 * swapping to use the second half of the kernel primitive mfile_swap.
27 * However, this test does _NOT_ cause swapping to occur. Instead it should be
28 * run with waves or at the same time as a test which does cause swapping (i.e.
29 * vsswapin or vfork_swap)
30 */
31 #define _KMEMUSER
32 #include <sys/types.h>
33 #include <sys/mman.h>
34 #include <unistd.h>
35 #include <stdio.h>
36 #include <errno.h>
37
38 /***** LTP Port *****/
39 #include "test.h"
40 #define FAILED 0
41 #define PASSED 1
42
43 int local_flag = PASSED;
44 char *TCID = "mmapstress06"; //mfile_swap
45 FILE *temp;
46 int TST_TOTAL = 1;
47
48 int anyfail();
49 void ok_exit();
50 /***** ** ** *****/
51
52 #define ANON_GRAN_PAGES_MAX (32U)
53
54 extern time_t time(time_t *);
55 extern char *ctime(const time_t *);
56 extern int atoi(const char *);
57
58 #define NMFPTEPG (1024)
59 #define ERROR(M) (void)fprintf(stderr, "%s: errno = %d; " M "\n", \
60 argv[0], errno);
61
main(int argc,char * argv[])62 int main(int argc, char *argv[])
63 {
64 caddr_t mmapaddr;
65 size_t pagesize = sysconf(_SC_PAGE_SIZE);
66 time_t t;
67 int sleep_time = 0;
68
69 if (!argc) {
70 (void)fprintf(stderr, "argc == 0\n");
71 anyfail();
72 }
73 if (argc != 2 || !(sleep_time = atoi(argv[1]))) {
74 (void)fprintf(stderr, "usage: %s sleep_time\n", argv[0]);
75 anyfail();
76 }
77 (void)time(&t);
78 // (void)printf("%s: Started %s", argv[0], ctime(&t)); LTP Port
79 if (sbrk(pagesize - ((ulong) sbrk(0) & (pagesize - 1))) == (char *)-1) {
80 ERROR("couldn't round up brk");
81 anyfail();
82 }
83 if ((mmapaddr = sbrk(0)) == (char *)-1) {
84 ERROR("couldn't find top of brk");
85 anyfail();
86 }
87 /* mmapaddr is now on a page boundary after the brk segment */
88 if (mmap
89 (mmapaddr, (ANON_GRAN_PAGES_MAX * NMFPTEPG + 1) * pagesize,
90 PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_SHARED, 0,
91 0) == (caddr_t) - 1) {
92 ERROR("large mmap failed");
93 printf("for this test to run, it needs a mmap space of\n");
94 printf("%d pages\n", (ANON_GRAN_PAGES_MAX * NMFPTEPG + 1));
95 return 1;
96 }
97 (void)sleep(sleep_time);
98 (void)time(&t);
99 // (void)printf("%s: Finished %s", argv[0], ctime(&t)); LTP Port
100 ok_exit();
101 tst_exit();
102 }
103
104 /***** LTP Port *****/
ok_exit(void)105 void ok_exit(void)
106 {
107 tst_resm(TPASS, "Test passed\n");
108 tst_exit();
109 }
110
anyfail(void)111 int anyfail(void)
112 {
113 tst_brkm(TFAIL, NULL, "Test failed\n");
114 }
115
116 /***** ** ** *****/
117