robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 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 |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 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" |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 40 | #define FAILED 0 |
| 41 | #define PASSED 1 |
| 42 | |
| 43 | int local_flag = PASSED; |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 44 | char *TCID = "mmapstress06"; //mfile_swap |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 45 | FILE *temp; |
| 46 | int TST_TOTAL = 1; |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 47 | |
| 48 | int anyfail(); |
| 49 | void ok_exit(); |
| 50 | /***** ** ** *****/ |
| 51 | |
| 52 | #define ANON_GRAN_PAGES_MAX (32U) |
| 53 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 54 | extern time_t time(time_t *); |
| 55 | extern char *ctime(const time_t *); |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 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 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 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; |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 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); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 78 | // (void)printf("%s: Started %s", argv[0], ctime(&t)); LTP Port |
| 79 | if (sbrk(pagesize - ((ulong) sbrk(0) & (pagesize - 1))) == (char *)-1) { |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 80 | ERROR("couldn't round up brk"); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 81 | anyfail(); |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 82 | } |
| 83 | if ((mmapaddr = sbrk(0)) == (char *)-1) { |
| 84 | ERROR("couldn't find top of brk"); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 85 | anyfail(); |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 86 | } |
| 87 | /* mmapaddr is now on a page boundary after the brk segment */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 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) { |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 92 | ERROR("large mmap failed"); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 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)); |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 95 | return 1; |
| 96 | } |
| 97 | (void)sleep(sleep_time); |
| 98 | (void)time(&t); |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 99 | // (void)printf("%s: Finished %s", argv[0], ctime(&t)); LTP Port |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 100 | ok_exit(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 101 | tst_exit(); |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | /***** LTP Port *****/ |
| 105 | void ok_exit() |
| 106 | { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 107 | tst_resm(TPASS, "Test passed\n"); |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 108 | tst_exit(); |
| 109 | } |
| 110 | |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 111 | int anyfail() |
| 112 | { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 113 | tst_brkm(TFAIL, NULL, "Test failed\n"); |
robbiew | 8445709 | 2003-01-10 17:48:12 +0000 | [diff] [blame] | 114 | } |
| 115 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 116 | /***** ** ** *****/ |