X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs2.git;a=blobdiff_plain;f=direct%2Ftests%2Fyaffs_test.c;h=b35c75025a821a99191b6593abc42553a4a9d770;hp=c2f1b55defcf47481ba9464c79fe4b729318a4c0;hb=f6a8cdab85cba8cfba3d6c44b99957e4e299670b;hpb=a90266d26463b8473743165376ba98b04353c64a diff --git a/direct/tests/yaffs_test.c b/direct/tests/yaffs_test.c index c2f1b55..b35c750 100644 --- a/direct/tests/yaffs_test.c +++ b/direct/tests/yaffs_test.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 @@ -19,13 +19,17 @@ #include #include #include +#include +#include #include "yaffsfs.h" +#include "yaffs_trace.h" + #include "nor_stress.h" #include "yaffs_fsx.h" - +void (*ext_fatal)(void); int random_seed; @@ -33,23 +37,166 @@ int simulate_power_failure = 0; int do_fsx; +int do_bash_around; + int init_test; int do_upgrade; int n_cycles = -1; +int fuzz_test=0; + + +int yaffs_test_max_mallocs; + +extern int ops_multiplier; char mount_point[200]; +#define BASH_HANDLES 20 +void yaffs_bash_around(const char *mountpt, int n_cycles) +{ + char name[200]; + char name1[200]; + int h[BASH_HANDLES]; + int i; + int op; + int pos; + int n; + int n1; + int start_op; + int op_max = 99; + + int cycle = 0; + + sprintf(name,"%s/bashdir",mountpt); + + yaffs_mkdir(name,0666); + + for(i = 0; i < BASH_HANDLES; i++) + h[i] = -1; + + while(n_cycles){ + if(cycle % 100 == 0){ + printf("CYCLE %8d mo %2d inodes %d space %d ",cycle,op_max, + yaffs_inodecount(mountpt),(int)yaffs_freespace(mountpt)); + for(i = 0; i < BASH_HANDLES; i++) + printf("%2d ",h[i]); + printf("\n"); + } + cycle++; + + if(n_cycles > 0) + n_cycles--; + i = rand() % BASH_HANDLES; + op = rand() % op_max; + pos = rand() & 20000000; + n = rand() % 100; + n1 = rand() % 100; + + sprintf(name,"%s/bashdir/xx%d",mountpt,n); + sprintf(name1,"%s/bashdir/xx%d",mountpt,n1); + + start_op = op; + + op-=1; + if(op < 0){ + if(h[i]>= 0){ + yaffs_close(h[i]); + h[i] = -1; + } + continue; + } + op-=1; + if(op < 0){ + if(h[i] < 0) + h[i] = yaffs_open(name,O_CREAT| O_RDWR, 0666); + continue; + } + + op-=5; + if(op< 0){ + yaffs_lseek(h[i],pos,SEEK_SET); + yaffs_write(h[i],name,n); + continue; + } + op-=1; + if(op < 0){ + yaffs_unlink(name); + continue; + } + op-=1; + if(op < 0){ + yaffs_rename(name,name1); + continue; + } + op-=1; + if(op < 0){ + yaffs_mkdir(name,0666); + continue; + } + op-=1; + if(op < 0){ + yaffs_rmdir(name); + continue; + } + + op_max = start_op-op; + } + + +} + void BadUsage(void) { + printf("Usage: yaffs_test [options] mountpoint\n"); + printf("options\n"); + printf(" f: do fsx testing\n"); + printf(" i: initialise for upgrade testing\n"); + printf(" l: multiply number of operations by 5\n"); + printf(" m: random max number of mallocs\n"); + printf(" n nnn: number of cycles\n"); + printf(" p: simulate power fail testing\n"); + printf(" s sss: set seed\n"); + printf(" u: do upgrade test\n"); + printf(" b: bash-about test\n"); + printf(" z: fuzz test - ignore verification errors\n"); exit(2); } +int sleep_exit = 0; +int sleep_time = 0; +void test_fatal(void) +{ + printf("fatal yaffs test pid %d sleeping\n",getpid()); + while(!sleep_exit){ + sleep(1); + sleep_time++; + } + + signal(SIGSEGV,SIG_IGN); + signal(SIGBUS,SIG_IGN); + signal(SIGABRT,SIG_IGN); + sleep_exit = 0; + +} + +void bad_ptr_handler(int sig) +{ + printf("signal %d received\n",sig); + test_fatal(); +} + int main(int argc, char **argv) { int ch; - + int random_mallocs=0; + ext_fatal = test_fatal; - while ((ch = getopt(argc,argv, "fin:ps:u")) +#if 1 + signal(SIGSEGV,bad_ptr_handler); + signal(SIGBUS,bad_ptr_handler); + signal(SIGABRT,bad_ptr_handler); +#endif + while ((ch = getopt(argc,argv, "bfilmn:ps:t:uz")) != EOF) switch (ch) { case 's': @@ -61,15 +208,29 @@ int main(int argc, char **argv) case 'i': init_test = 1; break; + case 'b': + do_bash_around = 1; + break; case 'f': do_fsx = 1; break; + case 'l': + ops_multiplier *= 5; + break; case 'u': do_upgrade = 1; break; + case 'm': + random_mallocs=1; + break; case 'n': n_cycles = atoi(optarg); break; + case 't': + yaffs_trace_mask = strtol(optarg,NULL,0); + break; + case 'z':fuzz_test=1; + break; default: BadUsage(); /* NOTREACHED */ @@ -77,29 +238,48 @@ int main(int argc, char **argv) argc -= optind; argv += optind; + if(random_mallocs){ + yaffs_test_max_mallocs = 0xFFF & random_seed; + } + if(argc == 1) { + int result; + strcpy(mount_point,argv[0]); if(simulate_power_failure) n_cycles = -1; - printf("Running test %s %s %s %s seed %d cycles %d\n", + printf("Running test %s %s %s %s %s seed %d cycles %d\n", do_upgrade ? "fw_upgrade" : "", init_test ? "initialise":"", + fuzz_test ? "fuzz-test" : "", do_fsx ? "fsx" :"", simulate_power_failure ? "power_fail" : "", random_seed, n_cycles); - yaffs_StartUp(); - yaffs_mount(mount_point); + yaffs_start_up(); + result = yaffs_mount(mount_point); + if(result < 0){ + printf("Mount of %s failed\n",mount_point); + printf("pid %d sleeping\n",getpid()); + + while(!sleep_exit){ + sleep(1); + sleep_time++; + } + } + printf("Mount complete\n"); if(do_upgrade && init_test){ simulate_power_failure = 0; NorStressTestInitialise(mount_point); } else if(do_upgrade){ - printf("Running stress on %s with seed %d\n",argv[1],random_seed); - NorStressTestRun(mount_point,n_cycles,do_fsx); + printf("Running stress on %s with seed %d\n",mount_point,random_seed); + NorStressTestRun(mount_point,n_cycles,do_fsx,fuzz_test); } else if(do_fsx){ - yaffs_fsx_main(mount_point); + yaffs_fsx_main(mount_point,n_cycles); + } else if(do_bash_around){ + yaffs_bash_around(mount_point,n_cycles); }else { printf("No test to run!\n"); BadUsage();