Skip to content

Commit 4f3aabc

Browse files
committed
Reshuffled memory usage for heap block device tests on small targets
Revert removal of printfs. Make the block device size smaller.
1 parent c82c40f commit 4f3aabc

File tree

1 file changed

+30
-1
lines changed
  • features/TESTS/filesystem/heap_block_device

1 file changed

+30
-1
lines changed

features/TESTS/filesystem/heap_block_device/main.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@
2424
using namespace utest::v1;
2525

2626
#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
2732
#define TEST_BLOCK_COUNT 10
28-
#define TEST_BLOCK_DEVICE_SIZE 16*TEST_BLOCK_SIZE
2933
#define TEST_ERROR_MASK 16
3034

3135
const struct {
@@ -47,9 +51,12 @@ void test_read_write() {
4751
TEST_ASSERT_EQUAL(0, err);
4852

4953
for (unsigned a = 0; a < sizeof(ATTRS)/sizeof(ATTRS[0]); a++) {
54+
static const char *prefixes[] = {"", "k", "M", "G"};
5055
for (int i = 3; i >= 0; i--) {
5156
bd_size_t size = (bd.*ATTRS[a].method)();
5257
if (size >= (1ULL << 10*i)) {
58+
printf("%s: %llu%sbytes (%llubytes)\n",
59+
ATTRS[a].name, size >> 10*i, prefixes[i], size);
5360
break;
5461
}
5562
}
@@ -59,6 +66,7 @@ void test_read_write() {
5966
uint8_t *write_block = new uint8_t[block_size];
6067
uint8_t *read_block = new uint8_t[block_size];
6168
uint8_t *error_mask = new uint8_t[TEST_ERROR_MASK];
69+
unsigned addrwidth = ceil(log(float(bd.size()-1)) / log(float(16)))+1;
6270

6371
for (int b = 0; b < TEST_BLOCK_COUNT; b++) {
6472
// Find a random block
@@ -74,15 +82,30 @@ void test_read_write() {
7482
write_block[i] = 0xff & rand();
7583
}
7684

85+
// erase, program, and read the block
86+
printf("test %0*llx:%llu...\n", addrwidth, block, block_size);
87+
7788
err = bd.erase(block, block_size);
7889
TEST_ASSERT_EQUAL(0, err);
7990

8091
err = bd.program(write_block, block, block_size);
8192
TEST_ASSERT_EQUAL(0, err);
8293

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+
83100
err = bd.read(read_block, block, block_size);
84101
TEST_ASSERT_EQUAL(0, err);
85102

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+
86109
// Find error mask for debugging
87110
memset(error_mask, 0, TEST_ERROR_MASK);
88111
bd_size_t error_scale = block_size / (TEST_ERROR_MASK*8);
@@ -96,6 +119,12 @@ void test_read_write() {
96119
}
97120
}
98121

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+
99128
// Check that the data was unmodified
100129
srand(seed);
101130
for (bd_size_t i = 0; i < block_size; i++) {

0 commit comments

Comments
 (0)