Import Mbed OS hard-float snapshot

This commit is contained in:
Beslan
2026-06-01 20:15:04 +03:00
commit d3738e2f89
16278 changed files with 10628036 additions and 0 deletions

View File

@@ -0,0 +1,111 @@
/* Copyright (c) 2020 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*
* 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 "gtest/gtest.h"
#include "blockdevice/HeapBlockDevice.h"
#include "kvstore/FileSystemStore.h"
#include "littlefs/LittleFileSystem.h"
#include "mbed_error.h"
#include <stdlib.h>
#define HEAPBLOCK_SIZE (4096)
using namespace mbed;
class FileSystemStoreModuleTest : public testing::Test {
protected:
HeapBlockDevice heap{HEAPBLOCK_SIZE};
LittleFileSystem *fs;
FileSystemStore *store;
virtual void SetUp()
{
fs = new LittleFileSystem("kvstore", &heap);
if(fs->mount(&heap) != MBED_SUCCESS) {
EXPECT_EQ(fs->reformat(&heap), MBED_SUCCESS);
}
store = new FileSystemStore(fs);
EXPECT_EQ(store->init(), MBED_SUCCESS);
}
virtual void TearDown()
{
EXPECT_EQ(store->deinit(), MBED_SUCCESS);
delete store;
EXPECT_EQ(fs->unmount(), MBED_SUCCESS);
delete fs;
}
};
TEST_F(FileSystemStoreModuleTest, init)
{
EXPECT_EQ(store->deinit(), MBED_SUCCESS);
EXPECT_EQ(store->init(), MBED_SUCCESS);
EXPECT_EQ(store->init(), MBED_SUCCESS);
}
TEST_F(FileSystemStoreModuleTest, set_get)
{
char buf[100];
size_t size;
EXPECT_EQ(store->set("key", "data", 5, 0), MBED_SUCCESS);
EXPECT_EQ(store->get("key", buf, 100, &size), MBED_SUCCESS);
EXPECT_EQ(size, 5);
EXPECT_STREQ("data", buf);
}
TEST_F(FileSystemStoreModuleTest, erased_set_get)
{
EXPECT_EQ(store->deinit(), MBED_SUCCESS);
EXPECT_EQ(heap.init(), MBED_SUCCESS);
EXPECT_EQ(heap.erase(0, heap.size()), MBED_SUCCESS);
EXPECT_EQ(heap.deinit(), MBED_SUCCESS);
EXPECT_EQ(store->init(), MBED_SUCCESS);
char buf[100];
size_t size;
EXPECT_EQ(store->set("key", "data", 5, 0), MBED_SUCCESS);
EXPECT_EQ(store->get("key", buf, 100, &size), MBED_SUCCESS);
EXPECT_EQ(size, 5);
EXPECT_STREQ("data", buf);
}
TEST_F(FileSystemStoreModuleTest, set_deinit_init_get)
{
char buf[100];
size_t size;
for (int i = 0; i < 100; ++i) {
EXPECT_EQ(store->set("key", "data", 5, 0), MBED_SUCCESS);
EXPECT_EQ(store->deinit(), MBED_SUCCESS);
EXPECT_EQ(store->init(), MBED_SUCCESS);
EXPECT_EQ(store->get("key", buf, 100, &size), MBED_SUCCESS);
EXPECT_EQ(size, 5);
EXPECT_STREQ("data", buf);
EXPECT_EQ(store->remove("key"), MBED_SUCCESS);
}
}
TEST_F(FileSystemStoreModuleTest, set_multiple_iterate)
{
char buf[100];
KVStore::iterator_t iterator;
EXPECT_EQ(store->set("primary_key", "data", 5, 0), MBED_SUCCESS);
EXPECT_EQ(store->set("primary_second_key", "value", 6, 0), MBED_SUCCESS);
EXPECT_EQ(store->iterator_open(&iterator, "primary"), MBED_SUCCESS);
EXPECT_EQ(store->iterator_next(iterator, buf, 100), MBED_SUCCESS);
EXPECT_EQ(store->iterator_next(iterator, buf, 100), MBED_SUCCESS);
EXPECT_EQ(store->iterator_next(iterator, buf, 100), MBED_ERROR_ITEM_NOT_FOUND);
EXPECT_EQ(store->iterator_close(iterator), MBED_SUCCESS);
}

View File

@@ -0,0 +1,40 @@
####################
# UNIT TESTS
####################
set(unittest-includes ${unittest-includes}
.
..
../features/frameworks/mbed-trace/mbed-trace
)
set(unittest-sources
../storage/blockdevice/source/HeapBlockDevice.cpp
../storage/kvstore/source/FileSystemStore.cpp
../storage/filesystem/littlefs/source/LittleFileSystem.cpp
../storage/filesystem/source/Dir.cpp
../storage/filesystem/source/File.cpp
../storage/filesystem/source/FileSystem.cpp
../features/frameworks/mbed-trace/source/mbed_trace.c
../storage/filesystem/littlefs/littlefs/lfs_util.c
../storage/filesystem/littlefs/littlefs/lfs.c
../platform/source/FileBase.cpp
../platform/source/FileSystemHandle.cpp
../platform/source/FileHandle.cpp
)
set(unittest-test-sources
${CMAKE_CURRENT_LIST_DIR}/moduletest.cpp
stubs/mbed_atomic_stub.c
stubs/mbed_assert_stub.cpp
stubs/mbed_error.c
stubs/kv_config_stub.cpp
stubs/mbed_retarget_stub.cpp
)
set(unittest-test-flags
-DMBED_LFS_READ_SIZE=64
-DMBED_LFS_PROG_SIZE=64
-DMBED_LFS_BLOCK_SIZE=512
-DMBED_LFS_LOOKAHEAD=512
)