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

5
Last change on this file since c4b8b147 was c4b8b147, checked in by Sebastian Huber <sebastian.huber@…>, on 11/03/17 at 07:35:38

tests: Use simple console driver

Update #3170.
Update #3199.

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