Skip to content

Commit 3c9f2be

Browse files
committed
Added test configuration support for block devices
Defaulted to HeapBlockDevice. Unfortunately this does mean that by default almost none of the tests are actually capable of running unless the dut has >512KB or RAM.
1 parent 5afec68 commit 3c9f2be

File tree

12 files changed

+137
-60
lines changed

12 files changed

+137
-60
lines changed

TESTS/filesystem/dirs/main.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ using namespace utest::v1;
1717
#endif
1818

1919
#ifndef MBED_TEST_BLOCKDEVICE
20-
#define MBED_TEST_BLOCKDEVICE SPIFBlockDevice
21-
#define MBED_TEST_BLOCKDEVICE_DECL SPIFBlockDevice bd(PTE2, PTE4, PTE1, PTE5)
20+
#error [NOT_SUPPORTED] Non-volatile block device required
2221
#endif
2322

2423
#ifndef MBED_TEST_BLOCKDEVICE_DECL

TESTS/filesystem/files/main.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ using namespace utest::v1;
1717
#endif
1818

1919
#ifndef MBED_TEST_BLOCKDEVICE
20-
#define MBED_TEST_BLOCKDEVICE SPIFBlockDevice
21-
#define MBED_TEST_BLOCKDEVICE_DECL SPIFBlockDevice bd(PTE2, PTE4, PTE1, PTE5)
20+
#error [NOT_SUPPORTED] Non-volatile block device required
2221
#endif
2322

2423
#ifndef MBED_TEST_BLOCKDEVICE_DECL

TESTS/filesystem/interspersed/main.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ using namespace utest::v1;
1717
#endif
1818

1919
#ifndef MBED_TEST_BLOCKDEVICE
20-
#define MBED_TEST_BLOCKDEVICE SPIFBlockDevice
21-
#define MBED_TEST_BLOCKDEVICE_DECL SPIFBlockDevice bd(PTE2, PTE4, PTE1, PTE5)
20+
#error [NOT_SUPPORTED] Non-volatile block device required
2221
#endif
2322

2423
#ifndef MBED_TEST_BLOCKDEVICE_DECL

TESTS/filesystem/seek/main.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ using namespace utest::v1;
1717
#endif
1818

1919
#ifndef MBED_TEST_BLOCKDEVICE
20-
#define MBED_TEST_BLOCKDEVICE SPIFBlockDevice
21-
#define MBED_TEST_BLOCKDEVICE_DECL SPIFBlockDevice bd(PTE2, PTE4, PTE1, PTE5)
20+
#error [NOT_SUPPORTED] Non-volatile block device required
2221
#endif
2322

2423
#ifndef MBED_TEST_BLOCKDEVICE_DECL

TESTS/filesystem_recovery/resilience/main.cpp

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,34 @@
2727

2828
#include "atomic_usage.h"
2929
#include "ObservingBlockDevice.h"
30-
#include "LittleFileSystem.h"
31-
3230

3331
using namespace utest::v1;
3432

35-
#define TEST_CYCLES 10
36-
#define TEST_BD_SIZE (16 * 1024)
33+
// test configuration
34+
#ifndef MBED_TEST_BLOCKDEVICE
35+
#define MBED_TEST_BLOCKDEVICE HeapBlockDevice
36+
#define MBED_TEST_BLOCKDEVICE_DECL MBED_TEST_BLOCKDEVICE bd(MBED_TEST_BLOCK_COUNT*512, 1, 1, 512)
37+
#endif
38+
39+
#ifndef MBED_TEST_BLOCKDEVICE_DECL
40+
#define MBED_TEST_BLOCKDEVICE_DECL MBED_TEST_BLOCKDEVICE bd
41+
#endif
42+
43+
#ifndef MBED_TEST_BLOCK_COUNT
44+
#define MBED_TEST_BLOCK_COUNT 64
45+
#endif
46+
47+
#ifndef MBED_TEST_CYCLES
48+
#define MBED_TEST_CYCLES 10
49+
#endif
50+
51+
// declarations
52+
#define STRINGIZE(x) STRINGIZE2(x)
53+
#define STRINGIZE2(x) #x
54+
#define INCLUDE(x) STRINGIZE(x.h)
55+
56+
#include INCLUDE(MBED_TEST_BLOCKDEVICE)
57+
3758

