source: rtems/testsuites/fstests/fsbdpart01/init.c @ 7b369af

4.11
Last change on this file since 7b369af was 7b369af, checked in by Sebastian Huber <sebastian.huber@…>, on Apr 11, 2013 at 11:58:33 AM

testsuites: Fix warnings

  • Property mode set to 100644
File size: 5.2 KB
Line 
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>
28#include <rtems/libcsupport.h>
29
30#define ASSERT_SC(sc) rtems_test_assert((sc) == RTEMS_SUCCESSFUL)
31
32#define PARTITION_COUNT 9
33
34static const char rda [] = "/dev/rda";
35
36static const char *const bdpart_rdax [PARTITION_COUNT] = {
37  "/dev/rda1",
38  "/dev/rda2",
39  "/dev/rda3",
40  "/dev/rda4",
41  "/dev/rda5",
42  "/dev/rda6",
43  "/dev/rda7",
44  "/dev/rda8",
45  "/dev/rda9"
46};
47
48static const char *const ide_part_table_rdax [PARTITION_COUNT] = {
49  "/dev/rda1",
50  "/dev/rda2",
51  "/dev/rda3",
52  "/dev/rda5",
53  "/dev/rda6",
54  "/dev/rda7",
55  "/dev/rda8",
56  "/dev/rda9",
57  "/dev/rda10"
58};
59
60static const rtems_blkdev_bnum starts [PARTITION_COUNT] = {
61  63, 126, 189, 315, 441, 567, 693, 819, 945
62};
63
64static const rtems_bdpart_format format = {
65  .mbr = {
66    .type = RTEMS_BDPART_FORMAT_MBR,
67    .disk_id = 0xdeadbeef,
68    .dos_compatibility = true
69  }
70};
71
72static const unsigned distribution [PARTITION_COUNT] = {
73  1, 1, 1, 1, 1, 1, 1, 1, 1
74};
75
76static void test_logical_disks(const char *const *rdax, bool exists)
77{
78  size_t i = 0;
79
80  for (i = 0; i < PARTITION_COUNT; ++i) {
81    int fd = open(rdax [i], O_RDONLY);
82
83    if (exists) {
84      rtems_disk_device *dd = NULL;
85      int rv = 0;
86
87      rtems_test_assert(fd >= 0);
88
89      rv = rtems_disk_fd_get_disk_device(fd, &dd);
90      rtems_test_assert(rv == 0);
91
92      rtems_test_assert(dd->start == starts [i]);
93      rtems_test_assert(dd->size == 63);
94
95      rv = close(fd);
96      rtems_test_assert(rv == 0);
97    } else {
98      rtems_test_assert(fd == -1);
99    }
100  }
101}
102
103static void test_bdpart(void)
104{
105  rtems_status_code sc = RTEMS_SUCCESSFUL;
106  rtems_bdpart_partition created_partitions [PARTITION_COUNT];
107  rtems_bdpart_format actual_format;
108  rtems_bdpart_partition actual_partitions [PARTITION_COUNT];
109  rtems_resource_snapshot before;
110  size_t actual_count = PARTITION_COUNT;
111  size_t i = 0;
112
113  memset(&created_partitions [0], 0, sizeof(created_partitions));
114  memset(&actual_format, 0, sizeof(actual_format));
115  memset(&actual_partitions [0], 0, sizeof(actual_partitions));
116
117  rtems_resource_snapshot_take(&before);
118
119  for (i = 0; i < PARTITION_COUNT; ++i) {
120    rtems_bdpart_to_partition_type(
121      RTEMS_BDPART_MBR_FAT_32,
122      created_partitions [i].type
123    );
124  }
125
126  sc = rtems_bdpart_create(
127    rda,
128    &format,
129    &created_partitions [0],
130    &distribution [0],
131    PARTITION_COUNT
132  );
133  ASSERT_SC(sc);
134
135  sc = rtems_bdpart_write(
136    rda,
137    &format,
138    &created_partitions [0],
139    PARTITION_COUNT
140  );
141  ASSERT_SC(sc);
142
143  sc = rtems_bdpart_read(
144    rda,
145    &actual_format,
146    &actual_partitions [0],
147    &actual_count
148  );
149  ASSERT_SC(sc);
150  rtems_test_assert(actual_format.mbr.disk_id == format.mbr.disk_id);
151  rtems_test_assert(
152    memcmp(
153      &actual_partitions [0],
154      &created_partitions [0],
155      PARTITION_COUNT
156    ) == 0
157  );
158
159  sc = rtems_bdpart_register(
160    rda,
161    actual_partitions,
162    actual_count
163  );
164  ASSERT_SC(sc);
165  test_logical_disks(&bdpart_rdax [0], true);
166
167  sc = rtems_bdpart_unregister(
168    rda,
169    actual_partitions,
170    actual_count
171  );
172  ASSERT_SC(sc);
173  test_logical_disks(&bdpart_rdax [0], false);
174
175  rtems_test_assert(rtems_resource_snapshot_check(&before));
176
177  sc = rtems_bdpart_register_from_disk(rda);
178  ASSERT_SC(sc);
179  test_logical_disks(&bdpart_rdax [0], true);
180
181  sc = rtems_bdpart_unregister(
182    rda,
183    actual_partitions,
184    actual_count
185  );
186  ASSERT_SC(sc);
187  test_logical_disks(&bdpart_rdax [0], false);
188
189  rtems_test_assert(rtems_resource_snapshot_check(&before));
190
191  rtems_bdpart_dump(&actual_partitions [0], actual_count);
192}
193
194static void test_ide_part_table(void)
195{
196  rtems_status_code sc = RTEMS_SUCCESSFUL;
197
198  test_logical_disks(&ide_part_table_rdax [0], false);
199#pragma GCC diagnostic push
200#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
201  sc = rtems_ide_part_table_initialize(rda);
202#pragma GCC diagnostic pop
203  ASSERT_SC(sc);
204  test_logical_disks(&ide_part_table_rdax [0], true);
205}
206
207static void Init(rtems_task_argument arg)
208{
209  printf("\n\n*** TEST FSBDPART 1 ***\n");
210
211  test_bdpart();
212  test_ide_part_table();
213
214  printf("*** END OF TEST FSBDPART 1 ***\n");
215
216  rtems_test_exit(0);
217}
218
219rtems_ramdisk_config rtems_ramdisk_configuration [] = {
220  { .block_size = 512, .block_num = 1024 }
221};
222
223size_t rtems_ramdisk_configuration_size = 1;
224
225#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
226#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
227#define CONFIGURE_APPLICATION_EXTRA_DRIVERS RAMDISK_DRIVER_TABLE_ENTRY
228#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
229
230#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 13
231
232#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM
233
234#define CONFIGURE_MAXIMUM_TASKS 2
235
236#define CONFIGURE_INIT_TASK_STACK_SIZE (32 * 1024)
237
238#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
239
240#define CONFIGURE_INIT
241
242#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.