X-Git-Url: https://yaffs.net/gitweb/?a=blobdiff_plain;f=direct%2Ftest-framework%2Fbasic-tests%2Fdtest.c;h=a6a8c9d6c10c986d57ba8167f92b36ea68c7e2c5;hb=ffa781d6427fba6469c60d91482079d5643ca7b7;hp=153d274d3a54db1db8b2cf0764faf9c099840674;hpb=c08faae4258b29a794ad55ca160c5a247145c838;p=yaffs2.git diff --git a/direct/test-framework/basic-tests/dtest.c b/direct/test-framework/basic-tests/dtest.c index 153d274..a6a8c9d 100644 --- a/direct/test-framework/basic-tests/dtest.c +++ b/direct/test-framework/basic-tests/dtest.c @@ -611,6 +611,63 @@ static void dump_directory_tree(const char *dname) printf("Free space in %s is %d\n\n",dname,(int)yaffs_freespace(dname)); } +void dump_directory_tree_worker_fd(const char *dname,int recursive) +{ + int h; + struct yaffs_dirent *de; + struct yaffs_stat s; + char str[1000]; + + h = yaffs_open(dname, O_RDONLY, 0); + + if(h < 0) + { + printf("open of dir failed\n"); + } + else + { + printf("using fd %d\n", h); + + while((de = yaffs_readdir_fd(h)) != NULL) + { + sprintf(str,"%s/%s",dname,de->d_name); + + yaffs_lstat(str,&s); + + printf("%s inode %d obj %x length %lld mode %X ", + str,s.st_ino,de->d_dont_use, s.st_size,s.st_mode); + switch(s.st_mode & S_IFMT) + { + case S_IFREG: printf("data file"); break; + case S_IFDIR: printf("directory"); break; + case S_IFLNK: printf("symlink -->"); + if(yaffs_readlink(str,str,100) < 0) + printf("no alias"); + else + printf("\"%s\"",str); + break; + default: printf("unknown"); break; + } + + printf("\n"); + + if((s.st_mode & S_IFMT) == S_IFDIR && recursive) + dump_directory_tree_worker_fd(str,1); + + } + + yaffs_close(h); + } + +} + +static void dump_directory_tree_fd(const char *dname) +{ + dump_directory_tree_worker_fd(dname,1); + printf("\n"); + printf("Free space in %s is %d\n\n",dname,(int)yaffs_freespace(dname)); +} + void dumpDir(const char *dname) { dump_directory_tree_worker(dname,0); printf("\n"); @@ -3042,6 +3099,70 @@ void large_file_test(const char *mountpt) } +int mk_dir(const char *mp, const char *name) +{ + char full_name[100]; + + sprintf(full_name, "%s/%s", mp, name); + + return yaffs_mkdir(full_name, S_IREAD| S_IWRITE); +} + +int mk_file(const char *mp, const char *name) +{ + char full_name[100]; + int h; + + sprintf(full_name, "%s/%s", mp, name); + + h = yaffs_open(full_name, O_RDWR | O_CREAT | O_TRUNC, S_IREAD| S_IWRITE); + + yaffs_write(h, name, strlen(name)); + + yaffs_close(h); + return 0; +} + +void xx_test(const char *mountpt) +{ + char xx_buffer[1000]; + + yaffs_start_up(); + + yaffs_format(mountpt,0,0,0); + + yaffs_mount(mountpt); + printf("mounted\n"); + dumpDir(mountpt); + + printf("create files\n"); + + mk_dir(mountpt, "foo"); + mk_file(mountpt, "foo/f1"); + mk_file(mountpt, "foo/f2"); + mk_file(mountpt, "foo/f3"); + mk_file(mountpt, "foo/f4"); + dump_directory_tree(mountpt); + + printf("unmount and remount\n"); + + /* Unmount/remount */ + yaffs_unmount(mountpt); + yaffs_mount(mountpt); + dump_directory_tree(mountpt); +} + +void yy_test(const char *mountpt) +{ + char xx_buffer[1000]; + + yaffs_start_up(); + + yaffs_mount(mountpt); + dump_directory_tree(mountpt); +} + + void readdir_test(const char *mountpt) { char xx_buffer[1000]; @@ -3078,9 +3199,106 @@ void readdir_test(const char *mountpt) yaffs_unmount(mountpt); +} + +void format_test(const char *mountpt) +{ + int ret; + + yaffs_start_up(); + + ret = yaffs_format(mountpt, 0, 0, 0); + printf("yaffs_format(...,0, 0, 0) of unmounted returned %d." + " Should return 0\n\n\n", ret); + yaffs_mount(mountpt); + + ret = yaffs_format(mountpt, 0, 0, 0); + printf("yaffs_format(...,0, 0, 0) of mounted returned %d." + " Should return -1 (busy)\n\n\n", ret); + + ret = yaffs_format(mountpt, 1, 0, 0); + printf("yaffs_format(...,1, 0, 0) of mounted returned %d." + " Should return 0.\n\n\n", ret); + + ret = yaffs_mount(mountpt); + printf("mount should return 0 returned %d\n\n\n", ret); + + ret = yaffs_format(mountpt, 1, 0, 1); + printf("yaffs_format(...,1, 0, 1) of mounted returned %d." + " Should return 0.\n\n\n", ret); + + ret = yaffs_mount(mountpt); + printf("mount should return -1 returned %d\n", ret); } +void dir_rename_test(const char *mountpt) +{ + char fname[100]; + char dname[100]; + int h; + int ret; + + yaffs_start_up(); + yaffs_mount(mountpt); + + sprintf(fname,"%s/file",mountpt); + sprintf(dname,"%s/directory",mountpt); + + h = yaffs_open(fname,O_CREAT | O_RDWR | O_TRUNC, 0666); + yaffs_close(h); + + yaffs_mkdir(dname, 0666); + + dump_directory_tree(mountpt); + + printf("Try to rename %s to %s\n", fname, dname); + ret = yaffs_rename(fname, dname); + printf("result %d, %d\n", ret, yaffs_get_error()); + + printf("Try to rename %s to %s\n", dname, fname); + ret = yaffs_rename(dname, fname); + printf("result %d, %d\n", ret, yaffs_get_error()); + + +} + + +void dir_fd_test(const char *mountpt) +{ + char name[100]; + int h; + int ret; + int i; + + yaffs_start_up(); + yaffs_mount(mountpt); + + sprintf(name,"%s/directory",mountpt); + yaffs_mkdir(name, 0666); + for(i=0; i < 20; i++) { + sprintf(name,"%s/directory/file%d",mountpt, i); + + h = yaffs_open(name, O_CREAT | O_TRUNC | O_RDWR, 0666); + yaffs_write(h, name, strlen(name)); + yaffs_close(h); + } + sprintf(name,"%s/dddd",mountpt); + yaffs_mkdir(name, 0666); + for(i=0; i < 20; i++) { + sprintf(name,"%s/dddd/filezzz%d",mountpt, i); + + h = yaffs_open(name, O_CREAT | O_TRUNC | O_RDWR, 0666); + yaffs_write(h, name, strlen(name)); + yaffs_close(h); + } + + + dump_directory_tree(mountpt); + dump_directory_tree_fd(mountpt); + dump_directory_tree_fd(mountpt); + +} int random_seed; int simulate_power_failure; @@ -3102,12 +3320,12 @@ int main(int argc, char *argv[]) //rename_over_test("//////////////////flash///////////////////yaffs1///////////"); - //fill_empty_files_test("/yaffs2/"); - //resize_stress_test("/yaffs2"); - //overwrite_test("/yaffs2"); + //fill_empty_files_test("/nand/"); + //resize_stress_test("/nand"); + //overwrite_test("/nand"); - //long_name_test("/yaffs2"); - //link_test0("/yaffs2"); + //long_name_test("/nand"); + //link_test0("/nand"); //link_test1("yaffs2"); //scan_pattern_test("/flash",10000,10); //short_scan_test("/flash/flash",40000,200); @@ -3140,24 +3358,34 @@ int main(int argc, char *argv[]) //check_resize_gc_bug("/flash"); - //basic_xattr_test("/yaffs2"); - //big_xattr_test("/yaffs2"); + //basic_xattr_test("/nand"); + //big_xattr_test("/nand"); //null_name_test("yaffs2"); //test_flash_traffic("yaffs2"); - // link_follow_test("/yaffs2"); - //basic_utime_test("/yaffs2"); + // link_follow_test("/nand"); + //basic_utime_test("/nand"); + + + //format_test("/nand"); + + //max_files_test("/nand"); + + //start_twice("/nand"); + + //large_file_test("/nand"); + //readdir_test("/nand"); - max_files_test("/yaffs2"); + //basic_utime_test("/nand"); + //case_insensitive_test("/nand"); - //start_twice("/yaffs2"); + //yy_test("/nand"); + //dir_rename_test("/nand"); - //large_file_test("/yaffs2"); - //readdir_test("/yaffs2"); + //dir_fd_test("/nand"); - //basic_utime_test("/yaffs2"); - //case_insensitive_test("/yaffs2"); + format_test("/nand"); return 0;