init

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2017 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #include "mbed.h"
00017 #include "greentea-client/test_env.h"
00018 #include "unity.h"
00019 #include "utest.h"
00020 #include <stdlib.h>
00021 #include <errno.h>
00022 
00023 using namespace utest::v1;
00024 
00025 // test configuration
00026 #ifndef MBED_TEST_FILESYSTEM
00027 #define MBED_TEST_FILESYSTEM LittleFileSystem
00028 #endif
00029 
00030 #ifndef MBED_TEST_FILESYSTEM_DECL
00031 #define MBED_TEST_FILESYSTEM_DECL MBED_TEST_FILESYSTEM fs("fs")
00032 #endif
00033 
00034 #ifndef MBED_TEST_BLOCKDEVICE
00035 #error [NOT_SUPPORTED] Non-volatile block device required
00036 #endif
00037 
00038 #ifndef MBED_TEST_BLOCKDEVICE_DECL
00039 #define MBED_TEST_BLOCKDEVICE_DECL MBED_TEST_BLOCKDEVICE bd
00040 #endif
00041 
00042 #ifndef MBED_TEST_FILES
00043 #define MBED_TEST_FILES 4
00044 #endif
00045 
00046 #ifndef MBED_TEST_DIRS
00047 #define MBED_TEST_DIRS 4
00048 #endif
00049 
00050 #ifndef MBED_TEST_BUFFER
00051 #define MBED_TEST_BUFFER 8192
00052 #endif
00053 
00054 #ifndef MBED_TEST_TIMEOUT
00055 #define MBED_TEST_TIMEOUT 480
00056 #endif
00057 
00058 
00059 // declarations
00060 #define STRINGIZE(x) STRINGIZE2(x)
00061 #define STRINGIZE2(x) #x
00062 #define INCLUDE(x) STRINGIZE(x.h)
00063 
00064 #include INCLUDE(MBED_TEST_FILESYSTEM)
00065 #include INCLUDE(MBED_TEST_BLOCKDEVICE)
00066 
00067 MBED_TEST_FILESYSTEM_DECL;
00068 MBED_TEST_BLOCKDEVICE_DECL;
00069 
00070 Dir dir[MBED_TEST_DIRS];
00071 File file[MBED_TEST_FILES];
00072 DIR *dd[MBED_TEST_DIRS];
00073 FILE *fd[MBED_TEST_FILES];
00074 struct dirent ent;
00075 struct dirent *ed;
00076 size_t size;
00077 uint8_t buffer[MBED_TEST_BUFFER];
00078 uint8_t rbuffer[MBED_TEST_BUFFER];
00079 uint8_t wbuffer[MBED_TEST_BUFFER];
00080 
00081 
00082 // tests
00083 
00084 void test_seek_tests()
00085 {
00086     int res = bd.init();
00087     TEST_ASSERT_EQUAL(0, res);
00088 
00089     {
00090         res = MBED_TEST_FILESYSTEM::format(&bd);
00091         TEST_ASSERT_EQUAL(0, res);
00092         res = fs.mount(&bd);
00093         TEST_ASSERT_EQUAL(0, res);
00094         res = fs.mkdir("hello", 0777);
00095         TEST_ASSERT_EQUAL(0, res);
00096         for (int i = 0; i < 132; i++) {
00097             sprintf((char*)buffer, "hello/kitty%d", i);
00098             res = file[0].open(&fs, (char*)buffer,
00099                     O_WRONLY | O_CREAT | O_APPEND);
00100             TEST_ASSERT_EQUAL(0, res);
00101     
00102             size = strlen("kittycatcat");
00103             memcpy(buffer, "kittycatcat", size);
00104             for (int j = 0; j < 132; j++) {
00105                 file[0].write(buffer, size);
00106             }
00107             res = file[0].close();
00108             TEST_ASSERT_EQUAL(0, res);
00109         }
00110         res = fs.unmount();
00111         TEST_ASSERT_EQUAL(0, res);
00112     }
00113 
00114     res = bd.deinit();
00115     TEST_ASSERT_EQUAL(0, res);
00116 }
00117 
00118 void test_simple_dir_seek()
00119 {
00120     int res = bd.init();
00121     TEST_ASSERT_EQUAL(0, res);
00122 
00123     {
00124         res = fs.mount(&bd);
00125         TEST_ASSERT_EQUAL(0, res);
00126         res = dir[0].open(&fs, "hello");
00127         TEST_ASSERT_EQUAL(0, res);
00128         res = dir[0].read(&ent);
00129         TEST_ASSERT_EQUAL(1, res);
00130         res = strcmp(ent.d_name, ".");
00131         TEST_ASSERT_EQUAL(0, res);
00132         res = dir[0].read(&ent);
00133         TEST_ASSERT_EQUAL(1, res);
00134         res = strcmp(ent.d_name, "..");
00135         TEST_ASSERT_EQUAL(0, res);
00136     
00137         off_t pos;
00138         int i;
00139         for (i = 0; i < 4; i++) {
00140             sprintf((char*)buffer, "kitty%d", i);
00141             res = dir[0].read(&ent);
00142             TEST_ASSERT_EQUAL(1, res);
00143             res = strcmp(ent.d_name, (char*)buffer);
00144             TEST_ASSERT_EQUAL(0, res);
00145             pos = dir[0].tell();
00146         }
00147         res = pos >= 0;
00148         TEST_ASSERT_EQUAL(1, res);
00149     
00150         dir[0].seek(pos);
00151         sprintf((char*)buffer, "kitty%d", i);
00152         res = dir[0].read(&ent);
00153         TEST_ASSERT_EQUAL(1, res);
00154         res = strcmp(ent.d_name, (char*)buffer);
00155         TEST_ASSERT_EQUAL(0, res);
00156     
00157         dir[0].rewind();
00158         sprintf((char*)buffer, "kitty%d", 0);
00159         res = dir[0].read(&ent);
00160         TEST_ASSERT_EQUAL(1, res);
00161         res = strcmp(ent.d_name, ".");
00162         TEST_ASSERT_EQUAL(0, res);
00163         res = dir[0].read(&ent);
00164         TEST_ASSERT_EQUAL(1, res);
00165         res = strcmp(ent.d_name, "..");
00166         TEST_ASSERT_EQUAL(0, res);
00167         res = dir[0].read(&ent);
00168         TEST_ASSERT_EQUAL(1, res);
00169         res = strcmp(ent.d_name, (char*)buffer);
00170         TEST_ASSERT_EQUAL(0, res);
00171     
00172         dir[0].seek(pos);
00173         sprintf((char*)buffer, "kitty%d", i);
00174         res = dir[0].read(&ent);
00175         TEST_ASSERT_EQUAL(1, res);
00176         res = strcmp(ent.d_name, (char*)buffer);
00177         TEST_ASSERT_EQUAL(0, res);
00178         res = dir[0].close();
00179         TEST_ASSERT_EQUAL(0, res);
00180         res = fs.unmount();
00181         TEST_ASSERT_EQUAL(0, res);
00182     }
00183 
00184     res = bd.deinit();
00185     TEST_ASSERT_EQUAL(0, res);
00186 }
00187 
00188 void test_large_dir_seek()
00189 {
00190     int res = bd.init();
00191     TEST_ASSERT_EQUAL(0, res);
00192 
00193     {
00194         res = fs.mount(&bd);
00195         TEST_ASSERT_EQUAL(0, res);
00196         res = dir[0].open(&fs, "hello");
00197         TEST_ASSERT_EQUAL(0, res);
00198         res = dir[0].read(&ent);
00199         TEST_ASSERT_EQUAL(1, res);
00200         res = strcmp(ent.d_name, ".");
00201         TEST_ASSERT_EQUAL(0, res);
00202         res = dir[0].read(&ent);
00203         TEST_ASSERT_EQUAL(1, res);
00204         res = strcmp(ent.d_name, "..");
00205         TEST_ASSERT_EQUAL(0, res);
00206     
00207         off_t pos;
00208         int i;
00209         for (i = 0; i < 128; i++) {
00210             sprintf((char*)buffer, "kitty%d", i);
00211             res = dir[0].read(&ent);
00212             TEST_ASSERT_EQUAL(1, res);
00213             res = strcmp(ent.d_name, (char*)buffer);
00214             TEST_ASSERT_EQUAL(0, res);
00215             pos = dir[0].tell();
00216         }
00217         res = pos >= 0;
00218         TEST_ASSERT_EQUAL(1, res);
00219     
00220         dir[0].seek(pos);
00221         sprintf((char*)buffer, "kitty%d", i);
00222         res = dir[0].read(&ent);
00223         TEST_ASSERT_EQUAL(1, res);
00224         res = strcmp(ent.d_name, (char*)buffer);
00225         TEST_ASSERT_EQUAL(0, res);
00226     
00227         dir[0].rewind();
00228         sprintf((char*)buffer, "kitty%d", 0);
00229         res = dir[0].read(&ent);
00230         TEST_ASSERT_EQUAL(1, res);
00231         res = strcmp(ent.d_name, ".");
00232         TEST_ASSERT_EQUAL(0, res);
00233         res = dir[0].read(&ent);
00234         TEST_ASSERT_EQUAL(1, res);
00235         res = strcmp(ent.d_name, "..");
00236         TEST_ASSERT_EQUAL(0, res);
00237         res = dir[0].read(&ent);
00238         TEST_ASSERT_EQUAL(1, res);
00239         res = strcmp(ent.d_name, (char*)buffer);
00240         TEST_ASSERT_EQUAL(0, res);
00241     
00242         dir[0].seek(pos);
00243         sprintf((char*)buffer, "kitty%d", i);
00244         res = dir[0].read(&ent);
00245         TEST_ASSERT_EQUAL(1, res);
00246         res = strcmp(ent.d_name, (char*)buffer);
00247         TEST_ASSERT_EQUAL(0, res);
00248         res = dir[0].close();
00249         TEST_ASSERT_EQUAL(0, res);
00250         res = fs.unmount();
00251         TEST_ASSERT_EQUAL(0, res);
00252     }
00253 
00254     res = bd.deinit();
00255     TEST_ASSERT_EQUAL(0, res);
00256 }
00257 
00258 void test_simple_file_seek()
00259 {
00260     int res = bd.init();
00261     TEST_ASSERT_EQUAL(0, res);
00262 
00263     {
00264         res = fs.mount(&bd);
00265         TEST_ASSERT_EQUAL(0, res);
00266         res = file[0].open(&fs, "hello/kitty42", O_RDONLY);
00267         TEST_ASSERT_EQUAL(0, res);
00268     
00269         off_t pos;
00270         size = strlen("kittycatcat");
00271         for (int i = 0; i < 4; i++) {
00272             res = file[0].read(buffer, size);
00273             TEST_ASSERT_EQUAL(size, res);
00274             res = memcmp(buffer, "kittycatcat", size);
00275             TEST_ASSERT_EQUAL(0, res);
00276             pos = file[0].tell();
00277         }
00278         res = pos >= 0;
00279         TEST_ASSERT_EQUAL(1, res);
00280         res = file[0].seek(pos, SEEK_SET);
00281         TEST_ASSERT_EQUAL(pos, res);
00282         res = file[0].read(buffer, size);
00283         TEST_ASSERT_EQUAL(size, res);
00284         res = memcmp(buffer, "kittycatcat", size);
00285         TEST_ASSERT_EQUAL(0, res);
00286     
00287         file[0].rewind();
00288         res = file[0].read(buffer, size);
00289         TEST_ASSERT_EQUAL(size, res);
00290         res = memcmp(buffer, "kittycatcat", size);
00291         TEST_ASSERT_EQUAL(0, res);
00292         res = file[0].seek(pos, SEEK_SET);
00293         TEST_ASSERT_EQUAL(pos, res);
00294         res = file[0].read(buffer, size);
00295         TEST_ASSERT_EQUAL(size, res);
00296         res = memcmp(buffer, "kittycatcat", size);
00297         TEST_ASSERT_EQUAL(0, res);
00298         res = file[0].seek(-size, SEEK_CUR);
00299         TEST_ASSERT_EQUAL(pos, res);
00300         res = file[0].read(buffer, size);
00301         TEST_ASSERT_EQUAL(size, res);
00302         res = memcmp(buffer, "kittycatcat", size);
00303         TEST_ASSERT_EQUAL(0, res);
00304         res = file[0].seek(-size, SEEK_END) >= 0;
00305         TEST_ASSERT_EQUAL(1, res);
00306         res = file[0].read(buffer, size);
00307         TEST_ASSERT_EQUAL(size, res);
00308         res = memcmp(buffer, "kittycatcat", size);
00309         TEST_ASSERT_EQUAL(0, res);
00310     
00311         size_t size = file[0].size();
00312         res = file[0].seek(0, SEEK_CUR);
00313         TEST_ASSERT_EQUAL(size, res);
00314         res = file[0].close();
00315         TEST_ASSERT_EQUAL(0, res);
00316         res = fs.unmount();
00317         TEST_ASSERT_EQUAL(0, res);
00318     }
00319 
00320     res = bd.deinit();
00321     TEST_ASSERT_EQUAL(0, res);
00322 }
00323 
00324 void test_large_file_seek()
00325 {
00326     int res = bd.init();
00327     TEST_ASSERT_EQUAL(0, res);
00328 
00329     {
00330         res = fs.mount(&bd);
00331         TEST_ASSERT_EQUAL(0, res);
00332         res = file[0].open(&fs, "hello/kitty42", O_RDONLY);
00333         TEST_ASSERT_EQUAL(0, res);
00334     
00335         off_t pos;
00336         size = strlen("kittycatcat");
00337         for (int i = 0; i < 128; i++) {
00338             res = file[0].read(buffer, size);
00339             TEST_ASSERT_EQUAL(size, res);
00340             res = memcmp(buffer, "kittycatcat", size);
00341             TEST_ASSERT_EQUAL(0, res);
00342             pos = file[0].tell();
00343         }
00344         res = pos >= 0;
00345         TEST_ASSERT_EQUAL(1, res);
00346         res = file[0].seek(pos, SEEK_SET);
00347         TEST_ASSERT_EQUAL(pos, res);
00348         res = file[0].read(buffer, size);
00349         TEST_ASSERT_EQUAL(size, res);
00350         res = memcmp(buffer, "kittycatcat", size);
00351         TEST_ASSERT_EQUAL(0, res);
00352     
00353         file[0].rewind();
00354         res = file[0].read(buffer, size);
00355         TEST_ASSERT_EQUAL(size, res);
00356         res = memcmp(buffer, "kittycatcat", size);
00357         TEST_ASSERT_EQUAL(0, res);
00358         res = file[0].seek(pos, SEEK_SET);
00359         TEST_ASSERT_EQUAL(pos, res);
00360         res = file[0].read(buffer, size);
00361         TEST_ASSERT_EQUAL(size, res);
00362         res = memcmp(buffer, "kittycatcat", size);
00363         TEST_ASSERT_EQUAL(0, res);
00364         res = file[0].seek(-size, SEEK_CUR);
00365         TEST_ASSERT_EQUAL(pos, res);
00366         res = file[0].read(buffer, size);
00367         TEST_ASSERT_EQUAL(size, res);
00368         res = memcmp(buffer, "kittycatcat", size);
00369         TEST_ASSERT_EQUAL(0, res);
00370         res = file[0].seek(-size, SEEK_END) >= 0;
00371         TEST_ASSERT_EQUAL(1, res);
00372         res = file[0].read(buffer, size);
00373         TEST_ASSERT_EQUAL(size, res);
00374         res = memcmp(buffer, "kittycatcat", size);
00375         TEST_ASSERT_EQUAL(0, res);
00376     
00377         size_t size = file[0].size();
00378         res = file[0].seek(0, SEEK_CUR);
00379         TEST_ASSERT_EQUAL(size, res);
00380         res = file[0].close();
00381         TEST_ASSERT_EQUAL(0, res);
00382         res = fs.unmount();
00383         TEST_ASSERT_EQUAL(0, res);
00384     }
00385 
00386     res = bd.deinit();
00387     TEST_ASSERT_EQUAL(0, res);
00388 }
00389 
00390 void test_simple_file_seek_and_write()
00391 {
00392     int res = bd.init();
00393     TEST_ASSERT_EQUAL(0, res);
00394 
00395     {
00396         res = fs.mount(&bd);
00397         TEST_ASSERT_EQUAL(0, res);
00398         res = file[0].open(&fs, "hello/kitty42", O_RDWR);
00399         TEST_ASSERT_EQUAL(0, res);
00400     
00401         off_t pos;
00402         size = strlen("kittycatcat");
00403         for (int i = 0; i < 4; i++) {
00404             res = file[0].read(buffer, size);
00405             TEST_ASSERT_EQUAL(size, res);
00406             res = memcmp(buffer, "kittycatcat", size);
00407             TEST_ASSERT_EQUAL(0, res);
00408             pos = file[0].tell();
00409         }
00410         res = pos >= 0;
00411         TEST_ASSERT_EQUAL(1, res);
00412     
00413         memcpy(buffer, "doggodogdog", size);
00414         res = file[0].seek(pos, SEEK_SET);
00415         TEST_ASSERT_EQUAL(pos, res);
00416         res = file[0].write(buffer, size);
00417         TEST_ASSERT_EQUAL(size, res);
00418         res = file[0].seek(pos, SEEK_SET);
00419         TEST_ASSERT_EQUAL(pos, res);
00420         res = file[0].read(buffer, size);
00421         TEST_ASSERT_EQUAL(size, res);
00422         res = memcmp(buffer, "doggodogdog", size);
00423         TEST_ASSERT_EQUAL(0, res);
00424     
00425         file[0].rewind();
00426         res = file[0].read(buffer, size);
00427         TEST_ASSERT_EQUAL(size, res);
00428         res = memcmp(buffer, "kittycatcat", size);
00429         TEST_ASSERT_EQUAL(0, res);
00430         res = file[0].seek(pos, SEEK_SET);
00431         TEST_ASSERT_EQUAL(pos, res);
00432         res = file[0].read(buffer, size);
00433         TEST_ASSERT_EQUAL(size, res);
00434         res = memcmp(buffer, "doggodogdog", size);
00435         TEST_ASSERT_EQUAL(0, res);
00436         res = file[0].seek(-size, SEEK_END) >= 0;
00437         TEST_ASSERT_EQUAL(1, res);
00438         res = file[0].read(buffer, size);
00439         TEST_ASSERT_EQUAL(size, res);
00440         res = memcmp(buffer, "kittycatcat", size);
00441         TEST_ASSERT_EQUAL(0, res);
00442     
00443         size_t size = file[0].size();
00444         res = file[0].seek(0, SEEK_CUR);
00445         TEST_ASSERT_EQUAL(size, res);
00446         res = file[0].close();
00447         TEST_ASSERT_EQUAL(0, res);
00448         res = fs.unmount();
00449         TEST_ASSERT_EQUAL(0, res);
00450     }
00451 
00452     res = bd.deinit();
00453     TEST_ASSERT_EQUAL(0, res);
00454 }
00455 
00456 void test_large_file_seek_and_write()
00457 {
00458     int res = bd.init();
00459     TEST_ASSERT_EQUAL(0, res);
00460 
00461     {
00462         res = fs.mount(&bd);
00463         TEST_ASSERT_EQUAL(0, res);
00464         res = file[0].open(&fs, "hello/kitty42", O_RDWR);
00465         TEST_ASSERT_EQUAL(0, res);
00466     
00467         off_t pos;
00468         size = strlen("kittycatcat");
00469         for (int i = 0; i < 128; i++) {
00470             res = file[0].read(buffer, size);
00471             TEST_ASSERT_EQUAL(size, res);
00472             if (i != 4) {
00473                 res = memcmp(buffer, "kittycatcat", size);
00474                 TEST_ASSERT_EQUAL(0, res);
00475             }
00476             pos = file[0].tell();
00477         }
00478         res = pos >= 0;
00479         TEST_ASSERT_EQUAL(1, res);
00480     
00481         memcpy(buffer, "doggodogdog", size);
00482         res = file[0].seek(pos, SEEK_SET);
00483         TEST_ASSERT_EQUAL(pos, res);
00484         res = file[0].write(buffer, size);
00485         TEST_ASSERT_EQUAL(size, res);
00486         res = file[0].seek(pos, SEEK_SET);
00487         TEST_ASSERT_EQUAL(pos, res);
00488         res = file[0].read(buffer, size);
00489         TEST_ASSERT_EQUAL(size, res);
00490         res = memcmp(buffer, "doggodogdog", size);
00491         TEST_ASSERT_EQUAL(0, res);
00492     
00493         file[0].rewind();
00494         res = file[0].read(buffer, size);
00495         TEST_ASSERT_EQUAL(size, res);
00496         res = memcmp(buffer, "kittycatcat", size);
00497         TEST_ASSERT_EQUAL(0, res);
00498         res = file[0].seek(pos, SEEK_SET);
00499         TEST_ASSERT_EQUAL(pos, res);
00500         res = file[0].read(buffer, size);
00501         TEST_ASSERT_EQUAL(size, res);
00502         res = memcmp(buffer, "doggodogdog", size);
00503         TEST_ASSERT_EQUAL(0, res);
00504         res = file[0].seek(-size, SEEK_END) >= 0;
00505         TEST_ASSERT_EQUAL(1, res);
00506         res = file[0].read(buffer, size);
00507         TEST_ASSERT_EQUAL(size, res);
00508         res = memcmp(buffer, "kittycatcat", size);
00509         TEST_ASSERT_EQUAL(0, res);
00510     
00511         size_t size = file[0].size();
00512         res = file[0].seek(0, SEEK_CUR);
00513         TEST_ASSERT_EQUAL(size, res);
00514         res = file[0].close();
00515         TEST_ASSERT_EQUAL(0, res);
00516         res = fs.unmount();
00517         TEST_ASSERT_EQUAL(0, res);
00518     }
00519 
00520     res = bd.deinit();
00521     TEST_ASSERT_EQUAL(0, res);
00522 }
00523 
00524 void test_boundary_seek_and_write()
00525 {
00526     int res = bd.init();
00527     TEST_ASSERT_EQUAL(0, res);
00528 
00529     {
00530         res = fs.mount(&bd);
00531         TEST_ASSERT_EQUAL(0, res);
00532         res = file[0].open(&fs, "hello/kitty42", O_RDWR);
00533         TEST_ASSERT_EQUAL(0, res);
00534     
00535         size = strlen("hedgehoghog");
00536         const off_t offsets[] = {512, 1020, 513, 1021, 511, 1019};
00537     
00538         for (int i = 0; i < sizeof(offsets) / sizeof(offsets[0]); i++) {
00539             off_t off = offsets[i];
00540             memcpy(buffer, "hedgehoghog", size);
00541             res = file[0].seek(off, SEEK_SET);
00542             TEST_ASSERT_EQUAL(off, res);
00543             res = file[0].write(buffer, size);
00544             TEST_ASSERT_EQUAL(size, res);
00545             res = file[0].seek(off, SEEK_SET);
00546             TEST_ASSERT_EQUAL(off, res);
00547             res = file[0].read(buffer, size);
00548             TEST_ASSERT_EQUAL(size, res);
00549             res = memcmp(buffer, "hedgehoghog", size);
00550             TEST_ASSERT_EQUAL(0, res);
00551             res = file[0].seek(0, SEEK_SET);
00552             TEST_ASSERT_EQUAL(0, res);
00553             res = file[0].read(buffer, size);
00554             TEST_ASSERT_EQUAL(size, res);
00555             res = memcmp(buffer, "kittycatcat", size);
00556             TEST_ASSERT_EQUAL(0, res);
00557             res = file[0].sync();
00558             TEST_ASSERT_EQUAL(0, res);
00559         }
00560         res = file[0].close();
00561         TEST_ASSERT_EQUAL(0, res);
00562         res = fs.unmount();
00563         TEST_ASSERT_EQUAL(0, res);
00564     }
00565 
00566     res = bd.deinit();
00567     TEST_ASSERT_EQUAL(0, res);
00568 }
00569 
00570 void test_out_of_bounds_seek()
00571 {
00572     int res = bd.init();
00573     TEST_ASSERT_EQUAL(0, res);
00574 
00575     {
00576         res = fs.mount(&bd);
00577         TEST_ASSERT_EQUAL(0, res);
00578         res = file[0].open(&fs, "hello/kitty42", O_RDWR);
00579         TEST_ASSERT_EQUAL(0, res);
00580     
00581         size = strlen("kittycatcat");
00582         res = file[0].size();
00583         TEST_ASSERT_EQUAL(132*size, res);
00584         res = file[0].seek((132+4)*size,
00585                 SEEK_SET);
00586         TEST_ASSERT_EQUAL((132+4)*size, res);
00587         res = file[0].read(buffer, size);
00588         TEST_ASSERT_EQUAL(0, res);
00589     
00590         memcpy(buffer, "porcupineee", size);
00591         res = file[0].write(buffer, size);
00592         TEST_ASSERT_EQUAL(size, res);
00593         res = file[0].seek((132+4)*size,
00594                 SEEK_SET);
00595         TEST_ASSERT_EQUAL((132+4)*size, res);
00596         res = file[0].read(buffer, size);
00597         TEST_ASSERT_EQUAL(size, res);
00598         res = memcmp(buffer, "porcupineee", size);
00599         TEST_ASSERT_EQUAL(0, res);
00600         res = file[0].seek(132*size,
00601                 SEEK_SET);
00602         TEST_ASSERT_EQUAL(132*size, res);
00603         res = file[0].read(buffer, size);
00604         TEST_ASSERT_EQUAL(size, res);
00605         res = memcmp(buffer, "\0\0\0\0\0\0\0\0\0\0\0", size);
00606         TEST_ASSERT_EQUAL(0, res);
00607         res = file[0].close();
00608         TEST_ASSERT_EQUAL(0, res);
00609         res = fs.unmount();
00610         TEST_ASSERT_EQUAL(0, res);
00611     }
00612 
00613     res = bd.deinit();
00614     TEST_ASSERT_EQUAL(0, res);
00615 }
00616 
00617 
00618 
00619 // test setup
00620 utest::v1::status_t test_setup(const size_t number_of_cases)
00621 {
00622     GREENTEA_SETUP(MBED_TEST_TIMEOUT, "default_auto");
00623     return verbose_test_setup_handler(number_of_cases);
00624 }
00625 
00626 Case cases[] = {
00627     Case("Seek tests", test_seek_tests),
00628     Case("Simple dir seek", test_simple_dir_seek),
00629     Case("Large dir seek", test_large_dir_seek),
00630     Case("Simple file seek", test_simple_file_seek),
00631     Case("Large file seek", test_large_file_seek),
00632     Case("Simple file seek and write", test_simple_file_seek_and_write),
00633     Case("Large file seek and write", test_large_file_seek_and_write),
00634     Case("Boundary seek and write", test_boundary_seek_and_write),
00635     Case("Out-of-bounds seek", test_out_of_bounds_seek),
00636 };
00637 
00638 Specification specification(test_setup, cases);
00639 
00640 int main()
00641 {
00642     return !Harness::run(specification);
00643 }