Skip to content

Commit 9844a39

Browse files
authored
Merge pull request ARMmbed#3762 from simonqhughes/ms_20170213_fs_integration
STORAGE: Merging feature-storage branch commits to master
2 parents 371aaa5 + 794c6f8 commit 9844a39

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2394
-1353
lines changed

drivers/DirHandle.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#ifndef MBED_DIRHANDLE_H
1717
#define MBED_DIRHANDLE_H
1818

19+
#include <stdint.h>
20+
1921
#if defined(__ARMCC_VERSION) || defined(__ICCARM__)
2022
# define NAME_MAX 255
2123
typedef int mode_t;
@@ -28,6 +30,18 @@ typedef int mode_t;
2830

2931
struct dirent {
3032
char d_name[NAME_MAX+1];
33+
uint8_t d_type;
34+
};
35+
36+
enum {
37+
DT_UNKNOWN, // The file type could not be determined.
38+
DT_FIFO, // This is a named pipe (FIFO).
39+
DT_CHR, // This is a character device.
40+
DT_DIR, // This is a directory.
41+
DT_BLK, // This is a block device.
42+
DT_REG, // This is a regular file.
43+
DT_LNK, // This is a symbolic link.
44+
DT_SOCK, // This is a UNIX domain socket.
3145
};
3246

3347
namespace mbed {

drivers/FileSystemLike.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,15 @@ class FileSystemLike : public FileBase {
100100
*/
101101
virtual int mkdir(const char *name, mode_t mode) { (void) name, (void) mode; return -1; }
102102

103-
// TODO other filesystem functions (mkdir, rm, rn, ls etc)
103+
/** Store information about file in stat structure
104+
*
105+
* @param name The name of the file to find information about
106+
* @param st The stat buffer to write to
107+
* @returns
108+
* 0 on success or un-needed,
109+
* -1 on error
110+
*/
111+
virtual int stat(const char *name, struct stat *st) = 0;
104112
};
105113

106114
} // namespace mbed

features/FEATURE_LWIP/lwip-interface/lwip/src/api/lwip_err.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
#include "lwip/def.h"
4141
#include "lwip/sys.h"
4242

43-
#include "lwip/errno.h"
43+
#include "lwip/lwip_errno.h"
4444

4545
#if !NO_SYS
4646
/** Table to quickly map an lwIP error (err_t) to a socket error

features/FEATURE_LWIP/lwip-interface/lwip/src/include/lwip/sockets.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
#include "lwip/ip_addr.h"
4747
#include "lwip/err.h"
4848
#include "lwip/inet.h"
49-
#include "lwip/errno.h"
49+
#include "lwip/lwip_errno.h"
5050

5151
#ifdef __cplusplus
5252
extern "C" {

features/FEATURE_LWIP/lwip-interface/lwip/src/include/posix/errno.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@
3030
*
3131
*/
3232

