source: rtems/testsuites/psxtests/psximfs01/init.c @ 43efb633

4.115
Last change on this file since 43efb633 was 43efb633, checked in by Joel Sherrill <joel.sherrill@…>, on 06/28/10 at 18:48:25

2010-06-28 Joel Sherrill <joel.sherrill@…>

  • Makefile.am, configure.ac: Add test to exercise IMFS behaviour with files of maximum sizes.
  • psximfs01/.cvsignore, psximfs01/Makefile.am, psximfs01/init.c, psximfs01/psximfs01.doc, psximfs01/psximfs01.scn: New files.
  • Property mode set to 100644
File size: 3.6 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
12#include <tmacros.h>
13#include "test_support.h"
14
15#include <unistd.h>
16#include <sys/types.h>
17#include <sys/stat.h>
18#include <fcntl.h>
19#include <errno.h>
20
21int TestFd;
22uint8_t Buffer[256];
23ssize_t TotalWritten;
24
25#define FILE_NAME "biggie"
26
27void open_it(bool readOnly, bool create)
28{
29  int flag = 0;
30
31  if ( readOnly )
32    flag |= O_RDONLY;
33  else {
34    if ( create )
35      flag |= O_CREAT;
36    flag |= O_RDWR;
37  }
38
39  /* open the file */
40  puts( "open(" FILE_NAME ") - OK " );
41  TestFd = open( FILE_NAME, flag, 0777 );
42  rtems_test_assert( TestFd != -1 );
43}
44
45void write_helper(void)
46{
47  ssize_t written;
48
49  TotalWritten = 0;
50  puts( "write(" FILE_NAME ") - OK " );
51  do {
52    written = write( TestFd, Buffer, sizeof(Buffer) );
53    if ( written == -1 ) {
54      if ( errno == ENOSPC ) {
55        printf( "Total written = %d\n", TotalWritten );
56        return;
57      }
58      fprintf(
59        stderr,
60        "Unable to create largest IMFS file (error=%s)\n",
61        strerror(errno)
62      );
63      rtems_test_exit(0);
64    }
65    TotalWritten += written;
66  } while (1);
67 
68}
69
70void read_helper(void)
71{
72  uint8_t ch;
73  ssize_t sc;
74  int     i=0;
75
76  puts( "read(" FILE_NAME ") - OK " );
77  do {
78    sc = read( TestFd, &ch, sizeof(ch) );
79    if ( sc == 1 ) {
80      if ( ch != (i%256) ) {
81        fprintf(
82          stderr,
83          "MISMATCH 0x%02x != 0x%02x at offset %d\n",
84          ch,
85          i % 256,
86          i
87        );
88        rtems_test_exit(0);
89      }
90      i++;
91      continue;
92    }
93    /* Unsure if ENOSPC is the write error to be returned */
94    if ( errno == ENOSPC && i == TotalWritten ) {
95      puts( "File correctly read until ENOSPC returned\n" );
96      return;
97    }
98    fprintf(
99      stderr,
100      "ERROR - at offset %d - returned %d and error=%s\n",
101      i,
102      sc,
103      strerror( errno )
104    );
105    rtems_test_exit(0);
106  } while (1);
107}
108
109void truncate_helper(void)
110{
111  off_t position;
112  off_t new;
113  off_t sc;
114  int   rc;
115
116  position = lseek( TestFd, 0, SEEK_END );
117  printf( "Seek to end .. returned %d\n", (int) position );
118  rtems_test_assert( position == TotalWritten );
119
120  puts( "lseek/ftruncate loop.." );
121  new = position;
122  do {
123    sc = lseek( TestFd, new, SEEK_SET );
124    rtems_test_assert( sc == new );
125
126    rc = ftruncate( TestFd, new );
127    if ( rc != 0 ) {
128      fprintf(
129        stderr,
130        "ERROR - at offset %d - returned %d and error=%s\n",
131        (int) new,
132        rc,
133        strerror( errno )
134      );
135    }
136    rtems_test_assert( rc == 0 );
137    --new;
138  } while (new > 0);
139}
140
141void close_it(void)
142{
143  int rc;
144
145  puts( "close(" FILE_NAME ") - OK " );
146  rc = close( TestFd );
147  rtems_test_assert( rc == 0 );
148}
149
150rtems_task Init(
151  rtems_task_argument argument
152)
153{
154  int i;
155  puts( "\n\n*** TEST IMFS 01 ***" );
156
157  for (i=0 ; i<sizeof(Buffer) ; i++ )
158    Buffer[i] = (uint8_t) i;
159
160  open_it(false, true);
161  write_helper();
162  close_it();
163
164  puts( "" );
165
166  open_it(true, false);
167  read_helper();
168  close_it();
169 
170  open_it(false, false);
171  truncate_helper();
172  close_it();
173 
174
175  puts( "*** END OF TEST IMFS 01 ***" );
176
177  rtems_test_exit(0);
178}
179
180/* configuration information */
181
182#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
183#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
184
185#define CONFIGURE_MAXIMUM_TASKS             1
186#define CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK 16
187#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4
188#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
189
190#define CONFIGURE_INIT
191
192#include <rtems/confdefs.h>
193/* end of file */
Note: See TracBrowser for help on using the repository browser.