[PATCH 2/2] fsdosfsname01: New test

Ralf Kirchner ralf.kirchner at embedded-brains.de
Fri Feb 1 09:41:59 UTC 2013


---
 testsuites/fstests/fsdosfsname01/Makefile.am       |   19 +
 testsuites/fstests/fsdosfsname01/fsdosfsname01.doc |   10 +
 testsuites/fstests/fsdosfsname01/fsdosfsname01.scn |    2 +
 testsuites/fstests/fsdosfsname01/init.c            |  391 ++++++++++++++++++++
 4 Dateien geändert, 422 Zeilen hinzugefügt(+)
 create mode 100644 testsuites/fstests/fsdosfsname01/Makefile.am
 create mode 100644 testsuites/fstests/fsdosfsname01/fsdosfsname01.doc
 create mode 100644 testsuites/fstests/fsdosfsname01/fsdosfsname01.scn
 create mode 100644 testsuites/fstests/fsdosfsname01/init.c

diff --git a/testsuites/fstests/fsdosfsname01/Makefile.am b/testsuites/fstests/fsdosfsname01/Makefile.am
new file mode 100644
index 0000000..7438b3e
--- /dev/null
+++ b/testsuites/fstests/fsdosfsname01/Makefile.am
@@ -0,0 +1,19 @@
+rtems_tests_PROGRAMS = fsdosfsname01
+fsdosfsname01_SOURCES = init.c
+
+dist_rtems_tests_DATA = fsdosfsname01.scn fsdosfsname01.doc
+
+include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP at .cfg
+include $(top_srcdir)/../automake/compile.am
+include $(top_srcdir)/../automake/leaf.am
+
+AM_CPPFLAGS += -I$(top_srcdir)/../support/include
+
+LINK_OBJS = $(fsdosfsname01_OBJECTS)
+LINK_LIBS = $(fsdosfsname01_LDLIBS)
+
+fsdosfsname01$(EXEEXT): $(fsdosfsname01_OBJECTS) $(fsdosfsname01_DEPENDENCIES)
+	@rm -f fsdosfsname01$(EXEEXT)
+	$(make-exe)
+
+include $(top_srcdir)/../automake/local.am
diff --git a/testsuites/fstests/fsdosfsname01/fsdosfsname01.doc b/testsuites/fstests/fsdosfsname01/fsdosfsname01.doc
new file mode 100644
index 0000000..f23e4bb
--- /dev/null
+++ b/testsuites/fstests/fsdosfsname01/fsdosfsname01.doc
@@ -0,0 +1,10 @@
+This file describes the directives and concepts tested by this test set.
+
+test set name: fsdosfsname01
+
+directives:
+
+  TBD
+
+concepts:
+- Make sure short file- and directory names and long file- and directory names are handled correctly for the default character set
diff --git a/testsuites/fstests/fsdosfsname01/fsdosfsname01.scn b/testsuites/fstests/fsdosfsname01/fsdosfsname01.scn
new file mode 100644
index 0000000..218ddf9
--- /dev/null
+++ b/testsuites/fstests/fsdosfsname01/fsdosfsname01.scn
@@ -0,0 +1,2 @@
+*** TEST fsdosfsname01 ***
+*** END OF TEST fsdosfsname01 ***
diff --git a/testsuites/fstests/fsdosfsname01/init.c b/testsuites/fstests/fsdosfsname01/init.c
new file mode 100644
index 0000000..e2208a7
--- /dev/null
+++ b/testsuites/fstests/fsdosfsname01/init.c
@@ -0,0 +1,391 @@
+/*
+ * Copyright (c) 2012, 2013 embedded brains GmbH.  All rights reserved.
+ *
+ *  embedded brains GmbH
+ *  Dornierstr. 4
+ *  82178 Puchheim
+ *  Germany
+ *  <rtems at embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+  #include "config.h"
+#endif
+
+#include "tmacros.h"
+
+#include <fcntl.h>
+#include <dirent.h>
+
+#include <rtems/libio.h>
+#include <rtems/dosfs.h>
+#include <rtems/ramdisk.h>
+
+#define DEV_NAME  "/dev/rda"
+#define MOUNT_DIR "/mnt"
+
+#define NUMBER_OF_DIRECTORIES             5
+#define NUMBER_OF_DIRECTORIES_INVALID     1
+#define MAX_DIRECTORY_NAME_LENGTH       255
+#define NUMBER_OF_FILES                   4
+#define MAX_FILE_NAME_LENGTH            255
+#define MAX_DUPLICATES_PER_NAME           3
+#define NUMBER_OF_DIRECTORIES_DUPLICATED  2
+#define NUMBER_OF_FILES_DUPLICATED        2
+
+static const char DIRECTORY_NAMES[NUMBER_OF_DIRECTORIES][MAX_DIRECTORY_NAME_LENGTH] = {
+  "Shortdir",
+  "shrtdir",
+  "long_conventional_dir",
+  "long_conventional.dir",
+  "LongConventionalDir"
+};
+
+static const char DIRECTORY_NAMES_INVALID[NUMBER_OF_DIRECTORIES_INVALID][MAX_DIRECTORY_NAME_LENGTH] = {
+  "shrt.dir",
+};
+
+
+static const char FILE_NAMES[NUMBER_OF_FILES][MAX_FILE_NAME_LENGTH] = {
+  "shrtfile",
+  "ShrtFle",
+  "The quick brown.fox",
+  "long_conventional_file"
+};
+
+typedef struct {
+  char name[MAX_FILE_NAME_LENGTH];
+  unsigned int number_of_duplicates;
+  char name_duplicates[MAX_DUPLICATES_PER_NAME][MAX_FILE_NAME_LENGTH];
+} name_duplicates;
+
+static const name_duplicates DIRECTORY_DUPLICATES[NUMBER_OF_DIRECTORIES_DUPLICATED] = {
+  {
+    "shrtdir",
+    3,
+    {
+      "shrtdir",
+      "SHRTDIR",
+      "Shrtdir"
+    }
+  },
+  {
+    "long_conventional_dir",
+    3,
+    {
+      "long_conventional_dir",
+      "LONG_CONVENTIONAL_DIR",
+      "Long_conventional_dir"
+    }
+  }
+};
+
+static const name_duplicates FILES_DUPLICATES[NUMBER_OF_FILES_DUPLICATED] = {
+  {
+    "shrtfile",
+    3,
+    {
+      "shrtfile",
+      "SHRTFILE",
+      "Shrtfile"
+    }
+  },
+  {
+    "long_conventional_file",
+    3,
+    {
+      "long_conventional_file",
+      "LONG_CONVENTIONAL_FILE",
+      "Long_conventional_file"
+    }
+  }
+};
+
+static int
+open_and_mount_device(const void *mount_opts)
+{
+  int disk_fd;
+  int rv;
+
+  disk_fd = open ( DEV_NAME, O_RDWR );
+  rtems_test_assert ( disk_fd >= 0 );
+
+  rv = msdos_format ( DEV_NAME, NULL );
+  rtems_test_assert ( rv == 0 );
+
+  rv = mount_and_make_target_path(
+    DEV_NAME,
+    MOUNT_DIR,
+    RTEMS_FILESYSTEM_TYPE_DOSFS,
+    RTEMS_FILESYSTEM_READ_WRITE,
+    mount_opts
+  );
+  rtems_test_assert ( rv == 0 );
+
+  return disk_fd;
+}
+
+static void
+unmount_and_close_device(const int disk_fd)
+{
+  int rv;
+
+  rv = unmount ( MOUNT_DIR );
+  rtems_test_assert ( rv == 0 );
+
+  rv = close ( disk_fd );
+  rtems_test_assert ( rv == 0 );
+}
+
+/*
+ * Simply create a few directories. These tests should all succeed
+ */
+static void
+test_creating_directories(void)
+{
+  unsigned int index;
+  int            rv;
+  char           dirname[MAX_DIRECTORY_NAME_LENGTH + strlen(MOUNT_DIR) +1];
+  DIR           *dirp;
+  struct dirent *dp;
+
+  for (index = 0; index < NUMBER_OF_DIRECTORIES; ++index) {
+    snprintf ( dirname, sizeof ( dirname ) -1, "%s/%s", MOUNT_DIR, DIRECTORY_NAMES[index] );
+    rv = mkdir ( dirname, S_IRWXU | S_IRWXG | S_IRWXO );
+    rtems_test_assert( rv == 0 );
+  }
+  dirp = opendir ( MOUNT_DIR );
+  rtems_test_assert ( NULL != dirp );
+
+  index = 0;
+  dp = readdir ( dirp );
+  rtems_test_assert ( dp != NULL );
+
+  while ( dp != NULL ) {
+    rtems_test_assert ( 0 == strcmp ( DIRECTORY_NAMES[index], dp->d_name ) );
+    ++index;
+    dp = readdir ( dirp );
+  }
+  rtems_test_assert ( NUMBER_OF_DIRECTORIES == index );
+
+  rv = closedir ( dirp );
+  rtems_test_assert ( rv == 0 );
+}
+
+/*
+ * Try creating directories with invalid names.
+ */
+static void
+test_creating_invalid_directories(void)
+{
+  unsigned int index;
+  int            rv;
+  char           dirname[MAX_DIRECTORY_NAME_LENGTH + strlen(MOUNT_DIR) +1];
+
+  for (index = 0; index < NUMBER_OF_DIRECTORIES_INVALID; ++index) {
+    snprintf ( dirname, sizeof ( dirname ) -1, "%s/%s", MOUNT_DIR, DIRECTORY_NAMES_INVALID[index] );
+    rv = mkdir ( dirname, S_IRWXU | S_IRWXG | S_IRWXO );
+    rtems_test_assert( rv == -1 );
+  }
+}
+
+/*
+ * Try creating directories which do already exist (although names may have different catalization)
+ */
+static void
+test_creating_duplicate_directories(void)
+{
+  unsigned int   index_dir;
+  unsigned int   index_duplicate;
+  int            rv;
+  char           dirname[MAX_DIRECTORY_NAME_LENGTH + strlen(MOUNT_DIR) +1];
+
+  for ( index_dir = 0; index_dir < NUMBER_OF_DIRECTORIES_DUPLICATED; ++index_dir ) {
+    snprintf ( dirname, sizeof ( dirname ) -1, "%s/%s", MOUNT_DIR, DIRECTORY_DUPLICATES[index_dir].name );
+    rv = mkdir ( dirname, S_IRWXU | S_IRWXG | S_IRWXO );
+    rtems_test_assert( rv == 0 );
+    for ( index_duplicate = 0; index_duplicate < DIRECTORY_DUPLICATES[index_dir].number_of_duplicates; ++index_duplicate ) {
+      snprintf ( dirname, sizeof ( dirname ) -1, "%s/%s", MOUNT_DIR, DIRECTORY_DUPLICATES[index_dir].name_duplicates[index_duplicate] );
+      rv = mkdir ( dirname, S_IRWXU | S_IRWXG | S_IRWXO );
+      rtems_test_assert( rv < 0 );
+    }
+  }
+}
+
+/*
+ * Try creating and opening files with valid names
+ */
+static void
+test_handling_files(char* dirname)
+{
+  unsigned int index;
+  int          rv;
+  char         filename[MAX_FILE_NAME_LENGTH + strlen(dirname) +1];
+  int          fd;
+
+  for (index = 0; index < NUMBER_OF_FILES; ++index) {
+    snprintf ( filename, sizeof ( filename ) -1, "%s/%s", dirname, FILE_NAMES[index] );
+    fd = open ( filename, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
+    rtems_test_assert ( fd >= 0 );
+
+    rv = close ( fd );
+    rtems_test_assert ( rv == 0 );
+
+    /* See if the file still exists and can be found */
+    fd = open ( filename, O_RDWR );
+    rtems_test_assert ( fd >= 0 );
+
+    rv = close ( fd );
+    rtems_test_assert ( rv == 0 );
+  }
+}
+
+/*
+ * Try opening files which do already exist (with different capitalization in their names)
+ */
+static void
+test_duplicated_files(char* dirname)
+{
+  unsigned int index_file;
+  unsigned int index_duplicate;
+  int          rv;
+  char         filename[MAX_FILE_NAME_LENGTH + strlen(dirname) +1];
+  int          fd;
+
+  for (index_file = 0; index_file < NUMBER_OF_FILES_DUPLICATED; ++index_file) {
+    snprintf ( filename, sizeof ( filename ) -1, "%s/%s", dirname, FILES_DUPLICATES[index_file].name );
+    fd = open ( filename, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
+    rtems_test_assert ( fd >= 0 );
+
+    rv = close ( fd );
+    rtems_test_assert ( rv == 0 );
+
+    for ( index_duplicate = 0; index_duplicate < FILES_DUPLICATES[index_file].number_of_duplicates; ++index_duplicate )
+    {
+      snprintf ( filename, sizeof ( filename ) -1, "%s/%s", dirname, FILES_DUPLICATES[index_file].name_duplicates[index_duplicate] );
+      fd = open ( filename, O_RDWR );
+      rtems_test_assert ( fd >= 0 );
+
+      rv = close ( fd );
+      rtems_test_assert ( rv == 0 );
+    }
+  }
+}
+
+/*
+ * Open and read existing valid directories
+ */
+static void
+test_handling_directories(void)
+{
+  unsigned int   index_directory;
+  unsigned int   index_file;
+  int            rv;
+  DIR*           dir_stream;
+  char           dirname[MAX_DIRECTORY_NAME_LENGTH + strlen(MOUNT_DIR) +1];
+  struct dirent *dp;
+
+  for (index_directory = 0; index_directory < NUMBER_OF_DIRECTORIES; ++index_directory) {
+    snprintf ( dirname, sizeof ( dirname ) -1, "%s/%s", MOUNT_DIR, DIRECTORY_NAMES[index_directory] );
+
+    test_handling_files ( dirname );
+
+    dir_stream = opendir ( dirname );
+    rtems_test_assert( dir_stream != NULL );
+
+    dp = readdir ( dir_stream );
+    rtems_test_assert ( dp != NULL );
+    rtems_test_assert ( 0 == strcmp ( ".", dp->d_name ) );
+
+    dp = readdir ( dir_stream );
+    rtems_test_assert ( dp != NULL );
+    rtems_test_assert ( 0 == strcmp ( "..", dp->d_name ) );
+
+    dp = readdir ( dir_stream );
+    rtems_test_assert ( dp != NULL );
+    index_file = 0;
+    while ( dp != NULL ) {
+      rtems_test_assert ( 0 == strcmp ( FILE_NAMES[index_file], dp->d_name ) );
+      ++index_file;
+      dp = readdir ( dir_stream );
+    }
+    rtems_test_assert ( NUMBER_OF_FILES == index_file );
+
+    rv = closedir ( dir_stream );
+    rtems_test_assert( rv == 0 );
+  }
+}
+
+static void test(void)
+{
+  rtems_status_code         sc;
+  int                       disk_fd;
+
+  sc = rtems_disk_io_initialize ( );
+  rtems_test_assert ( sc == RTEMS_SUCCESSFUL );
+
+  disk_fd = open_and_mount_device ( NULL );
+
+  test_creating_invalid_directories ( );
+
+  test_creating_directories ( );
+
+  test_handling_directories ( );
+
+  unmount_and_close_device ( disk_fd );
+
+  disk_fd = open_and_mount_device ( NULL );
+
+  test_creating_duplicate_directories ( );
+
+  unmount_and_close_device ( disk_fd );
+
+  disk_fd = open_and_mount_device ( NULL );
+
+  test_duplicated_files ( MOUNT_DIR );
+
+  unmount_and_close_device ( disk_fd );
+}
+
+static void Init(rtems_task_argument arg)
+{
+  puts ( "\n\n*** TEST fsdosfsname01 ***" );
+
+  test ( );
+
+  puts ( "*** END OF TEST fsdosfsname01 ***" );
+
+  rtems_test_exit ( 0 );
+}
+
+
+rtems_ramdisk_config rtems_ramdisk_configuration [] = {
+  { .block_size = 512, .block_num = 1024 }
+};
+
+size_t rtems_ramdisk_configuration_size = 1;
+
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+#define CONFIGURE_APPLICATION_EXTRA_DRIVERS RAMDISK_DRIVER_TABLE_ENTRY
+
+#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
+
+#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
+
+#define CONFIGURE_FILESYSTEM_DOSFS
+
+/* 1 RAM disk device file + 1 mount_dir + stdin + stdout + stderr + 1 for open directory */
+#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS (5 + 1)
+
+#define CONFIGURE_MAXIMUM_TASKS 1
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_INIT
+
+#include <rtems/confdefs.h>
-- 
1.7.10.4




More information about the devel mailing list