a0f9bdbd1daf70036d61498b9745970f943c4bad
[yaffs2.git] / direct / tests / yaffs_test.c
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>
22
23 #include "yaffsfs.h"
24
25 #include "nor_stress.h"
26 #include "yaffs_fsx.h"
27
28
29
30
31 int random_seed;
32 int simulate_power_failure = 0;
33
34
35 int do_fsx;
36 int init_test;
37 int do_upgrade;
38 int n_cycles = -1;
39
40 extern int ops_multiplier;
41
42 char mount_point[200];
43
44 void BadUsage(void)
45 {
46         printf("Usage: yaffs_test [options] mountpoint\n");
47         printf("options\n");
48         printf(" f: do fsx testing\n");
49         printf(" i: initialise for upgrade testing\n");
50         printf(" l: multiply number of operations by 5\n");
51         printf(" n nnn: number of cycles\n");
52         printf(" p: simulate power fail testing\n");
53         printf(" s sss: set seed\n");
54         printf(" u: do upgrade test\n);
55         exit(2);
56 }
57
58 int main(int argc, char **argv)
59 {
60         int ch;
61         
62
63         while ((ch = getopt(argc,argv, "filn:ps:u"))
64                != EOF)
65                 switch (ch) {
66                 case 's':
67                         random_seed = atoi(optarg);
68                         break;
69                 case 'p':
70                         simulate_power_failure =1;
71                         break;
72                 case 'i':
73                         init_test = 1;
74                         break;
75                 case 'f':
76                         do_fsx = 1;
77                         break;
78                 case 'l':
79                         ops_multiplier *= 5;
80                         break;
81                 case 'u':
82                         do_upgrade = 1;
83                         break;
84                 case 'n':
85                         n_cycles = atoi(optarg);
86                         break;
87                 default:
88                         BadUsage();
89                         /* NOTREACHED */
90                 }
91         argc -= optind;
92         argv += optind;
93         
94         if(argc == 1) {
95                 strcpy(mount_point,argv[0]);
96                 
97                 if(simulate_power_failure)
98                         n_cycles = -1;
99                 printf("Running test %s %s %s %s seed %d cycles %d\n",
100                         do_upgrade ? "fw_upgrade" : "",
101                         init_test ? "initialise":"",
102                         do_fsx ? "fsx" :"",
103                         simulate_power_failure ? "power_fail" : "",
104                         random_seed, n_cycles);
105
106                 yaffs_StartUp();
107                 yaffs_mount(mount_point);
108                         
109                 if(do_upgrade && init_test){
110                         simulate_power_failure = 0;
111                         NorStressTestInitialise(mount_point);
112                 } else if(do_upgrade){
113                         printf("Running stress on %s with seed %d\n",mount_point,random_seed);
114                         NorStressTestRun(mount_point,n_cycles,do_fsx);
115                 } else if(do_fsx){
116                         yaffs_fsx_main(mount_point,n_cycles);
117                 }else {
118                         printf("No test to run!\n");
119                         BadUsage();
120                 }
121                 yaffs_unmount(mount_point);
122                 
123                 printf("Test run completed!\n");
124         }
125         else
126                 BadUsage();
127         return 0;
128 }
129
130