[PATCH 10/21] libtests/block10: Use rtems_blkdev_create()

Sebastian Huber sebastian.huber at embedded-brains.de
Mon Aug 6 07:14:42 UTC 2018


Update #3358.
---
 testsuites/libtests/block10/init.c | 69 ++++++++++++++++----------------------
 1 file changed, 28 insertions(+), 41 deletions(-)

diff --git a/testsuites/libtests/block10/init.c b/testsuites/libtests/block10/init.c
index 27c0bb5478..d5ac44ad53 100644
--- a/testsuites/libtests/block10/init.c
+++ b/testsuites/libtests/block10/init.c
@@ -7,12 +7,13 @@
  */
 
 /*
- * Copyright (c) 2010
- * embedded brains GmbH
- * Obere Lagerstr. 30
- * D-82178 Puchheim
- * Germany
- * <rtems at embedded-brains.de>
+ * Copyright (c) 2010, 2018 embedded brains GmbH.
+ *
+ *   embedded brains GmbH
+ *   Dornierstr. 4
+ *   D-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
@@ -25,22 +26,19 @@
 
 #include "tmacros.h"
 
+#include <sys/stat.h>
 #include <assert.h>
 #include <errno.h>
+#include <fcntl.h>
 #include <stdlib.h>
+#include <unistd.h>
 
 #include <rtems.h>
 #include <rtems/bdbuf.h>
-#include <rtems/diskdevs.h>
 #include <rtems/test.h>
 
-#include <bsp.h>
-
 const char rtems_test_name[] = "BLOCK 10";
 
-/* forward declarations to avoid warnings */
-static rtems_task Init(rtems_task_argument argument);
-
 #define ASSERT_SC(sc) assert((sc) == RTEMS_SUCCESSFUL)
 
 #define PRIORITY_HIGH 1
@@ -59,6 +57,8 @@ static rtems_task Init(rtems_task_argument argument);
 
 #define BLOCK_COUNT 1
 
+#define DISK_PATH "/disk"
+
 typedef rtems_bdbuf_buffer *(*access_func)(char task);
 
 typedef void (*release_func)(char task, rtems_bdbuf_buffer *bd);
@@ -71,11 +71,6 @@ static rtems_id task_id_purger;
 
 static rtems_id task_id_waiter;
 
-static const rtems_driver_address_table disk_ops = {
-  .initialization_entry = NULL,
-  RTEMS_GENERIC_BLOCK_DEVICE_DRIVER_ENTRIES
-};
-
 static void set_task_prio(rtems_id task, rtems_task_priority prio)
 {
   rtems_status_code sc = RTEMS_SUCCESSFUL;
@@ -121,34 +116,33 @@ static int disk_ioctl(rtems_disk_device *dd, uint32_t req, void *arg)
   }
 }
 
-static rtems_status_code disk_register(
+static void disk_register(
   uint32_t block_size,
   rtems_blkdev_bnum block_count,
-  dev_t *dev_ptr
+  rtems_disk_device **dd
 )
 {
   rtems_status_code sc = RTEMS_SUCCESSFUL;
-  rtems_device_major_number major = 0;
-  dev_t dev = 0;
-
-  sc = rtems_io_register_driver(0, &disk_ops, &major);
-  ASSERT_SC(sc);
+  int fd;
+  int rv;
 
-  dev = rtems_filesystem_make_dev_t(major, 0);
-
-  sc = rtems_disk_create_phys(
-    dev,
+  sc = rtems_blkdev_create(
+    DISK_PATH,
     block_size,
     block_count,
     disk_ioctl,
-    NULL,
     NULL
   );
   ASSERT_SC(sc);
 
-  *dev_ptr = dev;
+  fd = open(DISK_PATH, O_RDWR);
+  rtems_test_assert(fd >= 0);
+
+  rv = rtems_disk_fd_get_disk_device(fd, dd);
+  rtems_test_assert(rv == 0);
 
-  return RTEMS_SUCCESSFUL;
+  rv = close(fd);
+  rtems_test_assert(rv == 0);
 }
 
 static rtems_bdbuf_buffer *do_get(char task)
@@ -398,7 +392,6 @@ static const char *purger_assoc_table [PURGER_COUNT] = {
 static rtems_task Init(rtems_task_argument argument)
 {
   rtems_status_code sc = RTEMS_SUCCESSFUL;
-  dev_t dev = 0;
   size_t i_w = 0;
   size_t i_ac = 0;
   size_t i_rel = 0;
@@ -408,14 +401,7 @@ static rtems_task Init(rtems_task_argument argument)
 
   task_id_init = rtems_task_self();
 
-  sc = rtems_disk_io_initialize();
-  ASSERT_SC(sc);
-
-  sc = disk_register(BLOCK_SIZE, BLOCK_COUNT, &dev);
-  ASSERT_SC(sc);
-
-  dd = rtems_disk_obtain(dev);
-  assert(dd != NULL);
+  disk_register(BLOCK_SIZE, BLOCK_COUNT, &dd);
 
   sc = rtems_task_create(
     rtems_build_name('P', 'U', 'R', 'G'),
@@ -479,8 +465,9 @@ static rtems_task Init(rtems_task_argument argument)
 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
 #define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
 
+#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4
+
 #define CONFIGURE_MAXIMUM_TASKS 3
-#define CONFIGURE_MAXIMUM_DRIVERS 4
 
 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
 
-- 
2.13.7




More information about the devel mailing list