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