22
22
*/
23
23
24
24
#if !INTEGRATION_TESTS
25
- #error [NOT_SUPPORTED] integration tests not enabled for this target
25
+ #error [NOT_SUPPORTED] integration tests not enabled
26
26
#elif !MBED_CONF_RTOS_PRESENT
27
27
#error [NOT_SUPPORTED] integration tests require RTOS
28
- #else
28
+ #endif
29
29
30
30
#include " mbed.h"
31
- #include " FATFileSystem.h"
32
31
#include " LittleFileSystem.h"
33
32
#include " utest/utest.h"
34
33
#include " unity/unity.h"
@@ -59,38 +58,38 @@ void led_thread()
59
58
#endif
60
59
61
60
BlockDevice *bd = BlockDevice::get_default_instance();
62
- SlicingBlockDevice sd (bd, 0 , MBED_CONF_APP_TESTS_FS_SIZE);
63
- #if TEST_USE_FILESYSTEM == FS_FAT
64
- FATFileSystem fs (" sd" );
65
- #else
61
+ SlicingBlockDevice sbd (bd, 0 , MBED_CONF_APP_TESTS_FS_SIZE);
66
62
LittleFileSystem fs (" sd" );
67
- #endif
68
63
69
- static control_t test_format (const size_t call_count)
70
- {
71
- int format_err = fs.format (&sd);
72
- TEST_ASSERT_EQUAL_INT_MESSAGE (0 , format_err, " could not format block device" );
64
+ constexpr char fname_prefix[] = " mbed-file-test-" ;
65
+ constexpr char fname_postfix[] = " .txt" ;
73
66
74
- int mount_err = fs.mount (&sd);
75
- TEST_ASSERT_EQUAL_INT_MESSAGE (0 , mount_err, " could not mount block device" );
67
+ static uint32_t thread_counter = 0 ;
76
68
77
- return CaseNext;
69
+ void print_memory_info ()
70
+ {
71
+ #if defined MBED_HEAP_STATS_ENABLED && MBED_MEM_TRACING_ENABLED
72
+ // Grab the heap statistics
73
+ mbed_stats_heap_t heap_stats;
74
+ mbed_stats_heap_get (&heap_stats);
75
+ printf (" Heap size: %lu / %lu bytes\r\n " ,
76
+ heap_stats.current_size ,
77
+ heap_stats.reserved_size );
78
+ #endif
78
79
}
79
80
80
- static uint32_t thread_counter = 0 ;
81
-
82
81
void file_fn (size_t *block_size)
83
82
{
84
83
uint32_t thread_id = core_util_atomic_incr_u32 (&thread_counter, 1 );
85
84
char filename[255 ] = { 0 };
86
- snprintf (filename, 255 , " mbed-file-test-% " PRIu32 " .txt " , thread_id);
85
+ snprintf (filename, 255 , " %s% " PRIu32 " %s " , fname_prefix, thread_id, fname_postfix );
87
86
file_test_write (filename, 0 , story, sizeof (story), *block_size);
88
87
file_test_read (filename, 0 , story, sizeof (story), *block_size);
88
+ print_memory_info ();
89
89
}
90
90
91
91
static control_t file_2_threads (const size_t call_count)
92
92
{
93
- thread_counter = 0 ;
94
93
size_t block_size1 = 4 ;
95
94
size_t block_size2 = 256 ;
96
95
@@ -104,39 +103,88 @@ static control_t file_2_threads(const size_t call_count)
104
103
return CaseNext;
105
104
}
106
105
107
- static control_t file_3_threads (const size_t call_count)
106
+ static control_t file_4_threads (const size_t call_count)
108
107
{
109
- thread_counter = 0 ;
110
- size_t block_size1 = 256 ;
111
- size_t block_size2 = 1024 ;
112
- size_t block_size3 = 4096 ;
108
+ size_t block_size1 = 4 ;
109
+ size_t block_size2 = 256 ;
110
+ size_t block_size3 = 1024 ;
111
+ size_t block_size4 = 4096 ;
113
112
114
113
Thread t1;
115
114
Thread t2;
116
115
Thread t3;
116
+ Thread t4;
117
117
t1.start (callback (file_fn, &block_size1));
118
118
t2.start (callback (file_fn, &block_size2));
119
119
t3.start (callback (file_fn, &block_size3));
120
+ t4.start (callback (file_fn, &block_size4));
120
121
t1.join ();
121
122
t2.join ();
122
123
t3.join ();
124
+ t4.join ();
123
125
124
126
return CaseNext;
125
127
}
126
128
127
- utest::v1::status_t greentea_setup (const size_t number_of_cases)
129
+ utest::v1::status_t test_setup_handler (const size_t number_of_cases)
128
130
{
129
131
GREENTEA_SETUP (10 * 60 , " default_auto" );
132
+
133
+ /* Format only once per each test run */
134
+ int format_err = fs.format (&sbd);
135
+ TEST_ASSERT_EQUAL_INT_MESSAGE (0 , format_err, " could not format block device" );
136
+
137
+ int mount_err = fs.mount (&sbd);
138
+ TEST_ASSERT_EQUAL_INT_MESSAGE (0 , mount_err, " could not mount block device" );
139
+
130
140
return greentea_test_setup_handler (number_of_cases);
131
141
}
132
142
143
+ void test_teardown_handler (const size_t passed, const size_t failed, const failure_t failure)
144
+ {
145
+ int mount_err = fs.unmount ();
146
+ TEST_ASSERT_EQUAL_INT_MESSAGE (0 , mount_err, " could not unmount block device" );
147
+
148
+ greentea_test_teardown_handler (passed, failed, failure);
149
+ }
150
+
151
+ utest::v1::status_t case_setup_handler (const Case *const source, const size_t index_of_case)
152
+ {
153
+ thread_counter = 0 ;
154
+
155
+ return greentea_case_setup_handler (source, index_of_case);
156
+ }
157
+
158
+ utest::v1::status_t case_teardown_handler (const Case *const source,
159
+ const size_t passed,
160
+ const size_t failed,
161
+ const failure_t reason)
162
+ {
163
+ char filename[255 ] = { 0 };
164
+
165
+ for (uint32_t idx = 1 ; idx <= thread_counter; idx++) {
166
+ snprintf (filename, 255 , " %s%" PRIu32 " %s" , fname_prefix, idx, fname_postfix);
167
+ int removal_err = fs.remove (filename);
168
+ TEST_ASSERT_EQUAL_INT_MESSAGE (0 , removal_err, " could not remove file" );
169
+ }
170
+
171
+ return greentea_case_teardown_handler (source, passed, failed, reason);
172
+ }
173
+
174
+
175
+
133
176
Case cases[] = {
134
- Case (TEST_BLOCK_DEVICE_TYPE " +" TEST_FILESYSTEM_TYPE " format" , test_format),
135
- Case (TEST_BLOCK_DEVICE_TYPE " +" TEST_FILESYSTEM_TYPE " 2 files, buff 4b/256b" , file_2_threads),
136
- Case (TEST_BLOCK_DEVICE_TYPE " +" TEST_FILESYSTEM_TYPE " 3 files, buff 256b/1kb/4kb" , file_3_threads),
177
+ Case (TEST_BLOCK_DEVICE_TYPE " +" TEST_FILESYSTEM_TYPE " 2 files, block size 4B/256B" ,
178
+ case_setup_handler,
179
+ file_2_threads,
180
+ case_teardown_handler),
181
+ Case (TEST_BLOCK_DEVICE_TYPE " +" TEST_FILESYSTEM_TYPE " 4 files, block size 4B/256B/1KiB/4KiB" ,
182
+ case_setup_handler,
183
+ file_4_threads,
184
+ case_teardown_handler),
137
185
};
138
186
139
- Specification specification (greentea_setup , cases);
187
+ Specification specification (test_setup_handler , cases, test_teardown_handler );
140
188
141
189
int main ()
142
190
{
@@ -148,4 +196,3 @@ int main()
148
196
149
197
return !Harness::run (specification);
150
198
}
151
- #endif // !INTEGRATION_TESTS
0 commit comments