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);
254 void yaffs_device_flush_test(const char *path)
264 do_some_file_stuff(path);
266 // Open and add some data to a few files
267 for(i = 0; i < 10; i++) {
269 sprintf(fn,"%s/ff%d",path,i);
271 h = yaffs_open(fn, O_CREAT | O_RDWR | O_TRUNC, S_IWRITE | S_IREAD);
272 yaffs_write(h,xxzz,2000);
273 yaffs_write(h,xxzz,2000);
282 void short_scan_test(const char *path, int fsize, int niterations)
287 sprintf(fn,"%s/%s",path,"f1");
290 for(i = 0; i < niterations; i++)
292 printf("\n*****************\nIteration %d\n",i);
294 printf("\nmount: Directory look-up of %s\n",path);
296 make_a_file(fn,1,fsize);
303 void scan_pattern_test(const char *path, int fsize, int niterations)
310 sprintf(fn[0],"%s/%s",path,"f0");
311 sprintf(fn[1],"%s/%s",path,"f1");
312 sprintf(fn[2],"%s/%s",path,"f2");
316 for(i = 0; i < niterations; i++)
318 printf("\n*****************\nIteration %d\n",i);
320 printf("\nmount: Directory look-up of %s\n",path);
322 for(j = 0; j < 3; j++)
324 result = dump_file_data(fn[j]);
325 result = check_pattern_file(fn[j]);
326 make_pattern_file(fn[j],fsize);
327 result = dump_file_data(fn[j]);
328 result = check_pattern_file(fn[j]);
334 void fill_disk(char *path,int nfiles)
343 for(n = 0; n < nfiles; n++)
345 sprintf(str,"%s/%d",path,n);
347 h = yaffs_open(str, O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
349 printf("writing file %s handle %d ",str, h);
351 while ((result = yaffs_write(h,xx,600)) == 600)
353 f = yaffs_freespace(path);
355 result = yaffs_close(h);
356 printf(" close %d\n",result);
360 void fill_disk_and_delete(char *path, int nfiles, int ncycles)
366 for(i = 0; i < ncycles; i++)
368 printf("@@@@@@@@@@@@@@ cycle %d\n",i);
369 fill_disk(path,nfiles);
371 for(j = 0; j < nfiles; j++)
373 sprintf(str,"%s/%d",path,j);
374 result = yaffs_unlink(str);
375 printf("unlinking file %s, result %d\n",str,result);
381 void fill_files(char *path,int flags, int maxIterations,int siz)
391 sprintf(str,"%s/%d",path,i);
392 h = yaffs_open(str, O_CREAT | O_TRUNC | O_RDWR,S_IREAD | S_IWRITE);
397 for(j = 0; j < siz; j++)
399 yaffs_write(h,str,1);
408 } while(h >= 0 && i < maxIterations);
414 sprintf(str,"%s/%d",path,i);
415 printf("unlink %s\n",str);
417 } while(yaffs_unlink(str) >= 0);
421 void leave_unlinked_file(char *path,int maxIterations,int siz)
430 sprintf(str,"%s/%d",path,i);
431 printf("create %s\n",str);
432 h = yaffs_open(str, O_CREAT | O_TRUNC | O_RDWR,S_IREAD | S_IWRITE);
438 } while(h < 0 && i < maxIterations);
442 for(i = 0; i < siz; i++)
444 yaffs_write(h,str,1);
448 printf("Leaving file %s open\n",str);
452 void dumpDirFollow(const char *dname)
459 d = yaffs_opendir(dname);
463 printf("opendir failed\n");
467 while((de = yaffs_readdir(d)) != NULL)
469 sprintf(str,"%s/%s",dname,de->d_name);
473 printf("%s length %d mode %X ",de->d_name,(int)s.st_size,s.st_mode);
474 switch(s.st_mode & S_IFMT)
476 case S_IFREG: printf("data file"); break;
477 case S_IFDIR: printf("directory"); break;
478 case S_IFLNK: printf("symlink -->");
479 if(yaffs_readlink(str,str,100) < 0)
482 printf("\"%s\"",str);
484 default: printf("unknown"); break;
494 printf("Free space in %s is %d\n\n",dname,(int)yaffs_freespace(dname));
499 void dumpDir(const char *dname)
506 d = yaffs_opendir(dname);
510 printf("opendir failed\n");
514 while((de = yaffs_readdir(d)) != NULL)
516 sprintf(str,"%s/%s",dname,de->d_name);
520 printf("%s length %d mode %X ",de->d_name,(int)s.st_size,s.st_mode);
521 switch(s.st_mode & S_IFMT)
523 case S_IFREG: printf("data file"); break;
524 case S_IFDIR: printf("directory"); break;
525 case S_IFLNK: printf("symlink -->");
526 if(yaffs_readlink(str,str,100) < 0)
529 printf("\"%s\"",str);
531 default: printf("unknown"); break;
541 printf("Free space in %s is %d\n\n",dname,(int)yaffs_freespace(dname));
546 static void PermissionsCheck(const char *path, mode_t tmode, int tflags,int expectedResult)
550 if(yaffs_chmod(path,tmode)< 0) printf("chmod failed\n");
552 fd = yaffs_open(path,tflags,0);
554 if((fd >= 0) != (expectedResult > 0))
556 printf("Permissions check %x %x %d failed\n",tmode,tflags,expectedResult);
560 printf("Permissions check %x %x %d OK\n",tmode,tflags,expectedResult);
569 int long_test(int argc, char *argv[])
580 struct yaffs_stat ystat;
584 yaffs_mount("/boot");
585 yaffs_mount("/data");
586 yaffs_mount("/flash");
589 printf("\nDirectory look-up of /boot\n");
591 printf("\nDirectory look-up of /data\n");
593 printf("\nDirectory look-up of /flash\n");
596 //leave_unlinked_file("/flash",20000,0);
597 //leave_unlinked_file("/data",20000,0);
599 leave_unlinked_file("/ram",20,0);
602 f = yaffs_open("/boot/b1", O_RDONLY,0);
604 printf("open /boot/b1 readonly, f=%d\n",f);
606 f = yaffs_open("/boot/b1", O_CREAT,S_IREAD | S_IWRITE);
608 printf("open /boot/b1 O_CREAT, f=%d\n",f);
611 r = yaffs_write(f,"hello",1);
612 printf("write %d attempted to write to a read-only file\n",r);
616 printf("close %d\n",r);
618 f = yaffs_open("/boot/b1", O_RDWR,0);
620 printf("open /boot/b1 O_RDWR,f=%d\n",f);
623 r = yaffs_write(f,"hello",2);
624 printf("write %d attempted to write to a writeable file\n",r);
625 r = yaffs_write(f,"world",3);
626 printf("write %d attempted to write to a writeable file\n",r);
628 r= yaffs_lseek(f,0,SEEK_END);
629 printf("seek end %d\n",r);
631 r = yaffs_read(f,buffer,10);
632 printf("read %d \"%s\"\n",r,buffer);
633 r= yaffs_lseek(f,0,SEEK_SET);
634 printf("seek set %d\n",r);
636 r = yaffs_read(f,buffer,10);
637 printf("read %d \"%s\"\n",r,buffer);
639 r = yaffs_read(f,buffer,10);
640 printf("read %d \"%s\"\n",r,buffer);
642 // Check values reading at end.
643 // A read past end of file should return 0 for 0 bytes read.
645 r= yaffs_lseek(f,0,SEEK_END);
646 r = yaffs_read(f,buffer,10);
647 printf("read at end returned %d\n",r);
648 r= yaffs_lseek(f,500,SEEK_END);
649 r = yaffs_read(f,buffer,10);
650 printf("read past end returned %d\n",r);
654 printf("close %d\n",r);
656 copy_in_a_file("/boot/yyfile","xxx");
658 // Create a file with a long name
660 copy_in_a_file("/boot/file with a long name","xxx");
663 printf("\nDirectory look-up of /boot\n");
667 r = yaffs_stat("/boot/file with a long name",&ystat);
671 r = yaffs_rename("/boot/file with a long name","/boot/r1");
673 printf("\nDirectory look-up of /boot\n");
677 r = yaffs_unlink("/boot/r1");
679 printf("\nDirectory look-up of /boot\n");
684 r = yaffs_mkdir("/boot/directory1",0);
686 printf("\nDirectory look-up of /boot\n");
688 printf("\nDirectory look-up of /boot/directory1\n");
689 dumpDir("/boot/directory1");
691 // add a file to the directory
692 copy_in_a_file("/boot/directory1/file with a long name","xxx");
694 printf("\nDirectory look-up of /boot\n");
696 printf("\nDirectory look-up of /boot/directory1\n");
697 dumpDir("/boot/directory1");
699 // Attempt to delete directory (should fail)
701 r = yaffs_rmdir("/boot/directory1");
703 printf("\nDirectory look-up of /boot\n");
705 printf("\nDirectory look-up of /boot/directory1\n");
706 dumpDir("/boot/directory1");
708 // Delete file first, then rmdir should work
709 r = yaffs_unlink("/boot/directory1/file with a long name");
710 r = yaffs_rmdir("/boot/directory1");
713 printf("\nDirectory look-up of /boot\n");
715 printf("\nDirectory look-up of /boot/directory1\n");
716 dumpDir("/boot/directory1");
719 fill_disk_and_delete("/boot",20,20);
721 printf("\nDirectory look-up of /boot\n");
725 yaffs_symlink("yyfile","/boot/slink");
727 yaffs_readlink("/boot/slink",str,100);
728 printf("symlink alias is %s\n",str);
733 printf("\nDirectory look-up of /boot\n");
735 printf("\nDirectory look-up of /boot (using stat instead of lstat)\n");
736 dumpDirFollow("/boot");
737 printf("\nDirectory look-up of /boot/directory1\n");
738 dumpDir("/boot/directory1");
740 h = yaffs_open("/boot/slink",O_RDWR,0);
742 printf("file length is %d\n",(int)yaffs_lseek(h,0,SEEK_END));
746 yaffs_unlink("/boot/slink");
749 printf("\nDirectory look-up of /boot\n");
754 yaffs_stat("/boot/yyfile",&ystat);
755 temp_mode = ystat.st_mode;
757 yaffs_chmod("/boot/yyfile",0x55555);
758 printf("\nDirectory look-up of /boot\n");
761 yaffs_chmod("/boot/yyfile",temp_mode);
762 printf("\nDirectory look-up of /boot\n");
765 // Permission checks...
766 PermissionsCheck("/boot/yyfile",0, O_WRONLY,0);
767 PermissionsCheck("/boot/yyfile",0, O_RDONLY,0);
768 PermissionsCheck("/boot/yyfile",0, O_RDWR,0);
770 PermissionsCheck("/boot/yyfile",S_IREAD, O_WRONLY,0);
771 PermissionsCheck("/boot/yyfile",S_IREAD, O_RDONLY,1);
772 PermissionsCheck("/boot/yyfile",S_IREAD, O_RDWR,0);
774 PermissionsCheck("/boot/yyfile",S_IWRITE, O_WRONLY,1);
775 PermissionsCheck("/boot/yyfile",S_IWRITE, O_RDONLY,0);
776 PermissionsCheck("/boot/yyfile",S_IWRITE, O_RDWR,0);
778 PermissionsCheck("/boot/yyfile",S_IREAD | S_IWRITE, O_WRONLY,1);
779 PermissionsCheck("/boot/yyfile",S_IREAD | S_IWRITE, O_RDONLY,1);
780 PermissionsCheck("/boot/yyfile",S_IREAD | S_IWRITE, O_RDWR,1);
782 yaffs_chmod("/boot/yyfile",temp_mode);
784 //create a zero-length file and unlink it (test for scan bug)
786 h = yaffs_open("/boot/zlf",O_CREAT | O_TRUNC | O_RDWR,0);
789 yaffs_unlink("/boot/zlf");
792 yaffs_DumpDevStruct("/boot");
794 fill_disk_and_delete("/boot",20,20);
796 yaffs_DumpDevStruct("/boot");
798 fill_files("/boot",1,10000,0);
799 fill_files("/boot",1,10000,5000);
800 fill_files("/boot",2,10000,0);
801 fill_files("/boot",2,10000,5000);
803 leave_unlinked_file("/data",20000,0);
804 leave_unlinked_file("/data",20000,5000);
805 leave_unlinked_file("/data",20000,5000);
806 leave_unlinked_file("/data",20000,5000);
807 leave_unlinked_file("/data",20000,5000);
808 leave_unlinked_file("/data",20000,5000);
810 yaffs_DumpDevStruct("/boot");
811 yaffs_DumpDevStruct("/data");
819 int huge_directory_test_on_path(char *path)
839 struct yaffs_stat ystat;
845 // Create a large number of files
847 for(i = 0; i < 2000; i++)
849 sprintf(str,"%s/%d",path,i);
851 f = yaffs_open(str,O_CREAT,S_IREAD | S_IWRITE);
857 d = yaffs_opendir(path);
860 while((de = yaffs_readdir(d)) != NULL) {
861 if (total >lastTotal+100*9*1024||(i & 1023)==0){
862 printf("files = %d, total = %d\n",i, total);
866 sprintf(str,"%s/%s",path,de->d_name);
868 switch(s.st_mode & S_IFMT){
870 //printf("data file");
882 int yaffs_scan_test(const char *path)
887 void rename_over_test(const char *mountpt)
893 sprintf(a,"%s/a",mountpt);
894 sprintf(b,"%s/b",mountpt);
898 yaffs_mount(mountpt);
899 i = yaffs_open(a,O_CREAT | O_TRUNC | O_RDWR, 0);
901 i = yaffs_open(b,O_CREAT | O_TRUNC | O_RDWR, 0);
903 yaffs_rename(a,b); // rename over
904 yaffs_rename(b,a); // rename back again (not renaimng over)
905 yaffs_rename(a,b); // rename back again (not renaimng over)
908 yaffs_unmount(mountpt);
912 int resize_stress_test(const char *path)
927 sprintf(aname,"%s%s",path,"/a");
928 sprintf(bname,"%s%s",path,"/b");
930 memset(abuffer,'a',1000);
931 memset(bbuffer,'b',1000);
933 a = yaffs_open(aname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
934 b = yaffs_open(bname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
936 printf(" %s %d %s %d\n",aname,a,bname,b);
940 for(j = 0; j < 100; j++)
942 yaffs_lseek(a,0,SEEK_END);
945 for(i = 0; i <20000; i++)
947 //r = yaffs_lseek(b,i,SEEK_SET);
948 //r = yaffs_write(b,bbuffer,1000);
953 int syz = yaffs_lseek(a,0,SEEK_END);
957 yaffs_truncate(a,syz);
963 r = yaffs_lseek(a,i * 500,SEEK_SET);
964 r = yaffs_write(a,abuffer,1000);
976 int resize_stress_test_no_grow_complex(const char *path,int iters)
991 sprintf(aname,"%s%s",path,"/a");
992 sprintf(bname,"%s%s",path,"/b");
994 memset(abuffer,'a',1000);
995 memset(bbuffer,'b',1000);
997 a = yaffs_open(aname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
998 b = yaffs_open(bname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1000 printf(" %s %d %s %d\n",aname,a,bname,b);
1004 for(j = 0; j < iters; j++)
1006 yaffs_lseek(a,0,SEEK_END);
1009 for(i = 0; i <20000; i++)
1011 //r = yaffs_lseek(b,i,SEEK_SET);
1012 //r = yaffs_write(b,bbuffer,1000);
1017 int syz = yaffs_lseek(a,0,SEEK_END);
1023 if(syz < 0) syz = 0;
1024 yaffs_truncate(a,syz);
1025 syz = yaffs_lseek(a,0,SEEK_END);
1026 printf("shrink to %d\n",syz);
1034 r = yaffs_lseek(a,500,SEEK_END);
1035 r = yaffs_write(a,abuffer,1000);
1041 printf("file size is %d\n",yaffs_lseek(a,0,SEEK_END));
1049 int resize_stress_test_no_grow(const char *path,int iters)
1064 sprintf(aname,"%s%s",path,"/a");
1065 sprintf(bname,"%s%s",path,"/b");
1067 memset(abuffer,'a',1000);
1068 memset(bbuffer,'b',1000);
1070 a = yaffs_open(aname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1071 b = yaffs_open(bname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1073 printf(" %s %d %s %d\n",aname,a,bname,b);
1077 for(j = 0; j < iters; j++)
1079 yaffs_lseek(a,0,SEEK_END);
1082 for(i = 0; i <20000; i++)
1084 //r = yaffs_lseek(b,i,SEEK_SET);
1085 //r = yaffs_write(b,bbuffer,1000);
1090 int syz = yaffs_lseek(a,0,SEEK_END);
1096 if(syz < 0) syz = 0;
1097 yaffs_truncate(a,syz);
1098 syz = yaffs_lseek(a,0,SEEK_END);
1099 printf("shrink to %d\n",syz);
1107 r = yaffs_lseek(a,-500,SEEK_END);
1108 r = yaffs_write(a,abuffer,1000);
1114 printf("file size is %d\n",yaffs_lseek(a,0,SEEK_END));
1122 int directory_rename_test(void)
1127 yaffs_mount("/ram");
1128 yaffs_mkdir("/ram/a",0);
1129 yaffs_mkdir("/ram/a/b",0);
1130 yaffs_mkdir("/ram/c",0);
1132 printf("\nDirectory look-up of /ram\n");
1135 dumpDir("/ram/a/b");
1137 printf("Do rename (should fail)\n");
1139 r = yaffs_rename("/ram/a","/ram/a/b/d");
1140 printf("\nDirectory look-up of /ram\n");
1143 dumpDir("/ram/a/b");
1145 printf("Do rename (should not fail)\n");
1147 r = yaffs_rename("/ram/c","/ram/a/b/d");
1148 printf("\nDirectory look-up of /ram\n");
1151 dumpDir("/ram/a/b");
1158 int cache_read_test(void)
1162 int sizeOfFiles = 500000;
1167 yaffs_mount("/boot");
1169 make_a_file("/boot/a",'a',sizeOfFiles);
1170 make_a_file("/boot/b",'b',sizeOfFiles);
1172 a = yaffs_open("/boot/a",O_RDONLY,0);
1173 b = yaffs_open("/boot/b",O_RDONLY,0);
1174 c = yaffs_open("/boot/c", O_CREAT | O_RDWR | O_TRUNC, S_IREAD | S_IWRITE);
1178 if (i > 100) i = 100;
1180 yaffs_read(a,buffer,i);
1181 yaffs_read(b,buffer,i);
1182 yaffs_write(c,buffer,i);
1183 } while(sizeOfFiles > 0);
1191 int cache_bypass_bug_test(void)
1193 // This test reporoduces a bug whereby YAFFS caching *was* buypassed
1194 // resulting in erroneous reads after writes.
1195 // This bug has been fixed.
1202 memset(buffer1,0,sizeof(buffer1));
1203 memset(buffer2,0,sizeof(buffer2));
1207 yaffs_mount("/boot");
1209 // Create a file of 2000 bytes.
1210 make_a_file("/boot/a",'X',2000);
1212 a = yaffs_open("/boot/a",O_RDWR, S_IREAD | S_IWRITE);
1214 // Write a short sequence to the file.
1215 // This will go into the cache.
1216 yaffs_lseek(a,0,SEEK_SET);
1217 yaffs_write(a,"abcdefghijklmnopqrstuvwxyz",20);
1219 // Read a short sequence from the file.
1220 // This will come from the cache.
1221 yaffs_lseek(a,0,SEEK_SET);
1222 yaffs_read(a,buffer1,30);
1224 // Read a page size sequence from the file.
1225 yaffs_lseek(a,0,SEEK_SET);
1226 yaffs_read(a,buffer2,512);
1228 printf("buffer 1 %s\n",buffer1);
1229 printf("buffer 2 %s\n",buffer2);
1231 if(strncmp(buffer1,buffer2,20))
1233 printf("Cache bypass bug detected!!!!!\n");
1241 int free_space_check(void)
1246 yaffs_mount("/boot");
1247 fill_disk("/boot/",2);
1248 f = yaffs_freespace("/boot");
1250 printf("%d free when disk full\n",f);
1254 int truncate_test(void)
1264 yaffs_mount("/boot");
1266 yaffs_unlink("/boot/trunctest");
1268 a = yaffs_open("/boot/trunctest", O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1270 yaffs_write(a,"abcdefghijklmnopqrstuvwzyz",26);
1272 yaffs_truncate(a,3);
1273 l= yaffs_lseek(a,0,SEEK_END);
1275 printf("truncated length is %d\n",l);
1277 yaffs_lseek(a,5,SEEK_SET);
1278 yaffs_write(a,"1",1);
1280 yaffs_lseek(a,0,SEEK_SET);
1282 r = yaffs_read(a,y,10);
1284 printf("read %d bytes:",r);
1286 for(i = 0; i < r; i++) printf("[%02X]",y[i]);
1298 void fill_disk_test(const char *mountpt)
1303 for(i = 0; i < 5; i++)
1305 yaffs_mount(mountpt);
1306 fill_disk_and_delete(mountpt,100,i+1);
1307 yaffs_unmount(mountpt);
1314 void lookup_test(const char *mountpt)
1324 struct yaffs_stat s;
1329 yaffs_mount(mountpt);
1331 d = yaffs_opendir(mountpt);
1335 printf("opendir failed\n");
1340 for(i = 0; (de = yaffs_readdir(d)) != NULL; i++)
1342 printf("unlinking %s\n",de->d_name);
1343 yaffs_unlink(de->d_name);
1346 printf("%d files deleted\n",i);
1350 for(i = 0; i < 2000; i++){
1351 sprintf(a,"%s/%d",mountpt,i);
1352 h = yaffs_open(a,O_CREAT | O_TRUNC | O_RDWR, 0);
1357 for(i = 0; (de = yaffs_readdir(d)) != NULL; i++)
1359 printf("%d %s\n",i,de->d_name);
1362 printf("%d files listed\n\n\n",i);
1369 for(i = 0; i < 2000; i++){
1370 sprintf(a,"%s/%d",mountpt,i);
1375 yaffs_unmount(mountpt);
1379 void link_test(const char *mountpt)
1391 sprintf(a,"%s/aaa",mountpt);
1392 sprintf(b,"%s/bbb",mountpt);
1393 sprintf(c,"%s/ccc",mountpt);
1397 yaffs_mount(mountpt);
1400 h = yaffs_open(a, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1401 for(i = 0; i < 100; i++)
1402 yaffs_write(h,a,100);
1415 yaffs_unmount(mountpt);
1416 yaffs_mount(mountpt);
1418 printf("link test done\n");
1422 void freespace_test(const char *mountpt)
1433 sprintf(a,"%s/aaa",mountpt);
1437 yaffs_mount(mountpt);
1439 f0 = yaffs_freespace(mountpt);
1441 h = yaffs_open(a, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1443 for(i = 0; i < 100; i++)
1444 yaffs_write(h,a,100);
1448 f1 = yaffs_freespace(mountpt);
1452 f2 = yaffs_freespace(mountpt);
1455 yaffs_unmount(mountpt);
1456 yaffs_mount(mountpt);
1458 f3 = yaffs_freespace(mountpt);
1460 printf("%d\n%d\n%d\n%d\n",f0, f1,f2,f3);
1465 void simple_rw_test(const char *mountpt)
1474 sprintf(a,"%s/aaa",mountpt);
1478 yaffs_mount(mountpt);
1482 h = yaffs_open(a,O_CREAT| O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1484 for(i = 100000;i < 200000; i++){
1485 result = yaffs_write(h,&i,sizeof(i));
1489 printf("write error\n");
1496 // h = yaffs_open(a,O_RDWR, S_IREAD | S_IWRITE);
1499 yaffs_lseek(h,0,SEEK_SET);
1501 for(i = 100000; i < 200000; i++){
1502 result = yaffs_read(h,&x,sizeof(x));
1504 if(result != 4 || x != i){
1505 printf("read error %d %x %x\n",i,result,x);
1509 printf("Simple rw test passed\n");
1516 void scan_deleted_files_test(const char *mountpt)
1528 sprintf(sub,"%s/sdir",mountpt);
1531 for(j = 0; j < 10; j++)
1533 printf("\n\n>>>>>>> Run %d <<<<<<<<<<<<<\n\n",j);
1534 yaffs_mount(mountpt);
1538 p = (j & 0) ? mountpt: sub;
1540 for(i = 0; i < 100; i++)
1542 sprintf(fn,"%s/%d",p,i);
1546 h = yaffs_open(fn,O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1547 for(k = 0; k < 1000; k++)
1548 yaffs_write(h,fn,100);
1555 for(i = 0; i < 10; i++)
1557 sprintf(fn,"%s/%d",p,i);
1565 yaffs_unmount(mountpt);
1574 void write_10k(int h)
1577 const char *s="0123456789";
1578 for(i = 0; i < 1000; i++)
1579 yaffs_write(h,s,10);
1582 void write_200k_file(const char *fn, const char *fdel, const char *fdel1)
1588 h1 = yaffs_open(fn, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE);
1590 for(i = 0; i < 100000; i+= 10000)
1596 if(yaffs_lseek(h1,0,SEEK_SET) != 1000000)
1598 printf("Could not write file\n");
1602 for(i = 0; i < 100000; i+= 10000)
1608 if(yaffs_lseek(h1,0,SEEK_SET) != 2000000)
1610 printf("Could not write file\n");
1615 yaffs_unlink(fdel1);
1621 void verify_200k_file(const char *fn)
1626 const char *s="0123456789";
1628 h1 = yaffs_open(fn, O_RDONLY, 0);
1630 for(i = 0; i < 200000; i+= 10)
1632 yaffs_read(h1,x,10);
1633 if(strncmp(x,s,10) != 0)
1635 printf("File verification failed at %d\n",i);
1644 void check_resize_gc_bug(const char *mountpt)
1653 sprintf(a,"%s/a",mountpt);
1654 sprintf(b,"%s/b",mountpt);
1655 sprintf(c,"%s/c",mountpt);
1661 yaffs_mount(mountpt);
1665 for(i = 0; i < 50; i++)
1667 printf("A\n");write_200k_file(a,"",c);
1668 printf("B\n");verify_200k_file(a);
1669 printf("C\n");write_200k_file(b,a,c);
1670 printf("D\n");verify_200k_file(b);
1671 yaffs_unmount(mountpt);
1672 yaffs_mount(mountpt);
1673 printf("E\n");verify_200k_file(a);
1674 printf("F\n");verify_200k_file(b);
1680 int main(int argc, char *argv[])
1682 //return long_test(argc,argv);
1684 //return cache_read_test();
1686 //resize_stress_test_no_grow("/flash",20);
1688 //huge_directory_test_on_path("/ram2k");
1690 //yaffs_backward_scan_test("/flash/flash");
1691 yaffs_device_flush_test("/flash/flash");
1694 //scan_pattern_test("/flash",10000,10);
1695 //short_scan_test("/flash",40000,200);
1698 //long_test_on_path("/ram2k");
1699 // long_test_on_path("/flash");
1700 //simple_rw_test("/flash/flash");
1701 //fill_disk_test("/flash/flash");
1702 // rename_over_test("/flash");
1703 //lookup_test("/flash");
1704 //freespace_test("/flash/flash");
1706 //link_test("/flash/flash");
1711 // cache_bypass_bug_test();
1713 //free_space_check();
1715 //check_resize_gc_bug("/flash");