Mercurial > yaffs-ecoscentric-gpl
comparison packages/fs/yaffs/current/tests/yaffs6.c @ 428:a386ed10401a ecos
Drop in eCos bridge work
| author | Ross Younger <wry@ecoscentric.com> |
|---|---|
| date | Fri, 14 May 2010 17:01:32 +0100 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 427:d52e3cced121 | 428:a386ed10401a |
|---|---|
| 1 //========================================================================== | |
| 2 // | |
| 3 // yaffs6.c | |
| 4 // | |
| 5 // Test FAT UTF-8 support | |
| 6 // | |
| 7 //========================================================================== | |
| 8 // ####ECOSGPLCOPYRIGHTBEGIN#### | |
| 9 // ------------------------------------------- | |
| 10 // This file is part of eCos, the Embedded Configurable Operating System. | |
| 11 // Copyright (C) 1998, 1999, 2000, 2001, 2002, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. | |
| 12 // Copyright (C) 2004, 2005, 2006, 2007 eCosCentric Limited | |
| 13 // | |
| 14 // eCos is free software; you can redistribute it and/or modify it under | |
| 15 // the terms of the GNU General Public License as published by the Free | |
| 16 // Software Foundation; either version 2 or (at your option) any later | |
| 17 // version. | |
| 18 // | |
| 19 // eCos is distributed in the hope that it will be useful, but WITHOUT | |
| 20 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 21 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 22 // for more details. | |
| 23 // | |
| 24 // You should have received a copy of the GNU General Public License | |
| 25 // along with eCos; if not, write to the Free Software Foundation, Inc., | |
| 26 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
| 27 // | |
| 28 // As a special exception, if other files instantiate templates or use | |
| 29 // macros or inline functions from this file, or you compile this file | |
| 30 // and link it with other works to produce a work based on this file, | |
| 31 // this file does not by itself cause the resulting work to be covered by | |
| 32 // the GNU General Public License. However the source code for this file | |
| 33 // must still be made available in accordance with section (3) of the GNU | |
| 34 // General Public License v2. | |
| 35 // | |
| 36 // This exception does not invalidate any other reasons why a work based | |
| 37 // on this file might be covered by the GNU General Public License. | |
| 38 // ------------------------------------------- | |
| 39 // ####ECOSGPLCOPYRIGHTEND#### | |
| 40 //========================================================================== | |
| 41 //#####DESCRIPTIONBEGIN#### | |
| 42 // | |
| 43 // Author(s): nickg | |
| 44 // Contributors: nickg | |
| 45 // Date: 2007-06-20 | |
| 46 // Purpose: Test fileio system | |
| 47 // Description: This test uses the testfs to check out the initialization | |
| 48 // and basic operation of the fileio system. | |
| 49 // This is essentially a copy of yaffs4 with UTF8 encoded | |
| 50 // file names. | |
| 51 // | |
| 52 //####DESCRIPTIONEND#### | |
| 53 // | |
| 54 //========================================================================== | |
| 55 | |
| 56 #include <pkgconf/system.h> | |
| 57 | |
| 58 #ifdef CYGPKG_KERNEL | |
| 59 | |
| 60 #include <pkgconf/hal.h> | |
| 61 #include <pkgconf/kernel.h> | |
| 62 #include <pkgconf/io_fileio.h> | |
| 63 | |
| 64 #include CYGDAT_DEVS_DISK_CFG // testing config defines | |
| 65 | |
| 66 #include <cyg/kernel/ktypes.h> // base kernel types | |
| 67 #include <cyg/infra/cyg_trac.h> // tracing macros | |
| 68 #include <cyg/infra/cyg_ass.h> // assertion macros | |
| 69 | |
| 70 #include <unistd.h> | |
| 71 #include <fcntl.h> | |
| 72 #include <sys/stat.h> | |
| 73 #include <errno.h> | |
| 74 #include <string.h> | |
| 75 #include <dirent.h> | |
| 76 | |
| 77 #include <cyg/fileio/fileio.h> | |
| 78 | |
| 79 #include <cyg/infra/testcase.h> | |
| 80 #include <cyg/infra/diag.h> // HAL polled output | |
| 81 | |
| 82 //========================================================================== | |
| 83 // Config options | |
| 84 | |
| 85 #define TEST_DEVICE CYGDAT_DEVS_DISK_TEST_DEVICE | |
| 86 | |
| 87 #define TEST_MOUNTPOINT CYGDAT_DEVS_DISK_TEST_MOUNTPOINT | |
| 88 | |
| 89 #define TEST_DIRECTORY CYGDAT_DEVS_DISK_TEST_DIRECTORY | |
| 90 | |
| 91 #define TEST_FSTYPE "yaffs" | |
| 92 | |
| 93 #ifdef CYGDAT_DEVS_DISK_TEST_MOUNTPOINT2 | |
| 94 | |
| 95 #define TEST_DEVICE2 CYGDAT_DEVS_DISK_TEST_DEVICE2 | |
| 96 | |
| 97 #define TEST_MOUNTPOINT2 CYGDAT_DEVS_DISK_TEST_MOUNTPOINT2 | |
| 98 | |
| 99 #define TEST_DIRECTORY2 CYGDAT_DEVS_DISK_TEST_DIRECTORY2 | |
| 100 | |
| 101 #define TEST_FSTYPE2 "yaffs" | |
| 102 | |
| 103 #endif | |
| 104 | |
| 105 //========================================================================== | |
| 106 | |
| 107 #define SHOW_RESULT( _fn, _res ) \ | |
| 108 { \ | |
| 109 diag_printf("<FAIL>: " #_fn "() returned %ld %s\n", (long)_res, _res<0?strerror(errno):""); \ | |
| 110 } | |
| 111 | |
| 112 //========================================================================== | |
| 113 | |
| 114 #define IOSIZE 100 | |
| 115 | |
| 116 #define CLEANUP | |
| 117 | |
| 118 //========================================================================== | |
| 119 // The following filenames are in Cyrillic and are UTF-8 encoded. | |
| 120 // | |
| 121 // WARNING: Only edit this file with an editor that is UTF-8 aware (I | |
| 122 // use EMACS on Linux, but Notepad on Windows also works). Saving this | |
| 123 // file from an unaware editor could cause these strings to be | |
| 124 // corrupted and make this test fail. If the strings below do not | |
| 125 // appear as clean Cyrillic characters then exit now without saving | |
| 126 // and look for a better editor. | |
| 127 | |
| 128 #if 1 | |
| 129 | |
| 130 #define FOO "Фоо" | |
| 131 #define FEE "Спутник" | |
| 132 #define BAR "Байконур" | |
| 133 #define BUNDY "СергеЬй ПаЬвлович Королёв" | |
| 134 #define FUM "Юрий Гагаринский" | |
| 135 #define DOO "Константин Эдуардович Циолковский" | |
| 136 //#define FIE "Федеральное космическое агентство России" | |
| 137 #define FIE "Федеральное космическое" | |
| 138 #define FOE "Валентин Петрович Глушко" | |
| 139 | |
| 140 #define TINKY "Восток" | |
| 141 #define LAALAA "Восход" | |
| 142 #define NOONOO "Салют" | |
| 143 #define DIPSY "Космодром" | |
| 144 #define PO "Лайка" | |
| 145 | |
| 146 #define XXXX "Гласность" | |
| 147 #define YYYY "перестройка" | |
| 148 #define ZZZZ "Калашникова" | |
| 149 #define WWWW "матрёшка" | |
| 150 | |
| 151 #else | |
| 152 | |
| 153 #define FOO "foo" | |
| 154 #define FEE "fee" | |
| 155 #define BAR "bar" | |
| 156 #define BUNDY "bundy" | |
| 157 #define FUM "fum" | |
| 158 #define DOO "doo" | |
| 159 #define FIE "fie" | |
| 160 #define FOE "foe" | |
| 161 | |
| 162 #define TINKY "tinky" | |
| 163 #define LAALAA "laalaa" | |
| 164 #define NOONOO "noonoo" | |
| 165 #define DIPSY "dipsy" | |
| 166 #define PO "po" | |
| 167 | |
| 168 #define XXXX "xxxx" | |
| 169 #define YYYY "yyyy" | |
| 170 #define ZZZZ "zzzz" | |
| 171 #define WWWW "wwww" | |
| 172 | |
| 173 #endif | |
| 174 | |
| 175 | |
| 176 //========================================================================== | |
| 177 | |
| 178 #ifndef CYGPKG_LIBC_STRING | |
| 179 | |
| 180 char *strcat( char *s1, const char *s2 ) | |
| 181 { | |
| 182 char *s = s1; | |
| 183 while( *s1 ) s1++; | |
| 184 while( (*s1++ = *s2++) != 0); | |
| 185 return s; | |
| 186 } | |
| 187 | |
| 188 #endif | |
| 189 | |
| 190 __externC int | |
| 191 rename( const char * /* oldpath */, const char * /* newpath */ ) __THROW; | |
| 192 | |
| 193 //========================================================================== | |
| 194 | |
| 195 static void listdir( char *name, int statp, int numexpected, int *numgot ) | |
| 196 { | |
| 197 int err; | |
| 198 DIR *dirp; | |
| 199 int num=0; | |
| 200 | |
| 201 diag_printf("<INFO>: reading directory %s\n",name); | |
| 202 | |
| 203 // diag_printf("<INFO>: opendir(%s)\n",name); | |
| 204 dirp = opendir( name ); | |
| 205 if( dirp == NULL ) SHOW_RESULT( opendir, -1 ); | |
| 206 | |
| 207 for(;;) | |
| 208 { | |
| 209 struct dirent *entry = readdir( dirp ); | |
| 210 | |
| 211 if( entry == NULL ) | |
| 212 break; | |
| 213 num++; | |
| 214 | |
| 215 diag_printf("<INFO>: entry "); | |
| 216 | |
| 217 if( statp ) | |
| 218 { | |
| 219 char fullname[PATH_MAX]; | |
| 220 struct stat sbuf; | |
| 221 | |
| 222 if( name[0] ) | |
| 223 { | |
| 224 strcpy(fullname, name ); | |
| 225 if( !(name[0] == '/' && name[1] == 0 ) ) | |
| 226 strcat(fullname, "/" ); | |
| 227 } | |
| 228 else fullname[0] = 0; | |
| 229 | |
| 230 strcat(fullname, entry->d_name ); | |
| 231 | |
| 232 err = stat( fullname, &sbuf ); | |
| 233 if( err < 0 ) | |
| 234 { | |
| 235 if( errno == ENOSYS ) | |
| 236 diag_printf(" <no status available>"); | |
| 237 else SHOW_RESULT( stat, err ); | |
| 238 } | |
| 239 else | |
| 240 { | |
| 241 diag_printf(" [mode %08x ino %08x nlink %d size %6ld]", | |
| 242 sbuf.st_mode,sbuf.st_ino,sbuf.st_nlink,sbuf.st_size); | |
| 243 } | |
| 244 } | |
| 245 | |
| 246 diag_printf(" %s\n",entry->d_name); | |
| 247 } | |
| 248 | |
| 249 // diag_printf("<INFO>: closedir(%s)\n",name); | |
| 250 err = closedir( dirp ); | |
| 251 if( err < 0 ) SHOW_RESULT( stat, err ); | |
| 252 if (numexpected >= 0 && num != numexpected) | |
| 253 CYG_TEST_FAIL("Wrong number of dir entries"); | |
| 254 if ( numgot != NULL ) | |
| 255 *numgot = num; | |
| 256 } | |
| 257 | |
| 258 //========================================================================== | |
| 259 | |
| 260 static void createfile( char *name, size_t size ) | |
| 261 { | |
| 262 char buf[IOSIZE]; | |
| 263 int fd; | |
| 264 ssize_t wrote; | |
| 265 int i; | |
| 266 int err; | |
| 267 | |
| 268 diag_printf("<INFO>: create file %s size %ld\n",name, (long)size); | |
| 269 | |
| 270 err = access( name, F_OK ); | |
| 271 if( err < 0 && errno != EACCES ) SHOW_RESULT( access, err ); | |
| 272 | |
| 273 for( i = 0; i < IOSIZE; i++ ) buf[i] = i%256; | |
| 274 | |
| 275 fd = open( name, O_WRONLY|O_CREAT ); | |
| 276 if( fd < 0 ) SHOW_RESULT( open, fd ); | |
| 277 | |
| 278 while( size > 0 ) | |
| 279 { | |
| 280 ssize_t len = size; | |
| 281 if ( len > IOSIZE ) len = IOSIZE; | |
| 282 | |
| 283 wrote = write( fd, buf, len ); | |
| 284 if( wrote != len ) SHOW_RESULT( write, wrote ); | |
| 285 | |
| 286 size -= wrote; | |
| 287 } | |
| 288 | |
| 289 err = close( fd ); | |
| 290 if( err < 0 ) SHOW_RESULT( close, err ); | |
| 291 } | |
| 292 | |
| 293 //========================================================================== | |
| 294 | |
| 295 #if 0 | |
| 296 static void maxfile( char *name ) | |
| 297 { | |
| 298 char buf[IOSIZE]; | |
| 299 int fd; | |
| 300 ssize_t wrote; | |
| 301 int i; | |
| 302 int err; | |
| 303 size_t size = 0; | |
| 304 size_t prevsize = 0; | |
| 305 | |
| 306 diag_printf("<INFO>: create maximal file %s\n",name); | |
| 307 diag_printf("<INFO>: This may take a few minutes\n"); | |
| 308 | |
| 309 err = access( name, F_OK ); | |
| 310 if( err < 0 && errno != EACCES ) SHOW_RESULT( access, err ); | |
| 311 | |
| 312 for( i = 0; i < IOSIZE; i++ ) buf[i] = i%256; | |
| 313 | |
| 314 fd = open( name, O_WRONLY|O_CREAT ); | |
| 315 if( fd < 0 ) SHOW_RESULT( open, fd ); | |
| 316 | |
| 317 do | |
| 318 { | |
| 319 wrote = write( fd, buf, IOSIZE ); | |
| 320 //if( wrote < 0 ) SHOW_RESULT( write, wrote ); | |
| 321 | |
| 322 if( wrote >= 0 ) | |
| 323 size += wrote; | |
| 324 | |
| 325 if( (size-prevsize) > 100000 ) | |
| 326 { | |
| 327 diag_printf("<INFO>: size = %ld \n", size); | |
| 328 prevsize = size; | |
| 329 } | |
| 330 | |
| 331 } while( wrote == IOSIZE ); | |
| 332 | |
| 333 diag_printf("<INFO>: file size == %ld\n",size); | |
| 334 | |
| 335 err = close( fd ); | |
| 336 if( err < 0 ) SHOW_RESULT( close, err ); | |
| 337 } | |
| 338 #endif | |
| 339 | |
| 340 //========================================================================== | |
| 341 | |
| 342 static void checkfile( char *name ) | |
| 343 { | |
| 344 char buf[IOSIZE]; | |
| 345 int fd; | |
| 346 ssize_t done; | |
| 347 int i; | |
| 348 int err; | |
| 349 off_t pos = 0; | |
| 350 | |
| 351 diag_printf("<INFO>: check file %s\n",name); | |
| 352 | |
| 353 err = access( name, F_OK ); | |
| 354 if( err != 0 ) SHOW_RESULT( access, err ); | |
| 355 | |
| 356 fd = open( name, O_RDONLY ); | |
| 357 if( fd < 0 ) SHOW_RESULT( open, fd ); | |
| 358 | |
| 359 for(;;) | |
| 360 { | |
| 361 done = read( fd, buf, IOSIZE ); | |
| 362 if( done < 0 ) SHOW_RESULT( read, done ); | |
| 363 | |
| 364 if( done == 0 ) break; | |
| 365 | |
| 366 for( i = 0; i < done; i++ ) | |
| 367 if( buf[i] != i%256 ) | |
| 368 { | |
| 369 diag_printf("buf[%ld+%d](%02x) != %02x\n",pos,i,buf[i],i%256); | |
| 370 CYG_TEST_FAIL("Data read not equal to data written\n"); | |
| 371 for(;;); | |
| 372 } | |
| 373 | |
| 374 pos += done; | |
| 375 } | |
| 376 | |
| 377 err = close( fd ); | |
| 378 if( err < 0 ) SHOW_RESULT( close, err ); | |
| 379 } | |
| 380 | |
| 381 //========================================================================== | |
| 382 | |
| 383 static void copyfile( char *name2, char *name1 ) | |
| 384 { | |
| 385 | |
| 386 int err; | |
| 387 char buf[IOSIZE]; | |
| 388 int fd1, fd2; | |
| 389 ssize_t done, wrote; | |
| 390 | |
| 391 diag_printf("<INFO>: copy file %s -> %s\n",name2,name1); | |
| 392 | |
| 393 err = access( name1, F_OK ); | |
| 394 if( err < 0 && errno != EACCES ) SHOW_RESULT( access, err ); | |
| 395 | |
| 396 err = access( name2, F_OK ); | |
| 397 if( err != 0 ) SHOW_RESULT( access, err ); | |
| 398 | |
| 399 fd1 = open( name1, O_WRONLY|O_CREAT ); | |
| 400 if( fd1 < 0 ) SHOW_RESULT( open, fd1 ); | |
| 401 | |
| 402 fd2 = open( name2, O_RDONLY ); | |
| 403 if( fd2 < 0 ) SHOW_RESULT( open, fd2 ); | |
| 404 | |
| 405 for(;;) | |
| 406 { | |
| 407 done = read( fd2, buf, IOSIZE ); | |
| 408 if( done < 0 ) SHOW_RESULT( read, done ); | |
| 409 | |
| 410 if( done == 0 ) break; | |
| 411 | |
| 412 wrote = write( fd1, buf, done ); | |
| 413 if( wrote != done ) SHOW_RESULT( write, wrote ); | |
| 414 | |
| 415 if( wrote != done ) break; | |
| 416 } | |
| 417 | |
| 418 err = close( fd1 ); | |
| 419 if( err < 0 ) SHOW_RESULT( close, err ); | |
| 420 | |
| 421 err = close( fd2 ); | |
| 422 if( err < 0 ) SHOW_RESULT( close, err ); | |
| 423 | |
| 424 } | |
| 425 | |
| 426 //========================================================================== | |
| 427 | |
| 428 static void comparefiles( char *name2, char *name1 ) | |
| 429 { | |
| 430 int err; | |
| 431 char buf1[IOSIZE]; | |
| 432 char buf2[IOSIZE]; | |
| 433 int fd1, fd2; | |
| 434 ssize_t done1, done2; | |
| 435 int i; | |
| 436 | |
| 437 diag_printf("<INFO>: compare files %s == %s\n",name2,name1); | |
| 438 | |
| 439 err = access( name1, F_OK ); | |
| 440 if( err != 0 ) SHOW_RESULT( access, err ); | |
| 441 | |
| 442 err = access( name1, F_OK ); | |
| 443 if( err != 0 ) SHOW_RESULT( access, err ); | |
| 444 | |
| 445 fd1 = open( name1, O_RDONLY ); | |
| 446 if( fd1 < 0 ) SHOW_RESULT( open, fd1 ); | |
| 447 | |
| 448 fd2 = open( name2, O_RDONLY ); | |
| 449 if( fd2 < 0 ) SHOW_RESULT( open, fd2 ); | |
| 450 | |
| 451 for(;;) | |
| 452 { | |
| 453 done1 = read( fd1, buf1, IOSIZE ); | |
| 454 if( done1 < 0 ) SHOW_RESULT( read, done1 ); | |
| 455 | |
| 456 done2 = read( fd2, buf2, IOSIZE ); | |
| 457 if( done2 < 0 ) SHOW_RESULT( read, done2 ); | |
| 458 | |
| 459 if( done1 != done2 ) | |
| 460 diag_printf("Files different sizes\n"); | |
| 461 | |
| 462 if( done1 == 0 ) break; | |
| 463 | |
| 464 for( i = 0; i < done1; i++ ) | |
| 465 if( buf1[i] != buf2[i] ) | |
| 466 { | |
| 467 diag_printf("buf1[%d](%02x) != buf1[%d](%02x)\n",i,buf1[i],i,buf2[i]); | |
| 468 CYG_TEST_FAIL("Data in files not equal\n"); | |
| 469 } | |
| 470 } | |
| 471 | |
| 472 err = close( fd1 ); | |
| 473 if( err < 0 ) SHOW_RESULT( close, err ); | |
| 474 | |
| 475 err = close( fd2 ); | |
| 476 if( err < 0 ) SHOW_RESULT( close, err ); | |
| 477 | |
| 478 } | |
| 479 | |
| 480 //========================================================================== | |
| 481 | |
| 482 void checkcwd( const char *cwd ) | |
| 483 { | |
| 484 static char cwdbuf[PATH_MAX]; | |
| 485 char *ret; | |
| 486 | |
| 487 ret = getcwd( cwdbuf, sizeof(cwdbuf)); | |
| 488 if( ret == NULL ) SHOW_RESULT( getcwd, ret ); | |
| 489 | |
| 490 if( strcmp( cwdbuf, cwd ) != 0 ) | |
| 491 { | |
| 492 diag_printf( "cwdbuf %s cwd %s\n",cwdbuf, cwd ); | |
| 493 CYG_TEST_FAIL( "Current directory mismatch"); | |
| 494 } | |
| 495 } | |
| 496 | |
| 497 //========================================================================== | |
| 498 // main | |
| 499 | |
| 500 void yaffs6_main( CYG_ADDRESS id ) | |
| 501 { | |
| 502 int err; | |
| 503 int existingdirents=-1; | |
| 504 cyg_bool mp2 = false; | |
| 505 int fd; | |
| 506 | |
| 507 char dirname[256]; | |
| 508 char filename1[256]; | |
| 509 char filename2[256]; | |
| 510 | |
| 511 #define NEW_FILENAME( fn, f ) \ | |
| 512 { \ | |
| 513 fn[0]=0; \ | |
| 514 strcat(fn, dirname); \ | |
| 515 strcat(fn, "/"); \ | |
| 516 strcat(fn,f); \ | |
| 517 } | |
| 518 | |
| 519 #define NEW_FILENAME1( f ) NEW_FILENAME( filename1, f ) | |
| 520 #define NEW_FILENAME2( f ) NEW_FILENAME( filename2, f ) | |
| 521 | |
| 522 CYG_TEST_INIT(); | |
| 523 | |
| 524 #ifdef CYGDBG_INFRA_DIAG_CHECK_STRINGS | |
| 525 diag_printf("WARNING: CYGDBG_INFRA_DIAG_CHECK_STRINGS is defined, Cyrillic file names will not be printed.\n"); | |
| 526 #else | |
| 527 diag_printf("WARNING: Cyrillic file names printed in UTF-8 may not be readable in some environments.\n"); | |
| 528 #endif | |
| 529 | |
| 530 // -------------------------------------------------------------- | |
| 531 | |
| 532 err = mount( TEST_DEVICE, TEST_MOUNTPOINT, TEST_FSTYPE ); | |
| 533 if( err < 0 ) { | |
| 534 SHOW_RESULT( mount, err ); | |
| 535 CYG_TEST_FAIL_FINISH("yaffs6"); | |
| 536 } | |
| 537 | |
| 538 err = access( TEST_MOUNTPOINT TEST_DIRECTORY, F_OK ); | |
| 539 if( err < 0 && errno != EACCES ) SHOW_RESULT( access, err ); | |
| 540 | |
| 541 if( err < 0 && errno == EACCES ) | |
| 542 { | |
| 543 diag_printf("<INFO>: create %s\n", | |
| 544 TEST_MOUNTPOINT TEST_DIRECTORY); | |
| 545 err = mkdir( TEST_MOUNTPOINT TEST_DIRECTORY, 0 ); | |
| 546 if( err < 0 ) SHOW_RESULT( mkdir, err ); | |
| 547 } | |
| 548 | |
| 549 err = chdir( TEST_MOUNTPOINT TEST_DIRECTORY ); | |
| 550 if( err < 0 ) SHOW_RESULT( chdir, err ); | |
| 551 | |
| 552 checkcwd( TEST_MOUNTPOINT TEST_DIRECTORY ); | |
| 553 | |
| 554 listdir( TEST_MOUNTPOINT TEST_DIRECTORY, true, -1, &existingdirents ); | |
| 555 | |
| 556 // -------------------------------------------------------------- | |
| 557 | |
| 558 dirname[0] = 0; | |
| 559 strcat(dirname, TEST_MOUNTPOINT ); | |
| 560 strcat(dirname, TEST_DIRECTORY ); | |
| 561 | |
| 562 // -------------------------------------------------------------- | |
| 563 | |
| 564 createfile( FOO, 20257 ); | |
| 565 checkfile( FOO ); | |
| 566 copyfile( FOO, FEE); | |
| 567 checkfile( FEE ); | |
| 568 comparefiles( FOO, FEE ); | |
| 569 | |
| 570 diag_printf("<INFO>: mkdir " BAR "\n"); | |
| 571 err = mkdir( BAR, 0 ); | |
| 572 if( err < 0 ) SHOW_RESULT( mkdir, err ); | |
| 573 | |
| 574 listdir( dirname , true, existingdirents+3, NULL ); | |
| 575 | |
| 576 copyfile( FEE, BAR "/" FUM ); | |
| 577 checkfile( BAR "/" FUM ); | |
| 578 comparefiles( FEE, BAR "/" FUM ); | |
| 579 | |
| 580 diag_printf("<INFO>: cd " BAR "\n"); | |
| 581 err = chdir( BAR ); | |
| 582 if( err < 0 ) SHOW_RESULT( chdir, err ); | |
| 583 | |
| 584 NEW_FILENAME1( BAR ); | |
| 585 checkcwd( filename1 ); | |
| 586 | |
| 587 diag_printf("<INFO>: rename ../" FOO " " BUNDY "\n"); | |
| 588 err = rename( "../" FOO, BUNDY ); | |
| 589 if( err < 0 ) SHOW_RESULT( rename, err ); | |
| 590 | |
| 591 listdir( dirname, true, existingdirents+2, NULL ); | |
| 592 listdir( "." , true, 4, NULL ); | |
| 593 | |
| 594 checkfile( "../" BAR "/" BUNDY ); | |
| 595 comparefiles("../" FEE, BUNDY ); | |
| 596 | |
| 597 #if 1 | |
| 598 | |
| 599 // -------------------------------------------------------------- | |
| 600 // Check for some common error cases | |
| 601 | |
| 602 // First make some directories | |
| 603 diag_printf("<INFO>: mkdir " DOO "\n"); | |
| 604 err = mkdir( DOO, 0 ); | |
| 605 if( err < 0 ) SHOW_RESULT( mkdir, err ); | |
| 606 | |
| 607 diag_printf("<INFO>: mkdir " FIE" \n"); | |
| 608 err = mkdir( FIE, 0 ); | |
| 609 if( err < 0 ) SHOW_RESULT( mkdir, err ); | |
| 610 | |
| 611 diag_printf("<INFO>: mkdir " FIE "/" FOE "\n"); | |
| 612 err = mkdir( FIE "/" FOE, 0 ); | |
| 613 if( err < 0 ) SHOW_RESULT( mkdir, err ); | |
| 614 | |
| 615 | |
| 616 diag_printf("<INFO>: rename " FUM " " DOO " -- should fail\n"); | |
| 617 err = rename( FUM, DOO ); | |
| 618 if( err < 0 && errno != EISDIR ) SHOW_RESULT( rename, err ); | |
| 619 | |
| 620 diag_printf("<INFO>: rename " DOO " " FUM " -- should fail\n"); | |
| 621 err = rename( DOO, FUM ); | |
| 622 if( err < 0 && errno != ENOTDIR ) SHOW_RESULT( rename, err ); | |
| 623 | |
| 624 diag_printf("<INFO>: rename " DOO " " FIE " -- should fail\n"); | |
| 625 err = rename( DOO, FIE ); | |
| 626 if( err < 0 && errno != EIO ) SHOW_RESULT( rename, err ); | |
| 627 | |
| 628 NEW_FILENAME1( XXXX "/" YYYY ) | |
| 629 diag_printf("<INFO>: rename " FUM " %s -- should fail\n",filename1); | |
| 630 err = rename( FUM, filename1 ); | |
| 631 if( err < 0 && errno != ENOENT ) SHOW_RESULT( rename, err ); | |
| 632 | |
| 633 diag_printf("<INFO>: rename " FUM " " FUM " -- should fail\n"); | |
| 634 err = rename( FUM, FUM ); | |
| 635 if( err < 0 ) SHOW_RESULT( rename, err ); | |
| 636 | |
| 637 diag_printf("<INFO>: unlink " FEE " -- should fail\n"); | |
| 638 err = unlink( FEE ); | |
| 639 if( err < 0 && errno != ENOENT ) SHOW_RESULT( unlink, err ); | |
| 640 | |
| 641 NEW_FILENAME1( BAR ); | |
| 642 diag_printf("<INFO>: rmdir %s -- should fail\n",filename1); | |
| 643 err = rmdir( filename1 ); | |
| 644 if( err < 0 && errno != ENOTEMPTY ) SHOW_RESULT( rmdir, err ); | |
| 645 | |
| 646 diag_printf("<INFO>: unlink %s -- should fail\n",filename1); | |
| 647 err = unlink( filename1 ); | |
| 648 if( err < 0 && errno != EISDIR ) SHOW_RESULT( unlink, err ); | |
| 649 | |
| 650 NEW_FILENAME1( BAR "/" FUM ); | |
| 651 diag_printf("<INFO>: rmdir %s -- should fail\n",filename1); | |
| 652 err = rmdir( filename1 ); | |
| 653 if( err < 0 && errno != ENOTDIR ) SHOW_RESULT( rmdir, err ); | |
| 654 | |
| 655 diag_printf("<INFO>: mkdir %s -- should fail\n",filename1); | |
| 656 err = mkdir( filename1, 0 ); | |
| 657 if( err < 0 && errno != EEXIST ) SHOW_RESULT( mkdir, err ); | |
| 658 | |
| 659 diag_printf("<INFO>: open " BUNDY " exclusive -- should fail\n"); | |
| 660 fd = open( BUNDY, O_WRONLY|O_CREAT|O_EXCL ); | |
| 661 if( fd < 0 && errno != EEXIST ) SHOW_RESULT( open, fd ); | |
| 662 | |
| 663 diag_printf("<INFO>: open %s -- should fail\n",dirname); | |
| 664 fd = open( dirname, O_WRONLY ); | |
| 665 if( fd < 0 && errno != EISDIR ) SHOW_RESULT( open, fd ); | |
| 666 | |
| 667 | |
| 668 listdir( dirname, true, existingdirents+2, NULL ); | |
| 669 listdir( "." , true, 6, NULL ); | |
| 670 | |
| 671 // -------------------------------------------------------------- | |
| 672 | |
| 673 #ifdef CLEANUP | |
| 674 | |
| 675 diag_printf("<INFO>: rename " FIE " " DOO "\n"); | |
| 676 err = rename( FIE, DOO ); | |
| 677 if( err < 0 ) SHOW_RESULT( unlink, err ); | |
| 678 | |
| 679 diag_printf("<INFO>: rmdir " DOO "/" FOE "\n"); | |
| 680 err = rmdir(DOO "/" FOE); | |
| 681 if( err < 0 ) SHOW_RESULT( unlink, err ); | |
| 682 | |
| 683 diag_printf("<INFO>: rmdir " DOO "\n"); | |
| 684 err = rmdir(DOO); | |
| 685 if( err < 0 ) SHOW_RESULT( unlink, err ); | |
| 686 | |
| 687 diag_printf("<INFO>: unlink ../" FEE "\n"); | |
| 688 err = unlink( "../" FEE ); | |
| 689 if( err < 0 ) SHOW_RESULT( unlink, err ); | |
| 690 | |
| 691 diag_printf("<INFO>: unlink " FUM "\n"); | |
| 692 err = unlink( FUM ); | |
| 693 if( err < 0 ) SHOW_RESULT( unlink, err ); | |
| 694 | |
| 695 diag_printf("<INFO>: unlink ../" BAR "/" BUNDY "\n"); | |
| 696 err = unlink( "../" BAR "/" BUNDY ); | |
| 697 if( err < 0 ) SHOW_RESULT( unlink, err ); | |
| 698 #endif | |
| 699 | |
| 700 diag_printf("<INFO>: cd ..\n"); | |
| 701 err = chdir( ".." ); | |
| 702 if( err < 0 ) SHOW_RESULT( chdir, err ); | |
| 703 | |
| 704 checkcwd( dirname ); | |
| 705 | |
| 706 #ifdef CLEANUP | |
| 707 diag_printf("<INFO>: rmdir " BAR "\n"); | |
| 708 err = rmdir( BAR ); | |
| 709 if( err < 0 ) SHOW_RESULT( rmdir, err ); | |
| 710 | |
| 711 listdir( dirname, false, existingdirents, NULL ); | |
| 712 #endif | |
| 713 | |
| 714 // -------------------------------------------------------------- | |
| 715 | |
| 716 #ifdef TEST_MOUNTPOINT2 | |
| 717 diag_printf("<INFO>: mount %s\n", TEST_MOUNTPOINT2); | |
| 718 err = mount( TEST_DEVICE2, TEST_MOUNTPOINT2, TEST_FSTYPE2 ); | |
| 719 | |
| 720 if( err == 0 ) | |
| 721 { | |
| 722 mp2 = true; | |
| 723 diag_printf("<INFO>: mount %s succeeded\n", TEST_MOUNTPOINT2); | |
| 724 err = access( TEST_MOUNTPOINT2 TEST_DIRECTORY2, F_OK ); | |
| 725 if( err < 0 && errno != EACCES ) SHOW_RESULT( access, err ); | |
| 726 | |
| 727 if( err < 0 && errno == EACCES ) | |
| 728 { | |
| 729 diag_printf("<INFO>: create %s\n", | |
| 730 TEST_MOUNTPOINT2 TEST_DIRECTORY2); | |
| 731 err = mkdir( TEST_MOUNTPOINT2 TEST_DIRECTORY2, 0 ); | |
| 732 if( err < 0 ) SHOW_RESULT( mkdir, err ); | |
| 733 } | |
| 734 | |
| 735 err = chdir( TEST_MOUNTPOINT2 TEST_DIRECTORY2 ); | |
| 736 if( err < 0 ) SHOW_RESULT( chdir, err ); | |
| 737 | |
| 738 checkcwd( TEST_MOUNTPOINT2 TEST_DIRECTORY2 ); | |
| 739 | |
| 740 dirname[0] = 0; | |
| 741 strcat(dirname, TEST_MOUNTPOINT2 ); | |
| 742 strcat(dirname, TEST_DIRECTORY2 ); | |
| 743 | |
| 744 } | |
| 745 else | |
| 746 { | |
| 747 mp2 = false; | |
| 748 diag_printf("<INFO>: mount %s failed, ", TEST_MOUNTPOINT2); | |
| 749 diag_printf("using %s instead\n", dirname ); | |
| 750 } | |
| 751 | |
| 752 #endif | |
| 753 | |
| 754 listdir( dirname , true, -1, &existingdirents); | |
| 755 | |
| 756 NEW_FILENAME1( TINKY ); | |
| 757 NEW_FILENAME2( LAALAA ); | |
| 758 | |
| 759 createfile( filename1, 4567 ); | |
| 760 copyfile( filename1, filename2 ); | |
| 761 checkfile( filename1); | |
| 762 checkfile( filename2); | |
| 763 comparefiles( filename1, filename2 ); | |
| 764 | |
| 765 diag_printf("<INFO>: cd %s\n",dirname); | |
| 766 err = chdir( dirname ); | |
| 767 if( err < 0 ) SHOW_RESULT( chdir, err ); | |
| 768 | |
| 769 checkcwd( dirname ); | |
| 770 | |
| 771 diag_printf("<INFO>: mkdir " NOONOO "\n"); | |
| 772 err = mkdir( NOONOO, 0 ); | |
| 773 if( err < 0 ) SHOW_RESULT( mkdir, err ); | |
| 774 | |
| 775 listdir( dirname , true, existingdirents+3, NULL); | |
| 776 | |
| 777 diag_printf("<INFO>: cd " NOONOO "\n"); | |
| 778 err = chdir( NOONOO ); | |
| 779 if( err < 0 ) SHOW_RESULT( chdir, err ); | |
| 780 | |
| 781 NEW_FILENAME1( NOONOO ); | |
| 782 checkcwd( filename1 ); | |
| 783 | |
| 784 createfile( TINKY, 6789 ); | |
| 785 checkfile( TINKY ); | |
| 786 | |
| 787 createfile( DIPSY, 34567 ); | |
| 788 checkfile( DIPSY ); | |
| 789 copyfile( DIPSY, PO ); | |
| 790 checkfile( PO ); | |
| 791 comparefiles( DIPSY, PO ); | |
| 792 | |
| 793 listdir( ".", true, 5, NULL ); | |
| 794 listdir( "..", true, existingdirents+3, NULL ); | |
| 795 | |
| 796 // -------------------------------------------------------------- | |
| 797 | |
| 798 #ifdef CLEANUP | |
| 799 diag_printf("<INFO>: unlink " TINKY "\n"); | |
| 800 err = unlink( TINKY ); | |
| 801 if( err < 0 ) SHOW_RESULT( unlink, err ); | |
| 802 | |
| 803 diag_printf("<INFO>: unlink " DIPSY "\n"); | |
| 804 err = unlink( DIPSY ); | |
| 805 if( err < 0 ) SHOW_RESULT( unlink, err ); | |
| 806 | |
| 807 diag_printf("<INFO>: unlink " PO "\n"); | |
| 808 err = unlink( PO ); | |
| 809 if( err < 0 ) SHOW_RESULT( unlink, err ); | |
| 810 #endif | |
| 811 | |
| 812 diag_printf("<INFO>: cd ..\n"); | |
| 813 err = chdir( ".." ); | |
| 814 if( err < 0 ) SHOW_RESULT( chdir, err ); | |
| 815 checkcwd( dirname ); | |
| 816 | |
| 817 #ifdef CLEANUP | |
| 818 diag_printf("<INFO>: rmdir " NOONOO "\n"); | |
| 819 err = rmdir( NOONOO ); | |
| 820 if( err < 0 ) SHOW_RESULT( rmdir, err ); | |
| 821 #endif | |
| 822 | |
| 823 // -------------------------------------------------------------- | |
| 824 | |
| 825 err = mkdir( XXXX, 0 ); | |
| 826 if( err < 0 ) SHOW_RESULT( mkdir, err ); | |
| 827 | |
| 828 err = mkdir( XXXX "/" YYYY, 0 ); | |
| 829 if( err < 0 ) SHOW_RESULT( mkdir, err ); | |
| 830 | |
| 831 err = mkdir( XXXX "/" YYYY "/" ZZZZ, 0 ); | |
| 832 if( err < 0 ) SHOW_RESULT( mkdir, err ); | |
| 833 | |
| 834 err = mkdir( XXXX "/" YYYY "/" ZZZZ "/" WWWW, 0 ); | |
| 835 if( err < 0 ) SHOW_RESULT( mkdir, err ); | |
| 836 | |
| 837 NEW_FILENAME1( XXXX "/" YYYY "/" ZZZZ "/" WWWW ); | |
| 838 diag_printf("<INFO>: cd %s\n",filename1); | |
| 839 err = chdir( filename1 ); | |
| 840 if( err < 0 ) SHOW_RESULT( chdir, err ); | |
| 841 checkcwd( filename1 ); | |
| 842 | |
| 843 NEW_FILENAME1( XXXX "/" YYYY "/" ZZZZ ); | |
| 844 diag_printf("<INFO>: cd ..\n"); | |
| 845 err = chdir( ".." ); | |
| 846 if( err < 0 ) SHOW_RESULT( chdir, err ); | |
| 847 checkcwd( filename1 ); | |
| 848 | |
| 849 NEW_FILENAME1( XXXX "/" YYYY "/" ZZZZ ); | |
| 850 diag_printf("<INFO>: cd .\n"); | |
| 851 err = chdir( "." ); | |
| 852 if( err < 0 ) SHOW_RESULT( chdir, err ); | |
| 853 checkcwd( filename1 ); | |
| 854 | |
| 855 NEW_FILENAME1( XXXX "/" YYYY ); | |
| 856 diag_printf("<INFO>: cd ../../" YYYY "\n"); | |
| 857 err = chdir( "../../" YYYY ); | |
| 858 if( err < 0 ) SHOW_RESULT( chdir, err ); | |
| 859 checkcwd( filename1 ); | |
| 860 | |
| 861 diag_printf("<INFO>: cd ../..\n"); | |
| 862 err = chdir( "../.." ); | |
| 863 if( err < 0 ) SHOW_RESULT( chdir, err ); | |
| 864 checkcwd( dirname ); | |
| 865 | |
| 866 diag_printf("<INFO>: rmdir " XXXX "/" YYYY "/" ZZZZ "/" WWWW "\n"); | |
| 867 err = rmdir( XXXX "/" YYYY "/" ZZZZ "/" WWWW ); | |
| 868 if( err < 0 ) SHOW_RESULT( rmdir, err ); | |
| 869 | |
| 870 diag_printf("<INFO>: rmdir "XXXX "/" YYYY "/" ZZZZ "\n"); | |
| 871 err = rmdir( XXXX "/" YYYY "/" ZZZZ ); | |
| 872 if( err < 0 ) SHOW_RESULT( rmdir, err ); | |
| 873 | |
| 874 diag_printf("<INFO>: rmdir " XXXX "/" YYYY "\n"); | |
| 875 err = rmdir( XXXX "/" YYYY ); | |
| 876 if( err < 0 ) SHOW_RESULT( rmdir, err ); | |
| 877 | |
| 878 diag_printf("<INFO>: rmdir "XXXX "\n"); | |
| 879 err = rmdir( XXXX ); | |
| 880 if( err < 0 ) SHOW_RESULT( rmdir, err ); | |
| 881 | |
| 882 // -------------------------------------------------------------- | |
| 883 | |
| 884 checkcwd( dirname ); | |
| 885 | |
| 886 #ifdef CLEANUP | |
| 887 diag_printf("<INFO>: unlink "TINKY "\n"); | |
| 888 err = unlink( TINKY ); | |
| 889 if( err < 0 ) SHOW_RESULT( unlink, err ); | |
| 890 | |
| 891 diag_printf("<INFO>: unlink " LAALAA" \n"); | |
| 892 err = unlink( LAALAA ); | |
| 893 if( err < 0 ) SHOW_RESULT( unlink, err ); | |
| 894 #endif | |
| 895 | |
| 896 // -------------------------------------------------------------- | |
| 897 | |
| 898 diag_printf("<INFO>: cd %s\n", TEST_MOUNTPOINT TEST_DIRECTORY); | |
| 899 err = chdir( TEST_MOUNTPOINT TEST_DIRECTORY); | |
| 900 if( err < 0 ) SHOW_RESULT( chdir, err ); | |
| 901 checkcwd( TEST_MOUNTPOINT TEST_DIRECTORY ); | |
| 902 | |
| 903 listdir( ".", true, -1, NULL ); | |
| 904 | |
| 905 #ifdef TEST_MOUNTPOINT2 | |
| 906 if( mp2 ) | |
| 907 { | |
| 908 diag_printf("<INFO>: umount %s\n",TEST_MOUNTPOINT2); | |
| 909 err = umount( TEST_MOUNTPOINT2 ); | |
| 910 if( err < 0 ) SHOW_RESULT( umount, err ); | |
| 911 } | |
| 912 #endif | |
| 913 | |
| 914 // -------------------------------------------------------------- | |
| 915 | |
| 916 #if 0 | |
| 917 maxfile("file.max"); | |
| 918 | |
| 919 listdir( "/", true, -1, NULL ); | |
| 920 | |
| 921 diag_printf("<INFO>: unlink file.max\n"); | |
| 922 err = unlink( "file.max" ); | |
| 923 if( err < 0 ) SHOW_RESULT( unlink, err ); | |
| 924 #endif | |
| 925 | |
| 926 // -------------------------------------------------------------- | |
| 927 | |
| 928 #endif | |
| 929 diag_printf("<INFO>: cd /\n"); | |
| 930 err = chdir( "/" ); | |
| 931 if( err == 0 ) | |
| 932 { | |
| 933 checkcwd( "/" ); | |
| 934 | |
| 935 diag_printf("<INFO>: umount %s\n",TEST_MOUNTPOINT); | |
| 936 err = umount( TEST_MOUNTPOINT ); | |
| 937 if( err < 0 ) SHOW_RESULT( umount, err ); | |
| 938 } | |
| 939 | |
| 940 diag_printf("<INFO>: syncing\n"); | |
| 941 cyg_fs_setinfo(TEST_MOUNTPOINT, FS_INFO_SYNC, NULL, 0); // sync(); | |
| 942 | |
| 943 CYG_TEST_PASS_FINISH("yaffs6"); | |
| 944 } | |
| 945 | |
| 946 // ------------------------------------------------------------------------- | |
| 947 | |
| 948 #include <cyg/kernel/kapi.h> | |
| 949 | |
| 950 static cyg_handle_t thread_handle; | |
| 951 static cyg_thread thread; | |
| 952 static char stack[CYGNUM_HAL_STACK_SIZE_TYPICAL+1024*4]; | |
| 953 | |
| 954 externC void | |
| 955 cyg_start( void ) | |
| 956 { | |
| 957 cyg_thread_create(3, // Priority - just a number | |
| 958 yaffs6_main, // entry | |
| 959 0, // index | |
| 960 0, // no name | |
| 961 &stack[0], // Stack | |
| 962 sizeof(stack), // Size | |
| 963 &thread_handle, // Handle | |
| 964 &thread // Thread data structure | |
| 965 ); | |
| 966 cyg_thread_resume(thread_handle); | |
| 967 | |
| 968 cyg_scheduler_start(); | |
| 969 } | |
| 970 | |
| 971 #else // CYGPKG_KERNEL | |
| 972 | |
| 973 #include <cyg/infra/testcase.h> | |
| 974 | |
| 975 externC void cyg_start(void) | |
| 976 { | |
| 977 CYG_TEST_NA("Needs CYGPKG_KERNEL"); | |
| 978 } | |
| 979 | |
| 980 #endif | |
| 981 | |
| 982 // ------------------------------------------------------------------------- | |
| 983 // EOF yaffs6.c |
