blob: d97bd6f9f55f478b068c08d337034d5951d4a2c4 [file] [log] [blame]
robbiew84457092003-01-10 17:48:12 +00001/* 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
Wanlong Gao4548c6c2012-10-19 18:03:36 +080020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
robbiew84457092003-01-10 17:48:12 +000021 */
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"
robbiew84457092003-01-10 17:48:12 +000040#define FAILED 0
41#define PASSED 1
42
43int local_flag = PASSED;
Wanlong Gao354ebb42012-12-07 10:10:04 +080044char *TCID = "mmapstress06"; //mfile_swap
robbiew84457092003-01-10 17:48:12 +000045FILE *temp;
46int TST_TOTAL = 1;
robbiew84457092003-01-10 17:48:12 +000047
48int anyfail();
49void ok_exit();
50/***** ** ** *****/
51
52#define ANON_GRAN_PAGES_MAX (32U)
53
Wanlong Gao354ebb42012-12-07 10:10:04 +080054extern time_t time(time_t *);
55extern char *ctime(const time_t *);
robbiew84457092003-01-10 17:48:12 +000056extern 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
Wanlong Gao354ebb42012-12-07 10:10:04 +080062int 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;
robbiew84457092003-01-10 17:48:12 +000068
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);
Wanlong Gao354ebb42012-12-07 10:10:04 +080078// (void)printf("%s: Started %s", argv[0], ctime(&t)); LTP Port
79 if (sbrk(pagesize - ((ulong) sbrk(0) & (pagesize - 1))) == (char *)-1) {
robbiew84457092003-01-10 17:48:12 +000080 ERROR("couldn't round up brk");
Wanlong Gao354ebb42012-12-07 10:10:04 +080081 anyfail();
robbiew84457092003-01-10 17:48:12 +000082 }
83 if ((mmapaddr = sbrk(0)) == (char *)-1) {
84 ERROR("couldn't find top of brk");
Wanlong Gao354ebb42012-12-07 10:10:04 +080085 anyfail();
robbiew84457092003-01-10 17:48:12 +000086 }
87 /* mmapaddr is now on a page boundary after the brk segment */
Wanlong Gao354ebb42012-12-07 10:10:04 +080088 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) {
robbiew84457092003-01-10 17:48:12 +000092 ERROR("large mmap failed");
Wanlong Gao354ebb42012-12-07 10:10:04 +080093 printf("for this test to run, it needs a mmap space of\n");
94 printf("%d pages\n", (ANON_GRAN_PAGES_MAX * NMFPTEPG + 1));
robbiew84457092003-01-10 17:48:12 +000095 return 1;
96 }
97 (void)sleep(sleep_time);
98 (void)time(&t);
Wanlong Gao354ebb42012-12-07 10:10:04 +080099// (void)printf("%s: Finished %s", argv[0], ctime(&t)); LTP Port
robbiew84457092003-01-10 17:48:12 +0000100 ok_exit();
Garrett Cooper2c282152010-12-16 00:55:50 -0800101 tst_exit();
robbiew84457092003-01-10 17:48:12 +0000102}
103
104/***** LTP Port *****/
105void ok_exit()
106{
Wanlong Gao354ebb42012-12-07 10:10:04 +0800107 tst_resm(TPASS, "Test passed\n");
robbiew84457092003-01-10 17:48:12 +0000108 tst_exit();
109}
110
robbiew84457092003-01-10 17:48:12 +0000111int anyfail()
112{
Cyril Hrubis526fdf82014-12-04 14:35:01 +0100113 tst_brkm(TFAIL, NULL, "Test failed\n");
robbiew84457092003-01-10 17:48:12 +0000114}
115
Chris Dearmanec6edca2012-10-17 19:54:01 -0700116/***** ** ** *****/