Skip to content

IOTSTOR-953: Fix address calculations from SlicingBlockDevice #11797

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 11 commits into from
Nov 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .astyleignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@
^TESTS/mbed_hal/trng/pithy
^TESTS/mbed_hal/trng/pithy
^tools
^UNITTESTS
2 changes: 1 addition & 1 deletion UNITTESTS/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ if (COVERAGE)
endif()

# Append coverage compiler flags
set(COVERAGE_COMPILER_FLAGS "-g -O0 --coverage -fprofile-arcs -ftest-coverage")
set(COVERAGE_COMPILER_FLAGS "-g -O0 --coverage")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COVERAGE_COMPILER_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_COMPILER_FLAGS}")

Expand Down
39 changes: 39 additions & 0 deletions UNITTESTS/empty_baseline/empty_baseline.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* Copyright (c) 2019 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"

/*
* Purpose of this test is just to be empty baseline
* that does nothing, but includes all source files
* in the build.
* Do not add any tests here
*/

class EmptyBaseline : public testing::Test {
virtual void SetUp()
{
}

virtual void TearDown()
{
}
};

TEST_F(EmptyBaseline, constructor)
{
EXPECT_TRUE(true);
}
54 changes: 54 additions & 0 deletions UNITTESTS/empty_baseline/unittest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

####################
# UNIT TESTS
####################

set(unittest-includes ${unittest-includes}
.
..
../features/mbedtls/mbed-crypto/inc/mbedtls/
../features/mbedtls/platform/inc/
../features/frameworks/mbed-trace/mbed-trace/
)

set(unittest-sources
../features/device_key/source/DeviceKey.cpp
../components/storage/blockdevice/COMPONENT_SPIF/SPIFBlockDevice.cpp
../components/storage/blockdevice/COMPONENT_I2CEE/I2CEEBlockDevice.cpp
../components/storage/blockdevice/COMPONENT_DATAFLASH/DataFlashBlockDevice.cpp
../components/storage/blockdevice/COMPONENT_FLASHIAP/FlashIAPBlockDevice.cpp
../components/storage/blockdevice/COMPONENT_RSPIF/SPIFReducedBlockDevice.cpp
../components/storage/blockdevice/COMPONENT_SD/SDBlockDevice.cpp
../components/storage/blockdevice/COMPONENT_QSPIF/QSPIFBlockDevice.cpp
../features/storage/filesystem/Dir.cpp
../features/storage/filesystem/FileSystem.cpp
../features/storage/filesystem/File.cpp
../features/storage/kvstore/global_api/kvstore_global_api.cpp
../features/storage/kvstore/securestore/SecureStore.cpp
../features/storage/kvstore/kv_map/KVMap.cpp
../features/storage/kvstore/tdbstore/TDBStore.cpp
../features/storage/kvstore/direct_access_devicekey/DirectAccessDevicekey.cpp
../features/storage/kvstore/conf/kv_config.cpp
../features/storage/kvstore/filesystemstore/FileSystemStore.cpp
../features/storage/system_storage/SystemStorage.cpp
../features/storage/nvstore/source/nvstore.cpp
../features/storage/blockdevice/ChainingBlockDevice.cpp
../features/storage/blockdevice/ReadOnlyBlockDevice.cpp
../features/storage/blockdevice/SlicingBlockDevice.cpp
../features/storage/blockdevice/MBRBlockDevice.cpp
../features/storage/blockdevice/HeapBlockDevice.cpp
../features/storage/blockdevice/FlashSimBlockDevice.cpp
../features/storage/blockdevice/ObservingBlockDevice.cpp
../features/storage/blockdevice/ProfilingBlockDevice.cpp
../features/storage/blockdevice/BufferedBlockDevice.cpp
../features/storage/blockdevice/ExhaustibleBlockDevice.cpp
)

set(unittest-test-sources
empty_baseline/empty_baseline.cpp
)

