X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs2.git;a=blobdiff_plain;f=direct%2Fdtest.c;h=cf832a957ea71f901044b9fa5c3fc006839865ff;hp=24f5ad28a2b5001162a480df1afafd7c5b148f69;hb=4a96d43bb566f00596a31a41c535cabbf52d4f20;hpb=0c0fee7366b8a5a26ce11cf44675f22ab818cbc8 diff --git a/direct/dtest.c b/direct/dtest.c index 24f5ad2..cf832a9 100644 --- a/direct/dtest.c +++ b/direct/dtest.c @@ -1,7 +1,7 @@ /* * YAFFS: Yet another FFS. A NAND-flash specific file system. * - * Copyright (C) 2002 Aleph One Ltd. + * Copyright (C) 2002-2010 Aleph One Ltd. * for Toby Churchill Ltd and Brightstar Engineering * * Created by Charles Manning @@ -1036,6 +1036,36 @@ int resize_stress_test(const char *path) } + +int overwrite_test(const char *path) +{ + char aname[100]; + char bname[100]; + int i; + int j; + int a; + int b; + yaffs_StartUp(); + + yaffs_mount(path); + + sprintf(aname,"%s%s",path,"/a"); + sprintf(bname,"%s%s",path,"/b"); + + b = yaffs_open(bname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE); + for(j= 0; j < 500; j++){ + yaffs_write(b,bname,100); + a = yaffs_open(aname, O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE); + for(i = 0; i < rand() % 20000; i++) + yaffs_write(a,&a,sizeof(a)); + yaffs_close(a); + } + + return 0; + +} + + int root_perm_remount(const char *path) { struct yaffs_stat s; @@ -2457,6 +2487,96 @@ void rmdir_test(const char *mountpt) yaffs_rmdir(name); yaffs_unmount(mountpt); } + + + +static void print_xattrib_val(const char *path, const char *name) +{ + char buffer[100]; + int n; + + n = yaffs_getxattr(path,name,buffer,sizeof(buffer)); + if(n >= 0){ + __u8 *b = (__u8 *)buffer; + + printf("%d bytes:",n); + while(n > 0){ + printf("[%02X]",*b); + b++; + n--; + } + printf("\n"); + } else + printf(" Novalue result %d\n",n); +} + +static void list_xattr(const char *path) +{ + char list[1000]; + int n=0; + int list_len; + int len; + + list_len = yaffs_listxattr(path,list,sizeof(list)); + printf("xattribs for %s, result is %d\n",path,list_len); + while(n < list_len){ + len = strlen(list + n); + printf("\"%s\" value ",list+n); + print_xattrib_val(path,list + n); + n += (len + 1); + } + printf("end\n"); +} +void basic_xattr_test(const char *mountpt) +{ + char name[100]; + int h; + int result; + int val1; + int valread; + + yaffs_StartUp(); + + yaffs_mount(mountpt); + + strcpy(name,mountpt); + strcat(name,"/"); + strcat(name,"xfile"); + + yaffs_unlink(name); + h = yaffs_open(name,O_CREAT | O_TRUNC | O_RDWR, S_IREAD | S_IWRITE); + yaffs_close(h); + + printf("Start\n"); + list_xattr(name); + + printf("Add an attribute\n"); + val1 = 0x123456; + result = yaffs_setxattr(name,"foo",&val1,sizeof(val1),0); + printf("wrote attribute foo: result %d\n",result); + list_xattr(name); + printf("Add an attribute\n"); + val1 = 0x7890; + result = yaffs_setxattr(name,"bar",&val1,sizeof(val1),0); + printf("wrote attribute bar: result %d\n",result); + list_xattr(name); + + printf("Get non-existanrt attribute\n"); + print_xattrib_val(name,"not here"); + + printf("Delete non existing attribute\n"); + yaffs_removexattr(name,"not here"); + list_xattr(name); + + printf("Remove foo\n"); + yaffs_removexattr(name,"foo"); + list_xattr(name); + + printf("Remove bar\n"); + yaffs_removexattr(name,"bar"); + list_xattr(name); + +} int random_seed; @@ -2479,7 +2599,10 @@ int main(int argc, char *argv[]) //rename_over_test("//////////////////flash///////////////////yaffs1///////////"); - fill_empty_files_test("/yaffs2/"); + //fill_empty_files_test("/yaffs2/"); + //resize_stress_test("/yaffs2"); + //overwrite_test("/yaffs2"); + //long_name_test("/yaffs2"); //link_test0("/yaffs2"); //link_test1("yaffs2"); @@ -2496,7 +2619,7 @@ int main(int argc, char *argv[]) // huge_array_test("/flash/flash",10); - handle_test("yaffs2/"); + // handle_test("yaffs2/"); //long_test_on_path("/ram2k"); // long_test_on_path("/flash"); @@ -2517,6 +2640,8 @@ int main(int argc, char *argv[]) //check_resize_gc_bug("/flash"); + basic_xattr_test("/yaffs2"); + return 0; }