X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs2.git;a=blobdiff_plain;f=direct%2Ftest-framework%2Fbasic-tests%2Fdtest.c;h=1a98bcb18d17ced144f73d389893af8bb05e0f7d;hp=5db05beb79a57fd028b77f056a93c5550931a8fa;hb=5af18695480b470eea2a2447a1c5211073b9c59b;hpb=413797fe98ba5f4ba219c8628273eea918eb8655 diff --git a/direct/test-framework/basic-tests/dtest.c b/direct/test-framework/basic-tests/dtest.c index 5db05be..1a98bcb 100644 --- a/direct/test-framework/basic-tests/dtest.c +++ b/direct/test-framework/basic-tests/dtest.c @@ -1,8 +1,7 @@ /* * YAFFS: Yet another FFS. A NAND-flash specific file system. * - * Copyright (C) 2002-2011 Aleph One Ltd. - * for Toby Churchill Ltd and Brightstar Engineering + * Copyright (C) 2002-2018 Aleph One Ltd. * * Created by Charles Manning * @@ -17,6 +16,7 @@ #include #include #include +#include #include "yaffsfs.h" @@ -215,6 +215,8 @@ void verify_file_of_size(const char *fn,int syze) l = strlen(xx); result = yaffs_read(h,yy,l); + if (result) + printf("result in line %d is %d", __LINE__, result); yy[l] = 0; if(strcmp(xx,yy)){ @@ -386,6 +388,8 @@ void scan_pattern_test(const char *path, int fsize, int niterations) make_pattern_file(fn[j],fsize); result = dump_file_data(fn[j]); result = check_pattern_file(fn[j]); + if (result) + printf("result in line %d is %d", __LINE__, result); } yaffs_unmount(path); } @@ -396,7 +400,7 @@ void fill_disk(const char *path,int nfiles) int h; int n; int result; - int f; + int f =0; static char xx[600]; char str[50]; @@ -413,8 +417,9 @@ void fill_disk(const char *path,int nfiles) { f = yaffs_freespace(path); } + printf("last freespace was %d\n", f); result = yaffs_close(h); - printf(" close %d\n",result); + printf(" close %d\n", result); } } @@ -433,7 +438,7 @@ void fill_disk_and_delete(const char *path, int nfiles, int ncycles) { sprintf(str,"%s/%d",path,j); result = yaffs_unlink(str); - printf("unlinking file %s, result %d\n",str,result); + printf("unlinking file %s, result %d\n", str, result); } } } @@ -514,7 +519,7 @@ void dumpDirFollow(const char *dname) yaffs_DIR *d; struct yaffs_dirent *de; struct yaffs_stat s; - char str[100]; + char str[300]; d = yaffs_opendir(dname); @@ -530,7 +535,8 @@ void dumpDirFollow(const char *dname) yaffs_lstat(str,&s); - printf("%s ino %lld length %d mode %X ",de->d_name,(int)s.st_ino,s.st_size,s.st_mode); + printf("%s ino %d length %d mode %X ", + de->d_name, (int)s.st_ino, (int)s.st_size, s.st_mode); switch(s.st_mode & S_IFMT) { case S_IFREG: printf("data file"); break; @@ -577,8 +583,8 @@ void dump_directory_tree_worker(const char *dname,int recursive) 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); + printf("%s inode %d length %d mode %X ", + str, s.st_ino, (int)s.st_size, s.st_mode); switch(s.st_mode & S_IFMT) { case S_IFREG: printf("data file"); break; @@ -634,8 +640,8 @@ void dump_directory_tree_worker_fd(const char *dname,int recursive) 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); + printf("%s inode %d length %d mode %X ", + str,s.st_ino, (int)s.st_size, s.st_mode); switch(s.st_mode & S_IFMT) { case S_IFREG: printf("data file"); break; @@ -711,6 +717,9 @@ int long_test(int argc, char *argv[]) mode_t temp_mode; struct yaffs_stat ystat; + (void) argc; + (void) argv; + yaffs_start_up(); yaffs_mount("/boot"); @@ -961,7 +970,7 @@ int huge_directory_test_on_path(char *path) int total = 0; int lastTotal = 0; - char str[100]; + char str[300]; yaffs_start_up(); @@ -1007,6 +1016,8 @@ int huge_directory_test_on_path(char *path) int yaffs_scan_test(const char *path) { + (void) path; + return 0; } @@ -1100,7 +1111,11 @@ int resize_stress_test(const char *path) { //expand r = yaffs_lseek(a,i * 500,SEEK_SET); + if (r < 0) + printf("At line %d, r is %d\n", __LINE__, r); r = yaffs_write(a,abuffer,1000); + if (r < 0) + printf("At line %d, r is %d\n", __LINE__, r); } x++; @@ -1225,6 +1240,8 @@ int resize_stress_test_no_grow_complex(const char *path,int iters) //expand r = yaffs_lseek(a,500,SEEK_END); r = yaffs_write(a,abuffer,1000); + if (r < 0) + printf("At line %d, r is %d\n", __LINE__, r); } x++; @@ -1299,6 +1316,8 @@ int resize_stress_test_no_grow(const char *path,int iters) //expand r = yaffs_lseek(a,-500,SEEK_END); r = yaffs_write(a,abuffer,1000); + if (r < 0) + printf("At line %d, r is %d\n", __LINE__, r); } x++; @@ -1330,6 +1349,9 @@ int directory_rename_test(void) printf("Do rename (should fail)\n"); r = yaffs_rename("/ram/a","/ram/a/b/d"); + if (r < 0) + printf("At line %d, r is %d\n", __LINE__, r); + printf("\nDirectory look-up of /ram\n"); dumpDir("/ram"); dumpDir("/ram/a"); @@ -1434,13 +1456,13 @@ int free_space_check(void) { int f; - yaffs_start_up(); - yaffs_mount("/boot"); - fill_disk("/boot/",2); - f = yaffs_freespace("/boot"); + yaffs_start_up(); + yaffs_mount("/boot"); + fill_disk("/boot/",2); + f = yaffs_freespace("/boot"); - printf("%d free when disk full\n",f); - return 1; + printf("%d free when disk full\n",f); + return 1; } int truncate_test(void) @@ -1473,7 +1495,7 @@ int truncate_test(void) r = yaffs_read(a,y,10); - printf("read %d bytes:",r); + printf("read %d bytes:", r); for(i = 0; i < r; i++) printf("[%02X]",y[i]); @@ -2042,10 +2064,7 @@ void multi_mount_test(const char *mountpt,int nmounts) for(i = 0; i < nmounts; i++){ int h0; int h1; - int len0; - int len1; - - static char xx[1000]; + char xx[1000]; printf("############### Iteration %d Start\n",i); if(1 || i == 0 || i == 5) @@ -2073,8 +2092,8 @@ void multi_mount_test(const char *mountpt,int nmounts) yaffs_write(h1,xx,1000); } #endif - len0 = yaffs_lseek(h0,0,SEEK_END); - len1 = yaffs_lseek(h1,0,SEEK_END); + yaffs_lseek(h0,0,SEEK_END); + yaffs_lseek(h1,0,SEEK_END); yaffs_lseek(h0,0,SEEK_SET); yaffs_lseek(h1,0,SEEK_SET); @@ -2108,8 +2127,6 @@ void small_mount_test(const char *mountpt,int nmounts) int h0; int h1; - int len0; - int len1; int nread; sprintf(a,"%s/a",mountpt); @@ -2120,7 +2137,7 @@ void small_mount_test(const char *mountpt,int nmounts) for(i = 0; i < nmounts; i++){ - static char xx[1000]; + char xx[1000]; printf("############### Iteration %d Start\n",i); if(1 || i == 0 || i == 5) @@ -2148,8 +2165,8 @@ void small_mount_test(const char *mountpt,int nmounts) yaffs_write(h1,xx,nread); - len0 = yaffs_lseek(h0,0,SEEK_END); - len1 = yaffs_lseek(h1,0,SEEK_END); + yaffs_lseek(h0,0,SEEK_END); + yaffs_lseek(h1,0,SEEK_END); yaffs_lseek(h0,0,SEEK_SET); yaffs_lseek(h1,0,SEEK_SET); @@ -2345,7 +2362,7 @@ int make_file2(const char *name1, const char *name2,int syz) extern void SetCheckpointReservedBlocks(int n); -void checkpoint_upgrade_test(const char *mountpt,int nmounts) +void checkpoint_upgrade_test(const char *mountpt, int nmounts) { char a[50]; @@ -2355,10 +2372,9 @@ void checkpoint_upgrade_test(const char *mountpt,int nmounts) int j; - sprintf(a,"%s/a",mountpt); - - + (void) nmounts; + sprintf(a,"%s/a",mountpt); printf("Create start condition\n"); yaffs_start_up(); @@ -2465,10 +2481,13 @@ void random_seek(int h) yaffs_lseek(h,n,SEEK_SET); } -void random_truncate(int h, char * name) +void random_truncate(int h, char *name) { int n; int flen; + + (void) name; + n = random() & 0xFFFFF; flen = yaffs_lseek(h,0,SEEK_END); if(n > flen) @@ -2609,7 +2628,6 @@ void basic_utime_test(const char *mountpt) char name[100]; int h; int result; - int val1; struct yaffs_utimbuf utb; struct yaffs_stat st; @@ -2626,24 +2644,32 @@ void basic_utime_test(const char *mountpt) printf("created\n"); h = yaffs_open(name,O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE); - yaffs_fstat(h,&st); printf(" times %u %u %u\n",st.yst_atime, st.yst_ctime, st.yst_mtime); + yaffs_fstat(h,&st); + printf(" times %lu %lu %lu\n", + st.yst_atime, st.yst_ctime, st.yst_mtime); utb.actime = 1000; utb.modtime = 2000; result = yaffs_futime(h,&utb); printf("futime to a 1000 m 2000 result %d\n",result); - yaffs_fstat(h,&st); printf(" times %u %u %u\n",st.yst_atime, st.yst_ctime, st.yst_mtime); + yaffs_fstat(h,&st); + printf(" times %lu %lu %lu\n", + st.yst_atime, st.yst_ctime, st.yst_mtime); utb.actime = 5000; utb.modtime = 8000; result = yaffs_utime(name, &utb); printf("utime to a 5000 m 8000 result %d\n",result); - yaffs_fstat(h,&st); printf(" times %u %u %u\n",st.yst_atime, st.yst_ctime, st.yst_mtime); + yaffs_fstat(h,&st); + printf(" times %lu %lu %lu\n", + st.yst_atime, st.yst_ctime, st.yst_mtime); result = yaffs_utime(name, NULL); printf("utime to NULL result %d\n",result); - yaffs_fstat(h,&st); printf(" times %u %u %u\n",st.yst_atime, st.yst_ctime, st.yst_mtime); + yaffs_fstat(h,&st); + printf(" times %lu %lu %lu\n", + st.yst_atime, st.yst_ctime, st.yst_mtime); } @@ -2806,6 +2832,9 @@ void link_follow_test(const char *mountpt) result = yaffs_symlink(fn,sn); result = yaffs_link(sn,hn); + if (result < 0) + printf("At line %d result is %d\n", __LINE__, result); + h =yaffs_open(hn,O_RDWR,0); } @@ -2813,8 +2842,7 @@ void link_follow_test(const char *mountpt) void max_files_test(const char *mountpt) { char fn[100]; - char sn[100]; - char hn[100]; + int result; int h; int i; @@ -2848,11 +2876,12 @@ void max_files_test(const char *mountpt) result = yaffs_close(h); } - yaffs_unmount(mountpt); - - //h =yaffs_open(hn,O_RDWR,0); + if (result < 0) + printf("At line %d result is %d\n", __LINE__, result); + yaffs_unmount(mountpt); } + void case_insensitive_test(const char *mountpt) { char fn[100]; @@ -2891,7 +2920,7 @@ void case_insensitive_test(const char *mountpt) h = yaffs_open(fn2, O_RDONLY, 0); ret = yaffs_read(h, buffer, 100); - if (ret != strlen(fn) + 1 || memcmp(buffer, fn, ret)){ + if (ret != (int)(strlen(fn) + 1) || memcmp(buffer, fn, ret)){ printf("wrong file read\n"); } else { printf("File %s is the same as file %s\n", fn, fn2); @@ -2924,7 +2953,6 @@ void start_twice(const char *mountpt) #define BUFFER_N 1100 unsigned xxbuffer[BUFFER_N]; - void set_buffer(int n) { int i; @@ -2941,12 +2969,12 @@ void write_big_sparse_file(int h) int wrote; for(i = 0; i < N_WRITES; i++) { - printf("writing at %lld\n", offset); + printf("writing at %d\n", (int)offset); set_buffer(i); pos = yaffs_lseek(h, offset, SEEK_SET); if(pos != offset) { - printf("mismatched seek pos %lld offset %lld\n", - pos, offset); + printf("mismatched seek pos %d offset %d\n", + (int)pos, (int)offset); perror("lseek64"); exit(1); } @@ -2964,9 +2992,6 @@ void write_big_sparse_file(int h) } - - - void verify_big_sparse_file(int h) { unsigned check_buffer[BUFFER_N]; @@ -2975,23 +3000,19 @@ void verify_big_sparse_file(int h) loff_t pos; int n = sizeof(check_buffer); int result; - const char * check_type; int checks_failed = 0; int checks_passed = 0; for(i = 0; i < N_WRITES * STRIDE; i++) { if(i % STRIDE) { - check_type = "zero"; memset(xxbuffer,0, n); } else { - check_type = "buffer"; set_buffer(i/STRIDE); } - //printf("%s checking %lld\n", check_type, offset); pos = yaffs_lseek(h, offset, SEEK_SET); if(pos != offset) { - printf("mismatched seek pos %lld offset %lld\n", - pos, offset); + printf("mismatched seek pos %d offset %d\n", + (int)pos, (int)offset); perror("lseek64"); exit(1); } @@ -3002,13 +3023,10 @@ void verify_big_sparse_file(int h) exit(1); } - - - if(memcmp(xxbuffer, check_buffer, n)) { int j; - printf("buffer at %lld mismatches\n", pos); + printf("buffer at %d mismatches\n", (int)pos); printf("xxbuffer "); for(j = 0; j < 20; j++) printf(" %d",xxbuffer[j]); @@ -3074,7 +3092,7 @@ void large_file_test(const char *mountpt) yaffs_unmount(mountpt); - yaffs_mount_common(mountpt, 0, 1); + yaffs_mount3(mountpt, 0, 1); printf("mounted with no checkpt\n"); dumpDir(mountpt); handle = yaffs_open(fullname, O_RDONLY, 0); @@ -3082,13 +3100,13 @@ void large_file_test(const char *mountpt) yaffs_unmount(mountpt); /* Check resize by adding to the end, resizing back and verifying. */ - yaffs_mount_common(mountpt, 0, 1); + yaffs_mount3(mountpt, 0, 1); printf("checking resize\n"); dumpDir(mountpt); handle = yaffs_open(fullname, O_RDWR, 0); file_end = yaffs_lseek(handle, 0, SEEK_END); - printf("file_end %lld\n", file_end); + printf("file_end %d\n", (int)file_end); for(i = 0; i < 10000; i++) yaffs_write(handle, xx_buffer, sizeof(xx_buffer)); yaffs_ftruncate(handle, file_end); @@ -3125,8 +3143,6 @@ int mk_file(const char *mp, const char *name) void xx_test(const char *mountpt) { - char xx_buffer[1000]; - yaffs_start_up(); yaffs_format(mountpt,0,0,0); @@ -3154,8 +3170,6 @@ void xx_test(const char *mountpt) void yy_test(const char *mountpt) { - char xx_buffer[1000]; - yaffs_start_up(); yaffs_mount(mountpt); @@ -3165,14 +3179,9 @@ void yy_test(const char *mountpt) void readdir_test(const char *mountpt) { - char xx_buffer[1000]; int i; - int handle; - char fullname[100]; - yaffs_DIR *dirs[100]; - yaffs_trace_mask = 0; yaffs_start_up(); @@ -3268,7 +3277,6 @@ void dir_fd_test(const char *mountpt) { char name[100]; int h; - int ret; int i; yaffs_start_up(); @@ -3300,8 +3308,6 @@ void dir_fd_test(const char *mountpt) } - - void create_delete_many_files_test(const char *mountpt) { @@ -3334,11 +3340,80 @@ void create_delete_many_files_test(const char *mountpt) } +void find_device_check(void) +{ + yaffs_start_up(); + yaffs_mount("/nand"); + yaffs_mount("/"); + yaffs_mkdir("/nandxxx", 0666); + yaffs_mkdir("/nand/xxx", 0666); +} + + +void try_opendir(const char *str) +{ + yaffs_DIR *d; + + d = yaffs_opendir(str); + + printf("%s --> %p\n", str, d); + + if (d) + yaffs_closedir(d); +} + +void opendir_test(void) +{ + yaffs_start_up(); + yaffs_mount("/nand/"); + yaffs_symlink("x", "/nand/sym"); + yaffs_mkdir("/nand/x",0666); + yaffs_mkdir("/nand/y",0666); + yaffs_mkdir("/nand/x/r",0666); + yaffs_mkdir("/nand/x/s",0666); + yaffs_mkdir("/nand/x/t",0666); + + try_opendir("nand/x/."); + try_opendir("nand/x/r/.."); + try_opendir("nand/x/./"); + try_opendir("nand/x/r/../"); + try_opendir("/nand/x"); + try_opendir("/nand/x/"); + try_opendir("nand/x"); + try_opendir("nand/sym"); + try_opendir("nand/sym/"); + +} + +void try_rmdir(const char *str) +{ + int ret; + + ret= yaffs_rmdir(str); + + printf("rmdir(\"%s\") --> %d, errno %d\n", str, ret, yaffs_get_error()); + +} + +void rmdir_test2(void) +{ + yaffs_start_up(); + + yaffs_mount("/nand/"); + yaffs_mkdir("/nand/z",0666); + try_rmdir("/nand/z"); + yaffs_mkdir("/nand/z",0666); + try_rmdir("/nand/z/"); +} + int random_seed; int simulate_power_failure; int main(int argc, char *argv[]) { + (void) argc; + (void) argv; + random_seed = time(NULL); //return long_test(argc,argv); @@ -3362,7 +3437,7 @@ int main(int argc, char *argv[]) //link_test0("/nand"); //link_test1("yaffs2"); //scan_pattern_test("/flash",10000,10); - //short_scan_test("/flash/flash",40000,200); + short_scan_test("/yflash2",40000,200); //small_mount_test("/flash/flash",1000); //small_overwrite_test("/flash/flash",1000); //seek_overwrite_test("/flash/flash",1000); @@ -3420,7 +3495,11 @@ int main(int argc, char *argv[]) //dir_fd_test("/nand"); //format_test("/nand"); - create_delete_many_files_test("/nand"); + + //opendir_test(); + //rmdir_test2(); + + //create_delete_many_files_test("/nand"); return 0; }