3859
/**
3960
* Check that the filesystem is valid after every change
@@ -44,18 +65,25 @@ using namespace utest::v1;
4465
*/
4566
void test_resilience()
4667
{
47-
HeapBlockDevice bd(TEST_BD_SIZE);
68+
MBED_TEST_BLOCKDEVICE_DECL;
69+
70+
// bring up to get block size
71+
bd.init();
72+
bd_size_t block_size = bd.get_erase_size();
73+
bd.deinit();
74+
75+
SlicingBlockDevice slice(&bd, 0, MBED_TEST_BLOCK_COUNT*block_size);
4876

4977
// Setup the test
50-
setup_atomic_operations(&bd, true);
78+
setup_atomic_operations(&slice, true);
5179

5280
// Run check on every write operation
53-
ObservingBlockDevice observer(&bd);
81+
ObservingBlockDevice observer(&slice);
5482
observer.attach(check_atomic_operations);
5583

5684
// Perform operations
57-
printf("Performing %i operations on flash\n", TEST_CYCLES);
58-
for (int i = 1; i <= TEST_CYCLES; i++) {
85+
printf("Performing %i operations on flash\n", MBED_TEST_CYCLES);
86+
for (int i = 1; i <= MBED_TEST_CYCLES; i++) {
5987
int64_t ret = perform_atomic_operations(&observer);
6088
TEST_ASSERT_EQUAL(i, ret);
6189
}
@@ -68,7 +96,7 @@ Case cases[] = {
6896

6997
utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
7098
{
71-
GREENTEA_SETUP(20, "default_auto");
99+
GREENTEA_SETUP(120, "default_auto");
72100
return greentea_test_setup_handler(number_of_cases);
73101
}
74102

TESTS/filesystem_recovery/resilience_functional/main.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,26 @@
3131

3232
#include <string.h>
3333

34-
3534
using namespace utest::v1;
3635

36+
37+
// test configuration
3738
#ifndef MBED_TEST_BLOCKDEVICE
38-
#define MBED_TEST_BLOCKDEVICE SPIFBlockDevice
39-
#define MBED_TEST_BLOCKDEVICE_DECL SPIFBlockDevice bd(PTE2, PTE4, PTE1, PTE5)
39+
#error [NOT_SUPPORTED] Non-volatile block device required for resilience_functional tests
4040
#endif
4141

4242
#ifndef MBED_TEST_BLOCKDEVICE_DECL
4343
#define MBED_TEST_BLOCKDEVICE_DECL MBED_TEST_BLOCKDEVICE bd
4444
#endif
4545

46+
#ifndef MBED_TEST_BLOCK_COUNT
47+
#define MBED_TEST_BLOCK_COUNT 64
48+
#endif
49+
50+
#ifndef MBED_TEST_CYCLES
51+
#define MBED_TEST_CYCLES 10
52+
#endif
53+
4654
// declarations
4755
#define STRINGIZE(x) STRINGIZE2(x)
4856
#define STRINGIZE2(x) #x
@@ -94,7 +102,7 @@ static cmd_status_t handle_command(const char *key, const char *value)
94102

95103
int main()
96104
{
97-
GREENTEA_SETUP(60, "unexpected_reset");
105+
GREENTEA_SETUP(120, "unexpected_reset");
98106

99107
static char _key[10 + 1] = {};
100108
static char _value[128 + 1] = {};

TESTS/filesystem_recovery/wear_leveling/main.cpp

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,50 @@
2727

2828
#include "atomic_usage.h"
2929
#include "ExhaustibleBlockDevice.h"
30-
#include "LittleFileSystem.h"
30+
#include "SlicingBlockDevice.h"
3131

3232
using namespace utest::v1;
3333

34-
#define ERASE_CYCLES 20
35-
#define TEST_BD_SIZE (8 * 1024)
34+
// test configuration
35+
#ifndef MBED_TEST_BLOCKDEVICE
36+
#define MBED_TEST_BLOCKDEVICE HeapBlockDevice
37+
#define MBED_TEST_BLOCKDEVICE_DECL MBED_TEST_BLOCKDEVICE bd(MBED_TEST_BLOCK_COUNT*512, 1, 1, 512)
38+
#endif
3639

37-
static uint32_t test_wear_leveling_size(uint32_t bd_size)
40+
#ifndef MBED_TEST_BLOCKDEVICE_DECL
41+
#define MBED_TEST_BLOCKDEVICE_DECL MBED_TEST_BLOCKDEVICE bd
42+
#endif
43+
44+
#ifndef MBED_TEST_BLOCK_COUNT
45+
#define MBED_TEST_BLOCK_COUNT 64
46+
#endif
47+
48+
#ifndef MBED_TEST_ERASE_CYCLES
49+
#define MBED_TEST_ERASE_CYCLES 100
50+
#endif
51+
52+
// declarations
53+
#define STRINGIZE(x) STRINGIZE2(x)
54+
#define STRINGIZE2(x) #x
55+
#define INCLUDE(x) STRINGIZE(x.h)
56+
57+
#include INCLUDE(MBED_TEST_BLOCKDEVICE)
58+
59+
60+
static uint32_t test_wear_leveling_size(uint32_t block_count)
3861
{
39-
HeapBlockDevice hbd(bd_size, 1, 1, 512);
40-
ExhaustibleBlockDevice ebd(&hbd, ERASE_CYCLES);
62+
MBED_TEST_BLOCKDEVICE_DECL;
63+
64+
// bring up to get block size
65+
bd.init();
66+
bd_size_t block_size = bd.get_erase_size();
67+
bd.deinit();
68+
69+
SlicingBlockDevice slice(&bd, 0, block_count*block_size);
70+
ExhaustibleBlockDevice ebd(&slice, MBED_TEST_ERASE_CYCLES);
4171

42-
printf("Testing size %lu\n", bd_size);
72+
printf("Testing size %llu bytes (%lux%llu) blocks\n",
73+
block_count*block_size, block_count, block_size);
4374
setup_atomic_operations(&ebd, true);
4475

4576
int64_t cycles = 0;
@@ -70,8 +101,8 @@ static uint32_t test_wear_leveling_size(uint32_t bd_size)
70101
*/
71102
void test_wear_leveling()
72103
{
73-
uint32_t cycles_1 = test_wear_leveling_size(TEST_BD_SIZE * 1);
74-
uint32_t cycles_2 = test_wear_leveling_size(TEST_BD_SIZE * 2);
104+
uint32_t cycles_1 = test_wear_leveling_size(MBED_TEST_BLOCK_COUNT / 2);
105+
uint32_t cycles_2 = test_wear_leveling_size(MBED_TEST_BLOCK_COUNT / 1);
75106
TEST_ASSERT(cycles_2 > cycles_1 * 2);
76107
}
77108

@@ -81,7 +112,7 @@ Case cases[] = {
81112

82113
utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
83114
{
84-
GREENTEA_SETUP(60, "default_auto");
115+
GREENTEA_SETUP(120, "default_auto");
85116
return greentea_test_setup_handler(number_of_cases);
86117
}
87118

TESTS/filesystem_retarget/dirs/main.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ using namespace utest::v1;
1717
#endif
1818

1919
#ifndef MBED_TEST_BLOCKDEVICE
20-
#define MBED_TEST_BLOCKDEVICE SPIFBlockDevice
21-
#define MBED_TEST_BLOCKDEVICE_DECL SPIFBlockDevice bd(PTE2, PTE4, PTE1, PTE5)
20+
#error [NOT_SUPPORTED] Non-volatile block device required
2221
#endif
2322

2423
#ifndef MBED_TEST_BLOCKDEVICE_DECL

TESTS/filesystem_retarget/files/main.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ using namespace utest::v1;
1717
#endif
1818

1919
#ifndef MBED_TEST_BLOCKDEVICE
20-
#define MBED_TEST_BLOCKDEVICE SPIFBlockDevice
21-
#define MBED_TEST_BLOCKDEVICE_DECL SPIFBlockDevice bd(PTE2, PTE4, PTE1, PTE5)
20+
#error [NOT_SUPPORTED] Non-volatile block device required
2221
#endif
2322

2423
#ifndef MBED_TEST_BLOCKDEVICE_DECL

TESTS/filesystem_retarget/interspersed/main.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ using namespace utest::v1;
1717
#endif
1818

1919
#ifndef MBED_TEST_BLOCKDEVICE
20-
#define MBED_TEST_BLOCKDEVICE SPIFBlockDevice
21-
#define MBED_TEST_BLOCKDEVICE_DECL SPIFBlockDevice bd(PTE2, PTE4, PTE1, PTE5)
20+
#error [NOT_SUPPORTED] Non-volatile block device required
2221
#endif
2322

2423
#ifndef MBED_TEST_BLOCKDEVICE_DECL

0 commit comments

Comments
 (0)