source: rtems/testsuites/psxtests/psxpipe01/init.c @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • 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
24/* forward declarations to avoid warnings */
25rtems_task Init(rtems_task_argument ignored);
26
27rtems_task Init(
28  rtems_task_argument ignored
29)
30{
31  int fd[2] = {0,0};
32  int dummy_fd[2] = {0,0};
33  int status = 0;
34  void *opaque = NULL;
35
36  puts( "*** TEST POSIX PIPE CREATION - 01 ***" );
37
38  puts( "Init - attempt to create pipe -- expect EFAULT" );
39  status = pipe( NULL );
40  rtems_test_assert( status == -1 );
41  rtems_test_assert( errno == EFAULT );
42
43  puts( "Init - create pipe -- OK" );
44  status = pipe( fd );
45  rtems_test_assert( status == 0 );
46
47  status = close( fd[0] );
48  status |= close( fd[1] );
49  rtems_test_assert( status == 0 );
50
51  puts( "Init - create pipe -- OK" );
52  status = pipe( fd );
53  rtems_test_assert( status == 0 );
54
55  status = close( fd[0] );
56  status |= close( fd[1] );
57  rtems_test_assert( status == 0 );
58
59  opaque = rtems_heap_greedy_allocate( NULL, 0 );
60
61  /* case where mkfifo fails */
62  puts( "Init - attempt to create pipe -- expect ENOMEM" );
63  status = pipe( fd );
64  rtems_test_assert( status == -1 );
65  rtems_test_assert( errno == ENOMEM );
66
67  rtems_heap_greedy_free( opaque );
68 
69  dummy_fd[0] = open( "/file01", O_RDONLY | O_CREAT, S_IRWXU );
70  rtems_test_assert( dummy_fd[0] != -1 );
71  dummy_fd[1] = open( "/file02", O_RDONLY | O_CREAT, S_IRWXU );
72  rtems_test_assert( dummy_fd[1] != -1 );
73
74  /* case where fifo_open for read => open fails */
75  puts( "Init - create pipe -- expect ENFILE" );
76  status = pipe( fd );
77  rtems_test_assert( status == -1 );
78  rtems_test_assert( errno == ENFILE );
79
80  status = close( dummy_fd[1] );
81  status |= unlink( "/file02" );
82  rtems_test_assert( status == 0 );
83
84  /* case where fifo_open for write => open fails */
85  puts( "Init - create pipe -- expect ENFILE" );
86  status = pipe( fd );
87  rtems_test_assert( status == -1 );
88  rtems_test_assert( errno == ENFILE );
89
90  status = close( dummy_fd[0] );
91  status |= unlink( "/file01" );
92  rtems_test_assert( status == 0 );
93
94  puts( "*** END OF TEST POSIX PIPE CREATION - 01 ***" );
95  rtems_test_exit( 0 );
96}
97
98/* configuration information */
99
100#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
101#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
102
103#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
104#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 5
105
106#define CONFIGURE_MAXIMUM_TASKS 1
107#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
108
109#define CONFIGURE_PIPES_ENABLED
110#define CONFIGURE_MAXIMUM_PIPES 2
111
112#define CONFIGURE_INIT
113#include <rtems/confdefs.h>
114/* end of file */
Note: See TracBrowser for help on using the repository browser.