33-
#include "lwip/errno.h"
33+
#include "lwip/lwip_errno.h"
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2017 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#include "mbed.h"
17+
#include "greentea-client/test_env.h"
18+
#include "unity.h"
19+
#include "utest.h"
20+
21+
#include "HeapBlockDevice.h"
22+
#include <stdlib.h>
23+
24+
using namespace utest::v1;
25+
26+
/* It is not possible to build a KL25Z image with IAR including the file system if
27+
* stack tracking statistics are enabled. If this is the case, build dummy
28+
* tests.
29+
*/
30+
#if ! defined(__ICCARM__) && ! defined(TARGET_KL25Z) && ! defined(MBED_STACK_STATS_ENABLED)
31+
32+
#define BLOCK_SIZE 512
33+
#define HEAP_BLOCK_DEVICE_TEST_01 test_read_write
34+
uint8_t write_block[BLOCK_SIZE];
35+
uint8_t read_block[BLOCK_SIZE];
36+
37+
// Simple test which reads and writes a block
38+
void test_read_write() {
39+
HeapBlockDevice bd(16*BLOCK_SIZE, BLOCK_SIZE);
40+
41+
int err = bd.init();
42+
TEST_ASSERT_EQUAL(0, err);
43+
44+
// Fill with random sequence
45+
srand(1);
46+
for (int i = 0; i < BLOCK_SIZE; i++) {
47+
write_block[i] = 0xff & rand();
48+
}
49+
50+
// Write, sync, and read the block
51+
err = bd.program(write_block, 0, BLOCK_SIZE);
52+
TEST_ASSERT_EQUAL(0, err);
53+
54+
err = bd.read(read_block, 0, BLOCK_SIZE);
55+
TEST_ASSERT_EQUAL(0, err);
56+
57+
// Check that the data was unmodified
58+
srand(1);
59+
for (int i = 0; i < BLOCK_SIZE; i++) {
60+
TEST_ASSERT_EQUAL(0xff & rand(), read_block[i]);
61+
}
62+
63+
err = bd.deinit();
64+
TEST_ASSERT_EQUAL(0, err);
65+
}
66+
67+
#else /* ! defined(__ICCARM__) && ! defined(TARGET_KL25Z) && ! defined(MBED_STACK_STATS_ENABLED) */
68+
69+
#define HEAP_BLOCK_DEVICE_TEST_01 heap_block_device_test_dummy
70+
71+
/** @brief heap_block_device_test_dummy Dummy test case for testing when KL25Z being built with stack statistics enabled.
72+
*
73+
* @return success always
74+
*/
75+
static control_t heap_block_device_test_dummy()
76+
{
77+
printf("Null test\n");
78+
return CaseNext;
79+
}
80+
81+
#endif /* ! defined(__ICCARM__) && ! defined(TARGET_KL25Z) && ! defined(MBED_STACK_STATS_ENABLED) */
82+
83+
// Test setup
84+
utest::v1::status_t test_setup(const size_t number_of_cases) {
85+
GREENTEA_SETUP(10, "default_auto");
86+
return verbose_test_setup_handler(number_of_cases);
87+
}
88+
89+
Case cases[] = {
90+
Case("Testing read write of a block", HEAP_BLOCK_DEVICE_TEST_01),
91+
};
92+
93+
Specification specification(test_setup, cases);
94+
95+
int main() {
96+
return !Harness::run(specification);
97+
}
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2017 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#include "mbed.h"
17+
#include "greentea-client/test_env.h"
18+
#include "unity.h"
19+
#include "utest.h"
20+
21+
#include "HeapBlockDevice.h"
22+
#include "SlicingBlockDevice.h"
23+
#include "ChainingBlockDevice.h"
24+
#include <stdlib.h>
25+
26+
using namespace utest::v1;
27+
28+
/* It is not possible to build a KL25Z image with IAR including the file system if
29+
* stack tracking statistics are enabled. If this is the case, build dummy
30+
* tests.
31+
*/
32+
#if ! defined(TOOLCHAIN_IAR) && ! defined(TARGET_KL25Z) && ! defined(MBED_STACK_STATS_ENABLED)
33+
34+
#define BLOCK_COUNT 16
35+
#define BLOCK_SIZE 512
36+
#define UTIL_BLOCK_DEVICE_TEST_01 test_slicing
37+
#define UTIL_BLOCK_DEVICE_TEST_02 test_chaining
38+
uint8_t write_block[BLOCK_SIZE];
39+
uint8_t read_block[BLOCK_SIZE];
40+
41+
42+
// Simple test which read/writes blocks on a sliced block device
43+
void test_slicing() {
44+
HeapBlockDevice bd(BLOCK_COUNT*BLOCK_SIZE, BLOCK_SIZE);
45+
46+
// Test with first slice of block device
47+
SlicingBlockDevice slice1(&bd, 0, (BLOCK_COUNT/2)*BLOCK_SIZE);
48+
49+
int err = slice1.init();
50+
TEST_ASSERT_EQUAL(0, err);
51+
52+
TEST_ASSERT_EQUAL(BLOCK_SIZE, slice1.get_program_size());
53+
TEST_ASSERT_EQUAL((BLOCK_COUNT/2)*BLOCK_SIZE, slice1.size());
54+
55+
// Fill with random sequence
56+
srand(1);
57+
for (int i = 0; i < BLOCK_SIZE; i++) {
58+
write_block[i] = 0xff & rand();
59+
}
60+
61+
// Write, sync, and read the block
62+
err = slice1.program(write_block, 0, BLOCK_SIZE);
63+
TEST_ASSERT_EQUAL(0, err);
64+
65+
err = slice1.read(read_block, 0, BLOCK_SIZE);
66+
TEST_ASSERT_EQUAL(0, err);
67+
68+
// Check that the data was unmodified
69+
srand(1);
70+
for (int i = 0; i < BLOCK_SIZE; i++) {
71+
TEST_ASSERT_EQUAL(0xff & rand(), read_block[i]);
72+
}
73+
74+
// Check with original block device
75+
err = bd.read(read_block, 0, BLOCK_SIZE);
76+
TEST_ASSERT_EQUAL(0, err);
77+
78+
// Check that the data was unmodified
79+
srand(1);
80+
for (int i = 0; i < BLOCK_SIZE; i++) {
81+
TEST_ASSERT_EQUAL(0xff & rand(), read_block[i]);
82+
}
83+
84+
err = slice1.deinit();
85+
TEST_ASSERT_EQUAL(0, err);
86+
87+
88+
// Test with second slice of block device
89+
SlicingBlockDevice slice2(&bd, -(BLOCK_COUNT/2)*BLOCK_SIZE);
90+
91+
err = slice2.init();
92+
TEST_ASSERT_EQUAL(0, err);
93+
94+
TEST_ASSERT_EQUAL(BLOCK_SIZE, slice2.get_program_size());
95+
TEST_ASSERT_EQUAL((BLOCK_COUNT/2)*BLOCK_SIZE, slice2.size());
96+
97+
// Fill with random sequence
98+
srand(1);
99+
for (int i = 0; i < BLOCK_SIZE; i++) {
100+
write_block[i] = 0xff & rand();
101+
}
102+
103+
// Write, sync, and read the block
104+
err = slice2.program(write_block, 0, BLOCK_SIZE);
105+
TEST_ASSERT_EQUAL(0, err);
106+
107+
err = slice2.read(read_block, 0, BLOCK_SIZE);
108+
TEST_ASSERT_EQUAL(0, err);
109+
110+
// Check that the data was unmodified
111+
srand(1);
112+
for (int i = 0; i < BLOCK_SIZE; i++) {
113+
TEST_ASSERT_EQUAL(0xff & rand(), read_block[i]);
114+
}
115+
116+
// Check with original block device
117+
err = bd.read(read_block, (BLOCK_COUNT/2)*BLOCK_SIZE, BLOCK_SIZE);
118+
TEST_ASSERT_EQUAL(0, err);
119+
120+
// Check that the data was unmodified
121+
srand(1);
122+
for (int i = 0; i < BLOCK_SIZE; i++) {
123+
TEST_ASSERT_EQUAL(0xff & rand(), read_block[i]);
124+
}
125+
126+
err = slice2.deinit();
127+
TEST_ASSERT_EQUAL(0, err);
128+
}
129+
130+
// Simple test which read/writes blocks on a chain of block devices
131+
void test_chaining() {
132+
HeapBlockDevice bd1((BLOCK_COUNT/2)*BLOCK_SIZE, BLOCK_SIZE);
133+
HeapBlockDevice bd2((BLOCK_COUNT/2)*BLOCK_SIZE, BLOCK_SIZE);
134+
135+
// Test with chain of block device
136+
BlockDevice *bds[] = {&bd1, &bd2};
137+
ChainingBlockDevice chain(bds);
138+
139+
int err = chain.init();
140+
TEST_ASSERT_EQUAL(0, err);
141+
142+
TEST_ASSERT_EQUAL(BLOCK_SIZE, chain.get_program_size());
143+
TEST_ASSERT_EQUAL(BLOCK_COUNT*BLOCK_SIZE, chain.size());
144+
145+
// Fill with random sequence
146+
srand(1);
147+
for (int i = 0; i < BLOCK_SIZE; i++) {
148+
write_block[i] = 0xff & rand();
149+
}
150+
151+
// Write, sync, and read the block
152+
err = chain.program(write_block, 0, BLOCK_SIZE);
153+
TEST_ASSERT_EQUAL(0, err);
154+
155+
err = chain.read(read_block, 0, BLOCK_SIZE);
156+
TEST_ASSERT_EQUAL(0, err);
157+
158+
// Check that the data was unmodified
159+
srand(1);
160+
for (int i = 0; i < BLOCK_SIZE; i++) {
161+
TEST_ASSERT_EQUAL(0xff & rand(), read_block[i]);
162+
}
163+
164+
// Write, sync, and read the block
165+
err = chain.program(write_block, (BLOCK_COUNT/2)*BLOCK_SIZE, BLOCK_SIZE);
166+
TEST_ASSERT_EQUAL(0, err);
167+
168+
err = chain.read(read_block, (BLOCK_COUNT/2)*BLOCK_SIZE, BLOCK_SIZE);
169+
TEST_ASSERT_EQUAL(0, err);
170+
171+
// Check that the data was unmodified
172+
srand(1);
173+
for (int i = 0; i < BLOCK_SIZE; i++) {
174+
TEST_ASSERT_EQUAL(0xff & rand(), read_block[i]);
175+
}
176+
177+
err = chain.deinit();
178+
TEST_ASSERT_EQUAL(0, err);
179+
}
180+
181+
#else /* ! defined(TOOLCHAIN_IAR) && ! defined(TARGET_KL25Z) && ! defined(MBED_STACK_STATS_ENABLED) */
182+
183+
#define UTIL_BLOCK_DEVICE_TEST_01 util_block_device_test_dummy
184+
#define UTIL_BLOCK_DEVICE_TEST_02 util_block_device_test_dummy
185+
186+
/** @brief util_block_device_test_dummy Dummy test case for testing when KL25Z being built with stack statistics enabled.
187+
*
188+
* @return success always
189+
*/
190+
static control_t util_block_device_test_dummy()
191+
{
192+
printf("Null test\n");
193+
return CaseNext;
194+
}
195+
196+
#endif /* ! defined(TOOLCHAIN_IAR) && ! defined(TARGET_KL25Z) && ! defined(MBED_STACK_STATS_ENABLED) */
197+
198+
// Test setup
199+
utest::v1::status_t test_setup(const size_t number_of_cases) {
200+
GREENTEA_SETUP(10, "default_auto");
201+
return verbose_test_setup_handler(number_of_cases);
202+
}
203+
204+
Case cases[] = {
205+
Case("Testing slicing of a block device", UTIL_BLOCK_DEVICE_TEST_01),
206+
Case("Testing chaining of block devices", UTIL_BLOCK_DEVICE_TEST_02),
207+
};
208+
209+
Specification specification(test_setup, cases);
210+
211+
int main() {
212+
return !Harness::run(specification);
213+
}

0 commit comments

Comments
 (0)