From 01211720ec7e19f70e900c1e21b415e2a126436b Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Mon, 5 Mar 2012 15:06:02 +0100 Subject: libblock: Add generic IMFS block device nodes New functions o rtems_blkdev_create(), and o rtems_blkdev_create_partition(). New test libtests/block11. --- testsuites/libtests/Makefile.am | 2 +- testsuites/libtests/block11/Makefile.am | 25 ++ testsuites/libtests/block11/block11.doc | 12 + testsuites/libtests/block11/block11.scn | 2 + testsuites/libtests/block11/init.c | 402 ++++++++++++++++++++++++++++++++ testsuites/libtests/configure.ac | 1 + 6 files changed, 443 insertions(+), 1 deletion(-) create mode 100644 testsuites/libtests/block11/Makefile.am create mode 100644 testsuites/libtests/block11/block11.doc create mode 100644 testsuites/libtests/block11/block11.scn create mode 100644 testsuites/libtests/block11/init.c (limited to 'testsuites') diff --git a/testsuites/libtests/Makefile.am b/testsuites/libtests/Makefile.am index a3990325ec..0e30a51032 100644 --- a/testsuites/libtests/Makefile.am +++ b/testsuites/libtests/Makefile.am @@ -13,7 +13,7 @@ SUBDIRS += bspcmdline01 cpuuse devfs01 devfs02 devfs03 devfs04 \ termios termios01 termios02 termios03 termios04 termios05 \ termios06 termios07 termios08 \ rtems++ tztest block01 block02 block03 block04 block05 block06 block07 \ - block08 block09 block10 stringto01 \ + block08 block09 block10 block11 stringto01 \ tar01 tar02 tar03 \ math mathf mathl complex \ mouse01 diff --git a/testsuites/libtests/block11/Makefile.am b/testsuites/libtests/block11/Makefile.am new file mode 100644 index 0000000000..dee51b6584 --- /dev/null +++ b/testsuites/libtests/block11/Makefile.am @@ -0,0 +1,25 @@ +## +## $Id$ +## + + +rtems_tests_PROGRAMS = block11 +block11_SOURCES = init.c + +dist_rtems_tests_DATA = block11.scn block11.doc + +include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg +include $(top_srcdir)/../automake/compile.am +include $(top_srcdir)/../automake/leaf.am + + +AM_CPPFLAGS += -I$(top_srcdir)/../support/include + +LINK_OBJS = $(block11_OBJECTS) +LINK_LIBS = $(block11_LDLIBS) + +block11$(EXEEXT): $(block11_OBJECTS) $(block11_DEPENDENCIES) + @rm -f block11$(EXEEXT) + $(make-exe) + +include $(top_srcdir)/../automake/local.am diff --git a/testsuites/libtests/block11/block11.doc b/testsuites/libtests/block11/block11.doc new file mode 100644 index 0000000000..e52b2440a1 --- /dev/null +++ b/testsuites/libtests/block11/block11.doc @@ -0,0 +1,12 @@ +This file describes the directives and concepts tested by this test set. + +test set name: block11 + +directives: + + rtems_blkdev_create + rtems_blkdev_create_partition + +concepts: + + TBD diff --git a/testsuites/libtests/block11/block11.scn b/testsuites/libtests/block11/block11.scn new file mode 100644 index 0000000000..fff48c0d56 --- /dev/null +++ b/testsuites/libtests/block11/block11.scn @@ -0,0 +1,2 @@ +*** TEST BLOCK 11 *** +*** END OF TEST BLOCK 11 *** diff --git a/testsuites/libtests/block11/init.c b/testsuites/libtests/block11/init.c new file mode 100644 index 0000000000..31273313b5 --- /dev/null +++ b/testsuites/libtests/block11/init.c @@ -0,0 +1,402 @@ +/** + * @file + * + * @ingroup tests + * + * @brief Block device tests. + */ + +/* + * Copyright (c) 2012 embedded brains GmbH. All rights reserved. + * + * embedded brains GmbH + * Obere Lagerstr. 30 + * 82178 Puchheim + * Germany + * + * + * 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 +#include +#include +#include +#include + +#include +#include +#include +#include + +#define ASSERT_SC(sc) rtems_test_assert((sc) == RTEMS_SUCCESSFUL) + +#define CHUNK_MAX 32U + +#define AREA_SIZE ((CHUNK_MAX * (CHUNK_MAX + 1U)) / 2U) + +#define BLOCK_SIZE 4U + +#define BLOCK_COUNT (AREA_SIZE / BLOCK_SIZE) + +static const char rda [] = "/dev/rda"; + +static const char rda1 [] = "/dev/rda1"; + +static const char not_exist [] = "not_exist"; + +static const char not_blkdev [] = "not_blkdev"; + +static const char invalid_blkdev [] = "invalid_blkdev"; + +static long area_a [AREA_SIZE / sizeof(long)]; + +static long area_b [AREA_SIZE / sizeof(long)]; + +static void area_init(long *area) +{ + size_t i; + size_t n = AREA_SIZE / sizeof(long); + + for (i = 0; i < n; ++i) { + area [i] = mrand48(); + } +} + +static void area_read(int fd, long *area) +{ + size_t i; + size_t n = CHUNK_MAX; + char *dst = (char *) area; + + for (i = 0; i <= n; ++i) { + ssize_t m = read(fd, dst, i); + rtems_test_assert(m == (ssize_t) i); + dst += i; + } +} + +static void area_write(int fd, const long *area) +{ + size_t i; + size_t n = CHUNK_MAX; + const char *src = (const char *) area; + + for (i = 0; i <= n; ++i) { + ssize_t m = write(fd, src, i); + rtems_test_assert(m == (ssize_t) i); + src += i; + } +} + +static void area_compare(const long *area_a, const long *area_b, bool equal) +{ + bool actual_equal = memcmp(area_a, area_b, AREA_SIZE) == 0; + rtems_test_assert(actual_equal == equal); +} + +static void test_blkdev_imfs_read_and_write(void) +{ + rtems_status_code sc; + int rv; + ramdisk *rd; + int fd; + off_t off; + + rd = ramdisk_allocate(area_a, BLOCK_SIZE, BLOCK_COUNT, false); + rtems_test_assert(rd != NULL); + + ramdisk_enable_free_at_delete_request(rd); + + sc = rtems_blkdev_create( + rda, + BLOCK_SIZE, + BLOCK_COUNT, + ramdisk_ioctl, + rd + ); + ASSERT_SC(sc); + + fd = open(rda, O_RDWR); + rtems_test_assert(fd >= 0); + + area_init(area_a); + area_read(fd, area_b); + area_compare(area_a, area_b, true); + + off = lseek(fd, 0, SEEK_SET); + rtems_test_assert(off == 0); + + area_init(area_b); + area_write(fd, area_b); + area_compare(area_a, area_b, false); + + rv = close(fd); + rtems_test_assert(rv == 0); + + rv = unlink(rda); + rtems_test_assert(rv == 0); + + area_compare(area_a, area_b, true); +} + +static void test_blkdev_imfs_parameters(void) +{ + rtems_status_code sc; + int rv; + ramdisk *rd; + int fd; + const rtems_disk_device *dd; + struct stat st; + + rd = ramdisk_allocate(NULL, BLOCK_SIZE, BLOCK_COUNT, false); + rtems_test_assert(rd != NULL); + + ramdisk_enable_free_at_delete_request(rd); + + sc = rtems_blkdev_create( + rda, + BLOCK_SIZE, + BLOCK_COUNT, + ramdisk_ioctl, + rd + ); + ASSERT_SC(sc); + + sc = rtems_blkdev_create_partition( + rda1, + rda, + 1, + BLOCK_COUNT - 1 + ); + ASSERT_SC(sc); + + fd = open(rda, O_RDWR); + rtems_test_assert(fd >= 0); + + rv = fstat(fd, &st); + rtems_test_assert(rv == 0); + + rv = rtems_disk_fd_get_disk_device(fd, &dd); + rtems_test_assert(rv == 0); + + rtems_test_assert(rtems_disk_get_driver_data(dd) == rd); + rtems_test_assert(rtems_disk_get_device_identifier(dd) == st.st_rdev); + rtems_test_assert(rtems_disk_get_media_block_size(dd) == BLOCK_SIZE); + rtems_test_assert(rtems_disk_get_block_size(dd) == BLOCK_SIZE); + rtems_test_assert(rtems_disk_get_block_begin(dd) == 0); + rtems_test_assert(rtems_disk_get_block_count(dd) == BLOCK_COUNT); + + rv = close(fd); + rtems_test_assert(rv == 0); + + fd = open(rda1, O_RDWR); + rtems_test_assert(fd >= 0); + + rv = fstat(fd, &st); + rtems_test_assert(rv == 0); + + rv = rtems_disk_fd_get_disk_device(fd, &dd); + rtems_test_assert(rv == 0); + + rtems_test_assert(rtems_disk_get_driver_data(dd) == rd); + rtems_test_assert(rtems_disk_get_device_identifier(dd) == st.st_rdev); + rtems_test_assert(rtems_disk_get_media_block_size(dd) == BLOCK_SIZE); + rtems_test_assert(rtems_disk_get_block_size(dd) == BLOCK_SIZE); + rtems_test_assert(rtems_disk_get_block_begin(dd) == 1); + rtems_test_assert(rtems_disk_get_block_count(dd) == BLOCK_COUNT - 1); + + rv = close(fd); + rtems_test_assert(rv == 0); + + rv = unlink(rda1); + rtems_test_assert(rv == 0); + + rv = unlink(rda); + rtems_test_assert(rv == 0); +} + +static void test_blkdev_imfs_errors(void) +{ + rtems_status_code sc; + int rv; + ramdisk *rd; + void *opaque; + + rd = ramdisk_allocate(NULL, BLOCK_SIZE, BLOCK_COUNT, false); + rtems_test_assert(rd != NULL); + + ramdisk_enable_free_at_delete_request(rd); + + sc = rtems_blkdev_create( + rda, + 0, + BLOCK_COUNT, + ramdisk_ioctl, + rd + ); + rtems_test_assert(sc == RTEMS_INVALID_NUMBER); + + sc = rtems_blkdev_create( + rda, + BLOCK_SIZE, + 0, + ramdisk_ioctl, + rd + ); + rtems_test_assert(sc == RTEMS_INVALID_NUMBER); + + opaque = rtems_heap_greedy_allocate(0); + sc = rtems_blkdev_create( + rda, + BLOCK_SIZE, + BLOCK_COUNT, + ramdisk_ioctl, + rd + ); + rtems_test_assert(sc == RTEMS_NO_MEMORY); + rtems_heap_greedy_free(opaque); + + opaque = rtems_heap_greedy_allocate(sizeof(rtems_disk_device) + sizeof(int)); + sc = rtems_blkdev_create( + rda, + BLOCK_SIZE, + BLOCK_COUNT, + ramdisk_ioctl, + rd + ); + rtems_test_assert(sc == RTEMS_UNSATISFIED); + rtems_heap_greedy_free(opaque); + + sc = rtems_blkdev_create( + rda, + BLOCK_SIZE, + BLOCK_COUNT, + ramdisk_ioctl, + rd + ); + ASSERT_SC(sc); + + sc = rtems_blkdev_create_partition( + rda1, + not_exist, + 0, + BLOCK_COUNT + ); + rtems_test_assert(sc == RTEMS_INVALID_ID); + + rv = mknod(not_blkdev, S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO, 0); + rtems_test_assert(rv == 0); + + sc = rtems_blkdev_create_partition( + rda1, + not_blkdev, + 0, + BLOCK_COUNT + ); + rtems_test_assert(sc == RTEMS_INVALID_NODE); + + rv = mknod(invalid_blkdev, S_IFBLK | S_IRWXU | S_IRWXG | S_IRWXO, 0); + rtems_test_assert(rv == 0); + + sc = rtems_blkdev_create_partition( + rda1, + invalid_blkdev, + 0, + BLOCK_COUNT + ); + rtems_test_assert(sc == RTEMS_NOT_IMPLEMENTED); + + sc = rtems_blkdev_create_partition( + rda1, + rda, + 0, + 0 + ); + rtems_test_assert(sc == RTEMS_INVALID_NUMBER); + + sc = rtems_blkdev_create_partition( + rda1, + rda, + BLOCK_COUNT, + BLOCK_COUNT + ); + rtems_test_assert(sc == RTEMS_INVALID_NUMBER); + + sc = rtems_blkdev_create_partition( + rda1, + rda, + 0, + BLOCK_COUNT + 1 + ); + rtems_test_assert(sc == RTEMS_INVALID_NUMBER); + + opaque = rtems_heap_greedy_allocate(0); + sc = rtems_blkdev_create_partition( + rda1, + rda, + 0, + BLOCK_COUNT + ); + rtems_test_assert(sc == RTEMS_NO_MEMORY); + rtems_heap_greedy_free(opaque); + + opaque = rtems_heap_greedy_allocate(sizeof(rtems_disk_device) + sizeof(int)); + sc = rtems_blkdev_create_partition( + rda1, + rda, + 0, + BLOCK_COUNT + ); + rtems_test_assert(sc == RTEMS_UNSATISFIED); + rtems_heap_greedy_free(opaque); + + rv = unlink(rda); + rtems_test_assert(rv == 0); +} + +static rtems_task Init(rtems_task_argument argument) +{ + rtems_status_code sc; + + puts("\n\n*** TEST BLOCK 11 ***"); + + sc = rtems_disk_io_initialize(); + ASSERT_SC(sc); + + test_blkdev_imfs_read_and_write(); + test_blkdev_imfs_parameters(); + test_blkdev_imfs_errors(); + + sc = rtems_disk_io_done(); + ASSERT_SC(sc); + + puts("*** END OF TEST BLOCK 11 ***"); + + exit(0); +} + +#define CONFIGURE_INIT + +#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER +#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK + +#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM +#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 5 + +#define CONFIGURE_MAXIMUM_TASKS 2 +#define CONFIGURE_MAXIMUM_DRIVERS 2 +#define CONFIGURE_EXTRA_TASK_STACKS (8 * 1024) + +#define CONFIGURE_RTEMS_INIT_TASKS_TABLE + +#include diff --git a/testsuites/libtests/configure.ac b/testsuites/libtests/configure.ac index 675f3430b1..b634ff8246 100644 --- a/testsuites/libtests/configure.ac +++ b/testsuites/libtests/configure.ac @@ -53,6 +53,7 @@ block07/Makefile block08/Makefile block09/Makefile block10/Makefile +block11/Makefile bspcmdline01/Makefile cpuuse/Makefile devfs01/Makefile -- cgit v1.2.3