blob: 5f13d48dda0dba24f02bb000980891ebec5b57e9 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/******************************************************************************/
2/* */
3/* Copyright (c) International Business Machines Corp., 2001 */
Cyril Hrubis6538d512011-11-03 18:32:34 +01004/* Copyright (c) 2001 Manoj Iyer <manjo@austin.ibm.com> */
5/* Copyright (c) 2003 Robbie Williamson <robbiew@us.ibm.com> */
6/* Copyright (c) 2004 Paul Larson <plars@linuxtestproject.org> */
7/* Copyright (c) 2007 <rsalveti@linux.vnet.ibm.com> */
8/* Copyright (c) 2007 Suzuki K P <suzuki@in.ibm.com> */
9/* Copyright (c) 2011 Cyril Hrubis <chrubis@suse.cz> */
plars865695b2001-08-27 22:15:12 +000010/* */
11/* This program is free software; you can redistribute it and/or modify */
12/* it under the terms of the GNU General Public License as published by */
13/* the Free Software Foundation; either version 2 of the License, or */
14/* (at your option) any later version. */
15/* */
16/* This program is distributed in the hope that it will be useful, */
17/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
18/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */
19/* the GNU General Public License for more details. */
20/* */
21/* You should have received a copy of the GNU General Public License */
22/* along with this program; if not, write to the Free Software */
Wanlong Gao4548c6c2012-10-19 18:03:36 +080023/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
plars865695b2001-08-27 22:15:12 +000024/* */
25/******************************************************************************/
plars865695b2001-08-27 22:15:12 +000026/******************************************************************************/
plars865695b2001-08-27 22:15:12 +000027/* Description: Test the LINUX memory manager. The program is aimed at */
28/* stressing the memory manager by simultanious map/unmap/read */
29/* by light weight processes, the test is scheduled to run for */
30/* a mininum of 24 hours. */
31/* */
32/* Create two light weight processes X and Y. */
33/* X - maps, writes and unmap a file in a loop. */
34/* Y - read from this mapped region in a loop. */
35/* read must be a success between map and unmap of the region. */
36/* */
37/******************************************************************************/
plars865695b2001-08-27 22:15:12 +000038#include <stdio.h>
39#include <sys/types.h>
40#include <sys/stat.h>
41#include <fcntl.h>
42#include <sched.h>
43#include <unistd.h>
44#include <errno.h>
45#include <sys/mman.h>
46#include <sched.h>
47#include <stdlib.h>
48#include <signal.h>
49#include <sys/time.h>
50#include <sys/wait.h>
plars865695b2001-08-27 22:15:12 +000051#include <setjmp.h>
52#include <pthread.h>
53#include <signal.h>
iyermanojc839ac42001-11-09 23:24:13 +000054#include <string.h>
robbiew173b0452003-04-16 19:46:42 +000055#include "test.h"
plars865695b2001-08-27 22:15:12 +000056
Cyril Hrubis6538d512011-11-03 18:32:34 +010057#define OPT_MISSING(prog, opt) do { \
58 fprintf(stderr, "%s: option -%c ", prog, opt); \
59 fprintf(stderr, "requires an argument\n"); \
60 usage(prog); \
61} while (0)
iyermanoje37f2d12001-10-25 17:47:59 +000062
Cyril Hrubisd72816d2011-11-03 21:15:53 +010063static int verbose_print = 0;
Dave Kleikamp33242122013-08-28 08:07:23 -050064static char *volatile map_address;
Cyril Hrubisd72816d2011-11-03 21:15:53 +010065static jmp_buf jmpbuf;
66static volatile char read_lock = 0;
plars865695b2001-08-27 22:15:12 +000067
vapier475916e2007-07-21 20:58:17 +000068char *TCID = "mmap1";
69int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +000070
Wanlong Gao354ebb42012-12-07 10:10:04 +080071static void sig_handler(int signal, siginfo_t * info, void *ut)
plars865695b2001-08-27 22:15:12 +000072{
Cyril Hrubis6538d512011-11-03 18:32:34 +010073 switch (signal) {
74 case SIGALRM:
75 tst_resm(TPASS, "Test ended, success");
Cyril Hrubisd72816d2011-11-03 21:15:53 +010076 _exit(TPASS);
Cyril Hrubis6538d512011-11-03 18:32:34 +010077 case SIGSEGV:
Cyril Hrubisd72816d2011-11-03 21:15:53 +010078 longjmp(jmpbuf, 1);
Wanlong Gao354ebb42012-12-07 10:10:04 +080079 break;
80 default:
81 fprintf(stderr, "Unexpected signal - %d --- exiting\n", signal);
Cyril Hrubisd72816d2011-11-03 21:15:53 +010082 _exit(TBROK);
83 }
84}
85
86/*
87 * Signal handler that is active, when file is mapped, eg. we do not expect
88 * SIGSEGV to be delivered.
89 */
Wanlong Gao354ebb42012-12-07 10:10:04 +080090static void sig_handler_mapped(int signal, siginfo_t * info, void *ut)
Cyril Hrubisd72816d2011-11-03 21:15:53 +010091{
92 switch (signal) {
93 case SIGALRM:
94 tst_resm(TPASS, "Test ended, success");
95 _exit(TPASS);
96 case SIGSEGV:
97 tst_resm(TINFO, "[%lu] Unexpected page fault at %p",
Wanlong Gao354ebb42012-12-07 10:10:04 +080098 pthread_self(), info->si_addr);
Cyril Hrubisd72816d2011-11-03 21:15:53 +010099 _exit(TFAIL);
Wanlong Gao354ebb42012-12-07 10:10:04 +0800100 break;
101 default:
102 fprintf(stderr, "Unexpected signal - %d --- exiting\n", signal);
Cyril Hrubisd72816d2011-11-03 21:15:53 +0100103 _exit(TBROK);
Cyril Hrubis6538d512011-11-03 18:32:34 +0100104 }
plars865695b2001-08-27 22:15:12 +0000105}
106
Cyril Hrubis6538d512011-11-03 18:32:34 +0100107int mkfile(int size)
plars865695b2001-08-27 22:15:12 +0000108{
Cyril Hrubisd72816d2011-11-03 21:15:53 +0100109 char template[] = "/tmp/ashfileXXXXXX";
110 int fd, i;
plars865695b2001-08-27 22:15:12 +0000111
Cyril Hrubis6538d512011-11-03 18:32:34 +0100112 if ((fd = mkstemp(template)) == -1)
Wanlong Gao354ebb42012-12-07 10:10:04 +0800113 tst_brkm(TBROK | TERRNO, NULL, "mkstemp() failed");
plars865695b2001-08-27 22:15:12 +0000114
Cyril Hrubisd72816d2011-11-03 21:15:53 +0100115 unlink(template);
116
117 for (i = 0; i < size; i++)
118 if (write(fd, "a", 1) == -1)
Wanlong Gao354ebb42012-12-07 10:10:04 +0800119 tst_brkm(TBROK | TERRNO, NULL, "write() failed");
Chris Dearman37550cf2012-10-17 19:54:01 -0700120
Cyril Hrubis6538d512011-11-03 18:32:34 +0100121 if (write(fd, "\0", 1) == -1)
Wanlong Gao354ebb42012-12-07 10:10:04 +0800122 tst_brkm(TBROK | TERRNO, NULL, "write() failed");
Chris Dearman37550cf2012-10-17 19:54:01 -0700123
plars865695b2001-08-27 22:15:12 +0000124 if (fsync(fd) == -1)
Wanlong Gao354ebb42012-12-07 10:10:04 +0800125 tst_brkm(TBROK | TERRNO, NULL, "fsync() failed");
Garrett Cooper2c282152010-12-16 00:55:50 -0800126
Cyril Hrubis6538d512011-11-03 18:32:34 +0100127 return fd;
plars865695b2001-08-27 22:15:12 +0000128}
129
Cyril Hrubise01b27f2011-11-03 19:08:56 +0100130void *map_write_unmap(void *ptr)
plars865695b2001-08-27 22:15:12 +0000131{
Cyril Hrubisd72816d2011-11-03 21:15:53 +0100132 struct sigaction sa;
Cyril Hrubise01b27f2011-11-03 19:08:56 +0100133 long *args = ptr;
134 long i;
Cyril Hrubisd72816d2011-11-03 21:15:53 +0100135 int j;
plars865695b2001-08-27 22:15:12 +0000136
Cyril Hrubisd72816d2011-11-03 21:15:53 +0100137 tst_resm(TINFO, "[%lu] - map, change contents, unmap files %ld times",
Wanlong Gao354ebb42012-12-07 10:10:04 +0800138 pthread_self(), args[2]);
iyermanoje37f2d12001-10-25 17:47:59 +0000139
Cyril Hrubis6538d512011-11-03 18:32:34 +0100140 if (verbose_print)
141 tst_resm(TINFO, "map_write_unmap() arguments are: "
Wanlong Gao354ebb42012-12-07 10:10:04 +0800142 "fd - arg[0]: %ld; "
143 "size of file - arg[1]: %ld; "
144 "num of map/write/unmap - arg[2]: %ld",
145 args[0], args[1], args[2]);
Garrett Cooper2c282152010-12-16 00:55:50 -0800146
Cyril Hrubise01b27f2011-11-03 19:08:56 +0100147 for (i = 0; i < args[2]; i++) {
Chris Dearman37550cf2012-10-17 19:54:01 -0700148
Wanlong Gao354ebb42012-12-07 10:10:04 +0800149 map_address = mmap(0, (size_t) args[1], PROT_WRITE | PROT_READ,
150 MAP_SHARED, (int)args[0], 0);
Chris Dearman37550cf2012-10-17 19:54:01 -0700151
Wanlong Gao354ebb42012-12-07 10:10:04 +0800152 if (map_address == (void *)-1) {
Cyril Hrubis6538d512011-11-03 18:32:34 +0100153 perror("map_write_unmap(): mmap()");
154 pthread_exit((void *)1);
155 }
Chris Dearman37550cf2012-10-17 19:54:01 -0700156
Cyril Hrubisd72816d2011-11-03 21:15:53 +0100157 while (read_lock)
158 sched_yield();
159
160 sigfillset(&sa.sa_mask);
161 sigdelset(&sa.sa_mask, SIGSEGV);
Wanlong Gao354ebb42012-12-07 10:10:04 +0800162 sa.sa_flags = SA_SIGINFO | SA_NODEFER;
Cyril Hrubisd72816d2011-11-03 21:15:53 +0100163 sa.sa_sigaction = sig_handler_mapped;
164
165 if (sigaction(SIGSEGV, &sa, NULL)) {
166 perror("map_write_unmap(): sigaction()");
Wanlong Gao354ebb42012-12-07 10:10:04 +0800167 pthread_exit((void *)1);
Cyril Hrubisd72816d2011-11-03 21:15:53 +0100168 }
plars865695b2001-08-27 22:15:12 +0000169
Cyril Hrubis6538d512011-11-03 18:32:34 +0100170 if (verbose_print)
171 tst_resm(TINFO, "map address = %p", map_address);
plars865695b2001-08-27 22:15:12 +0000172
Cyril Hrubisd72816d2011-11-03 21:15:53 +0100173 for (j = 0; j < args[1]; j++) {
174 map_address[j] = 'a';
175 if (random() % 2)
176 sched_yield();
177 }
Garrett Cooper2c282152010-12-16 00:55:50 -0800178
Cyril Hrubis6538d512011-11-03 18:32:34 +0100179 if (verbose_print)
Wanlong Gao354ebb42012-12-07 10:10:04 +0800180 tst_resm(TINFO,
181 "[%ld] times done: of total [%ld] iterations, "
182 "map_write_unmap():memset() content of memory = %s",
183 i, args[2], (char *)map_address);
Chris Dearman37550cf2012-10-17 19:54:01 -0700184
Cyril Hrubisd72816d2011-11-03 21:15:53 +0100185 sigfillset(&sa.sa_mask);
186 sigdelset(&sa.sa_mask, SIGSEGV);
Wanlong Gao354ebb42012-12-07 10:10:04 +0800187 sa.sa_flags = SA_SIGINFO | SA_NODEFER;
Cyril Hrubisd72816d2011-11-03 21:15:53 +0100188 sa.sa_sigaction = sig_handler;
189
190 if (sigaction(SIGSEGV, &sa, NULL)) {
191 perror("map_write_unmap(): sigaction()");
Wanlong Gao354ebb42012-12-07 10:10:04 +0800192 pthread_exit((void *)1);
Cyril Hrubisd72816d2011-11-03 21:15:53 +0100193 }
plars865695b2001-08-27 22:15:12 +0000194
Wanlong Gao354ebb42012-12-07 10:10:04 +0800195 if (munmap(map_address, (size_t) args[1]) == -1) {
Cyril Hrubis6538d512011-11-03 18:32:34 +0100196 perror("map_write_unmap(): mmap()");
197 pthread_exit((void *)1);
198 }
Garrett Cooper2c282152010-12-16 00:55:50 -0800199 }
200
Cyril Hrubis4e2bab82014-09-24 16:34:35 +0200201 pthread_exit(NULL);
plars865695b2001-08-27 22:15:12 +0000202}
203
Cyril Hrubise01b27f2011-11-03 19:08:56 +0100204void *read_mem(void *ptr)
plars865695b2001-08-27 22:15:12 +0000205{
Cyril Hrubisd72816d2011-11-03 21:15:53 +0100206 long i;
Cyril Hrubise01b27f2011-11-03 19:08:56 +0100207 long *args = ptr;
Cyril Hrubisd72816d2011-11-03 21:15:53 +0100208 int j;
Cyril Hrubis6538d512011-11-03 18:32:34 +0100209
Cyril Hrubisd72816d2011-11-03 21:15:53 +0100210 tst_resm(TINFO, "[%lu] - read contents of memory %p %ld times",
Wanlong Gao354ebb42012-12-07 10:10:04 +0800211 pthread_self(), map_address, args[2]);
Cyril Hrubis6538d512011-11-03 18:32:34 +0100212
213 if (verbose_print)
214 tst_resm(TINFO, "read_mem() arguments are: "
Wanlong Gao354ebb42012-12-07 10:10:04 +0800215 "number of reads to be performed - arg[2]: %ld; "
216 "read from address %p", args[2], map_address);
Cyril Hrubis6538d512011-11-03 18:32:34 +0100217
Cyril Hrubise01b27f2011-11-03 19:08:56 +0100218 for (i = 0; i < args[2]; i++) {
Chris Dearman37550cf2012-10-17 19:54:01 -0700219
Cyril Hrubis6538d512011-11-03 18:32:34 +0100220 if (verbose_print)
221 tst_resm(TINFO, "read_mem() in while loop %ld times "
Wanlong Gao354ebb42012-12-07 10:10:04 +0800222 "to go %ld times", i, args[2]);
Cyril Hrubis6538d512011-11-03 18:32:34 +0100223
224 if (setjmp(jmpbuf) == 1) {
Cyril Hrubisd72816d2011-11-03 21:15:53 +0100225 read_lock = 0;
Cyril Hrubis6538d512011-11-03 18:32:34 +0100226 if (verbose_print)
227 tst_resm(TINFO, "page fault occurred due to "
Wanlong Gao354ebb42012-12-07 10:10:04 +0800228 "a read after an unmap");
Cyril Hrubis6538d512011-11-03 18:32:34 +0100229 } else {
Dave Kleikamp33242122013-08-28 08:07:23 -0500230 if (verbose_print) {
231 read_lock = 1;
Wanlong Gao354ebb42012-12-07 10:10:04 +0800232 tst_resm(TINFO,
233 "read_mem(): content of memory: %s",
234 (char *)map_address);
Dave Kleikamp33242122013-08-28 08:07:23 -0500235 read_lock = 0;
236 }
Cyril Hrubisd72816d2011-11-03 21:15:53 +0100237 for (j = 0; j < args[1]; j++) {
238 read_lock = 1;
239 if (map_address[j] != 'a')
240 pthread_exit((void *)-1);
241 read_lock = 0;
242 if (random() % 2)
243 sched_yield();
244 }
Cyril Hrubis6538d512011-11-03 18:32:34 +0100245 }
246 }
247
Cyril Hrubis4e2bab82014-09-24 16:34:35 +0200248 pthread_exit(NULL);
plars865695b2001-08-27 22:15:12 +0000249}
250
Cyril Hrubis6538d512011-11-03 18:32:34 +0100251static void usage(char *progname)
plars865695b2001-08-27 22:15:12 +0000252{
Cyril Hrubis6538d512011-11-03 18:32:34 +0100253 fprintf(stderr, "Usage: %s -d -l -s -v -x\n"
254 "\t -h help, usage message.\n"
255 "\t -l number of mmap/write/unmap default: 1000\n"
256 "\t -s size of the file to be mmapped default: 1024 bytes\n"
257 "\t -v print more info. default: quiet\n"
258 "\t -x test execution time default: 24 Hrs\n",
259 progname);
iyermanoje37f2d12001-10-25 17:47:59 +0000260
Cyril Hrubis6538d512011-11-03 18:32:34 +0100261 exit(-1);
262}
iyermanoje37f2d12001-10-25 17:47:59 +0000263
Cyril Hrubis6538d512011-11-03 18:32:34 +0100264struct signal_info {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800265 int signum;
Cyril Hrubis6538d512011-11-03 18:32:34 +0100266 char *signame;
267};
Garrett Cooper2c282152010-12-16 00:55:50 -0800268
Cyril Hrubis6538d512011-11-03 18:32:34 +0100269static struct signal_info sig_info[] = {
Wanlong Gao354ebb42012-12-07 10:10:04 +0800270 {SIGHUP, "SIGHUP"},
271 {SIGINT, "SIGINT"},
Cyril Hrubis6538d512011-11-03 18:32:34 +0100272 {SIGQUIT, "SIGQUIT"},
273 {SIGABRT, "SIGABRT"},
Wanlong Gao354ebb42012-12-07 10:10:04 +0800274 {SIGBUS, "SIGBUS"},
Cyril Hrubis6538d512011-11-03 18:32:34 +0100275 {SIGSEGV, "SIGSEGV"},
276 {SIGALRM, "SIGALRM"},
277 {SIGUSR1, "SIGUSR1"},
278 {SIGUSR2, "SIGUSR2"},
Wanlong Gao354ebb42012-12-07 10:10:04 +0800279 {-1, "ENDSIG"}
Cyril Hrubis6538d512011-11-03 18:32:34 +0100280};
plars865695b2001-08-27 22:15:12 +0000281
Cyril Hrubisd72816d2011-11-03 21:15:53 +0100282int main(int argc, char **argv)
Cyril Hrubis6538d512011-11-03 18:32:34 +0100283{
Cyril Hrubisea8e6bf2011-11-03 19:36:10 +0100284 int c, i;
Cyril Hrubis6538d512011-11-03 18:32:34 +0100285 int file_size;
286 int num_iter;
287 double exec_time;
288 int fd;
Dave Kleikamp981d33a2013-05-06 11:47:30 -0500289 void *status;
Cyril Hrubis6538d512011-11-03 18:32:34 +0100290 pthread_t thid[2];
291 long chld_args[3];
292 extern char *optarg;
293 struct sigaction sigptr;
Cyril Hrubisea8e6bf2011-11-03 19:36:10 +0100294 int ret;
plars865695b2001-08-27 22:15:12 +0000295
Cyril Hrubis6538d512011-11-03 18:32:34 +0100296 /* set up the default values */
297 file_size = 1024;
298 num_iter = 1000;
299 exec_time = 24;
300
Wanlong Gao354ebb42012-12-07 10:10:04 +0800301 while ((c = getopt(argc, argv, "hvl:s:x:")) != -1) {
302 switch (c) {
Cyril Hrubis6538d512011-11-03 18:32:34 +0100303 case 'h':
304 usage(argv[0]);
Wanlong Gao354ebb42012-12-07 10:10:04 +0800305 break;
Cyril Hrubis6538d512011-11-03 18:32:34 +0100306 case 'l':
307 if ((num_iter = atoi(optarg)) == 0)
308 OPT_MISSING(argv[0], optopt);
Wanlong Gao354ebb42012-12-07 10:10:04 +0800309 else if (num_iter < 0)
310 printf
311 ("WARNING: bad argument. Using default %d\n",
312 (num_iter = 1000));
313 break;
Cyril Hrubis6538d512011-11-03 18:32:34 +0100314 case 's':
315 if ((file_size = atoi(optarg)) == 0)
316 OPT_MISSING(argv[0], optopt);
Wanlong Gao354ebb42012-12-07 10:10:04 +0800317 else if (file_size < 0)
318 printf
319 ("WARNING: bad argument. Using default %d\n",
320 (file_size = 1024));
321 break;
Cyril Hrubis6538d512011-11-03 18:32:34 +0100322 case 'v':
323 verbose_print = 1;
Wanlong Gao354ebb42012-12-07 10:10:04 +0800324 break;
Cyril Hrubis6538d512011-11-03 18:32:34 +0100325 case 'x':
326 exec_time = atof(optarg);
327 if (exec_time == 0)
328 OPT_MISSING(argv[0], optopt);
Wanlong Gao354ebb42012-12-07 10:10:04 +0800329 else if (exec_time < 0)
330 printf
331 ("WARNING: bad argument. Using default %.0f\n",
332 (exec_time = 24));
333 break;
Cyril Hrubis6538d512011-11-03 18:32:34 +0100334 default:
335 usage(argv[0]);
Wanlong Gao354ebb42012-12-07 10:10:04 +0800336 break;
Cyril Hrubis6538d512011-11-03 18:32:34 +0100337 }
338 }
plars865695b2001-08-27 22:15:12 +0000339
Cyril Hrubis6538d512011-11-03 18:32:34 +0100340 if (verbose_print)
341 tst_resm(TINFO, "Input parameters are: File size: %d; "
Wanlong Gao354ebb42012-12-07 10:10:04 +0800342 "Scheduled to run: %lf hours; "
343 "Number of mmap/write/read: %d",
344 file_size, exec_time, num_iter);
plars865695b2001-08-27 22:15:12 +0000345
Cyril Hrubisfea169d2011-11-09 16:28:30 +0100346 alarm(exec_time * 3600);
subrata_modak4fb91392007-07-25 09:24:05 +0000347
Cyril Hrubis6538d512011-11-03 18:32:34 +0100348 /* Do not mask SIGSEGV, as we are interested in handling it. */
Cyril Hrubis80ec1342011-11-03 19:39:37 +0100349 sigptr.sa_sigaction = sig_handler;
Cyril Hrubis6538d512011-11-03 18:32:34 +0100350 sigfillset(&sigptr.sa_mask);
351 sigdelset(&sigptr.sa_mask, SIGSEGV);
352 sigptr.sa_flags = SA_SIGINFO | SA_NODEFER;
Chris Dearman37550cf2012-10-17 19:54:01 -0700353
Cyril Hrubisea8e6bf2011-11-03 19:36:10 +0100354 for (i = 0; sig_info[i].signum != -1; i++) {
355 if (sigaction(sig_info[i].signum, &sigptr, NULL) == -1) {
Cyril Hrubisd72816d2011-11-03 21:15:53 +0100356 perror("man(): sigaction()");
Wanlong Gao354ebb42012-12-07 10:10:04 +0800357 fprintf(stderr,
358 "could not set handler for %s, errno = %d\n",
359 sig_info[i].signame, errno);
Cyril Hrubis6538d512011-11-03 18:32:34 +0100360 exit(-1);
361 }
362 }
plars865695b2001-08-27 22:15:12 +0000363
Cyril Hrubis6538d512011-11-03 18:32:34 +0100364 for (;;) {
Cyril Hrubisea8e6bf2011-11-03 19:36:10 +0100365 if ((fd = mkfile(file_size)) == -1)
Wanlong Gao354ebb42012-12-07 10:10:04 +0800366 tst_brkm(TBROK, NULL,
367 "main(): mkfile(): Failed to create temp file");
Chris Dearman37550cf2012-10-17 19:54:01 -0700368
Cyril Hrubisea8e6bf2011-11-03 19:36:10 +0100369 if (verbose_print)
370 tst_resm(TINFO, "Tmp file created");
plars865695b2001-08-27 22:15:12 +0000371
Cyril Hrubis6538d512011-11-03 18:32:34 +0100372 chld_args[0] = fd;
373 chld_args[1] = file_size;
374 chld_args[2] = num_iter;
plars865695b2001-08-27 22:15:12 +0000375
Wanlong Gao354ebb42012-12-07 10:10:04 +0800376 if ((ret =
377 pthread_create(&thid[0], NULL, map_write_unmap,
378 chld_args)))
379 tst_brkm(TBROK, NULL, "main(): pthread_create(): %s",
380 strerror(ret));
Chris Dearman37550cf2012-10-17 19:54:01 -0700381
Cyril Hrubisd72816d2011-11-03 21:15:53 +0100382 tst_resm(TINFO, "created writing thread[%lu]", thid[0]);
Garrett Cooper2c282152010-12-16 00:55:50 -0800383
Cyril Hrubisea8e6bf2011-11-03 19:36:10 +0100384 if ((ret = pthread_create(&thid[1], NULL, read_mem, chld_args)))
Wanlong Gao354ebb42012-12-07 10:10:04 +0800385 tst_brkm(TBROK, NULL, "main(): pthread_create(): %s",
386 strerror(ret));
Chris Dearman37550cf2012-10-17 19:54:01 -0700387
Cyril Hrubisd72816d2011-11-03 21:15:53 +0100388 tst_resm(TINFO, "created reading thread[%lu]", thid[1]);
Cyril Hrubis6538d512011-11-03 18:32:34 +0100389
Cyril Hrubisea8e6bf2011-11-03 19:36:10 +0100390 for (i = 0; i < 2; i++) {
Dave Kleikamp981d33a2013-05-06 11:47:30 -0500391 if ((ret = pthread_join(thid[i], &status)))
Wanlong Gao354ebb42012-12-07 10:10:04 +0800392 tst_brkm(TBROK, NULL,
393 "main(): pthread_join(): %s",
394 strerror(ret));
Chris Dearman37550cf2012-10-17 19:54:01 -0700395
Dave Kleikamp981d33a2013-05-06 11:47:30 -0500396 if (status)
Wanlong Gao354ebb42012-12-07 10:10:04 +0800397 tst_brkm(TFAIL, NULL,
398 "thread [%lu] - process exited "
Dave Kleikamp981d33a2013-05-06 11:47:30 -0500399 "with %ld", thid[i], (long)status);
Cyril Hrubis6538d512011-11-03 18:32:34 +0100400 }
401
402 close(fd);
403 }
404
405 exit(0);
406}