SDHI_driver patch (mbedOS 5.11.5)
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2016 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 00017 #include "mbed.h" 00018 #include "greentea-client/test_env.h" 00019 #include "unity.h" 00020 #include "utest.h" 00021 #include <stdlib.h> 00022 #include <errno.h> 00023 00024 using namespace utest::v1; 00025 00026 // test configuration 00027 #ifndef MBED_TEST_FILESYSTEM 00028 #define MBED_TEST_FILESYSTEM FATFileSystem 00029 #endif 00030 00031 #ifndef MBED_TEST_FILESYSTEM_DECL 00032 #define MBED_TEST_FILESYSTEM_DECL MBED_TEST_FILESYSTEM fs("fs") 00033 #endif 00034 00035 #ifndef MBED_TEST_BLOCKDEVICE 00036 #define MBED_TEST_BLOCKDEVICE RZ_SDHIBlockDevice 00037 #define MBED_TEST_BLOCKDEVICE_DECL SDHIBlockDevice bd(MBED_CONF_RZ_SDHI_CH); 00038 #endif 00039 00040 #ifndef MBED_TEST_BLOCKDEVICE_DECL 00041 #define MBED_TEST_BLOCKDEVICE_DECL MBED_TEST_BLOCKDEVICE bd 00042 #endif 00043 00044 #ifndef MBED_TEST_FILES 00045 #define MBED_TEST_FILES 4 00046 #endif 00047 00048 #ifndef MBED_TEST_DIRS 00049 #define MBED_TEST_DIRS 4 00050 #endif 00051 00052 #ifndef MBED_TEST_TIMEOUT 00053 #define MBED_TEST_TIMEOUT 120 00054 #endif 00055 00056 00057 // declarations 00058 #define STRINGIZE(x) STRINGIZE2(x) 00059 #define STRINGIZE2(x) #x 00060 #define INCLUDE(x, ext) STRINGIZE(x.ext) 00061 00062 #include INCLUDE(MBED_TEST_FILESYSTEM, h) 00063 #include INCLUDE(MBED_TEST_BLOCKDEVICE, hpp) 00064 00065 MBED_TEST_FILESYSTEM_DECL; 00066 MBED_TEST_BLOCKDEVICE_DECL; 00067 00068 Dir dir[MBED_TEST_DIRS]; 00069 File file[MBED_TEST_FILES]; 00070 DIR *dd[MBED_TEST_DIRS]; 00071 FILE *fd[MBED_TEST_FILES]; 00072 struct dirent ent; 00073 struct dirent *ed; 00074 uint8_t buffer[MBED_CONF_RZ_SDHI_TEST_BUFFER]; 00075 00076 00077 // tests 00078 00079 void test_seek_tests() 00080 { 00081 int res = bd.init(); 00082 TEST_ASSERT_EQUAL(0, res); 00083 00084 { 00085 size_t size; 00086 res = MBED_TEST_FILESYSTEM::format(&bd); 00087 TEST_ASSERT_EQUAL(0, res); 00088 res = fs.mount(&bd); 00089 TEST_ASSERT_EQUAL(0, res); 00090 res = fs.mkdir("hello", 0777); 00091 TEST_ASSERT_EQUAL(0, res); 00092 for (int i = 0; i < 132; i++) { 00093 sprintf((char *)buffer, "hello/kitty%d", i); 00094 res = file[0].open(&fs, (char *)buffer, 00095 O_WRONLY | O_CREAT | O_APPEND); 00096 TEST_ASSERT_EQUAL(0, res); 00097 00098 size = strlen("kittycatcat"); 00099 memcpy(buffer, "kittycatcat", size); 00100 for (int j = 0; j < 132; j++) { 00101 file[0].write(buffer, size); 00102 } 00103 res = file[0].close(); 00104 TEST_ASSERT_EQUAL(0, res); 00105 } 00106 res = fs.unmount(); 00107 TEST_ASSERT_EQUAL(0, res); 00108 } 00109 00110 res = bd.deinit(); 00111 TEST_ASSERT_EQUAL(0, res); 00112 } 00113 00114 void test_simple_dir_seek() 00115 { 00116 int res = bd.init(); 00117 TEST_ASSERT_EQUAL(0, res); 00118 00119 { 00120 res = fs.mount(&bd); 00121 TEST_ASSERT_EQUAL(0, res); 00122 res = dir[0].open(&fs, "hello"); 00123 TEST_ASSERT_EQUAL(0, res); 00124 #if (MBED_TEST_FILESYSTEM != FATFileSystem) 00125 res = dir[0].read(&ent); 00126 TEST_ASSERT_EQUAL(1, res); 00127 res = strcmp(ent.d_name, "."); 00128 TEST_ASSERT_EQUAL(0, res); 00129 res = dir[0].read(&ent); 00130 TEST_ASSERT_EQUAL(1, res); 00131 res = strcmp(ent.d_name, ".."); 00132 TEST_ASSERT_EQUAL(0, res); 00133 #endif 00134 00135 off_t pos; 00136 int i; 00137 for (i = 0; i < 4; i++) { 00138 sprintf((char *)buffer, "kitty%d", i); 00139 res = dir[0].read(&ent); 00140 TEST_ASSERT_EQUAL(1, res); 00141 res = strcmp(ent.d_name, (char *)buffer); 00142 TEST_ASSERT_EQUAL(0, res); 00143 pos = dir[0].tell(); 00144 } 00145 res = pos >= 0; 00146 TEST_ASSERT_EQUAL(1, res); 00147 00148 dir[0].seek(pos); 00149 sprintf((char *)buffer, "kitty%d", i); 00150 res = dir[0].read(&ent); 00151 TEST_ASSERT_EQUAL(1, res); 00152 res = strcmp(ent.d_name, (char *)buffer); 00153 TEST_ASSERT_EQUAL(0, res); 00154 00155 dir[0].rewind(); 00156 sprintf((char *)buffer, "kitty%d", 0); 00157 #if (MBED_TEST_FILESYSTEM != FATFileSystem) 00158 res = dir[0].read(&ent); 00159 TEST_ASSERT_EQUAL(1, res); 00160 res = strcmp(ent.d_name, "."); 00161 TEST_ASSERT_EQUAL(0, res); 00162 res = dir[0].read(&ent); 00163 TEST_ASSERT_EQUAL(1, res); 00164 res = strcmp(ent.d_name, ".."); 00165 TEST_ASSERT_EQUAL(0, res); 00166 #endif 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 #if (MBED_TEST_FILESYSTEM != FATFileSystem) 00199 res = dir[0].read(&ent); 00200 TEST_ASSERT_EQUAL(1, res); 00201 res = strcmp(ent.d_name, "."); 00202 TEST_ASSERT_EQUAL(0, res); 00203 res = dir[0].read(&ent); 00204 TEST_ASSERT_EQUAL(1, res); 00205 res = strcmp(ent.d_name, ".."); 00206 TEST_ASSERT_EQUAL(0, res); 00207 #endif 00208 00209 off_t pos; 00210 int i; 00211 for (i = 0; i < 128; i++) { 00212 sprintf((char *)buffer, "kitty%d", i); 00213 res = dir[0].read(&ent); 00214 TEST_ASSERT_EQUAL(1, res); 00215 res = strcmp(ent.d_name, (char *)buffer); 00216 TEST_ASSERT_EQUAL(0, res); 00217 pos = dir[0].tell(); 00218 } 00219 res = pos >= 0; 00220 TEST_ASSERT_EQUAL(1, res); 00221 00222 dir[0].seek(pos); 00223 sprintf((char *)buffer, "kitty%d", i); 00224 res = dir[0].read(&ent); 00225 TEST_ASSERT_EQUAL(1, res); 00226 res = strcmp(ent.d_name, (char *)buffer); 00227 TEST_ASSERT_EQUAL(0, res); 00228 00229 dir[0].rewind(); 00230 sprintf((char *)buffer, "kitty%d", 0); 00231 #if (MBED_TEST_FILESYSTEM != FATFileSystem) 00232 res = dir[0].read(&ent); 00233 TEST_ASSERT_EQUAL(1, res); 00234 res = strcmp(ent.d_name, "."); 00235 TEST_ASSERT_EQUAL(0, res); 00236 res = dir[0].read(&ent); 00237 TEST_ASSERT_EQUAL(1, res); 00238 res = strcmp(ent.d_name, ".."); 00239 TEST_ASSERT_EQUAL(0, res); 00240 #endif 00241 res = dir[0].read(&ent); 00242 TEST_ASSERT_EQUAL(1, res); 00243 res = strcmp(ent.d_name, (char *)buffer); 00244 TEST_ASSERT_EQUAL(0, res); 00245 00246 dir[0].seek(pos); 00247 sprintf((char *)buffer, "kitty%d", i); 00248 res = dir[0].read(&ent); 00249 TEST_ASSERT_EQUAL(1, res); 00250 res = strcmp(ent.d_name, (char *)buffer); 00251 TEST_ASSERT_EQUAL(0, res); 00252 res = dir[0].close(); 00253 TEST_ASSERT_EQUAL(0, res); 00254 res = fs.unmount(); 00255 TEST_ASSERT_EQUAL(0, res); 00256 } 00257 00258 res = bd.deinit(); 00259 TEST_ASSERT_EQUAL(0, res); 00260 } 00261 00262 void test_simple_file_seek() 00263 { 00264 int res = bd.init(); 00265 TEST_ASSERT_EQUAL(0, res); 00266 00267 { 00268 size_t size; 00269 res = fs.mount(&bd); 00270 TEST_ASSERT_EQUAL(0, res); 00271 res = file[0].open(&fs, "hello/kitty42", O_RDONLY); 00272 TEST_ASSERT_EQUAL(0, res); 00273 00274 off_t pos; 00275 size = strlen("kittycatcat"); 00276 for (int i = 0; i < 4; i++) { 00277 res = file[0].read(buffer, size); 00278 TEST_ASSERT_EQUAL(size, res); 00279 res = memcmp(buffer, "kittycatcat", size); 00280 TEST_ASSERT_EQUAL(0, res); 00281 pos = file[0].tell(); 00282 } 00283 res = pos >= 0; 00284 TEST_ASSERT_EQUAL(1, res); 00285 res = file[0].seek(pos, SEEK_SET); 00286 TEST_ASSERT_EQUAL(pos, res); 00287 res = file[0].read(buffer, size); 00288 TEST_ASSERT_EQUAL(size, res); 00289 res = memcmp(buffer, "kittycatcat", size); 00290 TEST_ASSERT_EQUAL(0, res); 00291 00292 file[0].rewind(); 00293 res = file[0].read(buffer, size); 00294 TEST_ASSERT_EQUAL(size, res); 00295 res = memcmp(buffer, "kittycatcat", size); 00296 TEST_ASSERT_EQUAL(0, res); 00297 res = file[0].seek(pos, SEEK_SET); 00298 TEST_ASSERT_EQUAL(pos, res); 00299 res = file[0].read(buffer, size); 00300 TEST_ASSERT_EQUAL(size, res); 00301 res = memcmp(buffer, "kittycatcat", size); 00302 TEST_ASSERT_EQUAL(0, res); 00303 res = file[0].seek(-size, SEEK_CUR); 00304 TEST_ASSERT_EQUAL(pos, res); 00305 res = file[0].read(buffer, size); 00306 TEST_ASSERT_EQUAL(size, res); 00307 res = memcmp(buffer, "kittycatcat", size); 00308 TEST_ASSERT_EQUAL(0, res); 00309 res = file[0].seek(-size, SEEK_END) >= 0; 00310 TEST_ASSERT_EQUAL(1, res); 00311 res = file[0].read(buffer, size); 00312 TEST_ASSERT_EQUAL(size, res); 00313 res = memcmp(buffer, "kittycatcat", size); 00314 TEST_ASSERT_EQUAL(0, res); 00315 00316 size = file[0].size(); 00317 res = file[0].seek(0, SEEK_CUR); 00318 TEST_ASSERT_EQUAL(size, res); 00319 res = file[0].close(); 00320 TEST_ASSERT_EQUAL(0, res); 00321 res = fs.unmount(); 00322 TEST_ASSERT_EQUAL(0, res); 00323 } 00324 00325 res = bd.deinit(); 00326 TEST_ASSERT_EQUAL(0, res); 00327 } 00328 00329 void test_large_file_seek() 00330 { 00331 int res = bd.init(); 00332 TEST_ASSERT_EQUAL(0, res); 00333 00334 { 00335 size_t size; 00336 res = fs.mount(&bd); 00337 TEST_ASSERT_EQUAL(0, res); 00338 res = file[0].open(&fs, "hello/kitty42", O_RDONLY); 00339 TEST_ASSERT_EQUAL(0, res); 00340 00341 off_t pos; 00342 size = strlen("kittycatcat"); 00343 for (int i = 0; i < 128; i++) { 00344 res = file[0].read(buffer, size); 00345 TEST_ASSERT_EQUAL(size, res); 00346 res = memcmp(buffer, "kittycatcat", size); 00347 TEST_ASSERT_EQUAL(0, res); 00348 pos = file[0].tell(); 00349 } 00350 res = pos >= 0; 00351 TEST_ASSERT_EQUAL(1, res); 00352 res = file[0].seek(pos, SEEK_SET); 00353 TEST_ASSERT_EQUAL(pos, res); 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 00359 file[0].rewind(); 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(pos, SEEK_SET); 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_CUR); 00371 TEST_ASSERT_EQUAL(pos, 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 res = file[0].seek(-size, SEEK_END) >= 0; 00377 TEST_ASSERT_EQUAL(1, res); 00378 res = file[0].read(buffer, size); 00379 TEST_ASSERT_EQUAL(size, res); 00380 res = memcmp(buffer, "kittycatcat", size); 00381 TEST_ASSERT_EQUAL(0, res); 00382 00383 size = file[0].size(); 00384 res = file[0].seek(0, SEEK_CUR); 00385 TEST_ASSERT_EQUAL(size, res); 00386 res = file[0].close(); 00387 TEST_ASSERT_EQUAL(0, res); 00388 res = fs.unmount(); 00389 TEST_ASSERT_EQUAL(0, res); 00390 } 00391 00392 res = bd.deinit(); 00393 TEST_ASSERT_EQUAL(0, res); 00394 } 00395 00396 void test_simple_file_seek_and_write() 00397 { 00398 int res = bd.init(); 00399 TEST_ASSERT_EQUAL(0, res); 00400 00401 { 00402 size_t size; 00403 res = fs.mount(&bd); 00404 TEST_ASSERT_EQUAL(0, res); 00405 res = file[0].open(&fs, "hello/kitty42", O_RDWR); 00406 TEST_ASSERT_EQUAL(0, res); 00407 00408 off_t pos; 00409 size = strlen("kittycatcat"); 00410 for (int i = 0; i < 4; i++) { 00411 res = file[0].read(buffer, size); 00412 TEST_ASSERT_EQUAL(size, res); 00413 res = memcmp(buffer, "kittycatcat", size); 00414 TEST_ASSERT_EQUAL(0, res); 00415 pos = file[0].tell(); 00416 } 00417 res = pos >= 0; 00418 TEST_ASSERT_EQUAL(1, res); 00419 00420 memcpy(buffer, "doggodogdog", size); 00421 res = file[0].seek(pos, SEEK_SET); 00422 TEST_ASSERT_EQUAL(pos, res); 00423 res = file[0].write(buffer, size); 00424 TEST_ASSERT_EQUAL(size, res); 00425 res = file[0].seek(pos, SEEK_SET); 00426 TEST_ASSERT_EQUAL(pos, res); 00427 res = file[0].read(buffer, size); 00428 TEST_ASSERT_EQUAL(size, res); 00429 res = memcmp(buffer, "doggodogdog", size); 00430 TEST_ASSERT_EQUAL(0, res); 00431 00432 file[0].rewind(); 00433 res = file[0].read(buffer, size); 00434 TEST_ASSERT_EQUAL(size, res); 00435 res = memcmp(buffer, "kittycatcat", size); 00436 TEST_ASSERT_EQUAL(0, res); 00437 res = file[0].seek(pos, SEEK_SET); 00438 TEST_ASSERT_EQUAL(pos, res); 00439 res = file[0].read(buffer, size); 00440 TEST_ASSERT_EQUAL(size, res); 00441 res = memcmp(buffer, "doggodogdog", size); 00442 TEST_ASSERT_EQUAL(0, res); 00443 res = file[0].seek(-size, SEEK_END) >= 0; 00444 TEST_ASSERT_EQUAL(1, res); 00445 res = file[0].read(buffer, size); 00446 TEST_ASSERT_EQUAL(size, res); 00447 res = memcmp(buffer, "kittycatcat", size); 00448 TEST_ASSERT_EQUAL(0, res); 00449 00450 size = file[0].size(); 00451 res = file[0].seek(0, SEEK_CUR); 00452 TEST_ASSERT_EQUAL(size, res); 00453 res = file[0].close(); 00454 TEST_ASSERT_EQUAL(0, res); 00455 res = fs.unmount(); 00456 TEST_ASSERT_EQUAL(0, res); 00457 } 00458 00459 res = bd.deinit(); 00460 TEST_ASSERT_EQUAL(0, res); 00461 } 00462 00463 void test_large_file_seek_and_write() 00464 { 00465 int res = bd.init(); 00466 TEST_ASSERT_EQUAL(0, res); 00467 00468 { 00469 size_t size; 00470 res = fs.mount(&bd); 00471 TEST_ASSERT_EQUAL(0, res); 00472 res = file[0].open(&fs, "hello/kitty42", O_RDWR); 00473 TEST_ASSERT_EQUAL(0, res); 00474 00475 off_t pos; 00476 size = strlen("kittycatcat"); 00477 for (int i = 0; i < 128; i++) { 00478 res = file[0].read(buffer, size); 00479 TEST_ASSERT_EQUAL(size, res); 00480 if (i != 4) { 00481 res = memcmp(buffer, "kittycatcat", size); 00482 TEST_ASSERT_EQUAL(0, res); 00483 } 00484 pos = file[0].tell(); 00485 } 00486 res = pos >= 0; 00487 TEST_ASSERT_EQUAL(1, res); 00488 00489 memcpy(buffer, "doggodogdog", size); 00490 res = file[0].seek(pos, SEEK_SET); 00491 TEST_ASSERT_EQUAL(pos, res); 00492 res = file[0].write(buffer, size); 00493 TEST_ASSERT_EQUAL(size, res); 00494 res = file[0].seek(pos, SEEK_SET); 00495 TEST_ASSERT_EQUAL(pos, res); 00496 res = file[0].read(buffer, size); 00497 TEST_ASSERT_EQUAL(size, res); 00498 res = memcmp(buffer, "doggodogdog", size); 00499 TEST_ASSERT_EQUAL(0, res); 00500 00501 file[0].rewind(); 00502 res = file[0].read(buffer, size); 00503 TEST_ASSERT_EQUAL(size, res); 00504 res = memcmp(buffer, "kittycatcat", size); 00505 TEST_ASSERT_EQUAL(0, res); 00506 res = file[0].seek(pos, SEEK_SET); 00507 TEST_ASSERT_EQUAL(pos, res); 00508 res = file[0].read(buffer, size); 00509 TEST_ASSERT_EQUAL(size, res); 00510 res = memcmp(buffer, "doggodogdog", size); 00511 TEST_ASSERT_EQUAL(0, res); 00512 res = file[0].seek(-size, SEEK_END) >= 0; 00513 TEST_ASSERT_EQUAL(1, res); 00514 res = file[0].read(buffer, size); 00515 TEST_ASSERT_EQUAL(size, res); 00516 res = memcmp(buffer, "kittycatcat", size); 00517 TEST_ASSERT_EQUAL(0, res); 00518 00519 size = file[0].size(); 00520 res = file[0].seek(0, SEEK_CUR); 00521 TEST_ASSERT_EQUAL(size, res); 00522 res = file[0].close(); 00523 TEST_ASSERT_EQUAL(0, res); 00524 res = fs.unmount(); 00525 TEST_ASSERT_EQUAL(0, res); 00526 } 00527 00528 res = bd.deinit(); 00529 TEST_ASSERT_EQUAL(0, res); 00530 } 00531 00532 void test_boundary_seek_and_write() 00533 { 00534 int res = bd.init(); 00535 TEST_ASSERT_EQUAL(0, res); 00536 00537 { 00538 size_t size; 00539 res = fs.mount(&bd); 00540 TEST_ASSERT_EQUAL(0, res); 00541 res = file[0].open(&fs, "hello/kitty42", O_RDWR); 00542 TEST_ASSERT_EQUAL(0, res); 00543 00544 size = strlen("hedgehoghog"); 00545 const off_t offsets[] = {512, 1020, 513, 1021, 511, 1019}; 00546 00547 for (int i = 0; i < sizeof(offsets) / sizeof(offsets[0]); i++) { 00548 off_t off = offsets[i]; 00549 memcpy(buffer, "hedgehoghog", size); 00550 res = file[0].seek(off, SEEK_SET); 00551 TEST_ASSERT_EQUAL(off, res); 00552 res = file[0].write(buffer, size); 00553 TEST_ASSERT_EQUAL(size, res); 00554 res = file[0].seek(off, SEEK_SET); 00555 TEST_ASSERT_EQUAL(off, res); 00556 res = file[0].read(buffer, size); 00557 TEST_ASSERT_EQUAL(size, res); 00558 res = memcmp(buffer, "hedgehoghog", size); 00559 TEST_ASSERT_EQUAL(0, res); 00560 res = file[0].seek(0, SEEK_SET); 00561 TEST_ASSERT_EQUAL(0, res); 00562 res = file[0].read(buffer, size); 00563 TEST_ASSERT_EQUAL(size, res); 00564 res = memcmp(buffer, "kittycatcat", size); 00565 TEST_ASSERT_EQUAL(0, res); 00566 res = file[0].sync(); 00567 TEST_ASSERT_EQUAL(0, res); 00568 } 00569 res = file[0].close(); 00570 TEST_ASSERT_EQUAL(0, res); 00571 res = fs.unmount(); 00572 TEST_ASSERT_EQUAL(0, res); 00573 } 00574 00575 res = bd.deinit(); 00576 TEST_ASSERT_EQUAL(0, res); 00577 } 00578 00579 void test_out_of_bounds_seek() 00580 { 00581 int res = bd.init(); 00582 TEST_ASSERT_EQUAL(0, res); 00583 00584 { 00585 size_t size; 00586 res = fs.mount(&bd); 00587 TEST_ASSERT_EQUAL(0, res); 00588 res = file[0].open(&fs, "hello/kitty42", O_RDWR); 00589 TEST_ASSERT_EQUAL(0, res); 00590 00591 size = strlen("kittycatcat"); 00592 res = file[0].size(); 00593 TEST_ASSERT_EQUAL(132 * size, res); 00594 res = file[0].seek((132 + 4) * size, 00595 SEEK_SET); 00596 TEST_ASSERT_EQUAL((132 + 4)*size, res); 00597 res = file[0].read(buffer, size); 00598 TEST_ASSERT_EQUAL(0, res); 00599 00600 memcpy(buffer, "porcupineee", size); 00601 res = file[0].write(buffer, size); 00602 TEST_ASSERT_EQUAL(size, res); 00603 res = file[0].seek((132 + 4) * size, 00604 SEEK_SET); 00605 TEST_ASSERT_EQUAL((132 + 4)*size, res); 00606 res = file[0].read(buffer, size); 00607 TEST_ASSERT_EQUAL(size, res); 00608 res = memcmp(buffer, "porcupineee", size); 00609 TEST_ASSERT_EQUAL(0, res); 00610 res = file[0].seek(132 * size, 00611 SEEK_SET); 00612 TEST_ASSERT_EQUAL(132 * size, res); 00613 res = file[0].read(buffer, size); 00614 TEST_ASSERT_EQUAL(size, res); 00615 #if (MBED_TEST_FILESYSTEM != FATFileSystem) 00616 // FatFs does not guarantee empty expanded buffer 00617 res = memcmp(buffer, "\0\0\0\0\0\0\0\0\0\0\0", size); 00618 TEST_ASSERT_EQUAL(0, res); 00619 #endif 00620 res = file[0].close(); 00621 TEST_ASSERT_EQUAL(0, res); 00622 res = fs.unmount(); 00623 TEST_ASSERT_EQUAL(0, res); 00624 } 00625 00626 res = bd.deinit(); 00627 TEST_ASSERT_EQUAL(0, res); 00628 } 00629 00630 00631 00632 // test setup 00633 utest::v1::status_t test_setup(const size_t number_of_cases) 00634 { 00635 GREENTEA_SETUP(MBED_TEST_TIMEOUT, "default_auto"); 00636 return verbose_test_setup_handler(number_of_cases); 00637 } 00638 00639 Case cases[] = { 00640 Case("Seek tests", test_seek_tests), 00641 Case("Simple dir seek", test_simple_dir_seek), 00642 Case("Large dir seek", test_large_dir_seek), 00643 Case("Simple file seek", test_simple_file_seek), 00644 Case("Large file seek", test_large_file_seek), 00645 Case("Simple file seek and write", test_simple_file_seek_and_write), 00646 Case("Large file seek and write", test_large_file_seek_and_write), 00647 Case("Boundary seek and write", test_boundary_seek_and_write), 00648 Case("Out-of-bounds seek", test_out_of_bounds_seek), 00649 }; 00650 00651 Specification specification(test_setup, cases); 00652 00653 int main() 00654 { 00655 return !Harness::run(specification); 00656 }
Generated on Sun Jul 17 2022 03:41:56 by
1.7.2