• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) International Business Machines Corp., 2009
4  *
5  * Authors:
6  * Mimi Zohar <zohar@us.ibm.com>
7  */
8 
9 #include "tst_test.h"
10 
11 #define SLEEP_AFTER_CLOSE 3
12 #define MMAPSIZE 1024
13 
14 static char *filename;
15 static void *file;
16 static int fd;
17 
18 static struct tst_option options[] = {
19 	{"f:", &filename,
20 	 "-f file  File to mmap"},
21 	{NULL, NULL, NULL}
22 };
23 
cleanup(void)24 static void cleanup(void)
25 {
26 	if (file)
27 		SAFE_MUNMAP(file, MMAPSIZE);
28 
29 	if (fd > 0)
30 		SAFE_CLOSE(fd);
31 }
32 
run(void)33 static void run(void)
34 {
35 	if (!filename)
36 		tst_brk(TBROK, "Usage: %s -f filename", TCID);
37 
38 	fd = SAFE_OPEN(filename, O_CREAT | O_RDWR, S_IRWXU);
39 
40 	file = SAFE_MMAP(NULL, MMAPSIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
41 	SAFE_CLOSE(fd);
42 
43 	tst_res(TINFO, "sleep %ds", SLEEP_AFTER_CLOSE);
44 	sleep(SLEEP_AFTER_CLOSE);
45 
46 	tst_res(TPASS, "test completed");
47 }
48 
49 static struct tst_test test = {
50 	.options = options,
51 	.test_all = run,
52 	.cleanup = cleanup,
53 };
54