Skip to content

STORAGE: Merging feature-storage branch commits to master #3762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 54 commits into from
Feb 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
3fd14f2
Re-instating the FAT32/SDCard support with POSIX File API for mbed-cl…
simonqhughes Dec 19, 2016
8206663
Updated FAT32 readme file to switch to correct branch.
simonqhughes Dec 19, 2016
e848148
Ported glibc POSIX file API test test_rdwr to greentea.
simonqhughes Dec 19, 2016
a024a78
STORAGE: updated basic test case and README for moving work onto feat…
simonqhughes Dec 19, 2016
df099b8
First version of fopen test added.
simonqhughes Dec 20, 2016
a35919a
minor edits to fopen test.
simonqhughes Dec 20, 2016
4acf33f
FILESYSTEM: moved FAT filesystem implemenation to features/filesystem…
simonqhughes Dec 20, 2016
5c7fdc1
FILESYSTEM: renamed features/TESTS/fs-fat features/TESTS/filesystem.
simonqhughes Dec 20, 2016
1b562cc
Fix fopen test build error due to #include <sys/stat.h>, which is not…
simonqhughes Dec 21, 2016
6644627
FILESYSTEM: fix KL25Z CI build failure but not instantiaing SDFileSys…
simonqhughes Dec 21, 2016
7514476
FILESYSTEM: Fix to only build SDFileSystem if DEVICE_SPI defined, to …
simonqhughes Dec 22, 2016
9299a88
Filesystem: Add support for stat
geky Jan 19, 2017
b1a6851
Filesystem: Removed dependency on unistd.h
geky Jan 19, 2017
912044b
FILESYSTEM: fopen() and basic test improvements.
simonqhughes Dec 23, 2016
c8fecb6
STORAGE: tests added for errno, ferror() and clearerr().
simonqhughes Jan 19, 2017
39a1edd
Filesystem: Added EEXIST reporting to mkdir through errno
geky Jan 20, 2017
0c87537
Added errno codes to retarget, mkdir() and ftell() tests.
simonqhughes Jan 20, 2017
8378af0
Updated filesystem README.md.
simonqhughes Jan 20, 2017
cffea7e
Remove unnecesary symbol definitions.
simonqhughes Jan 31, 2017
29f8d83
STORAGE: updated filesystem readme.md.
simonqhughes Jan 31, 2017
aefb03c
ARMCC temporary fixes for undefined errno symbols.
simonqhughes Jan 31, 2017
67165e2
ARMCC temporary fixes for undefined errno symbols.
simonqhughes Jan 31, 2017
9969837
bd: Added prototype block device api
geky Jan 20, 2017
4633d31
bd: Adopted the block device api in the HeapBlockDevice
geky Jan 20, 2017
03a332c
bd: Adopted the block device api in the SDBlockDevice
geky Jan 20, 2017
ba5e142
bd: Added utility block device classes
geky Jan 20, 2017
0176450
bd: Adopted the block storage api in the FATFileSystem
geky Jan 20, 2017
90429f6
Fixed mbed 2 build_travis with block device
geky Jan 31, 2017
ad176c5
Updated filesystem tests to use FATFileSystem + SDBlockDevice
geky Feb 1, 2017
4f5e94c
STORAGE: test case fixes to support ARMCC and IAR toolchains.
simonqhughes Feb 3, 2017
26141f0
STORAGE: test case fixes to support ARMCC and IAR toolchains.
simonqhughes Feb 3, 2017
01baa72
STORAGE: change FATFileSystem::format() to include allocation_unit ar…
simonqhughes Feb 3, 2017
0b7a2ca
STORAGE: fixes for merging in format test with new block device imple…
simonqhughes Feb 6, 2017
860d7f0
STORAGE: fixing error handling for fopen() and other upper edge files…
simonqhughes Feb 3, 2017
c877fb6
STORAGE: compiler warning fixes.
simonqhughes Feb 6, 2017
fdadb8c
STORAGE: moved toolchain_support.h into platform/retarget.h
simonqhughes Feb 6, 2017
2b96c74
STORAGE: Pull Request 3704 requested minor changes including:
simonqhughes Feb 7, 2017
0b0fc7d
STORAGE: fix for heap_block_device and util_block_device test binarie…
simonqhughes Feb 7, 2017
cbcc445
Added d_type member of dirent struct to readdir
geky Feb 6, 2017
f84f2f2
STORAGE: missing retarget.h in fat_file_system/main.cpp for missing S…
simonqhughes Feb 8, 2017
c0a53a9
STORAGE: added opendir(), readdir(), closedir() test.
simonqhughes Feb 8, 2017
3e35d4b
STORAGE: added test case to write/check n x 25kB files storing ~250kB…
simonqhughes Feb 10, 2017
a79062f
Remove build_travis.py NUCLEO_F412ZG usb tests which requires other c…
simonqhughes Feb 14, 2017
b8e31c8
Removal of SD card driver (SDBlockDevice module) and related test cas…
simonqhughes Feb 14, 2017
840c777
STORAGE: Pull request 3762 review feedback changes.
simonqhughes Feb 22, 2017
e43f667
STORAGE: PR 3762 fix to remove FAT_FS, SD_FS, FS_LIBRARY from tools/l…
simonqhughes Feb 22, 2017
5a977ef
STORAGE: PR 3762 fix to remove FAT_FS, SD_FS, FS_LIBRARY from tools s…
simonqhughes Feb 22, 2017
ea5ac4b
Storage: Last minute changes to the block device api
geky Feb 23, 2017
9a1966f
STORAGE: fixes for BlockDevice test cases.
simonqhughes Feb 23, 2017
7b7db58
STORAGE: remove RTOS_9 test from tests.py.
simonqhughes Feb 23, 2017
410c2f8
STORAGE: rebased with master and fixed FATFileSystem.cpp merge confli…
simonqhughes Feb 23, 2017
2d41da2
Storage/lwip: Renamed lwip/errno.h -> lwip/lwip_errno.h to avoid conf…
geky Feb 23, 2017
2cf6773
Filesystem: Remove invalid write to unallocated memory in heap block …
geky Feb 24, 2017
794c6f8
STORAGE: move fat_file_system test into external repository as this i…
simonqhughes Feb 24, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions drivers/DirHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#ifndef MBED_DIRHANDLE_H
#define MBED_DIRHANDLE_H

