source: rtems/testsuites/psxtests/psxfile02/init.c @ 6cb7221

4.11
Last change on this file since 6cb7221 was 6cb7221, checked in by Jennifer Averett <Jennifer.Averett@…>, on Jun 23, 2010 at 6:43:24 PM

2010-06-23 Jennifer Averett <Jennifer Averett@…>

  • Makefile.am, configure.ac: Added test case for calls that check for an unopened file descriptor.
  • psxfile02/.cvsignore, psxfile02/Makefile.am, psxfile02/init.c, psxfile02/psxfile02.doc, psxfile02/psxfile02.scn: New files.
  • Property mode set to 100644
File size: 3.7 KB
Line 
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#include <stdio.h>
12#include <sys/uio.h>
13#include <sys/types.h>
14#include <sys/stat.h>
15#include <fcntl.h>
16#include <unistd.h>
17#include <errno.h>
18#include <string.h>
19#include <ctype.h>
20#include <rtems/imfs.h>
21
22#include <rtems.h>
23#include <rtems/libio.h>
24
25#include <tmacros.h>
26#include "test_support.h"
27
28int _fcntl_r(
29  struct _reent *ptr __attribute__((unused)),
30  int fd,
31  int cmd,
32  int arg
33);
34
35off_t _lseek_r(
36  struct _reent *ptr __attribute__((unused)),
37  int            fd,
38  off_t          offset,
39  int            whence
40);
41
42
43
44rtems_task Init(
45  rtems_task_argument argument
46)
47{
48  int               fd;
49  struct stat       stat_buff;
50  struct iovec      vec[4];
51  off_t             res;
52  int               status;
53
54  puts( "\n\n*** PSXFILE02 TEST  ***" );
55
56  /*
57   *  Simple open case where the file is created.
58   */
59  puts( "mkdir /tmp" );
60  status = mkdir( "/tmp", S_IRWXU );
61  rtems_test_assert( !status );
62
63  puts( "open /tmp/j" );
64  fd = open( "/tmp/j", O_RDWR|O_CREAT, S_IRWXU|S_IRWXG|S_IRWXO );
65  rtems_test_assert( fd != -1 );
66  printf( "open returned file descriptor %d\n", fd );
67
68  puts( "close /tmp/j" );
69  status = close( fd );
70  rtems_test_assert( !status );
71
72  puts("ftruncate an unopened file");
73  status = ftruncate(fd, 40);
74  rtems_test_assert( status == -1 );
75  printf( "%d: %s\n", errno, strerror( errno ) );
76  rtems_test_assert( errno == EBADF );
77
78  puts("_fcntl_r unopened file");
79  status = _fcntl_r( NULL, fd, F_SETFD, 1 );
80  rtems_test_assert( status == -1 );
81  printf( "%d: %s\n", errno, strerror( errno ) );
82  rtems_test_assert( errno == EBADF );
83
84  puts("fdatasync unopened file");
85  status = fdatasync( fd );
86  rtems_test_assert( status == -1 );
87  printf( "%d: %s\n", errno, strerror( errno ) );
88  rtems_test_assert( errno == EBADF );
89
90  puts("fstat unopened file");
91  status = fstat( fd, &stat_buff );
92  rtems_test_assert( status == -1 );
93  printf( "%d: %s\n", errno, strerror( errno ) );
94  rtems_test_assert( errno == EBADF );
95
96  puts("fsync unopened file");
97  status = fsync( fd );
98  rtems_test_assert( status == -1 );
99  printf( "%d: %s\n", errno, strerror( errno ) );
100  rtems_test_assert( errno == EBADF );
101
102  puts("ioctl unopened file");
103  status = ioctl( fd, 0 );
104  rtems_test_assert( status == -1 );
105  printf( "%d: %s\n", errno, strerror( errno ) );
106  rtems_test_assert( errno == EBADF );
107
108  puts("_lseek_r unopened file");
109  res = _lseek_r (NULL, fd, 0, SEEK_SET);
110  rtems_test_assert( res == -1 );
111  printf( "%d: %s\n", errno, strerror( errno ) );
112  rtems_test_assert( errno == EBADF );
113
114  puts("readv unopened file");
115  status = readv(fd, vec, 4);
116  rtems_test_assert( status == -1 );
117  printf( "%d: %s\n", errno, strerror( errno ) );
118  rtems_test_assert( errno == EBADF );
119
120  puts("writev unopened file");
121  status = writev(fd, vec, 4);
122  rtems_test_assert( status == -1 );
123  printf( "%d: %s\n", errno, strerror( errno ) );
124  rtems_test_assert( errno == EBADF );
125
126  puts("write unopened file");
127  status = write(fd, "1234", 4);
128  rtems_test_assert( status == -1 );
129  printf( "%d: %s\n", errno, strerror( errno ) );
130  rtems_test_assert( errno == EBADF );
131
132
133
134
135  puts( "*** END OF PSXFILE02 TEST  ***" );
136
137  rtems_test_exit(0);
138}
139
140/* configuration information */
141
142#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
143#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
144#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
145#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 6
146#define CONFIGURE_MAXIMUM_TASKS 1
147#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
148
149#define CONFIGURE_INIT
150
151#include <rtems/confdefs.h>
152/* end of file */
Note: See TracBrowser for help on using the repository browser.