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; 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);
112 int dump_file_data(char *fn)
121 h = yaffs_open(fn, O_RDWR,0);
125 while(yaffs_read(h,&b,1)> 0)
142 void dump_file(const char *fn)
148 h = yaffs_open(fn,O_RDONLY,0);
151 printf("*****\nDump file %s does not exist\n",fn);
155 size = yaffs_lseek(h,0,SEEK_SET);
156 printf("*****\nDump file %s size %d\n",fn,size);
157 for(i = 0; i < size; i++)
164 void create_file_of_size(const char *fn,int syze)
170 int iterations = (syze + strlen(fn) -1)/ strlen(fn);
172 h = yaffs_open(fn, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
174 while (iterations > 0)
176 yaffs_write(h,fn,strlen(fn));
182 void create_resized_file_of_size(const char *fn,int syze1,int reSyze, int syze2)
190 h = yaffs_open(fn, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
192 iterations = (syze1 + strlen(fn) -1)/ strlen(fn);
193 while (iterations > 0)
195 yaffs_write(h,fn,strlen(fn));
199 yaffs_truncate(h,reSyze);
201 yaffs_lseek(h,0,SEEK_SET);
202 iterations = (syze2 + strlen(fn) -1)/ strlen(fn);
203 while (iterations > 0)
205 yaffs_write(h,fn,strlen(fn));
213 void do_some_file_stuff(const char *path)
218 sprintf(fn,"%s/%s",path,"f1");
219 create_file_of_size(fn,10000);
221 sprintf(fn,"%s/%s",path,"fdel");
222 create_file_of_size(fn,10000);
225 sprintf(fn,"%s/%s",path,"f2");
227 create_resized_file_of_size(fn,10000,3000,4000);
230 void yaffs_backward_scan_test(const char *path)
238 do_some_file_stuff(path);
240 sprintf(fn,"%s/ddd",path);
244 do_some_file_stuff(fn);
253 void short_scan_test(const char *path, int fsize, int niterations)
258 sprintf(fn,"%s/%s",path,"f1");
261 for(i = 0; i < niterations; i++)
263 printf("\n*****************\nIteration %d\n",i);
265 printf("\nmount: Directory look-up of %s\n",path);
267 make_a_file(fn,1,fsize);
274 void scan_pattern_test(const char *path, int fsize, int niterations)
281 sprintf(fn[0],"%s/%s",path,"f0");
282 sprintf(fn[1],"%s/%s",path,"f1");
283 sprintf(fn[2],"%s/%s",path,"f2");
287 for(i = 0; i < niterations; i++)
289 printf("\n*****************\nIteration %d\n",i);
291 printf("\nmount: Directory look-up of %s\n",path);
293 for(j = 0; j < 3; j++)
295 result = dump_file_data(fn[j]);
296 result = check_pattern_file(fn[j]);
297 make_pattern_file(fn[j],fsize);
298 result = dump_file_data(fn[j]);
299 result = check_pattern_file(fn[j]);
305 void fill_disk(char *path,int nfiles)
314 for(n = 0; n < nfiles; n++)
316 sprintf(str,"%s/%d",path,n);
318 h = yaffs_open(str, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
320 printf("writing file %s handle %d ",str, h);
322 while ((result = yaffs_write(h,xx,600)) == 600)
324 f = yaffs_freespace(path);
326 result = yaffs_close(h);
327 printf(" close %d\n",result);
331 void fill_disk_and_delete(char *path, int nfiles, int ncycles)
337 for(i = 0; i < ncycles; i++)
339 printf("@@@@@@@@@@@@@@ cycle %d\n",i);
340 fill_disk(path,nfiles);
342 for(j = 0; j < nfiles; j++)
344 sprintf(str,"%s/%d",path,j);
345 result = yaffs_unlink(str);
346 printf("unlinking file %s, result %d\n",str,result);
352 void fill_files(char *path,int flags, int maxIterations,int siz)
362 sprintf(str,"%s/%d",path,i);
363 h = yaffs_open(str, O_CREAT | O_TRUNC | O_RDWR,S_IREAD | S_IWRITE);
368 for(j = 0; j < siz; j++)
370 yaffs_write(h,str,1);
379 } while(h >= 0 && i < maxIterations);
385 sprintf(str,"%s/%d",path,i);
386 printf("unlink %s\n",str);
388 } while(yaffs_unlink(str) >= 0);
392 void leave_unlinked_file(char *path,int maxIterations,int siz)
401 sprintf(str,"%s/%d",path,i);
402 printf("create %s\n",str);
403 h = yaffs_open(str, O_CREAT | O_TRUNC | O_RDWR,S_IREAD | S_IWRITE);
409 } while(h < 0 && i < maxIterations);
413 for(i = 0; i < siz; i++)
415 yaffs_write(h,str,1);
419 printf("Leaving file %s open\n",str);
423 void dumpDirFollow(const char *dname)
430 d = yaffs_opendir(dname);
434 printf("opendir failed\n");
438 while((de = yaffs_readdir(d)) != NULL)
440 sprintf(str,"%s/%s",dname,de->d_name);
444 printf("%s length %d mode %X ",de->d_name,(int)s.st_size,s.st_mode);
445 switch(s.st_mode & S_IFMT)
447 case S_IFREG: printf("data file"); break;
448 case S_IFDIR: printf("directory"); break;
449 case S_IFLNK: printf("symlink -->");
450 if(yaffs_readlink(str,str,100) < 0)
453 printf("\"%s\"",str);
455 default: printf("unknown"); break;
465 printf("Free space in %s is %d\n\n",dname,(int)yaffs_freespace(dname));
470 void dumpDir(const char *dname)
477 d = yaffs_opendir(dname);
481 printf("opendir failed\n");
485 while((de = yaffs_readdir(d)) != NULL)
487 sprintf(str,"%s/%s",dname,de->d_name);
491 printf("%s length %d mode %X ",de->d_name,(int)s.st_size,s.st_mode);
492 switch(s.st_mode & S_IFMT)
494 case S_IFREG: printf("data file"); break;
495 case S_IFDIR: printf("directory"); break;
496 case S_IFLNK: printf("symlink -->");
497 if(yaffs_readlink(str,str,100) < 0)
500 printf("\"%s\"",str);
502 default: printf("unknown"); break;
512 printf("Free space in %s is %d\n\n",dname,(int)yaffs_freespace(dname));
517 static void PermissionsCheck(const char *path, mode_t tmode, int tflags,int expectedResult)
521 if(yaffs_chmod(path,tmode)< 0) printf("chmod failed\n");
523 fd = yaffs_open(path,tflags,0);
525 if((fd >= 0) != (expectedResult > 0))
527 printf("Permissions check %x %x %d failed\n",tmode,tflags,expectedResult);
531 printf("Permissions check %x %x %d OK\n",tmode,tflags,expectedResult);
540 int long_test(int argc, char *argv[])
551 struct yaffs_stat ystat;
555 yaffs_mount("/boot");
556 yaffs_mount("/data");
557 yaffs_mount("/flash");
560 printf("\nDirectory look-up of /boot\n");
562 printf("\nDirectory look-up of /data\n");
564 printf("\nDirectory look-up of /flash\n");
567 //leave_unlinked_file("/flash",20000,0);
568 //leave_unlinked_file("/data",20000,0);
570 leave_unlinked_file("/ram",20,0);
573 f = yaffs_open("/boot/b1", O_RDONLY,0);
575 printf("open /boot/b1 readonly, f=%d\n",f);
577 f = yaffs_open("/boot/b1", O_CREAT,S_IREAD | S_IWRITE);
579 printf("open /boot/b1 O_CREAT, f=%d\n",f);
582 r = yaffs_write(f,"hello",1);
583 printf("write %d attempted to write to a read-only file\n",r);
587 printf("close %d\n",r);
589 f = yaffs_open("/boot/b1", O_RDWR,0);
591 printf("open /boot/b1 O_RDWR,f=%d\n",f);
594 r = yaffs_write(f,"hello",2);
595 printf("write %d attempted to write to a writeable file\n",r);
596 r = yaffs_write(f,"world",3);
597 printf("write %d attempted to write to a writeable file\n",r);
599 r= yaffs_lseek(f,0,SEEK_END);
600 printf("seek end %d\n",r);
602 r = yaffs_read(f,buffer,10);
603 printf("read %d \"%s\"\n",r,buffer);
604 r= yaffs_lseek(f,0,SEEK_SET);
605 printf("seek set %d\n",r);
607 r = yaffs_read(f,buffer,10);
608 printf("read %d \"%s\"\n",r,buffer);
610 r = yaffs_read(f,buffer,10);
611 printf("read %d \"%s\"\n",r,buffer);
613 // Check values reading at end.
614 // A read past end of file should return 0 for 0 bytes read.
616 r= yaffs_lseek(f,0,SEEK_END);
617 r = yaffs_read(f,buffer,10);
618 printf("read at end returned %d\n",r);
619 r= yaffs_lseek(f,500,SEEK_END);
620 r = yaffs_read(f,buffer,10);
621 printf("read past end returned %d\n",r);
625 printf("close %d\n",r);
627 copy_in_a_file("/boot/yyfile","xxx");
629 // Create a file with a long name
631 copy_in_a_file("/boot/file with a long name","xxx");
634 printf("\nDirectory look-up of /boot\n");
638 r = yaffs_stat("/boot/file with a long name",&ystat);
642 r = yaffs_rename("/boot/file with a long name","/boot/r1");
644 printf("\nDirectory look-up of /boot\n");
648 r = yaffs_unlink("/boot/r1");
650 printf("\nDirectory look-up of /boot\n");
655 r = yaffs_mkdir("/boot/directory1",0);
657 printf("\nDirectory look-up of /boot\n");
659 printf("\nDirectory look-up of /boot/directory1\n");
660 dumpDir("/boot/directory1");
662 // add a file to the directory
663 copy_in_a_file("/boot/directory1/file with a long name","xxx");
665 printf("\nDirectory look-up of /boot\n");
667 printf("\nDirectory look-up of /boot/directory1\n");
668 dumpDir("/boot/directory1");
670 // Attempt to delete directory (should fail)
672 r = yaffs_rmdir("/boot/directory1");
674 printf("\nDirectory look-up of /boot\n");
676 printf("\nDirectory look-up of /boot/directory1\n");
677 dumpDir("/boot/directory1");
679 // Delete file first, then rmdir should work
680 r = yaffs_unlink("/boot/directory1/file with a long name");
681 r = yaffs_rmdir("/boot/directory1");
684 printf("\nDirectory look-up of /boot\n");
686 printf("\nDirectory look-up of /boot/directory1\n");
687 dumpDir("/boot/directory1");
690 fill_disk_and_delete("/boot",20,20);
692 printf("\nDirectory look-up of /boot\n");
696 yaffs_symlink("yyfile","/boot/slink");
698 yaffs_readlink("/boot/slink",str,100);
699 printf("symlink alias is %s\n",str);
704 printf("\nDirectory look-up of /boot\n");
706 printf("\nDirectory look-up of /boot (using stat instead of lstat)\n");
707 dumpDirFollow("/boot");
708 printf("\nDirectory look-up of /boot/directory1\n");
709 dumpDir("/boot/directory1");
711 h = yaffs_open("/boot/slink",O_RDWR,0);
713 printf("file length is %d\n",(int)yaffs_lseek(h,0,SEEK_END));
717 yaffs_unlink("/boot/slink");
720 printf("\nDirectory look-up of /boot\n");
725 yaffs_stat("/boot/yyfile",&ystat);
726 temp_mode = ystat.st_mode;
728 yaffs_chmod("/boot/yyfile",0x55555);
729 printf("\nDirectory look-up of /boot\n");
732 yaffs_chmod("/boot/yyfile",temp_mode);
733 printf("\nDirectory look-up of /boot\n");
736 // Permission checks...
737 PermissionsCheck("/boot/yyfile",0, O_WRONLY,0);
738 PermissionsCheck("/boot/yyfile",0, O_RDONLY,0);
739 PermissionsCheck("/boot/yyfile",0, O_RDWR,0);
741 PermissionsCheck("/boot/yyfile",S_IREAD, O_WRONLY,0);
742 PermissionsCheck("/boot/yyfile",S_IREAD, O_RDONLY,1);
743 PermissionsCheck("/boot/yyfile",S_IREAD, O_RDWR,0);
745 PermissionsCheck("/boot/yyfile",S_IWRITE, O_WRONLY,1);
746 PermissionsCheck("/boot/yyfile",S_IWRITE, O_RDONLY,0);
747 PermissionsCheck("/boot/yyfile",S_IWRITE, O_RDWR,0);
749 PermissionsCheck("/boot/yyfile",S_IREAD | S_IWRITE, O_WRONLY,1);
750 PermissionsCheck("/boot/yyfile",S_IREAD | S_IWRITE, O_RDONLY,1);
751 PermissionsCheck("/boot/yyfile",S_IREAD | S_IWRITE, O_RDWR,1);
753 yaffs_chmod("/boot/yyfile",temp_mode);
755 //create a zero-length file and unlink it (test for scan bug)
757 h = yaffs_open("/boot/zlf",O_CREAT | O_TRUNC | O_RDWR,0);
760 yaffs_unlink("/boot/zlf");
763 yaffs_DumpDevStruct("/boot");
765 fill_disk_and_delete("/boot",20,20);
767 yaffs_DumpDevStruct("/boot");
769 fill_files("/boot",1,10000,0);
770 fill_files("/boot",1,10000,5000);
771 fill_files("/boot",2,10000,0);
772 fill_files("/boot",2,10000,5000);
774 leave_unlinked_file("/data",20000,0);
775 leave_unlinked_file("/data",20000,5000);
776 leave_unlinked_file("/data",20000,5000);
777 leave_unlinked_file("/data",20000,5000);
778 leave_unlinked_file("/data",20000,5000);
779 leave_unlinked_file("/data",20000,5000);
781 yaffs_DumpDevStruct("/boot");
782 yaffs_DumpDevStruct("/data");
790 int huge_directory_test_on_path(char *path)
810 struct yaffs_stat ystat;
816 // Create a large number of files
818 for(i = 0; i < 2000; i++)
820 sprintf(str,"%s/%d",path,i);
822 f = yaffs_open(str,O_CREAT,S_IREAD | S_IWRITE);
828 d = yaffs_opendir(path);
831 while((de = yaffs_readdir(d)) != NULL) {
832 if (total >lastTotal+100*9*1024||(i & 1023)==0){
833 printf("files = %d, total = %d\n",i, total);
837 sprintf(str,"%s/%s",path,de->d_name);
839 switch(s.st_mode & S_IFMT){
841 //printf("data file");
853 int yaffs_scan_test(const char *path)
858 void rename_over_test(const char *mountpt)
864 sprintf(a,"%s/a",mountpt);
865 sprintf(b,"%s/b",mountpt);
869 yaffs_mount(mountpt);
870 i = yaffs_open(a,O_CREAT | O_TRUNC | O_RDWR, 0);
872 i = yaffs_open(b,O_CREAT | O_TRUNC | O_RDWR, 0);
874 yaffs_rename(a,b); // rename over
875 yaffs_rename(b,a); // rename back again (not renaimng over)
876 yaffs_rename(a,b); // rename back again (not renaimng over)
879 yaffs_unmount(mountpt);
883 int resize_stress_test(const char *path)
898 sprintf(aname,"%s%s",path,"/a");
899 sprintf(bname,"%s%s",path,"/b");
901 memset(abuffer,'a',1000);
902 memset(bbuffer,'b',1000);
904 a = yaffs_open(aname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
905 b = yaffs_open(bname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
907 printf(" %s %d %s %d\n",aname,a,bname,b);
911 for(j = 0; j < 100; j++)
913 yaffs_lseek(a,0,SEEK_END);
916 for(i = 0; i <20000; i++)
918 //r = yaffs_lseek(b,i,SEEK_SET);
919 //r = yaffs_write(b,bbuffer,1000);
924 int syz = yaffs_lseek(a,0,SEEK_END);
928 yaffs_truncate(a,syz);
934 r = yaffs_lseek(a,i * 500,SEEK_SET);
935 r = yaffs_write(a,abuffer,1000);
947 int resize_stress_test_no_grow_complex(const char *path,int iters)
962 sprintf(aname,"%s%s",path,"/a");
963 sprintf(bname,"%s%s",path,"/b");
965 memset(abuffer,'a',1000);
966 memset(bbuffer,'b',1000);
968 a = yaffs_open(aname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
969 b = yaffs_open(bname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
971 printf(" %s %d %s %d\n",aname,a,bname,b);
975 for(j = 0; j < iters; j++)
977 yaffs_lseek(a,0,SEEK_END);
980 for(i = 0; i <20000; i++)
982 //r = yaffs_lseek(b,i,SEEK_SET);
983 //r = yaffs_write(b,bbuffer,1000);
988 int syz = yaffs_lseek(a,0,SEEK_END);
995 yaffs_truncate(a,syz);
996 syz = yaffs_lseek(a,0,SEEK_END);
997 printf("shrink to %d\n",syz);
1005 r = yaffs_lseek(a,500,SEEK_END);
1006 r = yaffs_write(a,abuffer,1000);
1012 printf("file size is %d\n",yaffs_lseek(a,0,SEEK_END));
1020 int resize_stress_test_no_grow(const char *path,int iters)
1035 sprintf(aname,"%s%s",path,"/a");
1036 sprintf(bname,"%s%s",path,"/b");
1038 memset(abuffer,'a',1000);
1039 memset(bbuffer,'b',1000);
1041 a = yaffs_open(aname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1042 b = yaffs_open(bname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1044 printf(" %s %d %s %d\n",aname,a,bname,b);
1048 for(j = 0; j < iters; j++)
1050 yaffs_lseek(a,0,SEEK_END);
1053 for(i = 0; i <20000; i++)
1055 //r = yaffs_lseek(b,i,SEEK_SET);
1056 //r = yaffs_write(b,bbuffer,1000);
1061 int syz = yaffs_lseek(a,0,SEEK_END);
1067 if(syz < 0) syz = 0;
1068 yaffs_truncate(a,syz);
1069 syz = yaffs_lseek(a,0,SEEK_END);
1070 printf("shrink to %d\n",syz);
1078 r = yaffs_lseek(a,-500,SEEK_END);
1079 r = yaffs_write(a,abuffer,1000);
1085 printf("file size is %d\n",yaffs_lseek(a,0,SEEK_END));
1093 int directory_rename_test(void)
1098 yaffs_mount("/ram");
1099 yaffs_mkdir("/ram/a",0);
1100 yaffs_mkdir("/ram/a/b",0);
1101 yaffs_mkdir("/ram/c",0);
1103 printf("\nDirectory look-up of /ram\n");
1106 dumpDir("/ram/a/b");
1108 printf("Do rename (should fail)\n");
1110 r = yaffs_rename("/ram/a","/ram/a/b/d");
1111 printf("\nDirectory look-up of /ram\n");
1114 dumpDir("/ram/a/b");
1116 printf("Do rename (should not fail)\n");
1118 r = yaffs_rename("/ram/c","/ram/a/b/d");
1119 printf("\nDirectory look-up of /ram\n");
1122 dumpDir("/ram/a/b");
1129 int cache_read_test(void)
1133 int sizeOfFiles = 500000;
1138 yaffs_mount("/boot");
1140 make_a_file("/boot/a",'a',sizeOfFiles);
1141 make_a_file("/boot/b",'b',sizeOfFiles);
1143 a = yaffs_open("/boot/a",O_RDONLY,0);
1144 b = yaffs_open("/boot/b",O_RDONLY,0);
1145 c = yaffs_open("/boot/c", O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
1149 if (i > 100) i = 100;
1151 yaffs_read(a,buffer,i);
1152 yaffs_read(b,buffer,i);
1153 yaffs_write(c,buffer,i);
1154 } while(sizeOfFiles > 0);
1162 int cache_bypass_bug_test(void)
1164 // This test reporoduces a bug whereby YAFFS caching *was* buypassed
1165 // resulting in erroneous reads after writes.
1166 // This bug has been fixed.
1173 memset(buffer1,0,sizeof(buffer1));
1174 memset(buffer2,0,sizeof(buffer2));
1178 yaffs_mount("/boot");
1180 // Create a file of 2000 bytes.
1181 make_a_file("/boot/a",'X',2000);
1183 a = yaffs_open("/boot/a",O_RDWR, S_IREAD | S_IWRITE);
1185 // Write a short sequence to the file.
1186 // This will go into the cache.
1187 yaffs_lseek(a,0,SEEK_SET);
1188 yaffs_write(a,"abcdefghijklmnopqrstuvwxyz",20);
1190 // Read a short sequence from the file.
1191 // This will come from the cache.
1192 yaffs_lseek(a,0,SEEK_SET);
1193 yaffs_read(a,buffer1,30);
1195 // Read a page size sequence from the file.
1196 yaffs_lseek(a,0,SEEK_SET);
1197 yaffs_read(a,buffer2,512);
1199 printf("buffer 1 %s\n",buffer1);
1200 printf("buffer 2 %s\n",buffer2);
1202 if(strncmp(buffer1,buffer2,20))
1204 printf("Cache bypass bug detected!!!!!\n");
1212 int free_space_check(void)
1217 yaffs_mount("/boot");
1218 fill_disk("/boot/",2);
1219 f = yaffs_freespace("/boot");
1221 printf("%d free when disk full\n",f);
1225 int truncate_test(void)
1235 yaffs_mount("/boot");
1237 yaffs_unlink("/boot/trunctest");
1239 a = yaffs_open("/boot/trunctest", O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1241 yaffs_write(a,"abcdefghijklmnopqrstuvwzyz",26);
1243 yaffs_truncate(a,3);
1244 l= yaffs_lseek(a,0,SEEK_END);
1246 printf("truncated length is %d\n",l);
1248 yaffs_lseek(a,5,SEEK_SET);
1249 yaffs_write(a,"1",1);
1251 yaffs_lseek(a,0,SEEK_SET);
1253 r = yaffs_read(a,y,10);
1255 printf("read %d bytes:",r);
1257 for(i = 0; i < r; i++) printf("[%02X]",y[i]);
1269 void fill_disk_test(const char *mountpt)
1274 for(i = 0; i < 5; i++)
1276 yaffs_mount(mountpt);
1277 fill_disk_and_delete(mountpt,100,i+1);
1278 yaffs_unmount(mountpt);
1285 void lookup_test(const char *mountpt)
1295 struct yaffs_stat s;
1300 yaffs_mount(mountpt);
1302 d = yaffs_opendir(mountpt);
1306 printf("opendir failed\n");
1311 for(i = 0; (de = yaffs_readdir(d)) != NULL; i++)
1313 printf("unlinking %s\n",de->d_name);
1314 yaffs_unlink(de->d_name);
1317 printf("%d files deleted\n",i);
1321 for(i = 0; i < 2000; i++){
1322 sprintf(a,"%s/%d",mountpt,i);
1323 h = yaffs_open(a,O_CREAT | O_TRUNC | O_RDWR, 0);
1328 for(i = 0; (de = yaffs_readdir(d)) != NULL; i++)
1330 printf("%d %s\n",i,de->d_name);
1333 printf("%d files listed\n\n\n",i);
1340 for(i = 0; i < 2000; i++){
1341 sprintf(a,"%s/%d",mountpt,i);
1346 yaffs_unmount(mountpt);
1350 void freespace_test(const char *mountpt)
1361 sprintf(a,"%s/aaa",mountpt);
1365 yaffs_mount(mountpt);
1367 f0 = yaffs_freespace(mountpt);
1369 h = yaffs_open(a, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1371 for(i = 0; i < 100; i++)
1372 yaffs_write(h,a,100);
1376 f1 = yaffs_freespace(mountpt);
1380 f2 = yaffs_freespace(mountpt);
1383 yaffs_unmount(mountpt);
1384 yaffs_mount(mountpt);
1386 f3 = yaffs_freespace(mountpt);
1388 printf("%d\n%d\n%d\n%d\n",f0, f1,f2,f3);
1393 void simple_rw_test(const char *mountpt)
1402 sprintf(a,"%s/aaa",mountpt);
1406 yaffs_mount(mountpt);
1410 h = yaffs_open(a,O_CREAT| O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1412 for(i = 100000;i < 200000; i++){
1413 result = yaffs_write(h,&i,sizeof(i));
1417 printf("write error\n");
1424 // h = yaffs_open(a,O_RDWR, S_IREAD | S_IWRITE);
1427 yaffs_lseek(h,0,SEEK_SET);
1429 for(i = 100000; i < 200000; i++){
1430 result = yaffs_read(h,&x,sizeof(x));
1432 if(result != 4 || x != i){
1433 printf("read error %d %x %x\n",i,result,x);
1437 printf("Simple rw test passed\n");
1444 void scan_deleted_files_test(const char *mountpt)
1456 sprintf(sub,"%s/sdir",mountpt);
1459 for(j = 0; j < 10; j++)
1461 printf("\n\n>>>>>>> Run %d <<<<<<<<<<<<<\n\n",j);
1462 yaffs_mount(mountpt);
1466 p = (j & 0) ? mountpt: sub;
1468 for(i = 0; i < 100; i++)
1470 sprintf(fn,"%s/%d",p,i);
1474 h = yaffs_open(fn,O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1475 for(k = 0; k < 1000; k++)
1476 yaffs_write(h,fn,100);
1483 for(i = 0; i < 10; i++)
1485 sprintf(fn,"%s/%d",p,i);
1493 yaffs_unmount(mountpt);
1502 void write_10k(int h)
1505 const char *s="0123456789";
1506 for(i = 0; i < 1000; i++)
1507 yaffs_write(h,s,10);
1510 void write_200k_file(const char *fn, const char *fdel, const char *fdel1)
1516 h1 = yaffs_open(fn, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1518 for(i = 0; i < 100000; i+= 10000)
1524 if(yaffs_lseek(h1,0,SEEK_SET) != 1000000)
1526 printf("Could not write file\n");
1530 for(i = 0; i < 100000; i+= 10000)
1536 if(yaffs_lseek(h1,0,SEEK_SET) != 2000000)
1538 printf("Could not write file\n");
1543 yaffs_unlink(fdel1);
1549 void verify_200k_file(const char *fn)
1554 const char *s="0123456789";
1556 h1 = yaffs_open(fn, O_RDONLY, 0);
1558 for(i = 0; i < 200000; i+= 10)
1560 yaffs_read(h1,x,10);
1561 if(strncmp(x,s,10) != 0)
1563 printf("File verification failed at %d\n",i);
1572 void check_resize_gc_bug(const char *mountpt)
1581 sprintf(a,"%s/a",mountpt);
1582 sprintf(b,"%s/b",mountpt);
1583 sprintf(c,"%s/c",mountpt);
1589 yaffs_mount(mountpt);
1593 for(i = 0; i < 50; i++)
1595 printf("A\n");write_200k_file(a,"",c);
1596 printf("B\n");verify_200k_file(a);
1597 printf("C\n");write_200k_file(b,a,c);
1598 printf("D\n");verify_200k_file(b);
1599 yaffs_unmount(mountpt);
1600 yaffs_mount(mountpt);
1601 printf("E\n");verify_200k_file(a);
1602 printf("F\n");verify_200k_file(b);
1608 int main(int argc, char *argv[])
1610 //return long_test(argc,argv);
1612 //return cache_read_test();
1614 //resize_stress_test_no_grow("/flash",20);
1616 //huge_directory_test_on_path("/ram2k");
1618 //yaffs_backward_scan_test("/flash") ;
1620 //scan_pattern_test("/flash",10000,10);
1621 //short_scan_test("/flash",40000,200);
1624 //long_test_on_path("/ram2k");
1625 // long_test_on_path("/flash");
1626 simple_rw_test("/flash/flash");
1627 fill_disk_test("/flash/flash");
1628 // rename_over_test("/flash");
1629 //lookup_test("/flash");
1630 freespace_test("/flash/flash");
1634 // cache_bypass_bug_test();
1636 //free_space_check();
1638 //check_resize_gc_bug("/flash");