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 <inttypes.h>
0039 #include <stdlib.h>
0040 #include <unistd.h>
0041
0042 #include <rtems/bdbuf.h>
0043
0044 const char rtems_test_name[] = "BLOCK 15";
0045
0046 #define BLOCK_COUNT 20
0047
0048 #define ACTION_COUNT 8
0049
0050 #define REQUEST_COUNT 4
0051
0052 #define WRITE_COUNT 16
0053
0054 #define MAX_WRITE_BLOCKS 3
0055
0056 #define MEDIA_BLOCK_SIZE 2
0057
0058 #define BLOCK_SIZE 4
0059
0060 #define DISK_PATH "/disk"
0061
0062 static const rtems_blkdev_bnum action_sequence [ACTION_COUNT] = {
0063 2, 1, 0, 4, 5, 6, 7, 9
0064 };
0065
0066 static size_t request_index;
0067
0068 static const uint32_t expected_request_bufnums [REQUEST_COUNT] = {
0069 3, 3, 1, 1
0070 };
0071
0072 static size_t write_index;
0073
0074 static const rtems_blkdev_bnum expected_write_blocks [WRITE_COUNT] = {
0075 0, 1, 2, 3, 4, 5, 8, 9, 10, 11, 12, 13, 14, 15, 18, 19
0076 };
0077
0078 static int test_disk_ioctl(rtems_disk_device *dd, uint32_t req, void *arg)
0079 {
0080 int rv = 0;
0081
0082 if (req == RTEMS_BLKIO_REQUEST) {
0083 rtems_blkdev_request *breq = arg;
0084 uint32_t i;
0085
0086 printf("REQ %" PRIu32 "\n", breq->bufnum);
0087
0088 rtems_test_assert(breq->req == RTEMS_BLKDEV_REQ_WRITE);
0089 rtems_test_assert(breq->bufnum == expected_request_bufnums [request_index]);
0090 ++request_index;
0091
0092 for (i = 0; i < breq->bufnum; ++i) {
0093 rtems_blkdev_sg_buffer *sg = &breq->bufs [i];
0094 rtems_blkdev_bnum j;
0095
0096 printf("W %" PRIu32 "\n", sg->block);
0097
0098 rtems_test_assert(sg->block < BLOCK_COUNT);
0099 rtems_test_assert(sg->length == BLOCK_SIZE);
0100
0101 for (j = 0; j < BLOCK_SIZE / MEDIA_BLOCK_SIZE; ++j) {
0102 rtems_test_assert(expected_write_blocks [write_index] == sg->block + j);
0103 ++write_index;
0104 }
0105 }
0106
0107 rtems_blkdev_request_done(breq, RTEMS_SUCCESSFUL);
0108 } else if (req == RTEMS_BLKIO_CAPABILITIES) {
0109 *(uint32_t *) arg = RTEMS_BLKDEV_CAP_MULTISECTOR_CONT;
0110 } else {
0111 rv = rtems_blkdev_ioctl(dd, req, arg);
0112 }
0113
0114 return rv;
0115 }
0116
0117 static void test_write_requests(rtems_disk_device *dd)
0118 {
0119 rtems_status_code sc;
0120 int i;
0121
0122 sc = rtems_bdbuf_set_block_size(dd, BLOCK_SIZE, true);
0123 rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0124
0125 for (i = 0; i < ACTION_COUNT; ++i) {
0126 rtems_blkdev_bnum block = action_sequence [i];
0127 rtems_bdbuf_buffer *bd;
0128
0129 sc = rtems_bdbuf_get(dd, block, &bd);
0130 rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0131
0132 sc = rtems_bdbuf_release_modified(bd);
0133 rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0134 }
0135
0136 sc = rtems_bdbuf_syncdev(dd);
0137 rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0138
0139 rtems_test_assert(request_index == REQUEST_COUNT);
0140 rtems_test_assert(write_index == WRITE_COUNT);
0141 }
0142
0143 static void test(void)
0144 {
0145 rtems_status_code sc;
0146 rtems_disk_device *dd;
0147 int fd;
0148 int rv;
0149
0150 sc = rtems_blkdev_create(
0151 DISK_PATH,
0152 MEDIA_BLOCK_SIZE,
0153 BLOCK_COUNT,
0154 test_disk_ioctl,
0155 NULL
0156 );
0157 rtems_test_assert(sc == RTEMS_SUCCESSFUL);
0158
0159 fd = open(DISK_PATH, O_RDWR);
0160 rtems_test_assert(fd >= 0);
0161
0162 rv = rtems_disk_fd_get_disk_device(fd, &dd);
0163 rtems_test_assert(rv == 0);
0164
0165 rv = close(fd);
0166 rtems_test_assert(rv == 0);
0167
0168 test_write_requests(dd);
0169
0170 rv = unlink(DISK_PATH);
0171 rtems_test_assert(rv == 0);
0172 }
0173
0174 static void Init(rtems_task_argument arg)
0175 {
0176 TEST_BEGIN();
0177
0178 test();
0179
0180 TEST_END();
0181
0182 rtems_test_exit(0);
0183 }
0184
0185 #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
0186 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0187 #define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
0188
0189 #define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 4
0190
0191 #define CONFIGURE_BDBUF_BUFFER_MIN_SIZE 1
0192 #define CONFIGURE_BDBUF_BUFFER_MAX_SIZE 4
0193 #define CONFIGURE_BDBUF_CACHE_MEMORY_SIZE (BLOCK_COUNT * BLOCK_SIZE)
0194 #define CONFIGURE_BDBUF_MAX_WRITE_BLOCKS MAX_WRITE_BLOCKS
0195
0196 #define CONFIGURE_MAXIMUM_TASKS 1
0197
0198 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0199
0200 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0201
0202 #define CONFIGURE_INIT
0203
0204 #include <rtems/confdefs.h>