2 * YAFFS: Yet another FFS. A NAND-flash specific file system.
4 * Copyright (C) 2002-2010 Aleph One Ltd.
5 * for Toby Churchill Ltd and Brightstar Engineering
7 * Created by Charles Manning <charles@aleph1.co.uk>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
27 #include "yaffs_trace.h"
29 #include "nor_stress.h"
30 #include "yaffs_fsx.h"
32 void (*ext_fatal)(void);
36 int simulate_power_failure = 0;
48 int yaffs_test_max_mallocs;
50 extern int ops_multiplier;
52 char mount_point[200];
54 #define BASH_HANDLES 20
55 void yaffs_bash_around(const char *mountpt, int n_cycles)
70 sprintf(name,"%s/bashdir",mountpt);
72 yaffs_mkdir(name,0666);
74 for(i = 0; i < BASH_HANDLES; i++)
79 printf("CYCLE %8d mo %2d inodes %d space %d ",cycle,op_max,
80 yaffs_inodecount(mountpt),(int)yaffs_freespace(mountpt));
81 for(i = 0; i < BASH_HANDLES; i++)
89 i = rand() % BASH_HANDLES;
91 pos = rand() & 20000000;
95 sprintf(name,"%s/bashdir/xx%d",mountpt,n);
96 sprintf(name1,"%s/bashdir/xx%d",mountpt,n1);
111 h[i] = yaffs_open(name,O_CREAT| O_RDWR, 0666);
117 yaffs_lseek(h[i],pos,SEEK_SET);
118 yaffs_write(h[i],name,n);
128 yaffs_rename(name,name1);
133 yaffs_mkdir(name,0666);
142 op_max = start_op-op;
150 printf("Usage: yaffs_test [options] mountpoint\n");
152 printf(" f: do fsx testing\n");
153 printf(" i: initialise for upgrade testing\n");
154 printf(" l: multiply number of operations by 5\n");
155 printf(" m: random max number of mallocs\n");
156 printf(" n nnn: number of cycles\n");
157 printf(" p: simulate power fail testing\n");
158 printf(" s sss: set seed\n");
159 printf(" u: do upgrade test\n");
160 printf(" b: bash-about test\n");
161 printf(" z: fuzz test - ignore verification errors\n");
167 void test_fatal(void)
169 printf("fatal yaffs test pid %d sleeping\n",getpid());
175 signal(SIGSEGV,SIG_IGN);
176 signal(SIGBUS,SIG_IGN);
177 signal(SIGABRT,SIG_IGN);
182 void bad_ptr_handler(int sig)
184 printf("signal %d received\n",sig);
188 int main(int argc, char **argv)
191 int random_mallocs=0;
192 ext_fatal = test_fatal;
195 signal(SIGSEGV,bad_ptr_handler);
196 signal(SIGBUS,bad_ptr_handler);
197 signal(SIGABRT,bad_ptr_handler);
199 while ((ch = getopt(argc,argv, "bfilmn:ps:t:uz"))
203 random_seed = atoi(optarg);
206 simulate_power_failure =1;
227 n_cycles = atoi(optarg);
230 yaffs_trace_mask = strtol(optarg,NULL,0);
232 case 'z':fuzz_test=1;
242 yaffs_test_max_mallocs = 0xFFF & random_seed;
248 strcpy(mount_point,argv[0]);
250 if(simulate_power_failure)
252 printf("Running test %s %s %s %s %s seed %d cycles %d\n",
253 do_upgrade ? "fw_upgrade" : "",
254 init_test ? "initialise":"",
255 fuzz_test ? "fuzz-test" : "",
257 simulate_power_failure ? "power_fail" : "",
258 random_seed, n_cycles);
261 result = yaffs_mount(mount_point);
263 printf("Mount of %s failed\n",mount_point);
264 printf("pid %d sleeping\n",getpid());
271 printf("Mount complete\n");
273 if(do_upgrade && init_test){
274 simulate_power_failure = 0;
275 NorStressTestInitialise(mount_point);
276 } else if(do_upgrade){
277 printf("Running stress on %s with seed %d\n",mount_point,random_seed);
278 NorStressTestRun(mount_point,n_cycles,do_fsx,fuzz_test);
280 yaffs_fsx_main(mount_point,n_cycles);
281 } else if(do_bash_around){
282 yaffs_bash_around(mount_point,n_cycles);
284 printf("No test to run!\n");
287 yaffs_unmount(mount_point);
289 printf("Test run completed!\n");