2 * YAFFS: Yet another FFS. A NAND-flash specific file system.
4 * Copyright (C) 2002-2018 Aleph One Ltd.
6 * Created by Charles Manning <charles@aleph1.co.uk>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
26 #include "yaffs_trace.h"
28 #include "nor_stress.h"
29 #include "yaffs_fsx.h"
31 void (*ext_fatal)(void);
35 int simulate_power_failure = 0;
47 int yaffs_test_max_mallocs;
49 extern int ops_multiplier;
51 char mount_point[200];
53 #define BASH_HANDLES 20
54 void yaffs_bash_around(const char *mountpt, int n_cycles)
69 sprintf(name,"%s/bashdir",mountpt);
71 yaffs_mkdir(name,0666);
73 for(i = 0; i < BASH_HANDLES; i++)
78 printf("CYCLE %8d mo %2d inodes %d space %d ",cycle,op_max,
79 yaffs_inodecount(mountpt),(int)yaffs_freespace(mountpt));
80 for(i = 0; i < BASH_HANDLES; i++)
88 i = rand() % BASH_HANDLES;
90 pos = rand() & 20000000;
94 sprintf(name,"%s/bashdir/xx%d",mountpt,n);
95 sprintf(name1,"%s/bashdir/xx%d",mountpt,n1);
110 h[i] = yaffs_open(name,O_CREAT| O_RDWR, 0666);
116 yaffs_lseek(h[i],pos,SEEK_SET);
117 yaffs_write(h[i],name,n);
127 yaffs_rename(name,name1);
132 yaffs_mkdir(name,0666);
141 op_max = start_op-op;
149 printf("Usage: yaffs_test [options] mountpoint\n");
151 printf(" f: do fsx testing\n");
152 printf(" i: initialise for upgrade testing\n");
153 printf(" l: multiply number of operations by 5\n");
154 printf(" m: random max number of mallocs\n");
155 printf(" n nnn: number of cycles\n");
156 printf(" p: simulate power fail testing\n");
157 printf(" s sss: set seed\n");
158 printf(" u: do upgrade test\n");
159 printf(" b: bash-about test\n");
160 printf(" z: fuzz test - ignore verification errors\n");
166 void test_fatal(void)
168 printf("fatal yaffs test pid %d sleeping\n",getpid());
174 signal(SIGSEGV,SIG_IGN);
175 signal(SIGBUS,SIG_IGN);
176 signal(SIGABRT,SIG_IGN);
181 void bad_ptr_handler(int sig)
183 printf("signal %d received\n",sig);
187 int main(int argc, char **argv)
190 int random_mallocs=0;
191 ext_fatal = test_fatal;
194 signal(SIGSEGV,bad_ptr_handler);
195 signal(SIGBUS,bad_ptr_handler);
196 signal(SIGABRT,bad_ptr_handler);
198 while ((ch = getopt(argc,argv, "bfilmn:ps:t:uz"))
202 random_seed = atoi(optarg);
205 simulate_power_failure =1;
226 n_cycles = atoi(optarg);
229 yaffs_trace_mask = strtol(optarg,NULL,0);
231 case 'z':fuzz_test=1;
241 yaffs_test_max_mallocs = 0xFFF & random_seed;
247 strcpy(mount_point,argv[0]);
249 if(simulate_power_failure)
251 printf("Running test %s %s %s %s %s seed %d cycles %d\n",
252 do_upgrade ? "fw_upgrade" : "",
253 init_test ? "initialise":"",
254 fuzz_test ? "fuzz-test" : "",
256 simulate_power_failure ? "power_fail" : "",
257 random_seed, n_cycles);
260 result = yaffs_mount(mount_point);
262 printf("Mount of %s failed\n",mount_point);
263 printf("pid %d sleeping\n",getpid());
270 printf("Mount complete\n");
272 if(do_upgrade && init_test){
273 simulate_power_failure = 0;
274 NorStressTestInitialise(mount_point);
275 } else if(do_upgrade){
276 printf("Running stress on %s with seed %d\n",mount_point,random_seed);
277 NorStressTestRun(mount_point,n_cycles,do_fsx,fuzz_test);
279 yaffs_fsx_main(mount_point,n_cycles);
280 } else if(do_bash_around){
281 yaffs_bash_around(mount_point,n_cycles);
283 printf("No test to run!\n");
286 yaffs_unmount(mount_point);
288 printf("Test run completed!\n");