Changeset 52f3aa0 in rtems for testsuites/fstests


Ignore:
Timestamp:
Feb 26, 2013, 2:18:55 PM (7 years ago)
Author:
Ralf Kirchner <ralf.kirchner@…>
Branches:
4.11, master
Children:
e148397
Parents:
83a4cbb
git-author:
Ralf Kirchner <ralf.kirchner@…> (02/26/13 14:18:55)
git-committer:
Sebastian Huber <sebastian.huber@…> (06/03/13 15:28:41)
Message:

fsdosfsname01: Add multibyte tests

Test handling of file names and directory names according to Microsofts specification
for the FAT file system. Tests for multibyte file names and directory names have been added.

Location:
testsuites/fstests/fsdosfsname01
Files:
2 edited

Legend:

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

    r83a4cbb r52f3aa0  
    3838#define NUMBER_OF_DIRECTORIES_INVALID 18
    3939#define NUMBER_OF_DIRECTORIES_DUPLICATED 2
     40#define NUMBER_OF_MULTIBYTE_NAMES_DUPLICATED 2
    4041#define NUMBER_OF_FILES_DUPLICATED 2
     42#define NUMBER_OF_NAMES_MULTIBYTE 10
    4143#define MAX_NAME_LENGTH ( 255 + 1 )
    4244#define MAX_NAME_LENGTH_INVALID ( 255 + 2 )
     
    9799};
    98100
     101static const char NAMES_MULTIBYTE[
     102  NUMBER_OF_NAMES_MULTIBYTE][MAX_NAME_LENGTH] = {
     103  "đây là một tên tập tin dài",
     104  "Bu uzun bir dosya adı",
     105  "هذا هو اسÙ
     106 Ù
     107لف طويل",
     108  "αÏ
     109τό είΜαι έΜα Όεγάλο όΜοΌα αρχείοÏ
     110",
     111  "этП ЎлОММПе ОЌя",
     112  "гэта ЎПўгае іЌя",
     113  "тПва е ЎългП ОЌе Ма файла",
     114  "这是䞀䞪长文件名",
     115  "shrtname",
     116  "long_conventional_name"
     117};
     118
     119static const char NAMES_MULTIBYTE_IN_CODEPAGE_FORMAT[
     120  NUMBER_OF_NAMES_MULTIBYTE][MAX_NAME_LENGTH] = {
     121  "_\2030005~1._t",
     122  "bu0008~1.bir",
     123  "__000b~1.__",
     124  "__000f~1.__",
     125  "__0012~1.___",
     126  "__0015~1.___",
     127  "__0018~1.___",
     128  "__001a~1",
     129  "shrtname",
     130  "long_conventional_name"
     131};
     132
    99133static const char FILE_NAMES[NUMBER_OF_FILES][
    100134  MAX_NAME_LENGTH] = {
     
    170204};
    171205
     206
    172207static const name_duplicates FILES_DUPLICATES[NUMBER_OF_FILES_DUPLICATED] = {
    173208  {
     
    265300}
    266301
     302static void mount_device_with_iconv( const char *start_dir )
     303{
     304  int                       rc;
     305  rtems_dosfs_mount_options mount_opts;
     306
     307
     308  rc = msdos_format( RAMDISK_PATH, &rqdata );
     309  rtems_test_assert( rc == 0 );
     310
     311  rtems_resource_snapshot_take( &before_mount );
     312
     313  mount_opts.string_opts = rtems_dosfs_string_options_init_utf8( "CP850" );
     314
     315  mount_device( start_dir, &mount_opts );
     316}
     317
    267318static void unmount_and_close_device( void )
    268319{
     
    429480
    430481/*
     482 * Try to find (and open) all of the file names from an
     483 * array in a given directory
     484 */
     485static void test_finding_files(
     486  const char        *dirname,
     487  const char        *file_names,
     488  const unsigned int number_of_files )
     489{
     490  int            rc;
     491  DIR           *dir_stream;
     492  struct dirent *dp;
     493  int            fd;
     494  unsigned int   index_file;
     495  char           filename[MAX_NAME_LENGTH * 2 + MOUNT_DIR_SIZE
     496                          + START_DIR_SIZE + 4];
     497
     498
     499  dir_stream = opendir( dirname );
     500  rtems_test_assert( dir_stream != NULL );
     501
     502  dp = readdir( dir_stream );
     503  rtems_test_assert( dp != NULL );
     504  rtems_test_assert( 0 == strcmp( ".", dp->d_name ) );
     505
     506  dp = readdir( dir_stream );
     507  rtems_test_assert( dp != NULL );
     508  rtems_test_assert( 0 == strcmp( "..", dp->d_name ) );
     509
     510  dp         = readdir( dir_stream );
     511  rtems_test_assert( dp != NULL );
     512  index_file = 0;
     513
     514  while ( dp != NULL ) {
     515    rtems_test_assert( 0 == strcmp(
     516                         file_names + index_file * MAX_NAME_LENGTH,
     517                         dp->d_name ) );
     518
     519    snprintf(
     520      filename,
     521      sizeof( filename ) - 1,
     522      "%s/%s",
     523      dirname,
     524      file_names + index_file * MAX_NAME_LENGTH );
     525
     526    /* See if the file still exists and can be found */
     527    fd = open( filename, O_RDWR );
     528    rtems_test_assert( fd >= 0 );
     529
     530    rc = close( fd );
     531    rtems_test_assert( rc == 0 );
     532
     533    ++index_file;
     534    dp = readdir( dir_stream );
     535  }
     536
     537  rtems_test_assert( number_of_files == index_file );
     538
     539  rc = closedir( dir_stream );
     540  rtems_test_assert( rc == 0 );
     541}
     542
     543/*
    431544 * Try opening files which do already exist (with different capitalization in their names)
    432545 */
     
    541654
    542655/*
     656 * Try to find all sub-directories from an array
     657 * in a given start directory.
     658 * In addition try to find and open files
     659 * in these sub-directories.
     660 */
     661static void test_finding_directories(
     662  const char        *start_dir,
     663  const char        *directory_names,
     664  const unsigned int number_of_directories,
     665  const char        *file_names,
     666  const unsigned int number_of_files )
     667{
     668  unsigned int   index_directory;
     669  int            rc;
     670  DIR           *dir_stream;
     671  struct dirent *dp;
     672  char           dirname[MAX_NAME_LENGTH * 2];
     673
     674
     675  dir_stream = opendir( start_dir );
     676  rtems_test_assert( dir_stream != NULL );
     677
     678  dp = readdir( dir_stream );
     679  rtems_test_assert( dp != NULL );
     680  rtems_test_assert( 0 == strcmp( ".", dp->d_name ) );
     681
     682  dp = readdir( dir_stream );
     683  rtems_test_assert( dp != NULL );
     684  rtems_test_assert( 0 == strcmp( "..", dp->d_name ) );
     685
     686  dp              = readdir( dir_stream );
     687  rtems_test_assert( dp != NULL );
     688  index_directory = 0;
     689
     690  while ( dp != NULL ) {
     691    rtems_test_assert( 0 == strcmp(
     692                         directory_names + index_directory * MAX_NAME_LENGTH,
     693                         dp->d_name ) );
     694
     695    snprintf(
     696      dirname,
     697      sizeof( dirname ) - 1,
     698      "%s/%s",
     699      start_dir,
     700      directory_names + index_directory * MAX_NAME_LENGTH );
     701
     702    test_finding_files(
     703      dirname,
     704      file_names,
     705      number_of_files );
     706
     707    ++index_directory;
     708    dp = readdir( dir_stream );
     709  }
     710
     711  rtems_test_assert( number_of_directories == index_directory );
     712
     713  rc = closedir( dir_stream );
     714  rtems_test_assert( rc == 0 );
     715}
     716
     717/*
    543718 * Main test method
    544719 */
     
    547722  int  rc;
    548723  char start_dir[MOUNT_DIR_SIZE + START_DIR_SIZE + 2];
    549 
    550724
    551725  rc = mkdir( MOUNT_DIR, S_IRWXU | S_IRWXG | S_IRWXO );
     
    595769    NUMBER_OF_FILES );
    596770
     771  rc = unmount( MOUNT_DIR );
     772  rtems_test_assert( rc == 0 );
     773
     774  /*
     775   * Again tests with code page 850 compatible directory and file names
     776   * but with multibyte string compatible conversion methods which use
     777   * iconv and utf8proc
     778   */
     779  rtems_dosfs_mount_options mount_opts;
     780  mount_opts.string_opts = rtems_dosfs_string_options_init_utf8( "CP850" );
     781  rc                     = mount(
     782    RAMDISK_PATH,
     783    MOUNT_DIR,
     784    "dosfs",
     785    RTEMS_FILESYSTEM_READ_WRITE,
     786    &mount_opts );
     787  rtems_test_assert( rc == 0 );
     788
     789  test_finding_directories(
     790    &start_dir[0],
     791    &DIRECTORY_NAMES[0][0],
     792    NUMBER_OF_DIRECTORIES,
     793    &FILE_NAMES[0][0],
     794    NUMBER_OF_FILES );
     795  unmount_and_close_device();
     796
     797  mount_device_with_iconv( start_dir );
     798  test_creating_invalid_directories();
     799
     800  test_creating_directories(
     801    &start_dir[0],
     802    &DIRECTORY_NAMES[0][0],
     803    NUMBER_OF_DIRECTORIES );
     804
     805  test_handling_directories(
     806    &start_dir[0],
     807    &DIRECTORY_NAMES[0][0],
     808    NUMBER_OF_DIRECTORIES,
     809    &FILE_NAMES[0][0],
     810    NUMBER_OF_FILES );
     811  unmount_and_close_device();
     812
     813  mount_device_with_iconv( start_dir );
     814
     815  test_creating_duplicate_directories(
     816    &start_dir[0],
     817    &DIRECTORY_DUPLICATES[0],
     818    NUMBER_OF_DIRECTORIES_DUPLICATED );
     819
     820  unmount_and_close_device();
     821
     822  mount_device_with_iconv( start_dir );
     823
     824  test_duplicated_files(
     825    MOUNT_DIR,
     826    FILES_DUPLICATES,
     827    NUMBER_OF_FILES_DUPLICATED );
     828
     829  unmount_and_close_device();
     830
     831  /*
     832   * Tests with multibyte directory and file names and
     833   * with multibyte string compatible conversion methods which use
     834   * iconv and utf8proc
     835   */
     836  mount_device_with_iconv( start_dir );
     837
     838  test_creating_duplicate_directories(
     839    &start_dir[0],
     840    &MULTIBYTE_DUPLICATES[0],
     841    NUMBER_OF_MULTIBYTE_NAMES_DUPLICATED );
     842
     843  unmount_and_close_device();
     844
     845  mount_device_with_iconv( start_dir );
     846
     847  test_duplicated_files(
     848    MOUNT_DIR,
     849    &MULTIBYTE_DUPLICATES[0],
     850    NUMBER_OF_MULTIBYTE_NAMES_DUPLICATED );
     851
     852  unmount_and_close_device();
     853
     854  mount_device_with_iconv( start_dir );
     855
     856  test_creating_directories(
     857    &start_dir[0],
     858    &NAMES_MULTIBYTE[0][0],
     859    NUMBER_OF_NAMES_MULTIBYTE );
     860  test_handling_directories(
     861    &start_dir[0],
     862    &NAMES_MULTIBYTE[0][0],
     863    NUMBER_OF_NAMES_MULTIBYTE,
     864    &NAMES_MULTIBYTE[0][0],
     865    NUMBER_OF_NAMES_MULTIBYTE );
     866
     867  rc = unmount( MOUNT_DIR );
     868  rtems_test_assert( rc == 0 );
     869
     870  rc = mount(
     871    RAMDISK_PATH,
     872    MOUNT_DIR,
     873    "dosfs",
     874    RTEMS_FILESYSTEM_READ_WRITE,
     875    NULL );
     876  rtems_test_assert( rc == 0 );
     877
     878  test_finding_directories(
     879    &start_dir[0],
     880    &NAMES_MULTIBYTE_IN_CODEPAGE_FORMAT[0][0],
     881    NUMBER_OF_NAMES_MULTIBYTE,
     882    &NAMES_MULTIBYTE_IN_CODEPAGE_FORMAT[0][0],
     883    NUMBER_OF_NAMES_MULTIBYTE );
     884
    597885  unmount_and_close_device();
    598886
Note: See TracChangeset for help on using the changeset viewer.