1 | /* |
---|
2 | * COPYRIGHT (c) 1989-2010. |
---|
3 | * On-Line Applications Research Corporation (OAR). |
---|
4 | * |
---|
5 | * The license and distribution terms for this file may be |
---|
6 | * found in the file LICENSE in this distribution or at |
---|
7 | * http://www.rtems.com/license/LICENSE. |
---|
8 | * |
---|
9 | * $Id$ |
---|
10 | */ |
---|
11 | |
---|
12 | #ifdef HAVE_CONFIG_H |
---|
13 | #include "config.h" |
---|
14 | #endif |
---|
15 | |
---|
16 | #include <bsp.h> |
---|
17 | #include <tmacros.h> |
---|
18 | #include <stdio.h> |
---|
19 | #include <sys/types.h> |
---|
20 | #include <sys/stat.h> |
---|
21 | #include <fcntl.h> |
---|
22 | #include <unistd.h> |
---|
23 | #include <errno.h> |
---|
24 | |
---|
25 | #include <rtems.h> |
---|
26 | #include <rtems/libio.h> |
---|
27 | |
---|
28 | #define SEND_RCV_BUFSIZ 12 |
---|
29 | |
---|
30 | rtems_task Init( |
---|
31 | rtems_task_argument not_used |
---|
32 | ) |
---|
33 | { |
---|
34 | int fd = -1; |
---|
35 | int status = -1; |
---|
36 | off_t offset = 4; |
---|
37 | int pipe_length = -1; |
---|
38 | int flag = 1; |
---|
39 | |
---|
40 | puts( "\n\n*** TEST PIPE/FIFO - 04 ***" ); |
---|
41 | |
---|
42 | puts( "Init - Creating /fifo" ); |
---|
43 | status = mkfifo( "/fifo", 0777 ); |
---|
44 | rtems_test_assert( status == 0 ); |
---|
45 | |
---|
46 | puts( "Init - Opening /fifo in readonly, non-blocking mode" ); |
---|
47 | fd = open( "/fifo", O_RDONLY | O_NONBLOCK ); |
---|
48 | rtems_test_assert( fd != -1 ); |
---|
49 | |
---|
50 | puts( "Init - Attempt to lseek on fifo -- Expected ESPIPE" ); |
---|
51 | offset = lseek( fd, offset, SEEK_CUR ); |
---|
52 | rtems_test_assert( offset == -1 ); |
---|
53 | rtems_test_assert( errno == ESPIPE ); |
---|
54 | |
---|
55 | puts( "Init - ioctl: FIONBIO -- Expected EFAULT" ); |
---|
56 | status = ioctl( fd, FIONBIO, NULL ); |
---|
57 | rtems_test_assert( status == -1 ); |
---|
58 | rtems_test_assert( errno == EFAULT ); |
---|
59 | |
---|
60 | puts( "Init - ioctl: FIONBIO -- OK" ); |
---|
61 | status = ioctl( fd, FIONBIO, &flag ); |
---|
62 | rtems_test_assert( status == 0 ); |
---|
63 | |
---|
64 | flag = 0; |
---|
65 | puts( "Init - ioctl: FIONBIO -- OK" ); |
---|
66 | status = ioctl( fd, FIONBIO, &flag ); |
---|
67 | rtems_test_assert( status == 0 ); |
---|
68 | |
---|
69 | puts( "Init - ioctl: Dummy Command -- Expected EINVAL" ); |
---|
70 | status = ioctl( fd, -1, NULL ); |
---|
71 | rtems_test_assert( status == -1 ); |
---|
72 | rtems_test_assert( errno == EINVAL ); |
---|
73 | |
---|
74 | puts( "Init - ioctl: FIONREAD -- Expected EFAULT" ); |
---|
75 | status = ioctl( fd, FIONREAD, NULL ); |
---|
76 | rtems_test_assert( status == -1 ); |
---|
77 | rtems_test_assert( errno == EFAULT ); |
---|
78 | |
---|
79 | puts( "Init - ioctl: FIONREAD -- OK" ); |
---|
80 | status = ioctl( fd, FIONREAD, &pipe_length ); |
---|
81 | rtems_test_assert( status == 0 ); |
---|
82 | rtems_test_assert( pipe_length == 0 ); |
---|
83 | |
---|
84 | puts( "Init - closing /fifo" ); |
---|
85 | status = close( fd ); |
---|
86 | rtems_test_assert( status == 0 ); |
---|
87 | |
---|
88 | puts( "Init - removing /fifo" ); |
---|
89 | status = unlink( "/fifo" ); |
---|
90 | rtems_test_assert( status == 0 ); |
---|
91 | |
---|
92 | puts( "*** END OF TEST PIPE/FIFO - 04 ***" ); |
---|
93 | rtems_test_exit(0); |
---|
94 | } |
---|
95 | |
---|
96 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
97 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
98 | |
---|
99 | #define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM |
---|
100 | #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 6 |
---|
101 | |
---|
102 | #define CONFIGURE_MAXIMUM_TASKS 3 |
---|
103 | #define CONFIGURE_MAXIMUM_BARRIERS 1 |
---|
104 | #define CONFIGURE_MAXIMUM_FIFOS 1 |
---|
105 | |
---|
106 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
107 | |
---|
108 | #define CONFIGURE_FIFOS_ENABLED |
---|
109 | |
---|
110 | #define CONFIGURE_INIT |
---|
111 | #include <rtems/confdefs.h> |
---|
112 | /* end of file */ |
---|