set(DEVICE_FLAGS "-DDEVICE_ANALOGIN -DDEVICE_ANALOGOUT -DDEVICE_CAN -DDEVICE_CRC -DDEVICE_ETHERNET -DDEVICE_FLASH -DDEVICE_I2C -DDEVICE_I2CSLAVE -DDEVICE_I2C_ASYNCH -DDEVICE_INTERRUPTIN -DDEVICE_LPTICKER -DDEVICE_PORTIN -DDEVICE_PORTINOUT -DDEVICE_PORTOUT -DDEVICE_PWMOUT -DDEVICE_QSPI -DDEVICE_SERIAL -DDEVICE_SERIAL_ASYNCH -DDEVICE_SERIAL_FC -DDEVICE_SPI -DDEVICE_SPISLAVE -DDEVICE_SPI_ASYNCH -DDEVICE_FLASH -DCOMPONENT_FLASHIAP")
set(CONF_FLAGS "-DMBED_CONF_PLATFORM_CTHUNK_COUNT_MAX=10 -DMBED_CONF_DATAFLASH_SPI_FREQ=1 -DMBED_CONF_FLASHIAP_BLOCK_DEVICE_BASE_ADDRESS=0 -DMBED_CONF_FLASHIAP_BLOCK_DEVICE_SIZE=0 -DMBED_CONF_QSPIF_QSPI_FREQ=1 -DMBED_CONF_QSPIF_QSPI_MIN_READ_SIZE=1 -DMBED_CONF_QSPIF_QSPI_MIN_PROG_SIZE=1 -DMBED_LFS_READ_SIZE=64 -DMBED_LFS_PROG_SIZE=64 -DMBED_LFS_BLOCK_SIZE=512 -DMBED_LFS_LOOKAHEAD=512 -DFLASHIAP_APP_ROM_END_ADDR=0x80000 -DMBED_CONF_STORAGE_TDB_INTERNAL_INTERNAL_SIZE=1024 -DMBED_CONF_STORAGE_TDB_INTERNAL_INTERNAL_BASE_ADDRESS=0x80000 -DMBED_CONF_STORAGE_STORAGE_TYPE=default")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${DEVICE_FLAGS} ${CONF_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${DEVICE_FLAGS} ${CONF_FLAGS}")
120 changes: 120 additions & 0 deletions UNITTESTS/features/storage/blockdevice/HeapBlockDevice/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/* Copyright (c) 2019 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 "features/storage/blockdevice/HeapBlockDevice.h"
#include <string.h>
#include "mbed_assert.h"

#define BLOCK_SIZE (512)
#define DEVICE_SIZE (BLOCK_SIZE*10)

class HeapBlockDeviceTest : public testing::Test {
protected:
virtual void SetUp()
{
bd.init();
}

virtual void TearDown()
{
bd.deinit();
}

mbed::HeapBlockDevice bd{DEVICE_SIZE};
};

TEST_F(HeapBlockDeviceTest, constructor)
{
// HeapBlockDevice(bd_size_t size, bd_size_t read, bd_size_t program, bd_size_t erase);
mbed::HeapBlockDevice one{3000, 100, 200, 300};
EXPECT_EQ(one.init(), BD_ERROR_OK);
EXPECT_EQ(one.size(), 3000);
EXPECT_EQ(one.get_read_size(), 100);
EXPECT_EQ(one.get_program_size(), 200);
EXPECT_EQ(one.get_erase_size(), 300);
EXPECT_EQ(one.get_erase_size(0), 300);
EXPECT_EQ(one.deinit(), BD_ERROR_OK);
}

TEST_F(HeapBlockDeviceTest, double_init)
{
mbed::HeapBlockDevice one{DEVICE_SIZE};
EXPECT_EQ(one.init(), BD_ERROR_OK);
EXPECT_EQ(one.init(), BD_ERROR_OK);
EXPECT_EQ(one.deinit(), BD_ERROR_OK); // First de-init does only decrement the counter
EXPECT_EQ(one.deinit(), BD_ERROR_OK);
EXPECT_EQ(one.deinit(), BD_ERROR_OK); //Third one does not de-init, but return immediately
}

TEST_F(HeapBlockDeviceTest, get_type)
{
EXPECT_EQ(0, strcmp(bd.get_type(), "HEAP"));
}

TEST_F(HeapBlockDeviceTest, erase_program_read)
{
uint8_t *block = new uint8_t[BLOCK_SIZE] {0xaa,0xbb,0xcc};
uint8_t *buf = new uint8_t[BLOCK_SIZE];
EXPECT_EQ(bd.erase(0, BLOCK_SIZE), BD_ERROR_OK);
EXPECT_EQ(bd.program(block, 0, BLOCK_SIZE), BD_ERROR_OK);
EXPECT_EQ(bd.read(buf, 0, BLOCK_SIZE), BD_ERROR_OK);
EXPECT_EQ(0, memcmp(block, buf, BLOCK_SIZE));
delete[] block;
delete[] buf;
}

TEST_F(HeapBlockDeviceTest, use_uninitialized)
{
mbed::HeapBlockDevice one{DEVICE_SIZE};
uint8_t *buf = new uint8_t[BLOCK_SIZE];
EXPECT_EQ(one.read(buf, 0, BLOCK_SIZE), BD_ERROR_DEVICE_ERROR);
EXPECT_EQ(one.program(buf, 0, BLOCK_SIZE), BD_ERROR_DEVICE_ERROR);
delete[] buf;
}

TEST_F(HeapBlockDeviceTest, over_read)
{
uint8_t *buf = new uint8_t[BLOCK_SIZE];
EXPECT_EQ(bd.read(buf, DEVICE_SIZE, BLOCK_SIZE), BD_ERROR_DEVICE_ERROR);
delete[] buf;
}

TEST_F(HeapBlockDeviceTest, over_write)
{
uint8_t *buf = new uint8_t[BLOCK_SIZE] {0xaa,0xbb,0xcc};
EXPECT_EQ(bd.program(buf, DEVICE_SIZE, BLOCK_SIZE), BD_ERROR_DEVICE_ERROR);
delete[] buf;
}

TEST_F(HeapBlockDeviceTest, over_erase)
{
EXPECT_EQ(bd.erase(DEVICE_SIZE, BLOCK_SIZE), BD_ERROR_DEVICE_ERROR);
}

TEST_F(HeapBlockDeviceTest, erase_uninitialized)
{
mbed::HeapBlockDevice one{DEVICE_SIZE};
EXPECT_EQ(one.erase(DEVICE_SIZE, BLOCK_SIZE), BD_ERROR_DEVICE_ERROR);
}

TEST_F(HeapBlockDeviceTest, read_unprogrammed)
{
uint8_t *buf = new uint8_t[BLOCK_SIZE];
EXPECT_EQ(bd.read(buf, DEVICE_SIZE - BLOCK_SIZE, BLOCK_SIZE), BD_ERROR_OK);
// Ignore the content, it is now zero, but does not need to be.
delete[] buf;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

####################
# UNIT TESTS
####################

set(unittest-includes ${unittest-includes}
.
..
)

set(unittest-sources
../features/storage/blockdevice/HeapBlockDevice.cpp
stubs/mbed_atomic_stub.c
stubs/mbed_assert_stub.c
)

set(unittest-test-sources
features/storage/blockdevice/HeapBlockDevice/test.cpp
)
Loading