#include <stdint.h>

#if defined(__ARMCC_VERSION) || defined(__ICCARM__)
# define NAME_MAX 255
typedef int mode_t;
Expand All @@ -28,6 +30,18 @@ typedef int mode_t;

struct dirent {
char d_name[NAME_MAX+1];
uint8_t d_type;
};

enum {
DT_UNKNOWN, // The file type could not be determined.
DT_FIFO, // This is a named pipe (FIFO).
DT_CHR, // This is a character device.
DT_DIR, // This is a directory.
DT_BLK, // This is a block device.
DT_REG, // This is a regular file.
DT_LNK, // This is a symbolic link.
DT_SOCK, // This is a UNIX domain socket.
};

namespace mbed {
Expand Down
10 changes: 9 additions & 1 deletion drivers/FileSystemLike.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,15 @@ class FileSystemLike : public FileBase {
*/
virtual int mkdir(const char *name, mode_t mode) { (void) name, (void) mode; return -1; }

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

} // namespace mbed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include "lwip/def.h"
#include "lwip/sys.h"

#include "lwip/errno.h"
#include "lwip/lwip_errno.h"

#if !NO_SYS
/** Table to quickly map an lwIP error (err_t) to a socket error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#include "lwip/ip_addr.h"
#include "lwip/err.h"
#include "lwip/inet.h"
#include "lwip/errno.h"
#include "lwip/lwip_errno.h"

#ifdef __cplusplus
extern "C" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@
*
*/

#include "lwip/errno.h"
#include "lwip/lwip_errno.h"
97 changes: 97 additions & 0 deletions features/TESTS/filesystem/heap_block_device/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/* mbed Microcontroller Library
* Copyright (c) 2017 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "mbed.h"
#include "greentea-client/test_env.h"
#include "unity.h"
#include "utest.h"

#include "HeapBlockDevice.h"
#include <stdlib.h>

using namespace utest::v1;

/* It is not possible to build a KL25Z image with IAR including the file system if
* stack tracking statistics are enabled. If this is the case, build dummy
* tests.
*/
#if ! defined(__ICCARM__) && ! defined(TARGET_KL25Z) && ! defined(MBED_STACK_STATS_ENABLED)

#define BLOCK_SIZE 512
#define HEAP_BLOCK_DEVICE_TEST_01 test_read_write
uint8_t write_block[BLOCK_SIZE];
uint8_t read_block[BLOCK_SIZE];

// Simple test which reads and writes a block
void test_read_write() {
HeapBlockDevice bd(16*BLOCK_SIZE, BLOCK_SIZE);

int err = bd.init();
TEST_ASSERT_EQUAL(0, err);

// Fill with random sequence
srand(1);
for (int i = 0; i < BLOCK_SIZE; i++) {
write_block[i] = 0xff & rand();
}

// Write, sync, and read the block
err = bd.program(write_block, 0, BLOCK_SIZE);
TEST_ASSERT_EQUAL(0, err);

err = bd.read(read_block, 0, BLOCK_SIZE);
TEST_ASSERT_EQUAL(0, err);

// Check that the data was unmodified
srand(1);
for (int i = 0; i < BLOCK_SIZE; i++) {
TEST_ASSERT_EQUAL(0xff & rand(), read_block[i]);
}

err = bd.deinit();
TEST_ASSERT_EQUAL(0, err);
}

#else /* ! defined(__ICCARM__) && ! defined(TARGET_KL25Z) && ! defined(MBED_STACK_STATS_ENABLED) */

#define HEAP_BLOCK_DEVICE_TEST_01 heap_block_device_test_dummy

/** @brief heap_block_device_test_dummy Dummy test case for testing when KL25Z being built with stack statistics enabled.
*
* @return success always
*/
static control_t heap_block_device_test_dummy()
{
printf("Null test\n");
return CaseNext;
}

#endif /* ! defined(__ICCARM__) && ! defined(TARGET_KL25Z) && ! defined(MBED_STACK_STATS_ENABLED) */

// Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) {
GREENTEA_SETUP(10, "default_auto");
return verbose_test_setup_handler(number_of_cases);
}

