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,119 @@ 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 ;
112
+
113
+ Thread t1;
114
+ Thread t2;
115
+ Thread t3;
116
+ Thread t4;
117
+ t1.start (callback (file_fn, &block_size1));
118
+ t2.start (callback (file_fn, &block_size2));
119
+ t3.start (callback (file_fn, &block_size3));
120
+ t4.start (callback (file_fn, &block_size4));
121
+ t1.join ();
122
+ t2.join ();
123
+ t3.join ();
124
+ t4.join ();
125
+
126
+ return CaseNext;
127
+ }
128
+
129
+ static control_t file_5_threads (const size_t call_count)
130
+ {
131
+ size_t block_size1 = 4 ;
132
+ size_t block_size2 = 256 ;
133
+ size_t block_size3 = 1024 ;
134
+ size_t block_size4 = 4096 ;
135
+ size_t block_size5 = 4096 ;
113
136
114
137
Thread t1;
115
138
Thread t2;
116
139
Thread t3;
140
+ Thread t4;
141
+ Thread t5;
117
142
t1.start (callback (file_fn, &block_size1));
118
143
t2.start (callback (file_fn, &block_size2));
119
144
t3.start (callback (file_fn, &block_size3));
145
+ t4.start (callback (file_fn, &block_size4));
146
+ t5.start (callback (file_fn, &block_size5));
120
147
t1.join ();
121
148
t2.join ();
122
149
t3.join ();
150
+ t4.join ();
151
+ t5.join ();
123
152
124
153
return CaseNext;
125
154
}
126
155
127
- utest::v1::status_t greentea_setup (const size_t number_of_cases)
156
+ utest::v1::status_t test_setup_handler (const size_t number_of_cases)
128
157
{
129
158
GREENTEA_SETUP (10 * 60 , " default_auto" );
159
+
160
+ /* Format only once per each test run */
161
+ int format_err = fs.format (&sbd);
162
+ TEST_ASSERT_EQUAL_INT_MESSAGE (0 , format_err, " could not format block device" );
163
+
164
+ int mount_err = fs.mount (&sbd);
165
+ TEST_ASSERT_EQUAL_INT_MESSAGE (0 , mount_err, " could not mount block device" );
166
+
130
167
return greentea_test_setup_handler (number_of_cases);
131
168
}
132
169
170
+ void test_teardown_handler (const size_t passed, const size_t failed, const failure_t failure)
171
+ {
172
+ int mount_err = fs.unmount ();
173
+ TEST_ASSERT_EQUAL_INT_MESSAGE (0 , mount_err, " could not unmount block device" );
174
+
175
+ greentea_test_teardown_handler (passed, failed, failure);
176
+ }
177
+
178
+ utest::v1::status_t case_setup_handler (const Case *const source, const size_t index_of_case)
179
+ {
180
+ thread_counter = 0 ;
181
+
182
+ return greentea_case_setup_handler (source, index_of_case);
183
+ }
184
+
185
+ utest::v1::status_t case_teardown_handler (const Case *const source,
186
+ const size_t passed,
187
+ const size_t failed,
188
+ const failure_t reason)
189
+ {
190
+ char filename[255 ] = { 0 };
191
+
192
+ for (uint32_t idx = 1 ; idx <= thread_counter; idx++) {
193
+ snprintf (filename, 255 , " %s%" PRIu32 " %s" , fname_prefix, idx, fname_postfix);
194
+ int removal_err = fs.remove (filename);
195
+ TEST_ASSERT_EQUAL_INT_MESSAGE (0 , removal_err, " could not remove file" );
196
+ }
197
+
198
+ return greentea_case_teardown_handler (source, passed, failed, reason);
199
+ }
200
+
201
+
202
+
133
203
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),
204
+ Case (TEST_BLOCK_DEVICE_TYPE " +" TEST_FILESYSTEM_TYPE " 2 files, block size 4B/256B" ,
205
+ case_setup_handler,
206
+ file_2_threads,
207
+ case_teardown_handler),
208
+ Case (TEST_BLOCK_DEVICE_TYPE " +" TEST_FILESYSTEM_TYPE " 4 files, block size 4B/256B/1KiB/4KiB" ,
209
+ case_setup_handler,
210
+ file_4_threads,
211
+ case_teardown_handler),
212
+ Case (TEST_BLOCK_DEVICE_TYPE " +" TEST_FILESYSTEM_TYPE " 5 files, block size 4B/256B/1KiB/4KiB/4KiB" ,
213
+ case_setup_handler,
214
+ file_5_threads,
215
+ case_teardown_handler),
137
216
};
138
217
139
- Specification specification (greentea_setup , cases);
218
+ Specification specification (test_setup_handler , cases, test_teardown_handler );
140
219
141
220
int main ()
142
221
{
@@ -148,4 +227,3 @@ int main()
148
227
149
228
return !Harness::run (specification);
150
229
}
151
- #endif // !INTEGRATION_TESTS
0 commit comments