|
237
|
1 /* |
|
|
2 * YAFFS: Yet another FFS. A NAND-flash specific file system. |
|
|
3 * |
|
|
4 * Copyright (C) 2002 Aleph One Ltd. |
|
|
5 * for Toby Churchill Ltd and Brightstar Engineering |
|
|
6 * |
|
|
7 * Created by Charles Manning <charles@aleph1.co.uk> |
|
|
8 * |
|
|
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. |
|
|
12 * |
|
|
13 */ |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 #include <stdio.h> |
|
|
19 #include <string.h> |
|
|
20 #include <unistd.h> |
|
|
21 #include <fcntl.h> |
|
312
|
22 #include <signal.h> |
|
237
|
23 |
|
|
24 #include "yaffsfs.h" |
|
|
25 |
|
|
26 #include "nor_stress.h" |
|
|
27 #include "yaffs_fsx.h" |
|
|
28 |
|
312
|
29 void (*ext_fatal)(void); |
|
237
|
30 |
|
|
31 |
|
|
32 int random_seed; |
|
|
33 int simulate_power_failure = 0; |
|
|
34 |
|
|
35 |
|
|
36 int do_fsx; |
|
|
37 int init_test; |
|
|
38 int do_upgrade; |
|
|
39 int n_cycles = -1; |
|
|
40 |
|
240
|
41 extern int ops_multiplier; |
|
|
42 |
|
237
|
43 char mount_point[200]; |
|
|
44 |
|
|
45 void BadUsage(void) |
|
|
46 { |
|
307
|
47 printf("Usage: yaffs_test [options] mountpoint\n"); |
|
|
48 printf("options\n"); |
|
|
49 printf(" f: do fsx testing\n"); |
|
|
50 printf(" i: initialise for upgrade testing\n"); |
|
|
51 printf(" l: multiply number of operations by 5\n"); |
|
|
52 printf(" n nnn: number of cycles\n"); |
|
|
53 printf(" p: simulate power fail testing\n"); |
|
|
54 printf(" s sss: set seed\n"); |
|
308
|
55 printf(" u: do upgrade test\n"); |
|
237
|
56 exit(2); |
|
|
57 } |
|
|
58 |
|
312
|
59 void test_fatal(void) |
|
|
60 { |
|
|
61 printf("fatal yaffs test pid %d sleeping\n",getpid()); |
|
|
62 while(1) |
|
|
63 sleep(1); |
|
|
64 |
|
|
65 } |
|
|
66 |
|
|
67 void bad_ptr_handler(int sig) |
|
|
68 { |
|
|
69 printf("signal %d received\n",sig); |
|
|
70 test_fatal(); |
|
|
71 } |
|
237
|
72 int main(int argc, char **argv) |
|
|
73 { |
|
|
74 int ch; |
|
|
75 |
|
312
|
76 ext_fatal = test_fatal; |
|
|
77 signal(SIGSEGV,bad_ptr_handler); |
|
|
78 signal(SIGBUS,bad_ptr_handler); |
|
|
79 signal(SIGABRT,bad_ptr_handler); |
|
|
80 |
|
240
|
81 while ((ch = getopt(argc,argv, "filn:ps:u")) |
|
237
|
82 != EOF) |
|
|
83 switch (ch) { |
|
|
84 case 's': |
|
|
85 random_seed = atoi(optarg); |
|
|
86 break; |
|
|
87 case 'p': |
|
|
88 simulate_power_failure =1; |
|
|
89 break; |
|
|
90 case 'i': |
|
|
91 init_test = 1; |
|
|
92 break; |
|
|
93 case 'f': |
|
|
94 do_fsx = 1; |
|
|
95 break; |
|
240
|
96 case 'l': |
|
|
97 ops_multiplier *= 5; |
|
|
98 break; |
|
237
|
99 case 'u': |
|
|
100 do_upgrade = 1; |
|
|
101 break; |
|
|
102 case 'n': |
|
|
103 n_cycles = atoi(optarg); |
|
|
104 break; |
|
|
105 default: |
|
|
106 BadUsage(); |
|
|
107 /* NOTREACHED */ |
|
|
108 } |
|
|
109 argc -= optind; |
|
|
110 argv += optind; |
|
|
111 |
|
|
112 if(argc == 1) { |
|
|
113 strcpy(mount_point,argv[0]); |
|
|
114 |
|
|
115 if(simulate_power_failure) |
|
|
116 n_cycles = -1; |
|
|
117 printf("Running test %s %s %s %s seed %d cycles %d\n", |
|
|
118 do_upgrade ? "fw_upgrade" : "", |
|
|
119 init_test ? "initialise":"", |
|
|
120 do_fsx ? "fsx" :"", |
|
|
121 simulate_power_failure ? "power_fail" : "", |
|
|
122 random_seed, n_cycles); |
|
|
123 |
|
|
124 yaffs_StartUp(); |
|
|
125 yaffs_mount(mount_point); |
|
308
|
126 printf("Mount complete\n"); |
|
237
|
127 |
|
|
128 if(do_upgrade && init_test){ |
|
|
129 simulate_power_failure = 0; |
|
|
130 NorStressTestInitialise(mount_point); |
|
|
131 } else if(do_upgrade){ |
|
245
|
132 printf("Running stress on %s with seed %d\n",mount_point,random_seed); |
|
237
|
133 NorStressTestRun(mount_point,n_cycles,do_fsx); |
|
|
134 } else if(do_fsx){ |
|
240
|
135 yaffs_fsx_main(mount_point,n_cycles); |
|
237
|
136 }else { |
|
|
137 printf("No test to run!\n"); |
|
|
138 BadUsage(); |
|
|
139 } |
|
|
140 yaffs_unmount(mount_point); |
|
|
141 |
|
|
142 printf("Test run completed!\n"); |
|
|
143 } |
|
|
144 else |
|
|
145 BadUsage(); |
|
|
146 return 0; |
|
|
147 } |
|
|
148 |
|
|
149 |