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