source: rtems/testsuites/fstests/jffs2_support/fs_support.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.4 KB
Line 
1/*
2 * Copyright (c) 2013 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <info@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#include "pmacros.h"
19
20#include <sys/stat.h>
21#include <sys/types.h>
22#include <string.h>
23
24#include <rtems/jffs2.h>
25#include <rtems/libio.h>
26#include <rtems/libcsupport.h>
27
28#include "fstest.h"
29#include "fstest_support.h"
30
31#define BLOCK_SIZE (16UL * 1024UL)
32
33#define FLASH_SIZE (8UL * BLOCK_SIZE)
34
35typedef struct {
36  rtems_jffs2_flash_control super;
37  unsigned char area[FLASH_SIZE];
38} flash_control;
39
40static flash_control *get_flash_control(rtems_jffs2_flash_control *super)
41{
42  return (flash_control *) super;
43}
44
45static int flash_read(
46  rtems_jffs2_flash_control *super,
47  uint32_t offset,
48  unsigned char *buffer,
49  size_t size_of_buffer
50)
51{
52  flash_control *self = get_flash_control(super);
53  unsigned char *chunk = &self->area[offset];
54
55  memcpy(buffer, chunk, size_of_buffer);
56
57  return 0;
58}
59
60static int flash_write(
61  rtems_jffs2_flash_control *super,
62  uint32_t offset,
63  const unsigned char *buffer,
64  size_t size_of_buffer
65)
66{
67  flash_control *self = get_flash_control(super);
68  unsigned char *chunk = &self->area[offset];
69  size_t i;
70
71  for (i = 0; i < size_of_buffer; ++i) {
72    chunk[i] &= buffer[i];
73  }
74
75  return 0;
76}
77
78static int flash_erase(
79  rtems_jffs2_flash_control *super,
80  uint32_t offset
81)
82{
83  flash_control *self = get_flash_control(super);
84  unsigned char *chunk = &self->area[offset];
85
86  memset(chunk, 0xff, BLOCK_SIZE);
87
88  return 0;
89}
90
91static flash_control flash_instance = {
92  .super = {
93    .block_size = BLOCK_SIZE,
94    .flash_size = FLASH_SIZE,
95    .read = flash_read,
96    .write = flash_write,
97    .erase = flash_erase
98  }
99};
100
101static rtems_jffs2_compressor_control compressor_instance = {
102  .compress = rtems_jffs2_compressor_rtime_compress,
103  .decompress = rtems_jffs2_compressor_rtime_decompress
104};
105
106static const rtems_jffs2_mount_data mount_data = {
107  .flash_control = &flash_instance.super,
108  .compressor_control = &compressor_instance
109};
110
111static void erase_all(void)
112{
113  memset(&flash_instance.area[0], 0xff, FLASH_SIZE);
114}
115
116static rtems_resource_snapshot before_mount;
117
118void test_initialize_filesystem(void)
119{
120  int rv;
121
122  erase_all();
123
124  rv = mkdir(BASE_FOR_TEST, S_IRWXU | S_IRWXG | S_IRWXO);
125  rtems_test_assert(rv == 0);
126
127  rtems_resource_snapshot_take(&before_mount);
128
129  rv = mount(
130    NULL,
131    BASE_FOR_TEST,
132    RTEMS_FILESYSTEM_TYPE_JFFS2,
133    RTEMS_FILESYSTEM_READ_WRITE,
134    &mount_data
135  );
136  rtems_test_assert(rv == 0);
137}
138
139void test_shutdown_filesystem(void)
140{
141  int rv = unmount(BASE_FOR_TEST);
142  rtems_test_assert(rv == 0);
143  rtems_test_assert(rtems_resource_snapshot_check(&before_mount));
144}
145
146#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
147#define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER
148
149#define CONFIGURE_FILESYSTEM_JFFS2
150
151#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 40
152
153#define CONFIGURE_MAXIMUM_TASKS 1
154
155#define CONFIGURE_INIT_TASK_STACK_SIZE (32 * 1024)
156#define CONFIGURE_INIT_TASK_ATTRIBUTES RTEMS_FLOATING_POINT
157
158#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
159
160#define CONFIGURE_MAXIMUM_POSIX_KEY_VALUE_PAIRS 1
161
162#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
163
164#define CONFIGURE_INIT
165#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.