File indexing completed on 2025-05-11 08:24:39
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #ifdef HAVE_CONFIG_H
0030 #include "config.h"
0031 #endif
0032
0033 #include <tmacros.h>
0034 #include "test_support.h"
0035
0036 #include <unistd.h>
0037 #include <sys/types.h>
0038 #include <sys/stat.h>
0039 #include <fcntl.h>
0040 #include <errno.h>
0041 #include <rtems/libcsupport.h>
0042
0043 const char rtems_test_name[] = "PSXIMFS 1";
0044
0045
0046 rtems_task Init(rtems_task_argument argument);
0047 void open_it(bool readOnly, bool create);
0048 void write_helper(void);
0049 void read_helper(void);
0050 void truncate_helper(void);
0051 void extend_helper(int eno);
0052 void close_it(void);
0053 void unlink_it(void);
0054
0055 int TestFd;
0056 uint8_t Buffer[256];
0057 ssize_t TotalWritten;
0058
0059 #define FILE_NAME "biggie"
0060
0061 void open_it(bool readOnly, bool create)
0062 {
0063 int flag = 0;
0064
0065 if ( readOnly )
0066 flag |= O_RDONLY;
0067 else {
0068 if ( create )
0069 flag |= O_CREAT;
0070 flag |= O_RDWR;
0071 }
0072
0073
0074 puts( "open(" FILE_NAME ") - OK " );
0075 TestFd = open( FILE_NAME, flag, 0777 );
0076 rtems_test_assert( TestFd != -1 );
0077 }
0078
0079 void write_helper(void)
0080 {
0081 ssize_t written;
0082
0083 TotalWritten = 0;
0084 puts( "write(" FILE_NAME ") - OK " );
0085 do {
0086 written = write( TestFd, Buffer, sizeof(Buffer) );
0087 if ( written == -1 ) {
0088 if ( errno == EFBIG ) {
0089 printf( "Total written = %zd\n", TotalWritten );
0090 return;
0091 }
0092 printf(
0093 "Unable to create largest IMFS file (error=%s)\n",
0094 strerror(errno)
0095 );
0096 rtems_test_exit(0);
0097 }
0098 TotalWritten += written;
0099 } while (1);
0100
0101 }
0102
0103 void read_helper(void)
0104 {
0105 uint8_t ch;
0106 ssize_t sc;
0107 int i=0;
0108
0109 puts( "read(" FILE_NAME ") - OK " );
0110 do {
0111 sc = read( TestFd, &ch, sizeof(ch) );
0112 if ( sc == 1 ) {
0113 if ( ch != (i%256) ) {
0114 printf(
0115 "MISMATCH 0x%02x != 0x%02x at offset %d\n",
0116 ch,
0117 i % 256,
0118 i
0119 );
0120 rtems_test_exit(0);
0121 }
0122 i++;
0123 } else if ( sc != 0 ) {
0124 printf(
0125 "ERROR - at offset %d - returned %zd and error=%s\n",
0126 i,
0127 sc,
0128 strerror( errno )
0129 );
0130 rtems_test_exit(0);
0131 }
0132 } while ( sc > 0 );
0133
0134 if ( i == TotalWritten ) {
0135 puts( "File correctly read until EOF returned\n" );
0136 }
0137 }
0138
0139 void truncate_helper(void)
0140 {
0141 off_t position;
0142 off_t new;
0143 off_t sc;
0144 int rc;
0145
0146 position = lseek( TestFd, 0, SEEK_END );
0147 printf( "Seek to end .. returned %d\n", (int) position );
0148 rtems_test_assert( position == TotalWritten );
0149
0150 puts( "lseek/ftruncate loop.." );
0151 new = position;
0152 do {
0153 sc = lseek( TestFd, new, SEEK_SET );
0154 rtems_test_assert( sc == new );
0155
0156 rc = ftruncate( TestFd, new );
0157 if ( rc != 0 ) {
0158 printf(
0159 "ERROR - at offset %d - returned %d and error=%s\n",
0160 (int) new,
0161 rc,
0162 strerror( errno )
0163 );
0164 }
0165 rtems_test_assert( rc == 0 );
0166 --new;
0167 } while (new > 0);
0168 }
0169
0170 void extend_helper(int eno)
0171 {
0172 off_t position;
0173 off_t new;
0174 off_t sc;
0175 int rc;
0176
0177 position = lseek( TestFd, 0, SEEK_END );
0178 printf( "Seek to end .. returned %d\n", (int) position );
0179
0180
0181
0182
0183
0184 rc = ftruncate( TestFd, 2 );
0185 rtems_test_assert( rc == 0 );
0186
0187 puts( "lseek/ftruncate loop.." );
0188 new = position;
0189 do {
0190 sc = lseek( TestFd, new, SEEK_SET );
0191 rtems_test_assert( sc == new );
0192
0193 rc = ftruncate( TestFd, new );
0194 if ( rc != 0 ) {
0195 if( errno != eno ) {
0196 printf(
0197 "ERROR - at offset %d - returned %d and error=%s\n",
0198 (int) new,
0199 rc,
0200 strerror( errno )
0201 );
0202 break;
0203 }
0204 else {
0205 break;
0206 }
0207 }
0208 rtems_test_assert( rc == 0 );
0209 ++new;
0210 } while ( 1 );
0211 }
0212
0213 void close_it(void)
0214 {
0215 int rc;
0216
0217 puts( "close(" FILE_NAME ") - OK " );
0218 rc = close( TestFd );
0219 rtems_test_assert( rc == 0 );
0220 }
0221
0222 void unlink_it(void)
0223 {
0224 int rc;
0225
0226 puts( "unlink(" FILE_NAME ") - OK" );
0227 rc = unlink( FILE_NAME );
0228 rtems_test_assert( rc == 0 );
0229 }
0230
0231 rtems_task Init(
0232 rtems_task_argument argument
0233 )
0234 {
0235 int i;
0236 void *alloc_ptr = (void *)0;
0237 off_t position;
0238 off_t new_position;
0239 char buf [1];
0240 ssize_t n;
0241
0242 TEST_BEGIN();
0243
0244 for (i=0 ; i<sizeof(Buffer) ; i++ )
0245 Buffer[i] = (uint8_t) i;
0246
0247 open_it(false, true);
0248 write_helper();
0249 close_it();
0250
0251 puts( "" );
0252
0253 open_it(true, false);
0254 read_helper();
0255 close_it();
0256
0257 open_it(false, false);
0258 truncate_helper();
0259
0260
0261
0262
0263 alloc_ptr = malloc( malloc_free_space() - 4 );
0264
0265 extend_helper(ENOSPC);
0266
0267
0268
0269
0270 free(alloc_ptr);
0271
0272 extend_helper(EFBIG);
0273 position = lseek( TestFd , 0, SEEK_END );
0274 new_position = lseek( TestFd, position + 2, SEEK_SET );
0275 rtems_test_assert( new_position == position + 2 );
0276
0277 n = write( TestFd, buf, sizeof(buf) );
0278 rtems_test_assert( n == -1 );
0279 rtems_test_assert( errno == EFBIG );
0280
0281 close_it();
0282 unlink_it();
0283
0284 TEST_END();
0285
0286 rtems_test_exit(0);
0287 }
0288
0289
0290
0291 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0292 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0293
0294 #define CONFIGURE_MAXIMUM_TASKS 1
0295 #define CONFIGURE_IMFS_MEMFILE_BYTES_PER_BLOCK 16
0296 #define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 4
0297 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0298
0299 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0300
0301 #define CONFIGURE_INIT
0302
0303 #include <rtems/confdefs.h>
0304