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
0029
0030
0031
0032
0033
0034
0035
0036 #ifdef HAVE_CONFIG_H
0037 #include "config.h"
0038 #endif
0039
0040 #include <sys/ioctl.h>
0041 #include <sys/types.h>
0042 #include <sys/stat.h>
0043 #include <fcntl.h>
0044 #include <unistd.h>
0045
0046 #include "tmacros.h"
0047
0048 #include <rtems.h>
0049 #include <rtems/ramdisk.h>
0050 #include <rtems/bdbuf.h>
0051
0052 const char rtems_test_name[] = "BLOCK 7";
0053
0054 #define ASSERT_SC(sc) rtems_test_assert((sc) == RTEMS_SUCCESSFUL)
0055
0056 #define PRIORITY_INIT 1
0057
0058 #define PRIORITY_HIGH 2
0059
0060 #define PRIORITY_MID 3
0061
0062 #define PRIORITY_LOW 4
0063
0064 #define PRIORITY_SWAPOUT 5
0065
0066 #define PRIORITY_IDLE 6
0067
0068 #define BLOCK_SIZE_A 1
0069
0070 #define BLOCK_SIZE_B 2
0071
0072 #define BLOCK_COUNT 2
0073
0074 static rtems_disk_device *dd;
0075
0076 static rtems_id task_id_low;
0077
0078 static rtems_id task_id_mid;
0079
0080 static rtems_id task_id_high;
0081
0082 static void change_block_size(void)
0083 {
0084 int rv = 0;
0085 int fd = open("/dev/rda", O_RDWR);
0086
0087 rtems_test_assert(fd >= 0);
0088
0089 rv = rtems_disk_fd_set_block_size(fd, BLOCK_SIZE_B);
0090 rtems_test_assert(rv == 0);
0091
0092 rv = close(fd);
0093 rtems_test_assert(rv == 0);
0094 }
0095
0096 static void task_low(rtems_task_argument arg)
0097 {
0098 rtems_status_code sc = RTEMS_SUCCESSFUL;
0099 rtems_bdbuf_buffer *bd = NULL;
0100
0101 printf("L: try access: 0\n");
0102
0103 sc = rtems_bdbuf_get(dd, 0, &bd);
0104 ASSERT_SC(sc);
0105
0106 printf("L: access: 0\n");
0107
0108 rtems_test_assert(bd->group->bds_per_group == 2);
0109
0110 printf("L: release: 0\n");
0111
0112 sc = rtems_bdbuf_release(bd);
0113 ASSERT_SC(sc);
0114
0115 printf("L: release done: 0\n");
0116
0117 TEST_END();
0118
0119 exit(0);
0120 }
0121
0122 static void task_mid(rtems_task_argument arg)
0123 {
0124 rtems_status_code sc = RTEMS_SUCCESSFUL;
0125 rtems_bdbuf_buffer *bd = NULL;
0126
0127 printf("M: try access: 0\n");
0128
0129 sc = rtems_bdbuf_get(dd, 0, &bd);
0130 ASSERT_SC(sc);
0131
0132 printf("M: access: 0\n");
0133
0134 rtems_test_assert(bd->group->bds_per_group == 1);
0135
0136 printf("M: release: 0\n");
0137
0138 sc = rtems_bdbuf_release(bd);
0139 ASSERT_SC(sc);
0140
0141 printf("M: release done: 0\n");
0142
0143 rtems_task_exit();
0144 }
0145
0146 static void task_high(rtems_task_argument arg)
0147 {
0148 rtems_status_code sc = RTEMS_SUCCESSFUL;
0149 rtems_bdbuf_buffer *bd = NULL;
0150
0151 change_block_size();
0152
0153 printf("H: try access: 0\n");
0154
0155 sc = rtems_bdbuf_get(dd, 0, &bd);
0156 ASSERT_SC(sc);
0157
0158 printf("H: access: 0\n");
0159
0160 rtems_test_assert(bd->group->bds_per_group == 1);
0161
0162 printf("H: release: 0\n");
0163
0164 sc = rtems_bdbuf_release(bd);
0165 ASSERT_SC(sc);
0166
0167 printf("H: release done: 0\n");
0168
0169 rtems_task_exit();
0170 }
0171
0172 static void do_ramdisk_register(
0173 uint32_t media_block_size,
0174 rtems_blkdev_bnum media_block_count,
0175 const char *disk,
0176 rtems_disk_device **dd
0177 )
0178 {
0179 rtems_status_code sc;
0180 int fd;
0181 int rv;
0182
0183 sc = ramdisk_register(media_block_size, media_block_count, false, disk);
0184 ASSERT_SC(sc);
0185
0186 fd = open(disk, O_RDWR);
0187 rtems_test_assert(fd >= 0);
0188
0189 rv = rtems_disk_fd_get_disk_device(fd, dd);
0190 rtems_test_assert(rv == 0);
0191
0192 rv = close(fd);
0193 rtems_test_assert(rv == 0);
0194 }
0195
0196 static rtems_task Init(rtems_task_argument argument)
0197 {
0198 rtems_status_code sc = RTEMS_SUCCESSFUL;
0199 rtems_task_priority cur_prio = 0;
0200 rtems_bdbuf_buffer *bd = NULL;
0201
0202 TEST_BEGIN();
0203
0204 do_ramdisk_register(BLOCK_SIZE_A, BLOCK_COUNT, "/dev/rda", &dd);
0205
0206 sc = rtems_task_create(
0207 rtems_build_name(' ', 'L', 'O', 'W'),
0208 PRIORITY_LOW,
0209 0,
0210 RTEMS_DEFAULT_MODES,
0211 RTEMS_DEFAULT_ATTRIBUTES,
0212 &task_id_low
0213 );
0214 ASSERT_SC(sc);
0215
0216 sc = rtems_task_start(task_id_low, task_low, 0);
0217 ASSERT_SC(sc);
0218
0219 sc = rtems_task_create(
0220 rtems_build_name(' ', 'M', 'I', 'D'),
0221 PRIORITY_MID,
0222 0,
0223 RTEMS_DEFAULT_MODES,
0224 RTEMS_DEFAULT_ATTRIBUTES,
0225 &task_id_mid
0226 );
0227 ASSERT_SC(sc);
0228
0229 sc = rtems_task_start(task_id_mid, task_mid, 0);
0230 ASSERT_SC(sc);
0231
0232 sc = rtems_task_create(
0233 rtems_build_name('H', 'I', 'G', 'H'),
0234 PRIORITY_HIGH,
0235 0,
0236 RTEMS_DEFAULT_MODES,
0237 RTEMS_DEFAULT_ATTRIBUTES,
0238 &task_id_high
0239 );
0240 ASSERT_SC(sc);
0241
0242 sc = rtems_task_start(task_id_high, task_high, 0);
0243 ASSERT_SC(sc);
0244
0245 sc = rtems_task_suspend(task_id_mid);
0246 ASSERT_SC(sc);
0247
0248 sc = rtems_task_suspend(task_id_high);
0249 ASSERT_SC(sc);
0250
0251 sc = rtems_bdbuf_get(dd, 1, &bd);
0252 ASSERT_SC(sc);
0253
0254 sc = rtems_bdbuf_release(bd);
0255 ASSERT_SC(sc);
0256
0257 printf("I: try access: 0\n");
0258
0259 sc = rtems_bdbuf_get(dd, 0, &bd);
0260 ASSERT_SC(sc);
0261
0262 printf("I: access: 0\n");
0263
0264 sc = rtems_task_set_priority(RTEMS_SELF, PRIORITY_IDLE, &cur_prio);
0265 ASSERT_SC(sc);
0266
0267 sc = rtems_task_resume(task_id_high);
0268 ASSERT_SC(sc);
0269
0270 sc = rtems_task_resume(task_id_mid);
0271 ASSERT_SC(sc);
0272
0273 sc = rtems_task_set_priority(RTEMS_SELF, PRIORITY_INIT, &cur_prio);
0274 ASSERT_SC(sc);
0275
0276 printf("I: release: 0\n");
0277
0278 sc = rtems_bdbuf_release(bd);
0279 ASSERT_SC(sc);
0280
0281 printf("I: release done: 0\n");
0282
0283 rtems_task_exit();
0284 }
0285
0286 #define CONFIGURE_INIT
0287
0288 #define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
0289 #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
0290 #define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
0291
0292 #define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 4
0293
0294 #define CONFIGURE_MAXIMUM_TASKS 4
0295
0296 #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
0297
0298 #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
0299
0300 #define CONFIGURE_INIT_TASK_PRIORITY PRIORITY_INIT
0301 #define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_DEFAULT_ATTRIBUTES
0302 #define CONFIGURE_INIT_TASK_INITIAL_MODES RTEMS_DEFAULT_MODES
0303
0304 #define CONFIGURE_SWAPOUT_TASK_PRIORITY PRIORITY_SWAPOUT
0305
0306 #define CONFIGURE_BDBUF_BUFFER_MIN_SIZE BLOCK_SIZE_A
0307 #define CONFIGURE_BDBUF_BUFFER_MAX_SIZE BLOCK_SIZE_B
0308 #define CONFIGURE_BDBUF_CACHE_MEMORY_SIZE (BLOCK_SIZE_A * BLOCK_COUNT)
0309
0310 #include <rtems/confdefs.h>