24
24
using namespace utest ::v1;
25
25
26
26
#define TEST_BLOCK_SIZE 512
27
+ #if MBED_SMALL_TARGET
28
+ # define TEST_BLOCK_DEVICE_SIZE 8 *TEST_BLOCK_SIZE
29
+ #else
30
+ # define TEST_BLOCK_DEVICE_SIZE 16 *TEST_BLOCK_SIZE
31
+ #endif
27
32
#define TEST_BLOCK_COUNT 10
28
- #define TEST_BLOCK_DEVICE_SIZE 16 *TEST_BLOCK_SIZE
29
33
#define TEST_ERROR_MASK 16
30
34
31
35
const struct {
@@ -47,9 +51,12 @@ void test_read_write() {
47
51
TEST_ASSERT_EQUAL (0 , err);
48
52
49
53
for (unsigned a = 0 ; a < sizeof (ATTRS)/sizeof (ATTRS[0 ]); a++) {
54
+ static const char *prefixes[] = {" " , " k" , " M" , " G" };
50
55
for (int i = 3 ; i >= 0 ; i--) {
51
56
bd_size_t size = (bd.*ATTRS[a].method )();
52
57
if (size >= (1ULL << 10 *i)) {
58
+ printf (" %s: %llu%sbytes (%llubytes)\n " ,
59
+ ATTRS[a].name , size >> 10 *i, prefixes[i], size);
53
60
break ;
54
61
}
55
62
}
@@ -59,6 +66,7 @@ void test_read_write() {
59
66
uint8_t *write_block = new uint8_t [block_size];
60
67
uint8_t *read_block = new uint8_t [block_size];
61
68
uint8_t *error_mask = new uint8_t [TEST_ERROR_MASK];
69
+ unsigned addrwidth = ceil (log (float (bd.size ()-1 )) / log (float (16 )))+1 ;
62
70
63
71
for (int b = 0 ; b < TEST_BLOCK_COUNT; b++) {
64
72
// Find a random block
@@ -74,15 +82,30 @@ void test_read_write() {
74
82
write_block[i] = 0xff & rand ();
75
83
}
76
84
85
+ // erase, program, and read the block
86
+ printf (" test %0*llx:%llu...\n " , addrwidth, block, block_size);
87
+
77
88
err = bd.erase (block, block_size);
78
89
TEST_ASSERT_EQUAL (0 , err);
79
90
80
91
err = bd.program (write_block, block, block_size);
81
92
TEST_ASSERT_EQUAL (0 , err);
82
93
94
+ printf (" write %0*llx:%llu " , addrwidth, block, block_size);
95
+ for (int i = 0 ; i < 16 ; i++) {
96
+ printf (" %02x" , write_block[i]);
97
+ }
98
+ printf (" ...\n " );
99
+
83
100
err = bd.read (read_block, block, block_size);
84
101
TEST_ASSERT_EQUAL (0 , err);
85
102
103
+ printf (" read %0*llx:%llu " , addrwidth, block, block_size);
104
+ for (int i = 0 ; i < 16 ; i++) {
105
+ printf (" %02x" , read_block[i]);
106
+ }
107
+ printf (" ...\n " );
108
+
86
109
// Find error mask for debugging
87
110
memset (error_mask, 0 , TEST_ERROR_MASK);
88
111
bd_size_t error_scale = block_size / (TEST_ERROR_MASK*8 );
@@ -96,6 +119,12 @@ void test_read_write() {
96
119
}
97
120
}
98
121
122
+ printf (" error %0*llx:%llu " , addrwidth, block, block_size);
123
+ for (int i = 0 ; i < 16 ; i++) {
124
+ printf (" %02x" , error_mask[i]);
125
+ }
126
+ printf (" \n " );
127
+
99
128
// Check that the data was unmodified
100
129
srand (seed);
101
130
for (bd_size_t i = 0 ; i < block_size; i++) {
0 commit comments