source: rtems/testsuites/fstests/fsdosfssync01/init.c @ 98c6d50

5
Last change on this file since 98c6d50 was 98c6d50, checked in by Chris Johns <chrisj@…>, on 10/19/17 at 05:39:16

testsuite: Use printk for all test output where possible.

  • Remove the printf support leaving the direct printk support configured with TESTS_USE_PRINTK and all other output goes via a buffered vsniprintf call to printk.
  • Control the test's single init for functions and global data with TEST_INIT and not CONFIGURE_INIT. They are now separate.

Updates #3170.

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