Changeset 581c9982 in rtems


Ignore:
Timestamp:
Mar 22, 2013, 2:14:11 PM (7 years ago)
Author:
Ralf Kirchner <ralf.kirchner@…>
Branches:
4.11, master
Children:
27170bae
Parents:
e148397
git-author:
Ralf Kirchner <ralf.kirchner@…> (03/22/13 14:14:11)
git-committer:
Sebastian Huber <sebastian.huber@…> (06/03/13 15:28:41)
Message:

fsdsosfsname01: Ensure endian correctness

Location:
testsuites/fstests/fsdosfsname01
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • testsuites/fstests/fsdosfsname01/init.c

    re148397 r581c9982  
    1717#endif
    1818
     19
    1920#include "tmacros.h"
    2021
     
    2829#include <rtems/ramdisk.h>
    2930#include <rtems/libcsupport.h>
    30 #include "ramdisk_support.h"
    3131#include "image.h"
     32#include "image_bin_le_singlebyte.h"
     33#include "image_bin_le_multibyte.h"
    3234#include "files.h"
     35
     36#include <errno.h>
     37
     38#define PRINT_DISK_IMAGE 0
    3339
    3440#define MOUNT_DIR "/mnt"
    3541#define MOUNT_DIR_SIZE 4
    3642#define START_DIR_SIZE 4
     43#define RAMDISK_PATH "/dev/rda"
     44#define BLOCK_NUM 47
     45#define BLOCK_SIZE 512
    3746
    3847#define NUMBER_OF_DIRECTORIES 8
    3948#define NUMBER_OF_FILES 13
    40 #define NUMBER_OF_DIRECTORIES_INVALID 18
     49#define NUMBER_OF_DIRECTORIES_INVALID 25
    4150#define NUMBER_OF_DIRECTORIES_DUPLICATED 2
    4251#define NUMBER_OF_MULTIBYTE_NAMES_DUPLICATED 2
     
    110119    10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
    111120    20, 21, 22, 23, 24, 25, 26, 17, 28, 29, 30, 31},
    112   {127}
     121  {127},
     122  "э*_тП ЎлОММПе ОЌя",
     123  "э:_тП ЎлОММПе ОЌя",
     124  "э<_тП ЎлОММПе ОЌя",
     125  "э>_тП ЎлОММПе ОЌя",
     126  "э?_тП ЎлОММПе ОЌя",
     127  "э|_тП ЎлОММПе ОЌя"
    113128};
    114129
     
    314329}
    315330
    316 static void mount_device_with_iconv( const char *start_dir )
     331static void mount_device_with_iconv(
     332  const char                *start_dir,
     333  rtems_dosfs_mount_options *mount_opts
     334)
    317335{
    318336  int                       rc;
    319   rtems_dosfs_mount_options mount_opts;
    320 
    321337
    322338  rc = msdos_format( RAMDISK_PATH, &rqdata );
     
    325341  rtems_resource_snapshot_take( &before_mount );
    326342
    327   mount_opts.string_opts = rtems_dosfs_string_options_init_utf8( "CP850" );
    328 
    329   mount_device( start_dir, &mount_opts );
     343  mount_opts->converter = rtems_dosfs_create_utf8_converter( "CP850" );
     344  rtems_test_assert( mount_opts->converter != NULL );
     345
     346  mount_device( start_dir, mount_opts );
    330347}
    331348
     
    729746}
    730747
     748#if (PRINT_DISK_IMAGE != 0)
     749static void print_image(
     750  const char* include_guard,
     751  const char* image_name
     752)
     753{
     754  #define                   BYTES_PER_ROW     8
     755  int                       rc;
     756  int                       fd;
     757  ssize_t                   bytes_read;
     758  uint8_t                   buf[BLOCK_SIZE];
     759  unsigned int              index_block;
     760  unsigned int              index_row;
     761  unsigned int              index_column;
     762  unsigned int              index_buf;
     763#ifdef SHOW_LINE_NUMBERS
     764  size_t                    index_row_start = 1;
     765#endif /* SWOW_LINE_NUMBERS */
     766  size_t                    bytes_written   = 0;
     767  const size_t              DISK_SIZE       = BLOCK_SIZE * BLOCK_NUM;
     768  const unsigned int        ROWS_PER_BLOCK  = BLOCK_SIZE / BYTES_PER_ROW;
     769
     770  printf ("/*\n"
     771          " *  Declarations for C structure representing a disk image\n"
     772          " *\n"
     773          " *  WARNING: Automatically generated by init.c -- do not edit!\n"
     774          " */\n"
     775          "#ifndef %s\n"
     776          "#define %s\n"
     777          "\n"
     778          "#include <sys/types.h>\n"
     779          "\n"
     780          "#ifdef __cplusplus\n"
     781          "extern \"C\" {\n"
     782          "#endif /* __cplusplus */\n"
     783          "\n"
     784          "static unsigned char %s[] = {\n",
     785          include_guard,
     786          include_guard,
     787          image_name);
     788  fd = open( RAMDISK_PATH, O_RDWR );
     789  rtems_test_assert( fd >= 0 );
     790
     791  for ( index_block = 0; index_block < BLOCK_NUM; ++index_block )
     792  {
     793    bytes_read = read( fd, &buf[0], BLOCK_SIZE );
     794    rtems_test_assert( bytes_read = BLOCK_SIZE );
     795
     796    index_buf = 0;
     797
     798    for ( index_row = 0; index_row < ROWS_PER_BLOCK; ++index_row )
     799    {
     800      printf( "  " );
     801      for ( index_column = 0;
     802            index_column < BYTES_PER_ROW;
     803            ++index_column ) {
     804        printf("0x%02x", buf[index_buf]);
     805        ++bytes_written;
     806        ++index_buf;
     807        if ( bytes_written < DISK_SIZE ) {
     808          printf (", ");
     809        } else {
     810          printf ("  ");
     811        }
     812      }
     813#ifdef SHOW_LINE_NUMBERS
     814      printf( "/* %6u - %6u */", index_row_start, bytes_written );
     815      index_row_start = bytes_written + 1;
     816#endif /* SWOW_LINE_NUMBERS */
     817      printf( "\n" );
     818    }
     819  }
     820
     821  rc = close( fd );
     822  rtems_test_assert( rc == 0 );
     823
     824  printf ("};\n"
     825          "#ifdef __cplusplus\n"
     826          "}\n"
     827          "#endif /* __cplusplus */\n"
     828          "\n"
     829          "#endif /* %s */\n",
     830          include_guard);
     831}
     832#else /* PRINT_DISK_IMAGE */
     833static void print_image(
     834  const char* include_guard,
     835  const char* image_name
     836)
     837{
     838  /* Nothing to be done */
     839}
     840#endif /* PRINT_DISK_IMAGE */
     841
     842
     843static void compare_files(
     844  const char *file0,
     845  const char *file1
     846)
     847{
     848  struct stat  stat_buf[2];
     849  int          fd[2];
     850  unsigned int index;
     851  uint8_t      buf[2];
     852  ssize_t      bytes_read;
     853  int          rc;
     854
     855  rc = stat( file0 , &stat_buf[0] );
     856  rtems_test_assert( rc == 0 );
     857  rc = stat( file1 , &stat_buf[1] );
     858  rtems_test_assert( rc == 0 );
     859
     860  rtems_test_assert( stat_buf[0].st_size == stat_buf[1].st_size );
     861
     862  fd[0] = open( file0, O_RDONLY );
     863  rtems_test_assert( fd[0] > 0 );
     864  fd[1] = open( file1, O_RDONLY );
     865  rtems_test_assert( fd[1] > 0 );
     866
     867  for ( index = 0; index < stat_buf[0].st_size; ++index ) {
     868    bytes_read = read( fd[0], &buf[0], 1 );
     869    rtems_test_assert( bytes_read == 1 );
     870    bytes_read = read( fd[1], &buf[1], 1 );
     871    rtems_test_assert( bytes_read == 1 );
     872    rtems_test_assert( buf[0] == buf[1] );
     873  }
     874  rc = close( fd[0] );
     875  rtems_test_assert( rc == 0 );
     876  rc = close( fd[1] );
     877  rtems_test_assert( rc == 0 );
     878}
     879
     880static void compare_directories(
     881  const char *dir0,
     882  const char *dir1)
     883{
     884  int                       rc;
     885  DIR                      *dir_stream[2];
     886  struct dirent            *dp;
     887  struct stat               stat_buf[2];
     888  char                     *path[2];
     889  const unsigned int        PATH_LENGTH = 1024;
     890
     891  path[0] = calloc( PATH_LENGTH, sizeof(char) );
     892  rtems_test_assert( path[0] != NULL );
     893  path[1] = calloc( PATH_LENGTH, sizeof(char) );
     894  rtems_test_assert( path[1] != NULL );
     895
     896  dir_stream[0] = opendir( dir0 );
     897  rtems_test_assert( dir_stream[0] != NULL );
     898
     899  dir_stream[1] = opendir( dir1 );
     900  rtems_test_assert( dir_stream[1] != NULL );
     901
     902  dp = readdir( dir_stream[0] );
     903  rtems_test_assert( dp != NULL );
     904
     905  while ( dp != NULL ) {
     906    rc = snprintf(path[0], PATH_LENGTH, "%s/%s", dir0, dp->d_name);
     907    rtems_test_assert( rc < PATH_LENGTH );
     908    rtems_test_assert( rc >= 0 );
     909    rc = snprintf(path[1], PATH_LENGTH, "%s/%s", dir1, dp->d_name);
     910    rtems_test_assert( rc < PATH_LENGTH );
     911    rtems_test_assert( rc >= 0 );
     912
     913    rc = stat( path[0] , &stat_buf[0] );
     914    rtems_test_assert( rc == 0 );
     915
     916    if (   ( strcmp( dp->d_name, "."  ) != 0)
     917        && ( strcmp( dp->d_name, ".." ) != 0) ) {
     918      if ( S_ISDIR( stat_buf[0].st_mode ) ) {
     919        compare_directories( path[0], path[1] );
     920      } else {
     921        compare_files( path[0], path[1] );
     922      }
     923    }
     924
     925    dp = readdir( dir_stream[0] );
     926
     927  }
     928  rc = closedir( dir_stream[0] );
     929  rtems_test_assert( rc == 0 );
     930
     931  rc = closedir( dir_stream[1] );
     932  rtems_test_assert( rc == 0 );
     933
     934  free (path[0]);
     935  free (path[1]);
     936}
     937
     938static void compare_image(
     939  const char                      *mount_dir,
     940  const char                      *dev,
     941  const rtems_dosfs_mount_options *mount_opts )
     942{
     943  #define MOUNT_DIR2 "/mnt2"
     944  int                       rc;
     945
     946  rc = mount_and_make_target_path(
     947    dev,
     948    MOUNT_DIR2,
     949    RTEMS_FILESYSTEM_TYPE_DOSFS,
     950    RTEMS_FILESYSTEM_READ_WRITE,
     951    mount_opts );
     952  rtems_test_assert( rc == 0 );
     953
     954  compare_directories(mount_dir, MOUNT_DIR2);
     955
     956  rc = unmount( MOUNT_DIR2 );
     957  rtems_test_assert( rc == 0 );
     958
     959  rc = rmdir( MOUNT_DIR2 );
     960  rtems_test_assert( rc == 0 );
     961
     962}
    731963/*
    732964 * Test the compatibility with a genuine MS Windows FAT file system.
     
    8421074  int  rc;
    8431075  char start_dir[MOUNT_DIR_SIZE + START_DIR_SIZE + 2];
     1076  rtems_dosfs_mount_options mount_opts[2];
    8441077
    8451078  rc = mkdir( MOUNT_DIR, S_IRWXU | S_IRWXG | S_IRWXO );
    8461079  rtems_test_assert( rc == 0 );
    847 
    848   init_ramdisk();
    8491080
    8501081  snprintf( start_dir, sizeof( start_dir ), "%s/%s", MOUNT_DIR, "strt" );
     
    8891120    NUMBER_OF_FILES );
    8901121
     1122  compare_image(
     1123    MOUNT_DIR,
     1124    "/dev/rdb",
     1125    NULL);
     1126
    8911127  rc = unmount( MOUNT_DIR );
    8921128  rtems_test_assert( rc == 0 );
     
    8971133   * iconv and utf8proc
    8981134   */
    899   rtems_dosfs_mount_options mount_opts;
    900   mount_opts.string_opts = rtems_dosfs_string_options_init_utf8( "CP850" );
     1135  mount_opts[0].converter = rtems_dosfs_create_utf8_converter( "CP850" );
     1136  rtems_test_assert( mount_opts[0].converter != NULL );
     1137
    9011138  rc                     = mount(
    9021139    RAMDISK_PATH,
     
    9151152  unmount_and_close_device();
    9161153
    917   mount_device_with_iconv( start_dir );
     1154  mount_device_with_iconv( start_dir, &mount_opts[0] );
    9181155  test_creating_invalid_directories();
     1156
     1157  test_creating_duplicate_directories(
     1158    &start_dir[0],
     1159    &DIRECTORY_DUPLICATES[0],
     1160    NUMBER_OF_DIRECTORIES_DUPLICATED );
     1161
     1162  unmount_and_close_device();
     1163
     1164  mount_device_with_iconv( start_dir, &mount_opts[0] );
     1165
     1166  test_duplicated_files(
     1167    MOUNT_DIR,
     1168    FILES_DUPLICATES,
     1169    NUMBER_OF_FILES_DUPLICATED );
     1170
     1171  unmount_and_close_device();
     1172
     1173  mount_device_with_iconv( start_dir, &mount_opts[0] );
    9191174
    9201175  test_creating_directories(
     
    9291184    &FILE_NAMES[0][0],
    9301185    NUMBER_OF_FILES );
     1186
     1187  mount_opts[1].converter = rtems_dosfs_create_utf8_converter( "CP850" );
     1188  rtems_test_assert( mount_opts[1].converter != NULL );
     1189
     1190  compare_image(
     1191    MOUNT_DIR,
     1192    "/dev/rdb",
     1193    &mount_opts[1]);
     1194
     1195  rc = unmount( MOUNT_DIR );
     1196  rtems_test_assert( rc == 0 );
     1197
     1198  print_image(
     1199      "IMAGE_BIN_LE_SINGLEBYTE_H_",
     1200      "IMAGE_BIN_LE_SINGLEBYTE");
     1201
     1202  rc = mount(
     1203    RAMDISK_PATH,
     1204    MOUNT_DIR,
     1205    "dosfs",
     1206    RTEMS_FILESYSTEM_READ_WRITE,
     1207    NULL );
     1208  rtems_test_assert( rc == 0 );
     1209
    9311210  unmount_and_close_device();
    9321211
    933   mount_device_with_iconv( start_dir );
    934 
    935   test_creating_duplicate_directories(
    936     &start_dir[0],
    937     &DIRECTORY_DUPLICATES[0],
    938     NUMBER_OF_DIRECTORIES_DUPLICATED );
    939 
    940   unmount_and_close_device();
    941 
    942   mount_device_with_iconv( start_dir );
    943 
    944   test_duplicated_files(
    945     MOUNT_DIR,
    946     FILES_DUPLICATES,
    947     NUMBER_OF_FILES_DUPLICATED );
    948 
    949   unmount_and_close_device();
    9501212
    9511213  /*
     
    9541216   * iconv and utf8proc
    9551217   */
    956   mount_device_with_iconv( start_dir );
     1218  mount_device_with_iconv( start_dir, &mount_opts[0] );
    9571219
    9581220  test_creating_duplicate_directories(
     
    9631225  unmount_and_close_device();
    9641226
    965   mount_device_with_iconv( start_dir );
     1227  mount_device_with_iconv( start_dir, &mount_opts[0] );
    9661228
    9671229  test_duplicated_files(
     
    9721234  unmount_and_close_device();
    9731235
    974   mount_device_with_iconv( start_dir );
     1236  mount_device_with_iconv( start_dir, &mount_opts[0] );
    9751237
    9761238  test_creating_directories(
     
    9781240    &NAMES_MULTIBYTE[0][0],
    9791241    NUMBER_OF_NAMES_MULTIBYTE );
     1242
    9801243  test_handling_directories(
    9811244    &start_dir[0],
     
    9851248    NUMBER_OF_NAMES_MULTIBYTE );
    9861249
     1250  mount_opts[1].converter = rtems_dosfs_create_utf8_converter( "CP850" );
     1251  rtems_test_assert( mount_opts[1].converter != NULL );
     1252
     1253  compare_image(
     1254    MOUNT_DIR,
     1255    "/dev/rdc",
     1256    &mount_opts[1]);
     1257
    9871258  rc = unmount( MOUNT_DIR );
    9881259  rtems_test_assert( rc == 0 );
     1260
     1261  print_image(
     1262    "IMAGE_BIN_LE_MULTIBYTE_H_",
     1263    "IMAGE_BIN_LE_MULTIBYTE");
    9891264
    9901265  rc = mount(
     
    10061281
    10071282  test_compatibility();
    1008 
    1009   del_ramdisk();
    10101283}
    10111284
     
    10211294}
    10221295
     1296rtems_ramdisk_config rtems_ramdisk_configuration [] = {
     1297  { .block_size = BLOCK_SIZE, .block_num = BLOCK_NUM },
     1298  { .block_size = BLOCK_SIZE, .block_num = BLOCK_NUM, .location = &IMAGE_BIN_LE_SINGLEBYTE[0] },
     1299  { .block_size = BLOCK_SIZE, .block_num = BLOCK_NUM, .location = &IMAGE_BIN_LE_MULTIBYTE[0] }
     1300};
     1301
     1302size_t rtems_ramdisk_configuration_size = RTEMS_ARRAY_SIZE(rtems_ramdisk_configuration);
     1303
    10231304#define CONFIGURE_INIT_TASK_STACK_SIZE ( 1024 * 64 )
    1024 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
     1305#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
    10251306#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
    10261307#define CONFIGURE_MAXIMUM_DRIVERS 4
    1027 #define CONFIGURE_MAXIMUM_SEMAPHORES RTEMS_DOSFS_SEMAPHORES_PER_INSTANCE
     1308#define CONFIGURE_MAXIMUM_SEMAPHORES (2 * RTEMS_DOSFS_SEMAPHORES_PER_INSTANCE)
     1309#define CONFIGURE_APPLICATION_EXTRA_DRIVERS RAMDISK_DRIVER_TABLE_ENTRY
    10281310
    10291311#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
     
    10331315#define CONFIGURE_FILESYSTEM_DOSFS
    10341316
    1035 /* 1 RAM disk device file + 1 mount_dir + stdin + stdout + stderr + 2 for open directories/files */
    1036 #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS ( 5 + 2 )
     1317/* 2 RAM disk device files + 2 mount_dir + stdin + stdout + stderr +
     1318 * 2 for open directories/files  + 4 * 2 for recursive tree compares*/
     1319#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS ( 7 + 2 + ( 4 * 2 ) )
    10371320
    10381321#define CONFIGURE_MAXIMUM_TASKS 1
Note: See TracChangeset for help on using the changeset viewer.