source: rtems/testsuites/fstests/fsdosfssync01/init.c @ 3cec2df

5
Last change on this file since 3cec2df was 3cec2df, checked in by Sebastian Huber <sebastian.huber@…>, on 12/17/19 at 08:17:43

config: CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS

Rename CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS into
CONFIGURE_MAXIMUM_FILE_DESCRIPTORS.

Update #3753.

  • Property mode set to 100644
File size: 3.4 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  int disk_fd;
100  int rv;
101
102  disk_fd = open(rda, O_RDWR);
103  rtems_test_assert(disk_fd >= 0);
104
105  rv = msdos_format(rda, &rqdata);
106  rtems_test_assert(rv == 0);
107
108  rv = mount_and_make_target_path(
109    rda,
110    mnt,
111    RTEMS_FILESYSTEM_TYPE_DOSFS,
112    RTEMS_FILESYSTEM_READ_WRITE,
113    NULL
114  );
115  rtems_test_assert(rv == 0);
116
117  create_file(file);
118  rv = rtems_disk_fd_purge(disk_fd);
119  rtems_test_assert(rv == 0);
120
121  write_to_file(file, false);
122  rv = rtems_disk_fd_purge(disk_fd);
123  rtems_test_assert(rv == 0);
124  check_file_size(file, 0);
125
126  write_to_file(file, true);
127  rv = rtems_disk_fd_purge(disk_fd);
128  rtems_test_assert(rv == 0);
129  check_file_size(file, 1);
130
131  rv = unmount(mnt);
132  rtems_test_assert(rv == 0);
133
134  rv = close(disk_fd);
135  rtems_test_assert(rv == 0);
136}
137
138static void Init(rtems_task_argument arg)
139{
140  TEST_BEGIN();
141
142  test("/dev/rda", "/mnt", "/mnt/file");
143
144  TEST_END();
145  rtems_test_exit(0);
146}
147
148rtems_ramdisk_config rtems_ramdisk_configuration [] = {
149  { .block_size = 512, .block_num = 1024 }
150};
151
152size_t rtems_ramdisk_configuration_size = 1;
153
154#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
155#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
156#define CONFIGURE_APPLICATION_EXTRA_DRIVERS RAMDISK_DRIVER_TABLE_ENTRY
157#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
158
159#define CONFIGURE_MAXIMUM_FILE_DESCRIPTORS 6
160
161#define CONFIGURE_FILESYSTEM_DOSFS
162
163#define CONFIGURE_MAXIMUM_TASKS 2
164
165#define CONFIGURE_EXTRA_TASK_STACKS (8 * 1024)
166
167#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
168
169#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
170
171#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
172
173#define CONFIGURE_INIT
174
175#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.