source: rtems/testsuites/psxtests/psxpipe01/init.c @ 9a4eca5

5
Last change on this file since 9a4eca5 was 16939b18, checked in by Sebastian Huber <sebastian.huber@…>, on 02/09/15 at 18:09:23

Filesystem: Simplify FIFO and pipe configuration

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2012.
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.org/license/LICENSE.
8 */
9
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
14#include <bsp.h>
15#include <pmacros.h>
16#include <sys/types.h>
17#include <sys/stat.h>
18#include <fcntl.h>
19#include <unistd.h>
20#include <errno.h>
21#include <rtems/libcsupport.h>
22#include <rtems/malloc.h>
23
24const char rtems_test_name[] = "PSXPIPE 1";
25
26/* forward declarations to avoid warnings */
27rtems_task Init(rtems_task_argument ignored);
28
29rtems_task Init(
30  rtems_task_argument ignored
31)
32{
33  int fd[2] = {0,0};
34  int dummy_fd[2] = {0,0};
35  int status = 0;
36  void *opaque = NULL;
37
38  TEST_BEGIN();
39
40  puts( "Init - attempt to create pipe -- expect EFAULT" );
41  status = pipe( NULL );
42  rtems_test_assert( status == -1 );
43  rtems_test_assert( errno == EFAULT );
44
45  puts( "Init - create pipe -- OK" );
46  status = pipe( fd );
47  rtems_test_assert( status == 0 );
48
49  status = close( fd[0] );
50  status |= close( fd[1] );
51  rtems_test_assert( status == 0 );
52
53  puts( "Init - create pipe -- OK" );
54  status = pipe( fd );
55  rtems_test_assert( status == 0 );
56
57  status = close( fd[0] );
58  status |= close( fd[1] );
59  rtems_test_assert( status == 0 );
60
61  opaque = rtems_heap_greedy_allocate( NULL, 0 );
62
63  /* case where mkfifo fails */
64  puts( "Init - attempt to create pipe -- expect ENOMEM" );
65  status = pipe( fd );
66  rtems_test_assert( status == -1 );
67  rtems_test_assert( errno == ENOMEM );
68
69  rtems_heap_greedy_free( opaque );
70 
71  dummy_fd[0] = open( "/file01", O_RDONLY | O_CREAT, S_IRWXU );
72  rtems_test_assert( dummy_fd[0] != -1 );
73  dummy_fd[1] = open( "/file02", O_RDONLY | O_CREAT, S_IRWXU );
74  rtems_test_assert( dummy_fd[1] != -1 );
75
76  /* case where fifo_open for read => open fails */
77  puts( "Init - create pipe -- expect ENFILE" );
78  status = pipe( fd );
79  rtems_test_assert( status == -1 );
80  rtems_test_assert( errno == ENFILE );
81
82  status = close( dummy_fd[1] );
83  status |= unlink( "/file02" );
84  rtems_test_assert( status == 0 );
85
86  /* case where fifo_open for write => open fails */
87  puts( "Init - create pipe -- expect ENFILE" );
88  status = pipe( fd );
89  rtems_test_assert( status == -1 );
90  rtems_test_assert( errno == ENFILE );
91
92  status = close( dummy_fd[0] );
93  status |= unlink( "/file01" );
94  rtems_test_assert( status == 0 );
95
96  TEST_END();
97  rtems_test_exit( 0 );
98}
99
100/* configuration information */
101
102#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
103#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
104
105#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 5
106
107#define CONFIGURE_MAXIMUM_TASKS 1
108#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
109
110#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
111
112#define CONFIGURE_MAXIMUM_PIPES 2
113
114#define CONFIGURE_INIT
115#include <rtems/confdefs.h>
116/* end of file */
Note: See TracBrowser for help on using the repository browser.