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 #include <stdio.h>
19 #include <stdlib.h>
20 #include <unistd.h>
21 #include <sys/mman.h>
22 #include <sys/types.h>
23 #include <sys/stat.h>
24 #include <fcntl.h>
25 #include <string.h>
26 #include <errno.h>
27 #include "posixtest.h"
28
main(void)29 int main(void)
30 {
31 int pipe_fd[2];
32 void *pa;
33
34 if (pipe(pipe_fd) == -1) {
35 printf("Error at pipe(): %s\n", strerror(errno));
36 return PTS_UNRESOLVED;
37 }
38
39 pa = mmap(NULL, 1024, PROT_READ, MAP_SHARED, pipe_fd[0], 0);
40
41 if (pa == MAP_FAILED && errno == ENODEV) {
42 printf("Test PASSED\n");
43 close(pipe_fd[0]);
44 close(pipe_fd[1]);
45 return PTS_PASS;
46 }
47
48 if (pa == MAP_FAILED) {
49 printf("Test FAILED: Expect ENODEV, get: %s\n",
50 strerror(errno));
51 } else {
52 printf("Text FAILED: mmap() succeded\n");
53 }
54
55 close(pipe_fd[0]);
56 close(pipe_fd[1]);
57
58 return PTS_FAIL;
59 }
60