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