Skip to content

Commit 355336c

Browse files
authored
Merge pull request #11797 from ARMmbed/IOTSTOR-941
IOTSTOR-953: Fix address calculations from SlicingBlockDevice
2 parents 18d4adf + 21987db commit 355336c

File tree

52 files changed

+838
-213
lines changed

Some content is hidden

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

52 files changed

+838
-213
lines changed

.astyleignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@
3131
^TESTS/mbed_hal/trng/pithy
3232
^TESTS/mbed_hal/trng/pithy
3333
^tools
34+
^UNITTESTS

UNITTESTS/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ if (COVERAGE)
7676
endif()
7777

7878
# Append coverage compiler flags
79-
set(COVERAGE_COMPILER_FLAGS "-g -O0 --coverage -fprofile-arcs -ftest-coverage")
79+
set(COVERAGE_COMPILER_FLAGS "-g -O0 --coverage")
8080
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COVERAGE_COMPILER_FLAGS}")
8181
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_COMPILER_FLAGS}")
8282

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* Copyright (c) 2019 ARM Limited
2+
* SPDX-License-Identifier: Apache-2.0
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+
17+
#include "gtest/gtest.h"
18+
19+
/*
20+
* Purpose of this test is just to be empty baseline
21+
* that does nothing, but includes all source files
22+
* in the build.
23+
* Do not add any tests here
24+
*/
25+
26+
class EmptyBaseline : public testing::Test {
27+
virtual void SetUp()
28+
{
29+
}
30+
31+
virtual void TearDown()
32+
{
33+
}
34+
};
35+
36+
TEST_F(EmptyBaseline, constructor)
37+
{
38+
EXPECT_TRUE(true);
39+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
####################
3+
# UNIT TESTS
4+
####################
5+
6+
set(unittest-includes ${unittest-includes}
7+
.
8+
..
9+
../features/mbedtls/mbed-crypto/inc/mbedtls/
10+
../features/mbedtls/platform/inc/
11+
../features/frameworks/mbed-trace/mbed-trace/
12+
)
13+
14+
set(unittest-sources
15+
../features/device_key/source/DeviceKey.cpp
16+
../components/storage/blockdevice/COMPONENT_SPIF/SPIFBlockDevice.cpp
17+
../components/storage/blockdevice/COMPONENT_I2CEE/I2CEEBlockDevice.cpp
18+
../components/storage/blockdevice/COMPONENT_DATAFLASH/DataFlashBlockDevice.cpp
19+
../components/storage/blockdevice/COMPONENT_FLASHIAP/FlashIAPBlockDevice.cpp
20+
../components/storage/blockdevice/COMPONENT_RSPIF/SPIFReducedBlockDevice.cpp
21+
../components/storage/blockdevice/COMPONENT_SD/SDBlockDevice.cpp
22+
../components/storage/blockdevice/COMPONENT_QSPIF/QSPIFBlockDevice.cpp
23+
../features/storage/filesystem/Dir.cpp
24+
../features/storage/filesystem/FileSystem.cpp
25+
../features/storage/filesystem/File.cpp
26+
../features/storage/kvstore/global_api/kvstore_global_api.cpp
27+
../features/storage/kvstore/securestore/SecureStore.cpp
28+
../features/storage/kvstore/kv_map/KVMap.cpp
29+
../features/storage/kvstore/tdbstore/TDBStore.cpp
30+
../features/storage/kvstore/direct_access_devicekey/DirectAccessDevicekey.cpp
31+
../features/storage/kvstore/conf/kv_config.cpp
32+
../features/storage/kvstore/filesystemstore/FileSystemStore.cpp
33+
../features/storage/system_storage/SystemStorage.cpp
34+
../features/storage/nvstore/source/nvstore.cpp
35+
../features/storage/blockdevice/ChainingBlockDevice.cpp
36+
../features/storage/blockdevice/ReadOnlyBlockDevice.cpp
37+
../features/storage/blockdevice/SlicingBlockDevice.cpp
38+
../features/storage/blockdevice/MBRBlockDevice.cpp
39+
../features/storage/blockdevice/HeapBlockDevice.cpp
40+
../features/storage/blockdevice/FlashSimBlockDevice.cpp
41+
../features/storage/blockdevice/ObservingBlockDevice.cpp
42+
../features/storage/blockdevice/ProfilingBlockDevice.cpp
43+
../features/storage/blockdevice/BufferedBlockDevice.cpp
44+
../features/storage/blockdevice/ExhaustibleBlockDevice.cpp
45+
)
46+
47+
set(unittest-test-sources
48+
empty_baseline/empty_baseline.cpp
49+
)
50+
51+
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")
52+
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")
53+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${DEVICE_FLAGS} ${CONF_FLAGS}")
54+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${DEVICE_FLAGS} ${CONF_FLAGS}")
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/* Copyright (c) 2019 ARM Limited
2+
* SPDX-License-Identifier: Apache-2.0
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+
17+
#include "gtest/gtest.h"
18+
#include "features/storage/blockdevice/HeapBlockDevice.h"
19+
#include <string.h>
20+
#include "mbed_assert.h"
21+
22+
#define BLOCK_SIZE (512)
23+
#define DEVICE_SIZE (BLOCK_SIZE*10)
24+
25+
class HeapBlockDeviceTest : public testing::Test {
26+
protected:
27+
virtual void SetUp()
28+
{
29+
bd.init();
30+
}
31+
32+
virtual void TearDown()
33+
{
34+
bd.deinit();
35+
}
36+
37+
mbed::HeapBlockDevice bd{DEVICE_SIZE};
38+
};
39+
40+
TEST_F(HeapBlockDeviceTest, constructor)
41+
{
42+
// HeapBlockDevice(bd_size_t size, bd_size_t read, bd_size_t program, bd_size_t erase);
43+
mbed::HeapBlockDevice one{3000, 100, 200, 300};
44+
EXPECT_EQ(one.init(), BD_ERROR_OK);
45+
EXPECT_EQ(one.size(), 3000);
46+
EXPECT_EQ(one.get_read_size(), 100);
47+
EXPECT_EQ(one.get_program_size(), 200);
48+
EXPECT_EQ(one.get_erase_size(), 300);
49+
EXPECT_EQ(one.get_erase_size(0), 300);
50+
EXPECT_EQ(one.deinit(), BD_ERROR_OK);
51+
}
52+
53+
TEST_F(HeapBlockDeviceTest, double_init)
54+
{
55+
mbed::HeapBlockDevice one{DEVICE_SIZE};
56+
EXPECT_EQ(one.init(), BD_ERROR_OK);
57+
EXPECT_EQ(one.init(), BD_ERROR_OK);
58+
EXPECT_EQ(one.deinit(), BD_ERROR_OK); // First de-init does only decrement the counter
59+
EXPECT_EQ(one.deinit(), BD_ERROR_OK);
60+
EXPECT_EQ(one.deinit(), BD_ERROR_OK); //Third one does not de-init, but return immediately
61+
}
62+
63+
TEST_F(HeapBlockDeviceTest, get_type)
64+
{
65+
EXPECT_EQ(0, strcmp(bd.get_type(), "HEAP"));
66+
}
67+
68+
TEST_F(HeapBlockDeviceTest, erase_program_read)
69+
{
70+
uint8_t *block = new uint8_t[BLOCK_SIZE] {0xaa,0xbb,0xcc};
71+
uint8_t *buf = new uint8_t[BLOCK_SIZE];
72+
EXPECT_EQ(bd.erase(0, BLOCK_SIZE), BD_ERROR_OK);
73+
EXPECT_EQ(bd.program(block, 0, BLOCK_SIZE), BD_ERROR_OK);
74+
EXPECT_EQ(bd.read(buf, 0, BLOCK_SIZE), BD_ERROR_OK);
75+
EXPECT_EQ(0, memcmp(block, buf, BLOCK_SIZE));
76+
delete[] block;
77+
delete[] buf;
78+
}
79+
80+
TEST_F(HeapBlockDeviceTest, use_uninitialized)
81+
{
82+
mbed::HeapBlockDevice one{DEVICE_SIZE};
83+
uint8_t *buf = new uint8_t[BLOCK_SIZE];
84+
EXPECT_EQ(one.read(buf, 0, BLOCK_SIZE), BD_ERROR_DEVICE_ERROR);
85+
EXPECT_EQ(one.program(buf, 0, BLOCK_SIZE), BD_ERROR_DEVICE_ERROR);
86+
delete[] buf;
87+
}
88+
89+
TEST_F(HeapBlockDeviceTest, over_read)
90+
{
91+
uint8_t *buf = new uint8_t[BLOCK_SIZE];
92+
EXPECT_EQ(bd.read(buf, DEVICE_SIZE, BLOCK_SIZE), BD_ERROR_DEVICE_ERROR);
93+
delete[] buf;
94+
}
95+
96+
TEST_F(HeapBlockDeviceTest, over_write)
97+
{
98+
uint8_t *buf = new uint8_t[BLOCK_SIZE] {0xaa,0xbb,0xcc};
99+
EXPECT_EQ(bd.program(buf, DEVICE_SIZE, BLOCK_SIZE), BD_ERROR_DEVICE_ERROR);
100+
delete[] buf;
101+
}
102+
103+
TEST_F(HeapBlockDeviceTest, over_erase)
104+
{
105+
EXPECT_EQ(bd.erase(DEVICE_SIZE, BLOCK_SIZE), BD_ERROR_DEVICE_ERROR);
106+
}
107+
108+
TEST_F(HeapBlockDeviceTest, erase_uninitialized)
109+
{
110+
mbed::HeapBlockDevice one{DEVICE_SIZE};
111+
EXPECT_EQ(one.erase(DEVICE_SIZE, BLOCK_SIZE), BD_ERROR_DEVICE_ERROR);
112+
}
113+
114+
TEST_F(HeapBlockDeviceTest, read_unprogrammed)
115+
{
116+
uint8_t *buf = new uint8_t[BLOCK_SIZE];
117+
EXPECT_EQ(bd.read(buf, DEVICE_SIZE - BLOCK_SIZE, BLOCK_SIZE), BD_ERROR_OK);
118+
// Ignore the content, it is now zero, but does not need to be.
119+
delete[] buf;
120+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
####################
3+
# UNIT TESTS
4+
####################
5+
6+
set(unittest-includes ${unittest-includes}
7+
.
8+
..
9+
)
10+
11+
set(unittest-sources
12+
../features/storage/blockdevice/HeapBlockDevice.cpp
13+
stubs/mbed_atomic_stub.c
14+
stubs/mbed_assert_stub.c
15+
)
16+
17+
set(unittest-test-sources
18+
features/storage/blockdevice/HeapBlockDevice/test.cpp
19+
)

0 commit comments

Comments
 (0)