Case cases[] = {
Case("Testing read write of a block", HEAP_BLOCK_DEVICE_TEST_01),
};

Specification specification(test_setup, cases);

int main() {
return !Harness::run(specification);
}
213 changes: 213 additions & 0 deletions features/TESTS/filesystem/util_block_device/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
/* mbed Microcontroller Library
* Copyright (c) 2017 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "mbed.h"
#include "greentea-client/test_env.h"
#include "unity.h"
#include "utest.h"

#include "HeapBlockDevice.h"
#include "SlicingBlockDevice.h"
#include "ChainingBlockDevice.h"
#include <stdlib.h>

using namespace utest::v1;

/* It is not possible to build a KL25Z image with IAR including the file system if
* stack tracking statistics are enabled. If this is the case, build dummy
* tests.
*/
#if ! defined(TOOLCHAIN_IAR) && ! defined(TARGET_KL25Z) && ! defined(MBED_STACK_STATS_ENABLED)

#define BLOCK_COUNT 16
#define BLOCK_SIZE 512
#define UTIL_BLOCK_DEVICE_TEST_01 test_slicing
#define UTIL_BLOCK_DEVICE_TEST_02 test_chaining
uint8_t write_block[BLOCK_SIZE];
uint8_t read_block[BLOCK_SIZE];


// Simple test which read/writes blocks on a sliced block device
void test_slicing() {
HeapBlockDevice bd(BLOCK_COUNT*BLOCK_SIZE, BLOCK_SIZE);

// Test with first slice of block device
SlicingBlockDevice slice1(&bd, 0, (BLOCK_COUNT/2)*BLOCK_SIZE);

int err = slice1.init();
TEST_ASSERT_EQUAL(0, err);

TEST_ASSERT_EQUAL(BLOCK_SIZE, slice1.get_program_size());
TEST_ASSERT_EQUAL((BLOCK_COUNT/2)*BLOCK_SIZE, slice1.size());

// Fill with random sequence
srand(1);
for (int i = 0; i < BLOCK_SIZE; i++) {
write_block[i] = 0xff & rand();
}

// Write, sync, and read the block
err = slice1.program(write_block, 0, BLOCK_SIZE);
TEST_ASSERT_EQUAL(0, err);

err = slice1.read(read_block, 0, BLOCK_SIZE);
TEST_ASSERT_EQUAL(0, err);

// Check that the data was unmodified
srand(1);
for (int i = 0; i < BLOCK_SIZE; i++) {
TEST_ASSERT_EQUAL(0xff & rand(), read_block[i]);
}

// Check with original block device
err = bd.read(read_block, 0, BLOCK_SIZE);
TEST_ASSERT_EQUAL(0, err);

// Check that the data was unmodified
srand(1);
for (int i = 0; i < BLOCK_SIZE; i++) {
TEST_ASSERT_EQUAL(0xff & rand(), read_block[i]);
}

err = slice1.deinit();
TEST_ASSERT_EQUAL(0, err);


// Test with second slice of block device
SlicingBlockDevice slice2(&bd, -(BLOCK_COUNT/2)*BLOCK_SIZE);

err = slice2.init();
TEST_ASSERT_EQUAL(0, err);

TEST_ASSERT_EQUAL(BLOCK_SIZE, slice2.get_program_size());
TEST_ASSERT_EQUAL((BLOCK_COUNT/2)*BLOCK_SIZE, slice2.size());

// Fill with random sequence
srand(1);
for (int i = 0; i < BLOCK_SIZE; i++) {
write_block[i] = 0xff & rand();
}

// Write, sync, and read the block
err = slice2.program(write_block, 0, BLOCK_SIZE);
TEST_ASSERT_EQUAL(0, err);

err = slice2.read(read_block, 0, BLOCK_SIZE);
TEST_ASSERT_EQUAL(0, err);

// Check that the data was unmodified
srand(1);
for (int i = 0; i < BLOCK_SIZE; i++) {
TEST_ASSERT_EQUAL(0xff & rand(), read_block[i]);
}

// Check with original block device
err = bd.read(read_block, (BLOCK_COUNT/2)*BLOCK_SIZE, BLOCK_SIZE);
TEST_ASSERT_EQUAL(0, err);

// Check that the data was unmodified
srand(1);
for (int i = 0; i < BLOCK_SIZE; i++) {
TEST_ASSERT_EQUAL(0xff & rand(), read_block[i]);
}

err = slice2.deinit();
TEST_ASSERT_EQUAL(0, err);
}

