@@ -133,42 +133,36 @@ static void test_spiffs_setup(void)
133133#if SPIFFS_HAL_CALLBACK_EXTRA == 1
134134 spiffs_desc .dev = _dev ;
135135#endif
136+ vfs_mount (& _test_spiffs_mount );
136137}
137138
138139static void test_spiffs_teardown (void )
139140{
140- vfs_mount (& _test_spiffs_mount );
141141 vfs_unlink ("/test-spiffs/test.txt" );
142142 vfs_unlink ("/test-spiffs/test0.txt" );
143143 vfs_unlink ("/test-spiffs/test1.txt" );
144144 vfs_unlink ("/test-spiffs/a/test2.txt" );
145145 vfs_umount (& _test_spiffs_mount );
146146}
147147
148- static void test_spiffs_mount_umount (void )
148+ static void tests_spiffs_mount_umount (void )
149149{
150150 int res ;
151- res = vfs_mount (& _test_spiffs_mount );
151+ res = vfs_umount (& _test_spiffs_mount );
152152 TEST_ASSERT_EQUAL_INT (0 , res );
153153
154- res = vfs_umount (& _test_spiffs_mount );
154+ res = vfs_mount (& _test_spiffs_mount );
155155 TEST_ASSERT_EQUAL_INT (0 , res );
156156}
157157
158158static void tests_spiffs_open_close (void )
159159{
160160 int res ;
161- res = vfs_mount (& _test_spiffs_mount );
162- TEST_ASSERT_EQUAL_INT (0 , res );
163-
164161 res = vfs_open ("/test-spiffs/test.txt" , O_CREAT | O_RDWR , 0 );
165162 TEST_ASSERT (res >= 0 );
166163
167164 res = vfs_close (res );
168165 TEST_ASSERT_EQUAL_INT (0 , res );
169-
170- res = vfs_umount (& _test_spiffs_mount );
171- TEST_ASSERT_EQUAL_INT (0 , res );
172166}
173167
174168static void tests_spiffs_write (void )
@@ -177,9 +171,6 @@ static void tests_spiffs_write(void)
177171 char r_buf [2 * sizeof (buf )];
178172
179173 int res ;
180- res = vfs_mount (& _test_spiffs_mount );
181- TEST_ASSERT_EQUAL_INT (0 , res );
182-
183174 int fd = vfs_open ("/test-spiffs/test.txt" , O_CREAT | O_RDWR , 0 );
184175 TEST_ASSERT (fd >= 0 );
185176
@@ -205,55 +196,13 @@ static void tests_spiffs_write(void)
205196
206197 res = vfs_close (fd );
207198 TEST_ASSERT_EQUAL_INT (0 , res );
208-
209- res = vfs_umount (& _test_spiffs_mount );
210- TEST_ASSERT_EQUAL_INT (0 , res );
211- }
212-
213- static void tests_spiffs_write2 (void )
214- {
215- char buf [256 ];
216- /*char r_buf[sizeof(buf) + 2];*/
217-
218- for (int i = 0 ; i < 256 ; i ++ ) {
219- buf [i ] = 'A' + (i % 30 );
220- }
221-
222- int mp = vfs_mount (& _test_spiffs_mount );
223- TEST_ASSERT (mp >= 0 );
224-
225- int res ;
226- for (int j = 0 ; j < 5 ; j ++ ) {
227- int fd = vfs_open ("/test-spiffs/test.txt" , O_CREAT | O_RDWR , 0 );
228- TEST_ASSERT (fd >= 0 );
229-
230- for (int i = 0 ; i < 128 ; i ++ ) {
231- res = vfs_write (fd , buf , sizeof (buf ));
232- TEST_ASSERT_EQUAL_INT (sizeof (buf ), res );
233- }
234-
235- res = vfs_lseek (fd , 0 , SEEK_SET );
236- TEST_ASSERT_EQUAL_INT (0 , res );
237-
238- res = vfs_close (fd );
239- TEST_ASSERT_EQUAL_INT (0 , res );
240-
241- res = vfs_unlink ("/test-spiffs/test.txt" );
242- TEST_ASSERT_EQUAL_INT (0 , res );
243- }
244-
245- res = vfs_umount (& _test_spiffs_mount );
246- TEST_ASSERT (res >= 0 );
247199}
248200
249201static void tests_spiffs_unlink (void )
250202{
251203 const char buf [] = "TESTSTRING" ;
252204
253205 int res ;
254- res = vfs_mount (& _test_spiffs_mount );
255- TEST_ASSERT_EQUAL_INT (0 , res );
256-
257206 int fd = vfs_open ("/test-spiffs/test.txt" , O_CREAT | O_RDWR , 0 );
258207 TEST_ASSERT (fd >= 0 );
259208
@@ -265,9 +214,6 @@ static void tests_spiffs_unlink(void)
265214
266215 res = vfs_unlink ("/test-spiffs/test.txt" );
267216 TEST_ASSERT_EQUAL_INT (0 , res );
268-
269- res = vfs_umount (& _test_spiffs_mount );
270- TEST_ASSERT_EQUAL_INT (0 , res );
271217}
272218
273219static void tests_spiffs_readdir (void )
@@ -277,9 +223,6 @@ static void tests_spiffs_readdir(void)
277223 const char buf2 [] = "TESTSTRINGSTRING" ;
278224
279225 int res ;
280- res = vfs_mount (& _test_spiffs_mount );
281- TEST_ASSERT_EQUAL_INT (0 , res );
282-
283226 int fd0 = vfs_open ("/test-spiffs/test0.txt" , O_CREAT | O_RDWR , 0 );
284227 TEST_ASSERT (fd0 >= 0 );
285228
@@ -311,15 +254,17 @@ static void tests_spiffs_readdir(void)
311254 res = vfs_opendir (& dirp , "/test-spiffs" );
312255
313256 vfs_dirent_t entry ;
314- for (int i = 0 ; i < 3 ; i ++ ) {
257+ int nb_files = 0 ;
258+ do {
315259 res = vfs_readdir (& dirp , & entry );
316- TEST_ASSERT_EQUAL_INT (1 , res );
317- TEST_ASSERT (strcmp ("/test0.txt" , & (entry .d_name [0 ])) == 0 ||
318- strcmp ("/test1.txt" , & (entry .d_name [0 ])) == 0 ||
319- strcmp ("/a/test2.txt" , & (entry .d_name [0 ])) == 0 );
320- }
260+ if (res == 1 && (strcmp ("/test0.txt" , & (entry .d_name [0 ])) == 0 ||
261+ strcmp ("/test1.txt" , & (entry .d_name [0 ])) == 0 ||
262+ strcmp ("/a/test2.txt" , & (entry .d_name [0 ])) == 0 )) {
263+ nb_files ++ ;
264+ }
265+ } while (res == 1 );
321266
322- res = vfs_readdir ( & dirp , & entry );
267+ TEST_ASSERT_EQUAL_INT ( 3 , nb_files );
323268 TEST_ASSERT_EQUAL_INT (0 , res );
324269
325270 res = vfs_closedir (& dirp );
@@ -333,9 +278,6 @@ static void tests_spiffs_readdir(void)
333278
334279 res = vfs_unlink ("/test-spiffs/a/test2.txt" );
335280 TEST_ASSERT_EQUAL_INT (0 , res );
336-
337- res = vfs_umount (& _test_spiffs_mount );
338- TEST_ASSERT_EQUAL_INT (0 , res );
339281}
340282
341283static void tests_spiffs_rename (void )
@@ -344,9 +286,6 @@ static void tests_spiffs_rename(void)
344286 char r_buf [2 * sizeof (buf )];
345287
346288 int res ;
347- res = vfs_mount (& _test_spiffs_mount );
348- TEST_ASSERT_EQUAL_INT (0 , res );
349-
350289 int fd = vfs_open ("/test-spiffs/test.txt" , O_CREAT | O_RDWR , 0 );
351290 TEST_ASSERT (fd >= 0 );
352291
@@ -384,21 +323,17 @@ static void tests_spiffs_rename(void)
384323
385324 res = vfs_unlink ("/test-spiffs/test1.txt" );
386325 TEST_ASSERT_EQUAL_INT (0 , res );
387-
388- res = vfs_umount (& _test_spiffs_mount );
389- TEST_ASSERT_EQUAL_INT (0 , res );
390326}
391327
392328Test * tests_spiffs_tests (void )
393329{
394330 EMB_UNIT_TESTFIXTURES (fixtures ) {
395- new_TestFixture (test_spiffs_mount_umount ),
331+ new_TestFixture (tests_spiffs_mount_umount ),
396332 new_TestFixture (tests_spiffs_open_close ),
397333 new_TestFixture (tests_spiffs_write ),
398334 new_TestFixture (tests_spiffs_unlink ),
399335 new_TestFixture (tests_spiffs_readdir ),
400336 new_TestFixture (tests_spiffs_rename ),
401- new_TestFixture (tests_spiffs_write2 ),
402337 };
403338
404339 EMB_UNIT_TESTCALLER (spiffs_tests , test_spiffs_setup , test_spiffs_teardown , fixtures );
0 commit comments