[113944fa] | 1 | /* |
---|
| 2 | * Copyright (c) 2012 embedded brains GmbH. All rights reserved. |
---|
| 3 | * |
---|
| 4 | * embedded brains GmbH |
---|
| 5 | * Obere Lagerstr. 30 |
---|
| 6 | * 82178 Puchheim |
---|
| 7 | * Germany |
---|
| 8 | * <rtems@embedded-brains.de> |
---|
| 9 | * |
---|
| 10 | * The license and distribution terms for this file may be |
---|
| 11 | * found in the file LICENSE in this distribution or at |
---|
| 12 | * http://www.rtems.com/license/LICENSE. |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | #ifdef HAVE_CONFIG_H |
---|
| 16 | #include "config.h" |
---|
| 17 | #endif |
---|
| 18 | |
---|
| 19 | #include "tmacros.h" |
---|
| 20 | |
---|
| 21 | #include <sys/stat.h> |
---|
| 22 | #include <fcntl.h> |
---|
| 23 | |
---|
| 24 | #include <rtems/bdpart.h> |
---|
| 25 | #include <rtems/blkdev.h> |
---|
| 26 | #include <rtems/ide_part_table.h> |
---|
| 27 | #include <rtems/ramdisk.h> |
---|
[72c6861] | 28 | #include <rtems/libcsupport.h> |
---|
[113944fa] | 29 | |
---|
[bc75887] | 30 | const char rtems_test_name[] = "FSBDPART 1"; |
---|
| 31 | |
---|
[113944fa] | 32 | #define ASSERT_SC(sc) rtems_test_assert((sc) == RTEMS_SUCCESSFUL) |
---|
| 33 | |
---|
| 34 | #define PARTITION_COUNT 9 |
---|
| 35 | |
---|
| 36 | static const char rda [] = "/dev/rda"; |
---|
| 37 | |
---|
| 38 | static const char *const bdpart_rdax [PARTITION_COUNT] = { |
---|
| 39 | "/dev/rda1", |
---|
| 40 | "/dev/rda2", |
---|
| 41 | "/dev/rda3", |
---|
| 42 | "/dev/rda4", |
---|
| 43 | "/dev/rda5", |
---|
| 44 | "/dev/rda6", |
---|
| 45 | "/dev/rda7", |
---|
| 46 | "/dev/rda8", |
---|
| 47 | "/dev/rda9" |
---|
| 48 | }; |
---|
| 49 | |
---|
| 50 | static const char *const ide_part_table_rdax [PARTITION_COUNT] = { |
---|
| 51 | "/dev/rda1", |
---|
| 52 | "/dev/rda2", |
---|
| 53 | "/dev/rda3", |
---|
| 54 | "/dev/rda5", |
---|
| 55 | "/dev/rda6", |
---|
| 56 | "/dev/rda7", |
---|
| 57 | "/dev/rda8", |
---|
| 58 | "/dev/rda9", |
---|
| 59 | "/dev/rda10" |
---|
| 60 | }; |
---|
| 61 | |
---|
| 62 | static const rtems_blkdev_bnum starts [PARTITION_COUNT] = { |
---|
| 63 | 63, 126, 189, 315, 441, 567, 693, 819, 945 |
---|
| 64 | }; |
---|
| 65 | |
---|
| 66 | static const rtems_bdpart_format format = { |
---|
| 67 | .mbr = { |
---|
| 68 | .type = RTEMS_BDPART_FORMAT_MBR, |
---|
| 69 | .disk_id = 0xdeadbeef, |
---|
| 70 | .dos_compatibility = true |
---|
| 71 | } |
---|
| 72 | }; |
---|
| 73 | |
---|
| 74 | static const unsigned distribution [PARTITION_COUNT] = { |
---|
| 75 | 1, 1, 1, 1, 1, 1, 1, 1, 1 |
---|
| 76 | }; |
---|
| 77 | |
---|
| 78 | static void test_logical_disks(const char *const *rdax, bool exists) |
---|
| 79 | { |
---|
| 80 | size_t i = 0; |
---|
| 81 | |
---|
| 82 | for (i = 0; i < PARTITION_COUNT; ++i) { |
---|
| 83 | int fd = open(rdax [i], O_RDONLY); |
---|
| 84 | |
---|
| 85 | if (exists) { |
---|
[40284de] | 86 | rtems_disk_device *dd = NULL; |
---|
[113944fa] | 87 | int rv = 0; |
---|
| 88 | |
---|
| 89 | rtems_test_assert(fd >= 0); |
---|
| 90 | |
---|
| 91 | rv = rtems_disk_fd_get_disk_device(fd, &dd); |
---|
| 92 | rtems_test_assert(rv == 0); |
---|
| 93 | |
---|
| 94 | rtems_test_assert(dd->start == starts [i]); |
---|
| 95 | rtems_test_assert(dd->size == 63); |
---|
| 96 | |
---|
| 97 | rv = close(fd); |
---|
| 98 | rtems_test_assert(rv == 0); |
---|
| 99 | } else { |
---|
| 100 | rtems_test_assert(fd == -1); |
---|
| 101 | } |
---|
| 102 | } |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | static void test_bdpart(void) |
---|
| 106 | { |
---|
| 107 | rtems_status_code sc = RTEMS_SUCCESSFUL; |
---|
| 108 | rtems_bdpart_partition created_partitions [PARTITION_COUNT]; |
---|
| 109 | rtems_bdpart_format actual_format; |
---|
| 110 | rtems_bdpart_partition actual_partitions [PARTITION_COUNT]; |
---|
[72c6861] | 111 | rtems_resource_snapshot before; |
---|
[113944fa] | 112 | size_t actual_count = PARTITION_COUNT; |
---|
| 113 | size_t i = 0; |
---|
| 114 | |
---|
| 115 | memset(&created_partitions [0], 0, sizeof(created_partitions)); |
---|
| 116 | memset(&actual_format, 0, sizeof(actual_format)); |
---|
| 117 | memset(&actual_partitions [0], 0, sizeof(actual_partitions)); |
---|
| 118 | |
---|
[72c6861] | 119 | rtems_resource_snapshot_take(&before); |
---|
| 120 | |
---|
[113944fa] | 121 | for (i = 0; i < PARTITION_COUNT; ++i) { |
---|
| 122 | rtems_bdpart_to_partition_type( |
---|
| 123 | RTEMS_BDPART_MBR_FAT_32, |
---|
| 124 | created_partitions [i].type |
---|
| 125 | ); |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | sc = rtems_bdpart_create( |
---|
| 129 | rda, |
---|
| 130 | &format, |
---|
| 131 | &created_partitions [0], |
---|
| 132 | &distribution [0], |
---|
| 133 | PARTITION_COUNT |
---|
| 134 | ); |
---|
| 135 | ASSERT_SC(sc); |
---|
| 136 | |
---|
| 137 | sc = rtems_bdpart_write( |
---|
| 138 | rda, |
---|
| 139 | &format, |
---|
| 140 | &created_partitions [0], |
---|
| 141 | PARTITION_COUNT |
---|
| 142 | ); |
---|
| 143 | ASSERT_SC(sc); |
---|
| 144 | |
---|
| 145 | sc = rtems_bdpart_read( |
---|
| 146 | rda, |
---|
| 147 | &actual_format, |
---|
| 148 | &actual_partitions [0], |
---|
| 149 | &actual_count |
---|
| 150 | ); |
---|
| 151 | ASSERT_SC(sc); |
---|
| 152 | rtems_test_assert(actual_format.mbr.disk_id == format.mbr.disk_id); |
---|
| 153 | rtems_test_assert( |
---|
| 154 | memcmp( |
---|
| 155 | &actual_partitions [0], |
---|
| 156 | &created_partitions [0], |
---|
| 157 | PARTITION_COUNT |
---|
| 158 | ) == 0 |
---|
| 159 | ); |
---|
| 160 | |
---|
| 161 | sc = rtems_bdpart_register( |
---|
| 162 | rda, |
---|
| 163 | actual_partitions, |
---|
| 164 | actual_count |
---|
| 165 | ); |
---|
| 166 | ASSERT_SC(sc); |
---|
| 167 | test_logical_disks(&bdpart_rdax [0], true); |
---|
| 168 | |
---|
| 169 | sc = rtems_bdpart_unregister( |
---|
| 170 | rda, |
---|
| 171 | actual_partitions, |
---|
| 172 | actual_count |
---|
| 173 | ); |
---|
| 174 | ASSERT_SC(sc); |
---|
| 175 | test_logical_disks(&bdpart_rdax [0], false); |
---|
| 176 | |
---|
[72c6861] | 177 | rtems_test_assert(rtems_resource_snapshot_check(&before)); |
---|
| 178 | |
---|
[113944fa] | 179 | sc = rtems_bdpart_register_from_disk(rda); |
---|
| 180 | ASSERT_SC(sc); |
---|
| 181 | test_logical_disks(&bdpart_rdax [0], true); |
---|
| 182 | |
---|
| 183 | sc = rtems_bdpart_unregister( |
---|
| 184 | rda, |
---|
| 185 | actual_partitions, |
---|
| 186 | actual_count |
---|
| 187 | ); |
---|
| 188 | ASSERT_SC(sc); |
---|
| 189 | test_logical_disks(&bdpart_rdax [0], false); |
---|
| 190 | |
---|
[72c6861] | 191 | rtems_test_assert(rtems_resource_snapshot_check(&before)); |
---|
| 192 | |
---|
[113944fa] | 193 | rtems_bdpart_dump(&actual_partitions [0], actual_count); |
---|
| 194 | } |
---|
| 195 | |
---|
| 196 | static void test_ide_part_table(void) |
---|
| 197 | { |
---|
| 198 | rtems_status_code sc = RTEMS_SUCCESSFUL; |
---|
| 199 | |
---|
| 200 | test_logical_disks(&ide_part_table_rdax [0], false); |
---|
[7b369af] | 201 | #pragma GCC diagnostic push |
---|
| 202 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
---|
[113944fa] | 203 | sc = rtems_ide_part_table_initialize(rda); |
---|
[7b369af] | 204 | #pragma GCC diagnostic pop |
---|
[113944fa] | 205 | ASSERT_SC(sc); |
---|
| 206 | test_logical_disks(&ide_part_table_rdax [0], true); |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | static void Init(rtems_task_argument arg) |
---|
| 210 | { |
---|
[bc75887] | 211 | TEST_BEGIN(); |
---|
[113944fa] | 212 | |
---|
| 213 | test_bdpart(); |
---|
| 214 | test_ide_part_table(); |
---|
| 215 | |
---|
[bc75887] | 216 | TEST_END(); |
---|
[113944fa] | 217 | rtems_test_exit(0); |
---|
| 218 | } |
---|
| 219 | |
---|
| 220 | rtems_ramdisk_config rtems_ramdisk_configuration [] = { |
---|
| 221 | { .block_size = 512, .block_num = 1024 } |
---|
| 222 | }; |
---|
| 223 | |
---|
| 224 | size_t rtems_ramdisk_configuration_size = 1; |
---|
| 225 | |
---|
| 226 | #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER |
---|
| 227 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
| 228 | #define CONFIGURE_APPLICATION_EXTRA_DRIVERS RAMDISK_DRIVER_TABLE_ENTRY |
---|
| 229 | #define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK |
---|
| 230 | |
---|
[72c6861] | 231 | #define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 13 |
---|
[113944fa] | 232 | |
---|
| 233 | #define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM |
---|
| 234 | |
---|
| 235 | #define CONFIGURE_MAXIMUM_TASKS 2 |
---|
| 236 | |
---|
[72c6861] | 237 | #define CONFIGURE_INIT_TASK_STACK_SIZE (32 * 1024) |
---|
[113944fa] | 238 | |
---|
[bc75887] | 239 | #define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION |
---|
| 240 | |
---|
[113944fa] | 241 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
| 242 | |
---|
| 243 | #define CONFIGURE_INIT |
---|
| 244 | |
---|
| 245 | #include <rtems/confdefs.h> |
---|