Skip to content

Commit 92a60c3

Browse files
author
Seppo Takalo
committed
Extend SlicingBlockDevice test coverage
1 parent 12dea71 commit 92a60c3

File tree

2 files changed

+54
-6
lines changed

2 files changed

+54
-6
lines changed

UNITTESTS/moduletests/storage/blockdevice/SlicingBlockDevice/moduletest.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,67 @@ TEST_F(SlicingBlockModuleTest, slice_at_the_end)
148148
TEST_F(SlicingBlockModuleTest, over_write)
149149
{
150150
uint8_t *program = new uint8_t[BLOCK_SIZE] {0xbb,0xbb,0xbb};
151+
uint8_t *buf = new uint8_t[BLOCK_SIZE];
151152

152153
//Screate sclicing device, with size of 2 blocks
153154
mbed::SlicingBlockDevice slice(&bd, BLOCK_SIZE, BLOCK_SIZE * 3);
154155
EXPECT_EQ(slice.init(), BD_ERROR_OK);
155156

156157
EXPECT_EQ(slice.program(program, 0, BLOCK_SIZE), BD_ERROR_OK);
157158
EXPECT_EQ(slice.program(program, BLOCK_SIZE, BLOCK_SIZE), BD_ERROR_OK);
159+
160+
// Verify written value
161+
EXPECT_EQ(slice.read(buf, BLOCK_SIZE, BLOCK_SIZE), BD_ERROR_OK);
162+
EXPECT_EQ(0, memcmp(buf, program, BLOCK_SIZE));
163+
158164
//Program a test value to address that is one pass the device size
159165
EXPECT_EQ(slice.program(program, 2 * BLOCK_SIZE, BLOCK_SIZE), BD_ERROR_DEVICE_ERROR);
160166
delete[] program;
161167
}
168+
169+
TEST_F(SlicingBlockModuleTest, over_read)
170+
{
171+
uint8_t *buf = new uint8_t[BLOCK_SIZE];
172+
173+
//Screate sclicing device, with size of 2 blocks
174+
mbed::SlicingBlockDevice slice(&bd, BLOCK_SIZE, BLOCK_SIZE * 3);
175+
EXPECT_EQ(slice.init(), BD_ERROR_OK);
176+
177+
//Try to read a block after the slice
178+
EXPECT_EQ(slice.read(buf, 2 * BLOCK_SIZE, BLOCK_SIZE), BD_ERROR_DEVICE_ERROR);
179+
delete[] buf;
180+
}
181+
182+
TEST_F(SlicingBlockModuleTest, get_type)
183+
{
184+
mbed::SlicingBlockDevice slice(&bd, BLOCK_SIZE, BLOCK_SIZE * 3);
185+
EXPECT_EQ(bd.get_type(), slice.get_type());
186+
}
187+
188+
TEST_F(SlicingBlockModuleTest, get_erase_value)
189+
{
190+
mbed::SlicingBlockDevice slice(&bd, BLOCK_SIZE, BLOCK_SIZE * 3);
191+
EXPECT_EQ(bd.get_erase_value(), slice.get_erase_value());
192+
}
193+
194+
TEST_F(SlicingBlockModuleTest, erase)
195+
{
196+
mbed::SlicingBlockDevice slice(&bd, BLOCK_SIZE, BLOCK_SIZE * 3);
197+
EXPECT_EQ(slice.erase(0, BLOCK_SIZE), BD_ERROR_OK);
198+
// Erase one block after the slice
199+
EXPECT_EQ(slice.erase(2*BLOCK_SIZE, BLOCK_SIZE), BD_ERROR_DEVICE_ERROR);
200+
}
201+
202+
TEST_F(SlicingBlockModuleTest, sync)
203+
{
204+
mbed::SlicingBlockDevice slice(&bd, BLOCK_SIZE, BLOCK_SIZE * 3);
205+
// Just a pass through
206+
EXPECT_EQ(slice.sync(), 0);
207+
}
208+
209+
TEST_F(SlicingBlockModuleTest, too_big_to_init)
210+
{
211+
mbed::SlicingBlockDevice slice(&bd, 0, DEVICE_SIZE + BLOCK_SIZE);
212+
// Just a pass through
213+
EXPECT_EQ(slice.init(), BD_ERROR_DEVICE_ERROR);
214+
}

features/storage/blockdevice/SlicingBlockDevice.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,7 @@ bd_size_t SlicingBlockDevice::size() const
147147

148148
const char *SlicingBlockDevice::get_type() const
149149
{
150-
if (_bd != NULL) {
151-
return _bd->get_type();
152-
}
153-
154-
return NULL;
150+
return _bd->get_type();
155151
}
156152

157153
} // namespace mbed
158-

0 commit comments

Comments
 (0)