// Simple test which read/writes blocks on a chain of block devices
void test_chaining() {
HeapBlockDevice bd1((BLOCK_COUNT/2)*BLOCK_SIZE, BLOCK_SIZE);
HeapBlockDevice bd2((BLOCK_COUNT/2)*BLOCK_SIZE, BLOCK_SIZE);

// Test with chain of block device
BlockDevice *bds[] = {&bd1, &bd2};
ChainingBlockDevice chain(bds);

int err = chain.init();
TEST_ASSERT_EQUAL(0, err);

TEST_ASSERT_EQUAL(BLOCK_SIZE, chain.get_program_size());
TEST_ASSERT_EQUAL(BLOCK_COUNT*BLOCK_SIZE, chain.size());

// Fill with random sequence
srand(1);
for (int i = 0; i < BLOCK_SIZE; i++) {
write_block[i] = 0xff & rand();
}

// Write, sync, and read the block
err = chain.program(write_block, 0, BLOCK_SIZE);
TEST_ASSERT_EQUAL(0, err);

err = chain.read(read_block, 0, BLOCK_SIZE);
TEST_ASSERT_EQUAL(0, err);

// Check that the data was unmodified
srand(1);
for (int i = 0; i < BLOCK_SIZE; i++) {
TEST_ASSERT_EQUAL(0xff & rand(), read_block[i]);
}

// Write, sync, and read the block
err = chain.program(write_block, (BLOCK_COUNT/2)*BLOCK_SIZE, BLOCK_SIZE);
TEST_ASSERT_EQUAL(0, err);

err = chain.read(read_block, (BLOCK_COUNT/2)*BLOCK_SIZE, BLOCK_SIZE);
TEST_ASSERT_EQUAL(0, err);

// Check that the data was unmodified
srand(1);
for (int i = 0; i < BLOCK_SIZE; i++) {
TEST_ASSERT_EQUAL(0xff & rand(), read_block[i]);
}

err = chain.deinit();
TEST_ASSERT_EQUAL(0, err);
}

#else /* ! defined(TOOLCHAIN_IAR) && ! defined(TARGET_KL25Z) && ! defined(MBED_STACK_STATS_ENABLED) */

#define UTIL_BLOCK_DEVICE_TEST_01 util_block_device_test_dummy
#define UTIL_BLOCK_DEVICE_TEST_02 util_block_device_test_dummy

/** @brief util_block_device_test_dummy Dummy test case for testing when KL25Z being built with stack statistics enabled.
*
* @return success always
*/
static control_t util_block_device_test_dummy()
{
printf("Null test\n");
return CaseNext;
}

#endif /* ! defined(TOOLCHAIN_IAR) && ! defined(TARGET_KL25Z) && ! defined(MBED_STACK_STATS_ENABLED) */

// Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) {
GREENTEA_SETUP(10, "default_auto");
return verbose_test_setup_handler(number_of_cases);
}

Case cases[] = {
Case("Testing slicing of a block device", UTIL_BLOCK_DEVICE_TEST_01),
Case("Testing chaining of block devices", UTIL_BLOCK_DEVICE_TEST_02),
};

Specification specification(test_setup, cases);

int main() {
return !Harness::run(specification);
}
Loading