Skip to content

Commit 40130cc

Browse files
committed
bd: Adopted the block device api in the SDBlockDevice
1 parent 5369673 commit 40130cc

File tree

4 files changed

+792
-3
lines changed

4 files changed

+792
-3
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include "mbed.h"
2+
#include "greentea-client/test_env.h"
3+
#include "unity.h"
4+
#include "utest.h"
5+
6+
#include "HeapBlockDevice.h"
7+
#include <stdlib.h>
8+
9+
using namespace utest::v1;
10+
11+
#define BLOCK_SIZE 512
12+
uint8_t write_block[BLOCK_SIZE];
13+
uint8_t read_block[BLOCK_SIZE];
14+
15+
16+
void test_read_write() {
17+
HeapBlockDevice bd(16*BLOCK_SIZE, BLOCK_SIZE);
18+
19+
int err = bd.init();
20+
TEST_ASSERT_EQUAL(0, err);
21+
22+
// Fill with random sequence
23+
srand(1);
24+
for (int i = 0; i < BLOCK_SIZE; i++) {
25+
write_block[i] = 0xff & rand();
26+
}
27+
28+
// Write, sync, and read the block
29+
err = bd.write(write_block, 0, BLOCK_SIZE);
30+
TEST_ASSERT_EQUAL(0, err);
31+
32+
err = bd.read(read_block, 0, BLOCK_SIZE);
33+
TEST_ASSERT_EQUAL(0, err);
34+
35+
// Check that the data was unmodified
36+
srand(1);
37+
for (int i = 0; i < BLOCK_SIZE; i++) {
38+
TEST_ASSERT_EQUAL(0xff & rand(), read_block[i]);
39+
}
40+
41+
err = bd.deinit();
42+
TEST_ASSERT_EQUAL(0, err);
43+
}
44+
45+
46+
// Test setup
47+
utest::v1::status_t test_setup(const size_t number_of_cases) {
48+
GREENTEA_SETUP(10, "default_auto");
49+
return verbose_test_setup_handler(number_of_cases);
50+
}
51+
52+
Case cases[] = {
53+
Case("Testing read write of a block", test_read_write),
54+
};
55+
56+
Specification specification(test_setup, cases);
57+
58+
int main() {
59+
return !Harness::run(specification);
60+
}

features/filesystem/bd/HeapBlockDevice.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ class HeapBlockDevice : public BlockDevice {
5858
*
5959
* @return 0 on success or a negative error code on failure
6060
*/
61-
virtual bd_error_t init() = 0;
61+
virtual bd_error_t init();
6262

6363
/** Deinitialize a block device
6464
*
6565
* @return 0 on success or a negative error code on failure
6666
*/
67-
virtual bd_error_t deinit() = 0;
67+
virtual bd_error_t deinit();
6868

6969
/** Read blocks from a block device
7070
*
@@ -73,7 +73,7 @@ class HeapBlockDevice : public BlockDevice {
7373
* @param size Size to read in bytes, must be a multiple of read block size
7474
* @return 0 on success, negative error code on failure
7575
*/
76-
virtual bd_error_t read(void *buffer, bd_addr_t addr, bd_size_t size) = 0;
76+
virtual bd_error_t read(void *buffer, bd_addr_t addr, bd_size_t size);
7777

7878
/** Program blocks to a block device
7979
*

0 commit comments

Comments
 (0)