source: rtems/testsuites/fstests/fsdosfssync01/init.c @ dd66fda

Last change on this file since dd66fda was dd66fda, checked in by Sebastian Huber <sebastian.huber@…>, on Aug 4, 2018 at 8:47:56 AM

tests: Avoid deprecated rtems_disk_io_initialize()

Update #3358.

  • Property mode set to 100644
File size: 3.5 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.org/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 <errno.h>
23#include <string.h>
24#include <stdint.h>
25#include <unistd.h>
26#include <fcntl.h>
27
28#include <rtems/libio.h>
29#include <rtems/blkdev.h>
30#include <rtems/dosfs.h>
31#include <rtems/ramdisk.h>
32
33const char rtems_test_name[] = "FSDOSFSSYNC 1";
34
35static void create_file(const char *file)
36{
37  int fd;
38  int rv;
39
40  fd = creat(file, S_IRWXU | S_IRWXG | S_IRWXO);
41  rtems_test_assert(fd >= 0);
42
43  rv = fsync(fd);
44  rtems_test_assert(rv == 0);
45
46  rv = close(fd);
47  rtems_test_assert(rv == 0);
48}
49
50static void write_to_file(const char *file, bool sync)
51{
52  int fd;
53  char buf [1];
54  ssize_t n;
55  off_t pos;
56  int rv;
57
58  fd = open(file, O_RDWR);
59  rtems_test_assert(fd >= 0);
60
61  n = write(fd, buf, sizeof(buf));
62  rtems_test_assert(n == (ssize_t) sizeof(buf));
63
64  pos = lseek(fd, 0, SEEK_END);
65  rtems_test_assert(pos == sizeof(buf));
66
67  if (sync) {
68    rv = fsync(fd);
69    rtems_test_assert(rv == 0);
70  }
71
72  rv = close(fd);
73  rtems_test_assert(rv == 0);
74}
75
76static void check_file_size(const char *file, off_t size)
77{
78  int fd;
79  off_t pos;
80  int rv;
81
82  fd = open(file, O_RDWR);
83  rtems_test_assert(fd >= 0);
84
85  pos = lseek(fd, 0, SEEK_END);
86  rtems_test_assert(pos == size);
87
88  rv = close(fd);
89  rtems_test_assert(rv == 0);
90}
91
92static void test(const char *rda, const char *mnt, const char *file)
93{
94  static const msdos_format_request_param_t rqdata = {
95    .quick_format = true,
96    .sync_device = true
97  };
98
99  rtems_status_code sc;
100  int disk_fd;
101  int rv;
102
103  disk_fd = open(rda, O_RDWR);
104  rtems_test_assert(disk_fd >= 0);
105
106  rv = msdos_format(rda, &rqdata);
107  rtems_test_assert(rv == 0);
108
109  rv = mount_and_make_target_path(
110    rda,
111    mnt,
112    RTEMS_FILESYSTEM_TYPE_DOSFS,
113    RTEMS_FILESYSTEM_READ_WRITE,
114    NULL
115  );
116  rtems_test_assert(rv == 0);
117
118  create_file(file);
119  rv = rtems_disk_fd_purge(disk_fd);
120  rtems_test_assert(rv == 0);
121
122  write_to_file(file, false);
123  rv = rtems_disk_fd_purge(disk_fd);
124  rtems_test_assert(rv == 0);
125  check_file_size(file, 0);
126
127  write_to_file(file, true);
128  rv = rtems_disk_fd_purge(disk_fd);
129  rtems_test_assert(rv == 0);
130  check_file_size(file, 1);
131
132  rv = unmount(mnt);
133  rtems_test_assert(rv == 0);
134
135  rv = close(disk_fd);
136  rtems_test_assert(rv == 0);
137}
138
139static void Init(rtems_task_argument arg)
140{
141  TEST_BEGIN();
142
143  test("/dev/rda", "/mnt", "/mnt/file");
144
145  TEST_END();
146  rtems_test_exit(0);
147}
148
149rtems_ramdisk_config rtems_ramdisk_configuration [] = {
150  { .block_size = 512, .block_num = 1024 }
151};
152
153size_t rtems_ramdisk_configuration_size = 1;
154
155#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
156#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
157#define CONFIGURE_APPLICATION_EXTRA_DRIVERS RAMDISK_DRIVER_TABLE_ENTRY
158#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
159
160#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 6
161
162#define CONFIGURE_FILESYSTEM_DOSFS
163
164#define CONFIGURE_MAXIMUM_TASKS 2
165
166#define CONFIGURE_EXTRA_TASK_STACKS (8 * 1024)
167
168#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
169
170#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
171
172#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
173
174#define CONFIGURE_INIT
175
176#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.