-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
82045b0
Remove extra GCC arquements.
376bbfc
Add enough stubs to allow drivers/* to compile.
7f089ac
Add empty unittest to generate zero baseline for untested files.
168b51c
Add storage related files to baseline unittest.
31fbed9
Add some functionality to atomic stubs
a6d8f74
Add unittest for HeapBlockDevice and change some MBED_ASSERTS to errors.
333b281
Add moduletest for SlicingBlockDevice
4ab3c8b
IOTSTOR-953: Fix address calculations from SlicingBlockDevice
f0790cd
Remove usage of Mbed TLS internal function from DeviceKey.
ccb7738
Remove linefeeds from debug prints
21987db
Remove commented-out code
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,3 +31,4 @@ | |
^TESTS/mbed_hal/trng/pithy | ||
^TESTS/mbed_hal/trng/pithy | ||
^tools | ||
^UNITTESTS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
120
UNITTESTS/features/storage/blockdevice/HeapBlockDevice/test.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
19 changes: 19 additions & 0 deletions
19
UNITTESTS/features/storage/blockdevice/HeapBlockDevice/unittest.cmake
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.