source: rtems/testsuites/fstests/fsrofs01/init.c @ 258bda3

Last change on this file since 258bda3 was 258bda3, checked in by Chris Johns <chrisj@…>, on Apr 3, 2017 at 10:11:24 PM

testsuite: Add a common test configuration. Fix configure.ac and Makefile.am errors.

  • Add a top level test configuration file for test states that are common to all BSPs. This saves adding a test configuration (tcfg) file for every BSP.
  • Add the test states 'user-input' and 'benchmark'. This lets 'rtems-test' stop the test rather than waiting for a timeout or letting a benchmark run without the user asking for it to run.
  • Implement rtems-test-check in Python to make it faster. The shell script had grown to a point it was noticably slowing the build down.
  • Fix the configure.ac and Makefile.am files for a number of the test directories. The files are difficiult to keep in sync with the number of tests and mistakes can happen such as tests being left out of the build. The test fsrofs01 is an example. Also a there was a mix of SUBDIRS and _SUBDIRS being used and only _SUBDIRS should be used.
  • Fix the test fsrofs01 so it compiles.

Closes #2963.

  • Property mode set to 100644
File size: 3.9 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 <fcntl.h>
23#include <errno.h>
24#include <unistd.h>
25#include <stdio.h>
26
27#include <rtems/libio.h>
28#include <rtems/rtems-rfs-format.h>
29#include <rtems/ramdisk.h>
30
31const char rtems_test_name[] = "FSROFS 1";
32
33static const rtems_rfs_format_config rfs_config;
34
35static const char rda [] = "/dev/rda";
36
37static const char mnt [] = "/mnt";
38
39static const char file [] = "/mnt/file";
40
41static const char not_exist [] = "/mnt/not_exist";
42
43static void test_mount(bool writeable)
44{
45  int rv;
46  const void *data = NULL;
47
48  rv = mount(
49    rda,
50    mnt,
51    RTEMS_FILESYSTEM_TYPE_RFS,
52    writeable ? RTEMS_FILESYSTEM_READ_WRITE : 0,
53    data
54  );
55  rtems_test_assert(rv == 0);
56}
57
58static void test_create_file_system(void)
59{
60  int rv;
61
62  rv = mkdir(mnt, S_IRWXU | S_IRWXG | S_IRWXO);
63  rtems_test_assert(rv == 0);
64
65  rv = rtems_rfs_format(rda, &rfs_config);
66  rtems_test_assert(rv == 0);
67
68  test_mount(true);
69
70  rv = mknod(file, S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO, 0);
71  rtems_test_assert(rv == 0);
72
73  rv = unmount(mnt);
74  rtems_test_assert(rv == 0);
75}
76
77static void test_rofs(void)
78{
79  int rv;
80  int fd;
81  char buf [1];
82  ssize_t n;
83
84  test_mount(false);
85
86  fd = open(file, O_RDONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
87  rtems_test_assert(fd >= 0);
88
89  n = read(fd, buf, sizeof(buf));
90  rtems_test_assert(n == 0);
91
92  errno = 0;
93  n = write(fd, buf, sizeof(buf));
94  rtems_test_assert(n == -1);
95  rtems_test_assert(errno == EBADF);
96
97  errno = 0;
98  rv = ftruncate(fd, 0);
99  rtems_test_assert(rv == -1);
100  rtems_test_assert(errno == EINVAL);
101
102  errno = 0;
103  rv = fchmod(fd, 0);
104  rtems_test_assert(rv == -1);
105  rtems_test_assert(errno == EROFS);
106
107  errno = 0;
108  rv = fchown(fd, 0, 0);
109  rtems_test_assert(rv == -1);
110  rtems_test_assert(errno == EROFS);
111
112  rv = close(fd);
113  rtems_test_assert(rv == 0);
114
115  errno = 0;
116  fd = open(not_exist, O_RDONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
117  rtems_test_assert(fd == -1);
118  rtems_test_assert(errno == EROFS);
119
120  errno = 0;
121  rv = mknod(not_exist, S_IFREG | S_IRWXU | S_IRWXG | S_IRWXO, 0);
122  rtems_test_assert(rv == -1);
123  rtems_test_assert(errno == EROFS);
124
125  errno = 0;
126  rv = mkdir(not_exist, S_IRWXU | S_IRWXG | S_IRWXO);
127  rtems_test_assert(rv == -1);
128  rtems_test_assert(errno == EROFS);
129
130  errno = 0;
131  rv = rename(file, not_exist);
132  rtems_test_assert(rv == -1);
133  rtems_test_assert(errno == EROFS);
134
135  errno = 0;
136  rv = link(file, not_exist);
137  rtems_test_assert(rv == -1);
138  rtems_test_assert(errno == EROFS);
139
140  errno = 0;
141  rv = unlink(file);
142  rtems_test_assert(rv == -1);
143  rtems_test_assert(errno == EROFS);
144
145  errno = 0;
146  rv = symlink(file, not_exist);
147  rtems_test_assert(rv == -1);
148  rtems_test_assert(errno == EROFS);
149
150  rv = unmount(mnt);
151  rtems_test_assert(rv == 0);
152}
153
154static void Init(rtems_task_argument arg)
155{
156  TEST_BEGIN();
157
158  test_create_file_system();
159  test_rofs();
160
161  TEST_END();
162  rtems_test_exit(0);
163}
164
165rtems_ramdisk_config rtems_ramdisk_configuration [] = {
166  { .block_size = 512, .block_num = 1024 }
167};
168
169size_t rtems_ramdisk_configuration_size = 1;
170
171#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
172#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
173#define CONFIGURE_APPLICATION_EXTRA_DRIVERS RAMDISK_DRIVER_TABLE_ENTRY
174#define CONFIGURE_APPLICATION_NEEDS_LIBBLOCK
175
176#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 5
177
178#define CONFIGURE_FILESYSTEM_RFS
179
180#define CONFIGURE_MAXIMUM_TASKS 2
181
182#define CONFIGURE_EXTRA_TASK_STACKS (8 * 1024)
183
184#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
185
186#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
187
188#define CONFIGURE_INIT
189
190#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.