2 * Test code for the "direct" interface.
13 void dumpDir(const char *dname);
17 void copy_in_a_file(char *yaffsName,char *inName)
20 unsigned char buffer[100];
22 inh = open(inName,O_RDONLY);
23 outh = yaffs_open(yaffsName, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
25 while((ni = read(inh,buffer,100)) > 0)
27 no = yaffs_write(outh,buffer,ni);
30 printf("problem writing yaffs file\n");
39 void make_a_file(char *yaffsName,char bval,int sizeOfFile)
43 unsigned char buffer[100];
45 outh = yaffs_open(yaffsName, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
47 memset(buffer,bval,100);
54 yaffs_write(outh,buffer,i);
56 } while (sizeOfFile > 0);
63 void make_pattern_file(char *fn,int size)
68 outh = yaffs_open(fn, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
69 yaffs_lseek(outh,size-1,SEEK_SET);
70 yaffs_write(outh,"A",1);
72 for(i = 0; i < size; i+=256)
75 yaffs_lseek(outh,i,SEEK_SET);
76 yaffs_write(outh,&marker,sizeof(marker));
82 int check_pattern_file(char *fn)
90 h = yaffs_open(fn, O_RDWR,0);
91 size = yaffs_lseek(h,0,SEEK_END);
93 for(i = 0; i < size && ok; i+=256)
95 yaffs_lseek(h,i,SEEK_SET);
96 yaffs_read(h,&marker,sizeof(marker));
100 printf("pattern check failed on file %s, size %d at position %d. Got %x instead of %x\n",
101 fn,size,i,marker,~i);
110 void dump_file(const char *fn)
116 h = yaffs_open(fn,O_RDONLY,0);
119 printf("*****\nDump file %s does not exist\n",fn);
123 size = yaffs_lseek(h,0,SEEK_SET);
124 printf("*****\nDump file %s size %d\n",fn,size);
125 for(i = 0; i < size; i++)
132 void short_scan_test(const char *path, int fsize, int niterations)
137 sprintf(fn,"%s/%s",path,"f1");
140 for(i = 0; i < niterations; i++)
142 printf("\n*****************\nIteration %d\n",i);
144 printf("\nmount: Directory look-up of %s\n",path);
146 make_a_file(fn,1,fsize);
151 void scan_pattern_test(const char *path, int fsize, int niterations)
158 sprintf(fn[0],"%s/%s",path,"f0");
159 sprintf(fn[1],"%s/%s",path,"f1");
160 sprintf(fn[2],"%s/%s",path,"f2");
164 for(i = 0; i < niterations; i++)
166 printf("\n*****************\nIteration %d\n",i);
168 printf("\nmount: Directory look-up of %s\n",path);
170 for(j = 0; j < 3; j++)
172 result = check_pattern_file(fn[j]);
173 make_pattern_file(fn[j],fsize);
174 result = check_pattern_file(fn[j]);
180 void fill_disk(char *path,int nfiles)
189 for(n = 0; n < nfiles; n++)
191 sprintf(str,"%s/%d",path,n);
193 h = yaffs_open(str, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
195 printf("writing file %s handle %d ",str, h);
197 while ((result = yaffs_write(h,xx,600)) == 600)
199 f = yaffs_freespace("/boot");
201 result = yaffs_close(h);
202 printf(" close %d\n",result);
206 void fill_disk_and_delete(char *path, int nfiles, int ncycles)
212 for(i = 0; i < ncycles; i++)
214 printf("@@@@@@@@@@@@@@ cycle %d\n",i);
215 fill_disk(path,nfiles);
217 for(j = 0; j < nfiles; j++)
219 sprintf(str,"%s/%d",path,j);
220 result = yaffs_unlink(str);
221 printf("unlinking file %s, result %d\n",str,result);
227 void fill_files(char *path,int flags, int maxIterations,int siz)
237 sprintf(str,"%s/%d",path,i);
238 h = yaffs_open(str, O_CREAT | O_TRUNC | O_RDWR,S_IREAD | S_IWRITE);
243 for(j = 0; j < siz; j++)
245 yaffs_write(h,str,1);
254 } while(h >= 0 && i < maxIterations);
260 sprintf(str,"%s/%d",path,i);
261 printf("unlink %s\n",str);
263 } while(yaffs_unlink(str) >= 0);
267 void leave_unlinked_file(char *path,int maxIterations,int siz)
276 sprintf(str,"%s/%d",path,i);
277 printf("create %s\n",str);
278 h = yaffs_open(str, O_CREAT | O_TRUNC | O_RDWR,S_IREAD | S_IWRITE);
284 } while(h < 0 && i < maxIterations);
288 for(i = 0; i < siz; i++)
290 yaffs_write(h,str,1);
294 printf("Leaving file %s open\n",str);
298 void dumpDirFollow(const char *dname)
305 d = yaffs_opendir(dname);
309 printf("opendir failed\n");
313 while((de = yaffs_readdir(d)) != NULL)
315 sprintf(str,"%s/%s",dname,de->d_name);
319 printf("%s length %d mode %X ",de->d_name,(int)s.st_size,s.st_mode);
320 switch(s.st_mode & S_IFMT)
322 case S_IFREG: printf("data file"); break;
323 case S_IFDIR: printf("directory"); break;
324 case S_IFLNK: printf("symlink -->");
325 if(yaffs_readlink(str,str,100) < 0)
328 printf("\"%s\"",str);
330 default: printf("unknown"); break;
340 printf("Free space in %s is %d\n\n",dname,(int)yaffs_freespace(dname));
345 void dumpDir(const char *dname)
352 d = yaffs_opendir(dname);
356 printf("opendir failed\n");
360 while((de = yaffs_readdir(d)) != NULL)
362 sprintf(str,"%s/%s",dname,de->d_name);
366 printf("%s length %d mode %X ",de->d_name,(int)s.st_size,s.st_mode);
367 switch(s.st_mode & S_IFMT)
369 case S_IFREG: printf("data file"); break;
370 case S_IFDIR: printf("directory"); break;
371 case S_IFLNK: printf("symlink -->");
372 if(yaffs_readlink(str,str,100) < 0)
375 printf("\"%s\"",str);
377 default: printf("unknown"); break;
387 printf("Free space in %s is %d\n\n",dname,(int)yaffs_freespace(dname));
392 static void PermissionsCheck(const char *path, mode_t tmode, int tflags,int expectedResult)
396 if(yaffs_chmod(path,tmode)< 0) printf("chmod failed\n");
398 fd = yaffs_open(path,tflags,0);
400 if((fd >= 0) != (expectedResult > 0))
402 printf("Permissions check %x %x %d failed\n",tmode,tflags,expectedResult);
406 printf("Permissions check %x %x %d OK\n",tmode,tflags,expectedResult);
415 int long_test(int argc, char *argv[])
426 struct yaffs_stat ystat;
430 yaffs_mount("/boot");
431 yaffs_mount("/data");
432 yaffs_mount("/flash");
435 printf("\nDirectory look-up of /boot\n");
437 printf("\nDirectory look-up of /data\n");
439 printf("\nDirectory look-up of /flash\n");
442 //leave_unlinked_file("/flash",20000,0);
443 //leave_unlinked_file("/data",20000,0);
445 leave_unlinked_file("/ram",20,0);
448 f = yaffs_open("/boot/b1", O_RDONLY,0);
450 printf("open /boot/b1 readonly, f=%d\n",f);
452 f = yaffs_open("/boot/b1", O_CREAT,S_IREAD | S_IWRITE);
454 printf("open /boot/b1 O_CREAT, f=%d\n",f);
457 r = yaffs_write(f,"hello",1);
458 printf("write %d attempted to write to a read-only file\n",r);
462 printf("close %d\n",r);
464 f = yaffs_open("/boot/b1", O_RDWR,0);
466 printf("open /boot/b1 O_RDWR,f=%d\n",f);
469 r = yaffs_write(f,"hello",2);
470 printf("write %d attempted to write to a writeable file\n",r);
471 r = yaffs_write(f,"world",3);
472 printf("write %d attempted to write to a writeable file\n",r);
474 r= yaffs_lseek(f,0,SEEK_END);
475 printf("seek end %d\n",r);
477 r = yaffs_read(f,buffer,10);
478 printf("read %d \"%s\"\n",r,buffer);
479 r= yaffs_lseek(f,0,SEEK_SET);
480 printf("seek set %d\n",r);
482 r = yaffs_read(f,buffer,10);
483 printf("read %d \"%s\"\n",r,buffer);
485 r = yaffs_read(f,buffer,10);
486 printf("read %d \"%s\"\n",r,buffer);
488 // Check values reading at end.
489 // A read past end of file should return 0 for 0 bytes read.
491 r= yaffs_lseek(f,0,SEEK_END);
492 r = yaffs_read(f,buffer,10);
493 printf("read at end returned %d\n",r);
494 r= yaffs_lseek(f,500,SEEK_END);
495 r = yaffs_read(f,buffer,10);
496 printf("read past end returned %d\n",r);
500 printf("close %d\n",r);
502 copy_in_a_file("/boot/yyfile","xxx");
504 // Create a file with a long name
506 copy_in_a_file("/boot/file with a long name","xxx");
509 printf("\nDirectory look-up of /boot\n");
513 r = yaffs_stat("/boot/file with a long name",&ystat);
517 r = yaffs_rename("/boot/file with a long name","/boot/r1");
519 printf("\nDirectory look-up of /boot\n");
523 r = yaffs_unlink("/boot/r1");
525 printf("\nDirectory look-up of /boot\n");
530 r = yaffs_mkdir("/boot/directory1",0);
532 printf("\nDirectory look-up of /boot\n");
534 printf("\nDirectory look-up of /boot/directory1\n");
535 dumpDir("/boot/directory1");
537 // add a file to the directory
538 copy_in_a_file("/boot/directory1/file with a long name","xxx");
540 printf("\nDirectory look-up of /boot\n");
542 printf("\nDirectory look-up of /boot/directory1\n");
543 dumpDir("/boot/directory1");
545 // Attempt to delete directory (should fail)
547 r = yaffs_rmdir("/boot/directory1");
549 printf("\nDirectory look-up of /boot\n");
551 printf("\nDirectory look-up of /boot/directory1\n");
552 dumpDir("/boot/directory1");
554 // Delete file first, then rmdir should work
555 r = yaffs_unlink("/boot/directory1/file with a long name");
556 r = yaffs_rmdir("/boot/directory1");
559 printf("\nDirectory look-up of /boot\n");
561 printf("\nDirectory look-up of /boot/directory1\n");
562 dumpDir("/boot/directory1");
565 fill_disk_and_delete("/boot",20,20);
567 printf("\nDirectory look-up of /boot\n");
571 yaffs_symlink("yyfile","/boot/slink");
573 yaffs_readlink("/boot/slink",str,100);
574 printf("symlink alias is %s\n",str);
579 printf("\nDirectory look-up of /boot\n");
581 printf("\nDirectory look-up of /boot (using stat instead of lstat)\n");
582 dumpDirFollow("/boot");
583 printf("\nDirectory look-up of /boot/directory1\n");
584 dumpDir("/boot/directory1");
586 h = yaffs_open("/boot/slink",O_RDWR,0);
588 printf("file length is %d\n",(int)yaffs_lseek(h,0,SEEK_END));
592 yaffs_unlink("/boot/slink");
595 printf("\nDirectory look-up of /boot\n");
600 yaffs_stat("/boot/yyfile",&ystat);
601 temp_mode = ystat.st_mode;
603 yaffs_chmod("/boot/yyfile",0x55555);
604 printf("\nDirectory look-up of /boot\n");
607 yaffs_chmod("/boot/yyfile",temp_mode);
608 printf("\nDirectory look-up of /boot\n");
611 // Permission checks...
612 PermissionsCheck("/boot/yyfile",0, O_WRONLY,0);
613 PermissionsCheck("/boot/yyfile",0, O_RDONLY,0);
614 PermissionsCheck("/boot/yyfile",0, O_RDWR,0);
616 PermissionsCheck("/boot/yyfile",S_IREAD, O_WRONLY,0);
617 PermissionsCheck("/boot/yyfile",S_IREAD, O_RDONLY,1);
618 PermissionsCheck("/boot/yyfile",S_IREAD, O_RDWR,0);
620 PermissionsCheck("/boot/yyfile",S_IWRITE, O_WRONLY,1);
621 PermissionsCheck("/boot/yyfile",S_IWRITE, O_RDONLY,0);
622 PermissionsCheck("/boot/yyfile",S_IWRITE, O_RDWR,0);
624 PermissionsCheck("/boot/yyfile",S_IREAD | S_IWRITE, O_WRONLY,1);
625 PermissionsCheck("/boot/yyfile",S_IREAD | S_IWRITE, O_RDONLY,1);
626 PermissionsCheck("/boot/yyfile",S_IREAD | S_IWRITE, O_RDWR,1);
628 yaffs_chmod("/boot/yyfile",temp_mode);
630 //create a zero-length file and unlink it (test for scan bug)
632 h = yaffs_open("/boot/zlf",O_CREAT | O_TRUNC | O_RDWR,0);
635 yaffs_unlink("/boot/zlf");
638 yaffs_DumpDevStruct("/boot");
640 fill_disk_and_delete("/boot",20,20);
642 yaffs_DumpDevStruct("/boot");
644 fill_files("/boot",1,10000,0);
645 fill_files("/boot",1,10000,5000);
646 fill_files("/boot",2,10000,0);
647 fill_files("/boot",2,10000,5000);
649 leave_unlinked_file("/data",20000,0);
650 leave_unlinked_file("/data",20000,5000);
651 leave_unlinked_file("/data",20000,5000);
652 leave_unlinked_file("/data",20000,5000);
653 leave_unlinked_file("/data",20000,5000);
654 leave_unlinked_file("/data",20000,5000);
656 yaffs_DumpDevStruct("/boot");
657 yaffs_DumpDevStruct("/data");
665 int long_test_on_path(char *path)
678 struct yaffs_stat ystat;
684 printf("\nDirectory look-up of %s\n",path);
687 //leave_unlinked_file("/flash",20000,0);
688 //leave_unlinked_file("/data",20000,0);
690 leave_unlinked_file(path,20,0);
693 sprintf(name,"%s/%s",path,"b1");
694 f = yaffs_open(name, O_RDONLY,0);
696 printf("open %s readonly, f=%d\n",name,f);
698 f = yaffs_open(name, O_CREAT,S_IREAD | S_IWRITE);
700 printf("open %s O_CREAT, f=%d\n",name,f);
703 r = yaffs_write(f,"hello",1);
704 printf("write %d attempted to write to a read-only file\n",r);
708 printf("close %d\n",r);
710 f = yaffs_open(name, O_RDWR,0);
712 printf("open %s O_RDWR,f=%d\n",name,f);
715 r = yaffs_write(f,"hello",2);
716 printf("write %d attempted to write to a writeable file\n",r);
717 r = yaffs_write(f,"world",3);
718 printf("write %d attempted to write to a writeable file\n",r);
720 r= yaffs_lseek(f,0,SEEK_END);
721 printf("seek end %d\n",r);
723 r = yaffs_read(f,buffer,10);
724 printf("read %d \"%s\"\n",r,buffer);
725 r= yaffs_lseek(f,0,SEEK_SET);
726 printf("seek set %d\n",r);
728 r = yaffs_read(f,buffer,10);
729 printf("read %d \"%s\"\n",r,buffer);
731 r = yaffs_read(f,buffer,10);
732 printf("read %d \"%s\"\n",r,buffer);
734 // Check values reading at end.
735 // A read past end of file should return 0 for 0 bytes read.
737 r= yaffs_lseek(f,0,SEEK_END);
738 r = yaffs_read(f,buffer,10);
739 printf("read at end returned %d\n",r);
740 r= yaffs_lseek(f,500,SEEK_END);
741 r = yaffs_read(f,buffer,10);
742 printf("read past end returned %d\n",r);
746 printf("close %d\n",r);
748 sprintf(name,"%s/%s",path,"yyfile");
749 copy_in_a_file(name,"xxx");
751 // Create a file with a long name
752 sprintf(name,"%s/%s",path,"file with a long name");
753 copy_in_a_file(name,"xxx");
756 printf("\nDirectory look-up of %s\n",path);
760 r = yaffs_stat(name,&ystat);
763 sprintf(name2,"%s/%s",path,"r1");
764 r = yaffs_rename(name,name2);
766 printf("\nDirectory look-up of %s\n",path);
770 r = yaffs_unlink(name2);
773 printf("\nDirectory look-up of %s\n",path);
778 sprintf(name,"%s/%s",path,"directory1");
779 r = yaffs_mkdir(name,0);
782 printf("\nDirectory look-up of %s\n",path);
784 printf("\nDirectory look-up of %s\n",name);
787 // add a file to the directory
788 sprintf(name2,"%s/%s",name,"/file in dir with a long name");
789 copy_in_a_file(name2,"xxx");
792 printf("\nDirectory look-up of %s\n",path);
794 printf("\nDirectory look-up of %s\n",name);
797 // Attempt to delete directory (should fail)
799 r = yaffs_rmdir(name);
801 printf("\nDirectory look-up of %s\n",path);
803 printf("\nDirectory look-up of %s\n",name);
809 // Delete file first, then rmdir should work
810 r = yaffs_unlink(name2);
811 r = yaffs_rmdir(name);
813 printf("\nDirectory look-up of %s\n",path);
815 printf("\nDirectory look-up of %s\n",name);
819 fill_disk_and_delete(path,20,20);
821 printf("\nDirectory look-up of %s\n",path);
829 yaffs_symlink("yyfile","/boot/slink");
831 yaffs_readlink("/boot/slink",str,100);
832 printf("symlink alias is %s\n",str);
837 printf("\nDirectory look-up of /boot\n");
839 printf("\nDirectory look-up of /boot (using stat instead of lstat)\n");
840 dumpDirFollow("/boot");
841 printf("\nDirectory look-up of /boot/directory1\n");
842 dumpDir("/boot/directory1");
844 h = yaffs_open("/boot/slink",O_RDWR,0);
846 printf("file length is %d\n",yaffs_lseek(h,0,SEEK_END));
850 yaffs_unlink("/boot/slink");
853 printf("\nDirectory look-up of /boot\n");
858 yaffs_stat("/boot/yyfile",&ystat);
859 temp_mode = ystat.st_mode;
861 yaffs_chmod("/boot/yyfile",0x55555);
862 printf("\nDirectory look-up of /boot\n");
865 yaffs_chmod("/boot/yyfile",temp_mode);
866 printf("\nDirectory look-up of /boot\n");
869 // Permission checks...
870 PermissionsCheck("/boot/yyfile",0, O_WRONLY,0);
871 PermissionsCheck("/boot/yyfile",0, O_RDONLY,0);
872 PermissionsCheck("/boot/yyfile",0, O_RDWR,0);
874 PermissionsCheck("/boot/yyfile",S_IREAD, O_WRONLY,0);
875 PermissionsCheck("/boot/yyfile",S_IREAD, O_RDONLY,1);
876 PermissionsCheck("/boot/yyfile",S_IREAD, O_RDWR,0);
878 PermissionsCheck("/boot/yyfile",S_IWRITE, O_WRONLY,1);
879 PermissionsCheck("/boot/yyfile",S_IWRITE, O_RDONLY,0);
880 PermissionsCheck("/boot/yyfile",S_IWRITE, O_RDWR,0);
882 PermissionsCheck("/boot/yyfile",S_IREAD | S_IWRITE, O_WRONLY,1);
883 PermissionsCheck("/boot/yyfile",S_IREAD | S_IWRITE, O_RDONLY,1);
884 PermissionsCheck("/boot/yyfile",S_IREAD | S_IWRITE, O_RDWR,1);
886 yaffs_chmod("/boot/yyfile",temp_mode);
888 //create a zero-length file and unlink it (test for scan bug)
890 h = yaffs_open("/boot/zlf",O_CREAT | O_TRUNC | O_RDWR,0);
893 yaffs_unlink("/boot/zlf");
896 yaffs_DumpDevStruct("/boot");
898 fill_disk_and_delete("/boot",20,20);
900 yaffs_DumpDevStruct("/boot");
902 fill_files("/boot",1,10000,0);
903 fill_files("/boot",1,10000,5000);
904 fill_files("/boot",2,10000,0);
905 fill_files("/boot",2,10000,5000);
907 leave_unlinked_file("/data",20000,0);
908 leave_unlinked_file("/data",20000,5000);
909 leave_unlinked_file("/data",20000,5000);
910 leave_unlinked_file("/data",20000,5000);
911 leave_unlinked_file("/data",20000,5000);
912 leave_unlinked_file("/data",20000,5000);
914 yaffs_DumpDevStruct("/boot");
915 yaffs_DumpDevStruct("/data");
922 int yaffs_scan_test(const char *path)
928 int resize_stress_test(const char *path)
943 sprintf(aname,"%s%s",path,"/a");
944 sprintf(bname,"%s%s",path,"/b");
946 memset(abuffer,'a',1000);
947 memset(bbuffer,'b',1000);
949 a = yaffs_open(aname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
950 b = yaffs_open(bname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
952 printf(" %s %d %s %d\n",aname,a,bname,b);
956 for(j = 0; j < 100; j++)
958 yaffs_lseek(a,0,SEEK_END);
961 for(i = 0; i <20000; i++)
963 //r = yaffs_lseek(b,i,SEEK_SET);
964 //r = yaffs_write(b,bbuffer,1000);
969 int syz = yaffs_lseek(a,0,SEEK_END);
973 yaffs_truncate(a,syz);
979 r = yaffs_lseek(a,i * 500,SEEK_SET);
980 r = yaffs_write(a,abuffer,1000);
992 int resize_stress_test_no_grow_complex(const char *path,int iters)
1007 sprintf(aname,"%s%s",path,"/a");
1008 sprintf(bname,"%s%s",path,"/b");
1010 memset(abuffer,'a',1000);
1011 memset(bbuffer,'b',1000);
1013 a = yaffs_open(aname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1014 b = yaffs_open(bname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1016 printf(" %s %d %s %d\n",aname,a,bname,b);
1020 for(j = 0; j < iters; j++)
1022 yaffs_lseek(a,0,SEEK_END);
1025 for(i = 0; i <20000; i++)
1027 //r = yaffs_lseek(b,i,SEEK_SET);
1028 //r = yaffs_write(b,bbuffer,1000);
1033 int syz = yaffs_lseek(a,0,SEEK_END);
1039 if(syz < 0) syz = 0;
1040 yaffs_truncate(a,syz);
1041 syz = yaffs_lseek(a,0,SEEK_END);
1042 printf("shrink to %d\n",syz);
1050 r = yaffs_lseek(a,500,SEEK_END);
1051 r = yaffs_write(a,abuffer,1000);
1057 printf("file size is %d\n",yaffs_lseek(a,0,SEEK_END));
1065 int resize_stress_test_no_grow(const char *path,int iters)
1080 sprintf(aname,"%s%s",path,"/a");
1081 sprintf(bname,"%s%s",path,"/b");
1083 memset(abuffer,'a',1000);
1084 memset(bbuffer,'b',1000);
1086 a = yaffs_open(aname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1087 b = yaffs_open(bname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1089 printf(" %s %d %s %d\n",aname,a,bname,b);
1093 for(j = 0; j < iters; j++)
1095 yaffs_lseek(a,0,SEEK_END);
1098 for(i = 0; i <20000; i++)
1100 //r = yaffs_lseek(b,i,SEEK_SET);
1101 //r = yaffs_write(b,bbuffer,1000);
1106 int syz = yaffs_lseek(a,0,SEEK_END);
1112 if(syz < 0) syz = 0;
1113 yaffs_truncate(a,syz);
1114 syz = yaffs_lseek(a,0,SEEK_END);
1115 printf("shrink to %d\n",syz);
1123 r = yaffs_lseek(a,-500,SEEK_END);
1124 r = yaffs_write(a,abuffer,1000);
1130 printf("file size is %d\n",yaffs_lseek(a,0,SEEK_END));
1138 int directory_rename_test(void)
1143 yaffs_mount("/ram");
1144 yaffs_mkdir("/ram/a",0);
1145 yaffs_mkdir("/ram/a/b",0);
1146 yaffs_mkdir("/ram/c",0);
1148 printf("\nDirectory look-up of /ram\n");
1151 dumpDir("/ram/a/b");
1153 printf("Do rename (should fail)\n");
1155 r = yaffs_rename("/ram/a","/ram/a/b/d");
1156 printf("\nDirectory look-up of /ram\n");
1159 dumpDir("/ram/a/b");
1161 printf("Do rename (should not fail)\n");
1163 r = yaffs_rename("/ram/c","/ram/a/b/d");
1164 printf("\nDirectory look-up of /ram\n");
1167 dumpDir("/ram/a/b");
1174 int cache_read_test(void)
1178 int sizeOfFiles = 500000;
1183 yaffs_mount("/boot");
1185 make_a_file("/boot/a",'a',sizeOfFiles);
1186 make_a_file("/boot/b",'b',sizeOfFiles);
1188 a = yaffs_open("/boot/a",O_RDONLY,0);
1189 b = yaffs_open("/boot/b",O_RDONLY,0);
1190 c = yaffs_open("/boot/c", O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
1194 if (i > 100) i = 100;
1196 yaffs_read(a,buffer,i);
1197 yaffs_read(b,buffer,i);
1198 yaffs_write(c,buffer,i);
1199 } while(sizeOfFiles > 0);
1207 int cache_bypass_bug_test(void)
1209 // This test reporoduces a bug whereby YAFFS caching *was* buypassed
1210 // resulting in erroneous reads after writes.
1211 // This bug has been fixed.
1218 memset(buffer1,0,sizeof(buffer1));
1219 memset(buffer2,0,sizeof(buffer2));
1223 yaffs_mount("/boot");
1225 // Create a file of 2000 bytes.
1226 make_a_file("/boot/a",'X',2000);
1228 a = yaffs_open("/boot/a",O_RDWR, S_IREAD | S_IWRITE);
1230 // Write a short sequence to the file.
1231 // This will go into the cache.
1232 yaffs_lseek(a,0,SEEK_SET);
1233 yaffs_write(a,"abcdefghijklmnopqrstuvwxyz",20);
1235 // Read a short sequence from the file.
1236 // This will come from the cache.
1237 yaffs_lseek(a,0,SEEK_SET);
1238 yaffs_read(a,buffer1,30);
1240 // Read a page size sequence from the file.
1241 yaffs_lseek(a,0,SEEK_SET);
1242 yaffs_read(a,buffer2,512);
1244 printf("buffer 1 %s\n",buffer1);
1245 printf("buffer 2 %s\n",buffer2);
1247 if(strncmp(buffer1,buffer2,20))
1249 printf("Cache bypass bug detected!!!!!\n");
1257 int free_space_check(void)
1262 yaffs_mount("/boot");
1263 fill_disk("/boot/",2);
1264 f = yaffs_freespace("/boot");
1266 printf("%d free when disk full\n",f);
1270 int truncate_test(void)
1280 yaffs_mount("/boot");
1282 yaffs_unlink("/boot/trunctest");
1284 a = yaffs_open("/boot/trunctest", O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1286 yaffs_write(a,"abcdefghijklmnopqrstuvwzyz",26);
1288 yaffs_truncate(a,3);
1289 l= yaffs_lseek(a,0,SEEK_END);
1291 printf("truncated length is %d\n",l);
1293 yaffs_lseek(a,5,SEEK_SET);
1294 yaffs_write(a,"1",1);
1296 yaffs_lseek(a,0,SEEK_SET);
1298 r = yaffs_read(a,y,10);
1300 printf("read %d bytes:",r);
1302 for(i = 0; i < r; i++) printf("[%02X]",y[i]);
1311 int main(int argc, char *argv[])
1313 //return long_test(argc,argv);
1315 //return cache_read_test();
1317 //return resize_stress_test_no_grow("/flash",2);
1321 scan_pattern_test("/ram2k",40000,10);
1322 //short_scan_test("/flash",40000,200);
1325 long_test_on_path("/ram2k");
1326 long_test_on_path("/ram2k");
1328 // cache_bypass_bug_test();