File indexing completed on 2025-05-11 08:24:32
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 #ifdef HAVE_CONFIG_H
0029 #include "config.h"
0030 #endif
0031
0032 #include "tmacros.h"
0033
0034 #include <sys/stat.h>
0035 #include <assert.h>
0036 #include <errno.h>
0037 #include <fcntl.h>
0038 #include <string.h>
0039 #include <unistd.h>
0040
0041 #include <rtems/blkdev.h>
0042 #include <rtems/bdbuf.h>
0043
0044 const char rtems_test_name[] = "BLOCK 12";
0045
0046 #define BLOCK_COUNT 15
0047
0048 #define DISK_PATH "/disk"
0049
0050 static int block_access_counts [BLOCK_COUNT];
0051
0052 static int expected_block_access_counts [BLOCK_COUNT] = {
0053 2, 0, 2, 0, 2, 0, 2, 2, 2, 0, 2, 0, 2, 0, 2
0054 };
0055
0056 static const rtems_blkdev_bnum read_sequence [] = {
0057 0, 2, 4, 6, 8, 10, 12, 14, 7
0058 };
0059
0060 static int test_disk_ioctl(rtems_disk_device *dd, uint32_t req, void *arg)
0061 {
0062 int rv = 0;
0063
0064 if (req == RTEMS_BLKIO_REQUEST) {
0065 rtems_blkdev_request *breq = arg;
0066 rtems_blkdev_sg_buffer *sg = breq->bufs;
0067 uint32_t i;
0068
0069 rtems_test_assert(breq->req == RTEMS_BLKDEV_REQ_READ);
0070
0071 for (i = 0; i < breq->bufnum; ++i) {
0072 rtems_blkdev_bnum block = sg [i].block;
0073
0074 rtems_test_assert(block < BLOCK_COUNT);
0075
0076 ++block_access_counts [block];
0077 }
0078
0079 rtems_blkdev_request_done(breq, RTEMS_SUCCESSFUL);
0080 } else {
0081 rv = rtems_blkdev_ioctl(dd, req, arg);
0082 }
0083
0084 return rv;
0085 }
0086
0087 static void do_read_sequence(rtems_disk_device *dd)
0088 {
0089 size_t i;
0090
0091 for (i = 0; i < sizeof(read_sequence) / sizeof(read_sequence [0]); ++i) {
0092 rtems_status_code sc;
0093 rtems_bdbuf_buffer *bd;
0094
0095 sc = rtems_bdbuf_read(dd, read_sequence [i], &bd);
0096 rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0097
0098 sc = rtems_bdbuf_release(bd);
0099 rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0100 }
0101 }
0102
0103 static void test(void)
0104 {
0105 rtems_status_code sc;
0106 int fd;
0107 int rv;
0108 rtems_disk_device *dd;
0109
0110 sc = rtems_blkdev_create(
0111 DISK_PATH,
0112 1,
0113 BLOCK_COUNT,
0114 test_disk_ioctl,
0115 NULL
0116 );
0117 rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0118
0119 fd = open(DISK_PATH, O_RDWR);
0120 rtems_test_assert(fd >= 0);
0121
0122 rv = rtems_disk_fd_get_disk_device(fd, &dd);
0123 rtems_test_assert(rv == 0);
0124
0125 rv = close(fd);
0126 rtems_test_assert(rv == 0);
0127
0128 do_read_sequence(dd);
0129 rtems_bdbuf_purge_dev(dd);
0130 do_read_sequence(dd);
0131
0132 rtems_test_assert(
0133 memcmp(
0134 block_access_counts,
0135 expected_block_access_counts,
0136 sizeof(block_access_counts)
0137 ) == 0
0138 );
0139
0140 rv = unlink(DISK_PATH);
0141 rtems_test_assert(rv == 0);
0142 }
0143
0144 static void Init(rtems_task_argument arg)
0145 {
0146 TEST_BEGIN();
0147
0148 test();
0149
0150 TEST_END();
0151
0152 rtems_test_exit(0);
0153 }
0154
0155 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0156 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0157 #define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
0158
0159 #define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 4
0160
0161 #define CONFIGURE_BDBUF_BUFFER_MIN_SIZE 1
0162 #define CONFIGURE_BDBUF_BUFFER_MAX_SIZE 1
0163 #define CONFIGURE_BDBUF_CACHE_MEMORY_SIZE BLOCK_COUNT
0164
0165 #define CONFIGURE_MAXIMUM_TASKS 1
0166
0167 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0168
0169 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0170
0171 #define CONFIGURE_INIT
0172
0173 #include <rtems/confdefs.h>