More test fiddling
[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         exit(2);
47 }
48
49 int main(int argc, char **argv)
50 {
51         int ch;
52         
53
54         while ((ch = getopt(argc,argv, "filn:ps:u"))
55                != EOF)
56                 switch (ch) {
57                 case 's':
58                         random_seed = atoi(optarg);
59                         break;
60                 case 'p':
61                         simulate_power_failure =1;
62                         break;
63                 case 'i':
64                         init_test = 1;
65                         break;
66                 case 'f':
67                         do_fsx = 1;
68                         break;
69                 case 'l':
70                         ops_multiplier *= 5;
71                         break;
72                 case 'u':
73                         do_upgrade = 1;
74                         break;
75                 case 'n':
76                         n_cycles = atoi(optarg);
77                         break;
78                 default:
79                         BadUsage();
80                         /* NOTREACHED */
81                 }
82         argc -= optind;
83         argv += optind;
84         
85         if(argc == 1) {
86                 strcpy(mount_point,argv[0]);
87                 
88                 if(simulate_power_failure)
89                         n_cycles = -1;
90                 printf("Running test %s %s %s %s seed %d cycles %d\n",
91                         do_upgrade ? "fw_upgrade" : "",
92                         init_test ? "initialise":"",
93                         do_fsx ? "fsx" :"",
94                         simulate_power_failure ? "power_fail" : "",
95                         random_seed, n_cycles);
96
97                 yaffs_StartUp();
98                 yaffs_mount(mount_point);
99                         
100                 if(do_upgrade && init_test){
101                         simulate_power_failure = 0;
102                         NorStressTestInitialise(mount_point);
103                 } else if(do_upgrade){
104                         printf("Running stress on %s with seed %d\n",argv[1],random_seed);
105                         NorStressTestRun(mount_point,n_cycles,do_fsx);
106                 } else if(do_fsx){
107                         yaffs_fsx_main(mount_point,n_cycles);
108                 }else {
109                         printf("No test to run!\n");
110                         BadUsage();
111                 }
112                 yaffs_unmount(mount_point);
113                 
114                 printf("Test run completed!\n");
115         }
116         else
117                 BadUsage();
118         return 0;
119 }
120
121