[PATCH 6/8] fstests/fsdosfsformat01: New test
Ralf Kirchner
ralf.kirchner at embedded-brains.de
Thu Nov 29 14:32:44 UTC 2012
---
testsuites/fstests/Makefile.am | 3 +-
testsuites/fstests/configure.ac | 1 +
testsuites/fstests/fsdosfsformat01/Makefile.am | 19 +
.../fstests/fsdosfsformat01/fsdosfsformat01.doc | 11 +
testsuites/fstests/fsdosfsformat01/init.c | 462 ++++++++++++++++++++
5 Dateien geändert, 495 Zeilen hinzugefügt(+), 1 Zeile entfernt(-)
create mode 100644 testsuites/fstests/fsdosfsformat01/Makefile.am
create mode 100644 testsuites/fstests/fsdosfsformat01/fsdosfsformat01.doc
create mode 100644 testsuites/fstests/fsdosfsformat01/fsdosfsformat01.scn
create mode 100644 testsuites/fstests/fsdosfsformat01/init.c
diff --git a/testsuites/fstests/Makefile.am b/testsuites/fstests/Makefile.am
index 9bba757..7cf6571 100644
--- a/testsuites/fstests/Makefile.am
+++ b/testsuites/fstests/Makefile.am
@@ -1,6 +1,7 @@
ACLOCAL_AMFLAGS = -I ../aclocal
-SUBDIRS =
+SUBDIRS =
+SUBDIRS += fsdosfsformat01
SUBDIRS += fsfseeko01
SUBDIRS += fsdosfssync01
SUBDIRS += imfs_fserror
diff --git a/testsuites/fstests/configure.ac b/testsuites/fstests/configure.ac
index 6dd15ac..3496de4 100644
--- a/testsuites/fstests/configure.ac
+++ b/testsuites/fstests/configure.ac
@@ -77,6 +77,7 @@ AC_CHECK_SIZEOF([blkcnt_t])
# Explicitly list all Makefiles here
AC_CONFIG_FILES([Makefile
+fsdosfsformat01/Makefile
fsfseeko01/Makefile
fsdosfssync01/Makefile
imfs_fserror/Makefile
diff --git a/testsuites/fstests/fsdosfsformat01/Makefile.am b/testsuites/fstests/fsdosfsformat01/Makefile.am
new file mode 100644
index 0000000..d7c91f0
--- /dev/null
+++ b/testsuites/fstests/fsdosfsformat01/Makefile.am
@@ -0,0 +1,19 @@
+rtems_tests_PROGRAMS = fsdosfsformat01
+fsdosfsformat01_SOURCES = init.c
+
+dist_rtems_tests_DATA = fsdosfsformat01.scn fsdosfsformat01.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 = $(fsdosfsformat01_OBJECTS)
+LINK_LIBS = $(fsdosfsformat01_LDLIBS)
+
+fsdosfsformat01$(EXEEXT): $(fsdosfsformat01_OBJECTS) $(fsdosfsformat01_DEPENDENCIES)
+ @rm -f fsdosfsformat01$(EXEEXT)
+ $(make-exe)
+
+include $(top_srcdir)/../automake/local.am
diff --git a/testsuites/fstests/fsdosfsformat01/fsdosfsformat01.doc b/testsuites/fstests/fsdosfsformat01/fsdosfsformat01.doc
new file mode 100644
index 0000000..6cdb669
--- /dev/null
+++ b/testsuites/fstests/fsdosfsformat01/fsdosfsformat01.doc
@@ -0,0 +1,11 @@
+This file describes the directives and concepts tested by this test set.
+
+test set name: fsdosfsformat01
+
+directives:
+
+ TBD
+
+concepts:
+
+ TBD
diff --git a/testsuites/fstests/fsdosfsformat01/fsdosfsformat01.scn b/testsuites/fstests/fsdosfsformat01/fsdosfsformat01.scn
new file mode 100644
index 0000000..e69de29
diff --git a/testsuites/fstests/fsdosfsformat01/init.c b/testsuites/fstests/fsdosfsformat01/init.c
new file mode 100644
index 0000000..14de46f
--- /dev/null
+++ b/testsuites/fstests/fsdosfsformat01/init.c
@@ -0,0 +1,462 @@
+/*
+ * Copyright (c) 2012 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Obere Lagerstr. 30
+ * 82178 Puchheim
+ * Germany
+ * <rtems at embedded-brains.de>
+ *
+ * The license and distribution terms for this file_name may be
+ * found in the file_name 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 <sys/statvfs.h>
+#include <rtems/libio.h>
+#include <rtems/blkdev.h>
+#include <rtems/dosfs.h>
+#include <rtems/sparse-disk.h>
+
+#define MAX_PATH_LENGTH 100 /* Maximum number of characters per path */
+#define SECTOR_SIZE 512 /* sector size (bytes) */
+#define FAT12_MAX_CLN 4085 /* maximum + 1 number of clusters for FAT12 */
+#define FAT16_MAX_CLN 65525 /* maximum + 1 number of clusters for FAT16 */
+#define FAT12_DEFAULT_SECTORS_PER_CLUSTER 8 /* Default number of sectors per cluster for FAT12 */
+#define FAT16_DEFAULT_SECTORS_PER_CLUSTER 32 /* Default number of sectors per cluster for FAT16 */
+
+
+
+
+
+
+static void
+test_disk_params (
+ const char* dev_name,
+ const char* mount_dir,
+ const blksize_t sector_size,
+ const blksize_t cluster_size,
+ const blkcnt_t sectors_per_cluster
+)
+{
+ int rv;
+ int fildes;
+ struct stat stat_buff;
+ char file_name[MAX_PATH_LENGTH +1];
+ ssize_t num_bytes;
+ unsigned int value = (unsigned int) -1;
+
+ snprintf (file_name, MAX_PATH_LENGTH, "%s/file1.txt", mount_dir);
+ memset (&stat_buff, 0, sizeof(stat_buff));
+
+ rv = mount (dev_name, mount_dir, RTEMS_FILESYSTEM_TYPE_DOSFS, RTEMS_FILESYSTEM_READ_WRITE, NULL);
+ rtems_test_assert(0 == rv);
+
+ fildes = open (file_name, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ rtems_test_assert(-1 != fildes);
+
+ num_bytes = write (fildes, &value, sizeof(value));
+ rtems_test_assert(sizeof(value) == num_bytes);
+
+ rv = fstat (fildes, &stat_buff);
+ rtems_test_assert(0 == rv);
+ rtems_test_assert(S_ISREG(stat_buff.st_mode));
+ rtems_test_assert(sizeof(value) == stat_buff.st_size);
+ rtems_test_assert(cluster_size == stat_buff.st_blksize);
+ rtems_test_assert(sectors_per_cluster == (stat_buff.st_blocks * sector_size / 512));
+ rtems_test_assert((((stat_buff.st_size + cluster_size - 1) / cluster_size) * cluster_size / 512) == stat_buff.st_blocks);
+ rv = close (fildes);
+ rtems_test_assert(0 == rv);
+
+ rv = unmount (mount_dir);
+ rtems_test_assert(0 == rv);
+}
+
+static void
+ test_file_creation (
+ const char* dev_name,
+ const char* mount_dir,
+ const unsigned int number_of_files
+)
+{
+ int rv;
+ int file_idx = 0;
+ int fildes[number_of_files + 1];
+ char file_name[MAX_PATH_LENGTH +1];
+ unsigned int files_created;
+
+ rv = mount (dev_name, mount_dir, RTEMS_FILESYSTEM_TYPE_DOSFS, RTEMS_FILESYSTEM_READ_WRITE, NULL);
+ rtems_test_assert(0 == rv);
+
+ /* Create as many files as should be supported */
+ do {
+ snprintf (file_name, MAX_PATH_LENGTH, "%s/file%u.txt", mount_dir, file_idx);
+ fildes[file_idx] = open (file_name, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ rtems_test_assert(-1 != fildes[file_idx]);
+
+ ++file_idx;
+ }
+ while (number_of_files > file_idx);
+
+ /* Try to create another file which should fail */
+ snprintf (file_name, MAX_PATH_LENGTH, "%s/file%u.txt", mount_dir, file_idx);
+ fildes[file_idx] = open (file_name, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+ rtems_test_assert(-1 == fildes[file_idx]);
+
+ /* Tidy up again by closing and deleting all files */
+ files_created = file_idx;
+ for (file_idx = 0; file_idx < files_created; file_idx++)
+ {
+ snprintf (file_name, MAX_PATH_LENGTH, "%s/file%u.txt", mount_dir, file_idx);
+ rv = close(fildes[file_idx]);
+ rtems_test_assert(0 == rv);
+ rv = unlink (file_name);
+ rtems_test_assert(0 == rv);
+ }
+ rv = unmount (mount_dir);
+ rtems_test_assert(0 == rv);
+}
+
+
+static void
+ test(void)
+{
+ rtems_status_code sc;
+ int rv;
+ const char dev_name[] = "/dev/rda";
+ const char mount_dir[] = "/mnt";
+ msdos_format_request_param_t rqdata;
+ rtems_sparse_disk *sparse_disk = NULL;
+
+ memset (&rqdata, 0, sizeof(rqdata));
+
+ sc = rtems_disk_io_initialize();
+ rtems_test_assert(sc == RTEMS_SUCCESSFUL);
+
+ rv = mkdir(mount_dir, S_IRWXU | S_IRWXG | S_IRWXO);
+ rtems_test_assert(0 == rv);
+
+
+
+ // FAT12
+ // For 1.44 MB disks
+ sc = rtems_sparse_disk_create(
+ SECTOR_SIZE,
+ 64L,
+ &sparse_disk
+ );
+ rtems_test_assert(RTEMS_SUCCESSFUL == sc);
+ sc = rtems_sparse_disk_register(
+ dev_name,
+ sparse_disk,
+ SECTOR_SIZE,
+ 2880,
+ 64L,
+ rtems_sparse_disk_delete,
+ 0
+ );
+ rtems_test_assert(RTEMS_SUCCESSFUL == sc);
+
+ // Optimized for disk space
+ rqdata.OEMName = NULL;
+ rqdata.VolLabel = NULL;
+ rqdata.sectors_per_cluster = 1;
+ rqdata.fat_num = 1;
+ rqdata.files_per_root_dir = 32;
+ rqdata.media = 0; /* Media code. 0 == Default */
+ rqdata.quick_format = true;
+ rqdata.skip_alignment = true;
+ rv = msdos_format(dev_name, &rqdata);
+ rtems_test_assert(rv == 0);
+ test_disk_params (dev_name, mount_dir, SECTOR_SIZE, SECTOR_SIZE, 1);
+ test_file_creation (dev_name, mount_dir, rqdata.files_per_root_dir);
+
+
+ // Try formatting with invalid values
+ rqdata.OEMName = NULL;
+ rqdata.VolLabel = NULL;
+ rqdata.sectors_per_cluster = 1;
+ rqdata.fat_num = 7; /* Invalid number of fats */
+ rqdata.files_per_root_dir = 32;
+ rqdata.media = 0; /* Media code. 0 == Default */
+ rqdata.quick_format = true;
+ rqdata.skip_alignment = true;
+ rv = msdos_format(dev_name, &rqdata);
+ rtems_test_assert(rv != 0);
+
+ rqdata.OEMName = NULL;
+ rqdata.VolLabel = NULL;
+ rqdata.sectors_per_cluster = 1;
+ rqdata.fat_num = 1;
+ rqdata.files_per_root_dir = 32;
+ rqdata.media = 0x11; /* Invalid media code */
+ rqdata.quick_format = true;
+ rqdata.skip_alignment = true;
+ rv = msdos_format(dev_name, &rqdata);
+ rtems_test_assert(rv != 0);
+
+ rqdata.OEMName = NULL;
+ rqdata.VolLabel = NULL;
+ rqdata.sectors_per_cluster = 16; /* Invalid number of sectors per cluster for FAT12 */
+ rqdata.fat_num = 1;
+ rqdata.files_per_root_dir = 32;
+ rqdata.media = 0; /* Media code. 0 == Default */
+ rqdata.quick_format = true;
+ rqdata.skip_alignment = false;
+ rv = msdos_format(dev_name, &rqdata);
+ rtems_test_assert(rv != 0);
+
+ // Optimized for read/write speed
+ rqdata.OEMName = NULL;
+ rqdata.VolLabel = NULL;
+ rqdata.sectors_per_cluster = 8;
+ rqdata.fat_num = 0;
+ rqdata.files_per_root_dir = 0;
+ rqdata.media = 0; /* Media code. 0 == Default */
+ rqdata.quick_format = true;
+ rqdata.skip_alignment = false;
+ rv = msdos_format(dev_name, &rqdata);
+ rtems_test_assert(rv == 0);
+ test_disk_params (dev_name, mount_dir, SECTOR_SIZE, SECTOR_SIZE * rqdata.sectors_per_cluster, rqdata.sectors_per_cluster);
+
+
+ rv = unlink (dev_name);
+ rtems_test_assert(rv == 0);
+
+ // Largest FAT12 disk
+ sc = rtems_sparse_disk_create(
+ SECTOR_SIZE,
+ 64L,
+ &sparse_disk
+ );
+ rtems_test_assert(RTEMS_SUCCESSFUL == sc);
+ sc = rtems_sparse_disk_register(
+ dev_name,
+ sparse_disk,
+ SECTOR_SIZE,
+ (FAT12_MAX_CLN * FAT12_DEFAULT_SECTORS_PER_CLUSTER) -1L,
+ 64L,
+ rtems_sparse_disk_delete,
+ 0
+ );
+ rtems_test_assert(RTEMS_SUCCESSFUL == sc);
+
+ // Default parameters (corresponds to optimization for read/write speed)
+ rv = msdos_format(dev_name, NULL);
+ rtems_test_assert(rv == 0);
+ test_disk_params (dev_name, mount_dir, SECTOR_SIZE, SECTOR_SIZE * FAT12_DEFAULT_SECTORS_PER_CLUSTER, FAT12_DEFAULT_SECTORS_PER_CLUSTER);
+
+
+ rv = unlink (dev_name);
+ rtems_test_assert(rv == 0);
+
+
+
+ // FAT16
+ sc = rtems_sparse_disk_create(
+ SECTOR_SIZE,
+ 1024L,
+ &sparse_disk
+ );
+ rtems_test_assert(RTEMS_SUCCESSFUL == sc);
+ sc = rtems_sparse_disk_register(
+ dev_name,
+ sparse_disk,
+ SECTOR_SIZE,
+ (FAT16_MAX_CLN * FAT16_DEFAULT_SECTORS_PER_CLUSTER) - 1L,
+ 1024L,
+ rtems_sparse_disk_delete,
+ 0
+ );
+ rtems_test_assert(RTEMS_SUCCESSFUL == sc);
+
+ // Optimized for disk space
+ rqdata.OEMName = NULL;
+ rqdata.VolLabel = NULL;
+ rqdata.sectors_per_cluster = 1;
+ rqdata.fat_num = 1;
+ rqdata.files_per_root_dir = 32;
+ rqdata.media = 0; /* Media code. 0 == Default */
+ rqdata.quick_format = true;
+ rqdata.skip_alignment = true;
+ rv = msdos_format(dev_name, &rqdata);
+ rtems_test_assert(rv == 0);
+ test_disk_params (dev_name, mount_dir, SECTOR_SIZE, SECTOR_SIZE, 1);
+
+ rv = unlink (dev_name);
+ rtems_test_assert(rv == 0);
+ sc = rtems_sparse_disk_create(
+ SECTOR_SIZE,
+ 1024L,
+ &sparse_disk
+ );
+ rtems_test_assert(RTEMS_SUCCESSFUL == sc);
+ sc = rtems_sparse_disk_register(
+ dev_name,
+ sparse_disk,
+ SECTOR_SIZE,
+ (FAT16_MAX_CLN * FAT16_DEFAULT_SECTORS_PER_CLUSTER) - 1L,
+ 1024L,
+ rtems_sparse_disk_delete,
+ 0
+ );
+ rtems_test_assert(RTEMS_SUCCESSFUL == sc);
+
+ // Optimized for read/write speed
+ rqdata.OEMName = NULL;
+ rqdata.VolLabel = NULL;
+ rqdata.sectors_per_cluster = 64;
+ rqdata.fat_num = 0;
+ rqdata.files_per_root_dir = 0;
+ rqdata.media = 0; /* Media code. 0 == Default */
+ rqdata.quick_format = true;
+ rqdata.skip_alignment = false;
+ rv = msdos_format(dev_name, &rqdata);
+ rtems_test_assert(rv == 0);
+ test_disk_params (dev_name, mount_dir, SECTOR_SIZE, SECTOR_SIZE * rqdata.sectors_per_cluster, rqdata.sectors_per_cluster);
+
+ // Default parameters (corresponds to optimization for read/write speed)
+ rv = msdos_format(dev_name, NULL);
+ rtems_test_assert(rv == 0);
+ test_disk_params (dev_name, mount_dir, SECTOR_SIZE, SECTOR_SIZE * FAT16_DEFAULT_SECTORS_PER_CLUSTER, FAT16_DEFAULT_SECTORS_PER_CLUSTER);
+
+ rv = unlink (dev_name);
+ rtems_test_assert(rv == 0);
+
+ sc = rtems_sparse_disk_create(
+ SECTOR_SIZE,
+ 1024L,
+ &sparse_disk
+ );
+ rtems_test_assert(RTEMS_SUCCESSFUL == sc);
+ sc = rtems_sparse_disk_register(
+ dev_name,
+ sparse_disk,
+ SECTOR_SIZE,
+ (FAT16_MAX_CLN + 10) * 64,
+ 1024L,
+ rtems_sparse_disk_delete,
+ 0
+ );
+ rtems_test_assert(RTEMS_SUCCESSFUL == sc);
+
+ rqdata.OEMName = NULL;
+ rqdata.VolLabel = NULL;
+ rqdata.sectors_per_cluster = 64;
+ rqdata.fat_num = 0;
+ rqdata.files_per_root_dir = 0;
+ rqdata.media = 0; /* Media code. 0 == Default */
+ rqdata.quick_format = true;
+ rqdata.skip_alignment = false;
+ rv = msdos_format(dev_name, &rqdata);
+ rtems_test_assert(rv == 0);
+ test_disk_params (dev_name, mount_dir, SECTOR_SIZE, SECTOR_SIZE * rqdata.sectors_per_cluster, rqdata.sectors_per_cluster);
+ rv = unlink (dev_name);
+ rtems_test_assert(rv == 0);
+
+
+
+ // FAT32
+
+ sc = rtems_sparse_disk_create(
+ SECTOR_SIZE,
+ 1024L,
+ &sparse_disk
+ );
+ rtems_test_assert(RTEMS_SUCCESSFUL == sc);
+ sc = rtems_sparse_disk_register(
+ dev_name,
+ sparse_disk,
+ SECTOR_SIZE,
+ (FAT16_MAX_CLN * FAT16_DEFAULT_SECTORS_PER_CLUSTER) + 41L,
+ 1024L,
+ rtems_sparse_disk_delete,
+ 0
+ );
+ rtems_test_assert(RTEMS_SUCCESSFUL == sc);
+
+ // Default parameters
+ rv = msdos_format(dev_name, NULL);
+ rtems_test_assert(rv == 0);
+ test_disk_params (dev_name, mount_dir, SECTOR_SIZE, SECTOR_SIZE, 1);
+ rv = unlink (dev_name);
+ rtems_test_assert(rv == 0);
+
+ sc = rtems_sparse_disk_create(
+ SECTOR_SIZE,
+ 1024L,
+ &sparse_disk
+ );
+ rtems_test_assert(RTEMS_SUCCESSFUL == sc);
+ sc = rtems_sparse_disk_register(
+ dev_name,
+ sparse_disk,
+ SECTOR_SIZE,
+ (FAT16_MAX_CLN + 20) * 64,
+ 1024L,
+ rtems_sparse_disk_delete,
+ 0
+ );
+ rtems_test_assert(RTEMS_SUCCESSFUL == sc);
+
+ // Optimized for read/write speed
+ rqdata.OEMName = NULL;
+ rqdata.VolLabel = NULL;
+ rqdata.sectors_per_cluster = 64;
+ rqdata.fat_num = 0;
+ rqdata.files_per_root_dir = 0;
+ rqdata.media = 0; /* Media code. 0 == Default */
+ rqdata.quick_format = true;
+ rqdata.skip_alignment = false;
+ rv = msdos_format(dev_name, &rqdata);
+ rtems_test_assert(rv == 0);
+ test_disk_params (dev_name, mount_dir, SECTOR_SIZE, SECTOR_SIZE * rqdata.sectors_per_cluster, rqdata.sectors_per_cluster);
+
+
+ rv = unlink (dev_name);
+ rtems_test_assert(rv == 0);
+}
+
+static void Init(rtems_task_argument arg)
+{
+ puts("\n\n*** TEST fsdosfsformat01 ***");
+
+ test();
+
+ puts("*** END OF TEST fsdosfsformat01 ***");
+
+ rtems_test_exit(0);
+}
+
+
+
+#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
+#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
+
+/* 32 root_dir entries tested for file creation + 1 mount_dir + stdin + stdout + stderr + device file when mounted */
+#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS (32 + 5)
+
+#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
+
+#define CONFIGURE_FILESYSTEM_DOSFS
+
+#define CONFIGURE_UNLIMITED_OBJECTS
+#define CONFIGURE_UNIFIED_WORK_AREAS
+
+#define CONFIGURE_INIT_TASK_STACK_SIZE (32 * 1024)
+
+#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
+
+#define CONFIGURE_BDBUF_BUFFER_MAX_SIZE (32 * 1024)
+
+#define CONFIGURE_INIT
+
+#include <rtems/confdefs.h>
--
1.7.10.4
More information about the devel
mailing list