2 * YAFFS: Yet another FFS. A NAND-flash specific file system.
4 * Copyright (C) 2002-2010 Aleph One Ltd.
5 * for Toby Churchill Ltd and Brightstar Engineering
7 * Created by Timothy Manning <timothy@yaffs.net>
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.
14 #include "linux_test.h"
17 int simulate_power_failure = 1;
19 char message[400]; //this is used for storing print messages.
23 const struct option long_options[]={
27 {"print_level", 1,NULL,'p'},
28 {"quiet", 0,NULL,'q'},
32 {"verbose", 0,NULL,'v'}
35 const char short_options[]="hp:qs:v";
38 void init(int argc, char *argv[])
46 x=(unsigned)time(NULL);
47 sprintf(message,"seeding srand with: %d\n",x);
48 print_message(2,message);
54 new_option=getopt_long(argc,argv,short_options,long_options,NULL);
56 printf("mirror_tests help\n");
57 printf("arguments:\n");
58 printf("\t-p [NUMBER] //sets the print level for mirror_tests.\n");
59 printf("\t-v //verbose mode everything is printed\n");
60 printf("\t-q //quiet mode nothing is printed.\n");
61 printf("\t-s [number] //seeds rand with the number\n");
65 } else if (new_option=='p'){
66 set_print_level(atoi(optarg));
67 } else if (new_option=='v'){
69 } else if (new_option=='q'){
71 } else if (new_option=='s'){
72 srand(atoi(argv[x+1]));
74 } else if (new_option==-1){
76 } else if (new_option=='?') {
77 printf("bad argument\n");
80 }while(new_option!=-1);
83 int main(int argc, char *argv[])
85 dir_struct *scanned_dir=NULL;
92 while (break_bool!=1){
95 if (x<0 &&(break_bool!=1)){
100 if (x<0 &&(break_bool!=1)){
105 if (x<0 &&(break_bool!=1)){
110 if (x<0 &&(break_bool!=1)){
111 output=symlink_test();
115 if (x<0 &&(break_bool!=1)){
120 if (x<0 &&(break_bool!=1)){
121 output=rename_test();
125 if (x<0 &&(break_bool!=1)){
126 scanned_dir=scan_dir();
128 output=remount_test();
129 check_dir(scanned_dir);
130 scanned_dir=NULL; //the scanned dir has been freed in check_dir.
134 //printf("resetting x\n");
135 check_function(output);
142 dir_struct * scan_dir(void)
144 struct dirent *dir_data;
145 dir_struct *dir=NULL;
146 dir=malloc(sizeof(dir_struct));
147 memset(dir, 0, sizeof(dir_struct));
151 open_dir=opendir(ROOT_PATH);
152 dir_data=readdir(open_dir);
154 dir->path_list=linked_list_add_node(HEAD,dir->path_list);
155 dir->path_list->string=malloc(strlen(dir_data->d_name)+1);
156 strcpy(dir->path_list->string,dir_data->d_name);
157 sprintf(message,"opened file: %s\n",dir->path_list->string);
158 print_message(3,message);
159 dir_data=readdir(open_dir);
162 //node_print_pointers(dir->path_list);
166 int check_dir(dir_struct *old_dir)
168 print_message(3,"scanning new dir\n");
169 dir_struct *new_dir=scan_dir();
170 node *new_list=new_dir->path_list;
171 node *old_list=old_dir->path_list;
172 int exit_loop=0,error=0;
173 print_message(3,"checking dir\n");
174 for (;old_list!= NULL;old_list=old_list->next){
175 //sprintf(message,"new_list=!NULL= %d, exit_loop !=1 = %d\n",(new_list!=NULL),(exit_loop !=1));
176 //print_message(3,message);
177 for (;(new_list!=NULL) && (exit_loop !=1);new_list=new_list->next){
178 //sprintf(message,"comparing %s and %s\n",old_list->string,new_list->string);
179 //print_message(3,message);
180 if (strcmp( new_list->string ,old_list->string)==0){
181 //files match -now compare the modes and contents of the files.
182 //and set the paths to NULL.
185 /*if (new_list->next==NULL){
186 print_message(3,"next is null\n");
191 //failed to find a matching file
192 sprintf(message,"a file has disappeared: %s\n",old_list->string);
193 print_message(3,message);
197 new_list=new_dir->path_list;
200 //now check if there are any old unmatched files
202 //free both data structs
203 delete_linked_list(old_dir->path_list);
204 delete_linked_list(new_dir->path_list);
205 new_dir->path_list=NULL;
206 old_dir->path_list=NULL;
210 print_message(3,"checking dir failed\n");
211 if (get_exit_on_error()==1){
212 print_message(3,"exiting_program\n");
218 print_message(3,"checking dir passed\n");
223 int remount_test(void)
226 print_message(3,"\nunmounting\n");
227 output=umount2("/mnt/y",1);
228 check_function(output);
229 print_message(3,"mounting\n");
230 mount("/dev/mtdblock0","/mnt/y","yaffs2",0,NULL);
231 check_function(output);
238 char string[FILE_NAME_LENGTH+strlen(ROOT_PATH)];
240 strcpy(string,ROOT_PATH);
241 strcat(string,generate_random_string(FILE_NAME_LENGTH));
242 mode = ((S_IREAD|S_IWRITE)&random_int());
243 sprintf(message,"\nmaking directory: %s, with mode %d\n",string,mode);
244 print_message(3,message);
245 output= mkdir(string,mode);
251 char string[FILE_NAME_LENGTH+strlen(ROOT_PATH)];
253 strcpy(string,ROOT_PATH);
254 strcat(string,generate_random_string(FILE_NAME_LENGTH));
256 sprintf(message,"\nremoving directory: %s\n",string);
257 print_message(3,message);
258 output= rmdir(string);
261 int symlink_test(void)
263 char string[FILE_NAME_LENGTH+strlen(ROOT_PATH)];
264 char string2[FILE_NAME_LENGTH+strlen(ROOT_PATH)];
266 strcpy(string,ROOT_PATH);
267 strcat(string,generate_random_string(FILE_NAME_LENGTH));
268 strcpy(string2,ROOT_PATH);
269 strcat(string2,generate_random_string(FILE_NAME_LENGTH));
270 sprintf(message,"\nsymlink from: %s, to %s\n",string,string2);
271 print_message(3,message);
272 output= symlink(string,string2);
275 int rename_test(void)
277 char string[FILE_NAME_LENGTH+strlen(ROOT_PATH)];
278 char string2[FILE_NAME_LENGTH+strlen(ROOT_PATH)];
280 strcpy(string,ROOT_PATH);
281 strcat(string,generate_random_string(FILE_NAME_LENGTH));
282 strcpy(string2,ROOT_PATH);
283 strcat(string2,generate_random_string(FILE_NAME_LENGTH));
284 sprintf(message,"\nrenaming from: %s, to %s\n",string,string2);
285 print_message(3,message);
286 output= rename(string,string2);
291 char string[FILE_NAME_LENGTH+strlen(ROOT_PATH)];
292 char string2[FILE_NAME_LENGTH+strlen(ROOT_PATH)];
294 strcpy(string,ROOT_PATH);
295 strcat(string,generate_random_string(FILE_NAME_LENGTH));
296 strcpy(string2,ROOT_PATH);
297 strcat(string2,generate_random_string(FILE_NAME_LENGTH));
298 sprintf(message,"\nlink from: %s, to %s\n",string,string2);
299 print_message(3,message);
300 output= link(string,string2);
305 char string[FILE_NAME_LENGTH+strlen(ROOT_PATH)];
306 int mode=0,dev=0,output=0;
307 strcpy(string,ROOT_PATH);
308 strcat(string,generate_random_string(FILE_NAME_LENGTH));
309 mode = ((S_IREAD|S_IWRITE)&random_int());
311 sprintf(message,"\nmaking node: %s, with mode %d, dev %d\n",string,mode,dev);
312 print_message(3,message);
313 output= mknod(string,mode,dev);