1 /*
2  * Copyright (c) 2002, Intel Corporation. All rights reserved.
3  * Copyright (c) 2012, Cyril Hrubis <chrubis@suse.cz>
4  *
5  * This file is licensed under the GPL license.  For the full content
6  * of this license, see the COPYING file at the top level of this
7  * source tree.
8  *
9  * The mmap() function shall fail if: [ENODEV] The fildes argument refers to a
10  * file whose type is not supported by mmap().
11  *
12  * Test Steps:
13  * 1. Create pipe;
14  * 2. mmap the pipe fd to memory, should get ENODEV;
15  *
16  */
17 
18 #define _XOPEN_SOURCE 600
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <unistd.h>
22 #include <sys/mman.h>
23 #include <sys/types.h>
24 #include <sys/stat.h>
25 #include <fcntl.h>
26 #include <string.h>
27 #include <errno.h>
28 #include "posixtest.h"
29 
main(void)30 int main(void)
31 {
32 	int pipe_fd[2];
33 	void *pa;
34 
35 	if (pipe(pipe_fd) == -1) {
36 		printf("Error at pipe(): %s\n", strerror(errno));
37 		return PTS_UNRESOLVED;
38 	}
39 
40 	pa = mmap(NULL, 1024, PROT_READ, MAP_SHARED, pipe_fd[0], 0);
41 
42 	if (pa == MAP_FAILED && errno == ENODEV) {
43 		printf("Test PASSED\n");
44 		close(pipe_fd[0]);
45 		close(pipe_fd[1]);
46 		return PTS_PASS;
47 	}
48 
49 	if (pa == MAP_FAILED) {
50 		printf("Test FAILED: Expect ENODEV, get: %s\n",
51 		       strerror(errno));
52 	} else {
53 		printf("Text FAILED: mmap() succeded\n");
54 	}
55 
56 	close(pipe_fd[0]);
57 	close(pipe_fd[1]);
58 
59 	return PTS_FAIL;
60 }
61