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);
153 sprintf(message,"failed to find the directory: %s",ROOT_PATH);
154 print_message(1,message);
156 dir_data=readdir(open_dir);
158 dir->path_list=linked_list_add_node(HEAD,dir->path_list);
159 dir->path_list->string=malloc(strlen(dir_data->d_name)+1);
160 strcpy(dir->path_list->string,dir_data->d_name);
161 sprintf(message,"opened file: %s\n",dir->path_list->string);
162 print_message(5,message);
163 dir_data=readdir(open_dir);
166 //node_print_pointers(dir->path_list);
170 int check_dir(dir_struct *old_dir)
172 print_message(3,"scanning new dir\n");
173 dir_struct *new_dir=scan_dir();
174 node *new_list=new_dir->path_list;
175 node *old_list=old_dir->path_list;
176 int exit_loop=0,error=0;
177 print_message(3,"checking dir\n");
178 for (;old_list!= NULL;old_list=old_list->next){
179 //sprintf(message,"new_list=!NULL= %d, exit_loop !=1 = %d\n",(new_list!=NULL),(exit_loop !=1));
180 //print_message(3,message);
181 for (;(new_list!=NULL) && (exit_loop !=1);new_list=new_list->next){
182 //sprintf(message,"comparing %s and %s\n",old_list->string,new_list->string);
183 //print_message(3,message);
184 if (strcmp( new_list->string ,old_list->string)==0){
185 //files match -now compare the modes and contents of the files.
186 //and set the paths to NULL.
189 /*if (new_list->next==NULL){
190 print_message(3,"next is null\n");
195 //failed to find a matching file
196 sprintf(message,"a file has disappeared: %s\n",old_list->string);
197 print_message(3,message);
201 new_list=new_dir->path_list;
204 //now check if there are any old unmatched files
206 //free both data structs
207 delete_linked_list(old_dir->path_list);
208 delete_linked_list(new_dir->path_list);
209 new_dir->path_list=NULL;
210 old_dir->path_list=NULL;
214 print_message(3,"checking dir failed\n");
215 if (get_exit_on_error()==1){
216 print_message(3,"exiting_program\n");
222 print_message(3,"checking dir passed\n");
227 int remount_test(void)
230 print_message(3,"\nunmounting\n");
231 output=umount2("/mnt/y",1);
232 check_function(output);
233 print_message(3,"mounting\n");
234 mount("/dev/mtdblock0","/mnt/y","yaffs2",0,NULL);
235 check_function(output);
242 char string[FILE_NAME_LENGTH+strlen(ROOT_PATH)];
244 strcpy(string,ROOT_PATH);
245 strcat(string,generate_random_string(FILE_NAME_LENGTH));
246 mode = ((S_IREAD|S_IWRITE)&random_int());
247 sprintf(message,"\nmaking directory: %s, with mode %d\n",string,mode);
248 print_message(3,message);
249 output= mkdir(string,mode);
255 char string[FILE_NAME_LENGTH+strlen(ROOT_PATH)];
257 strcpy(string,ROOT_PATH);
258 strcat(string,generate_random_string(FILE_NAME_LENGTH));
260 sprintf(message,"\nremoving directory: %s\n",string);
261 print_message(3,message);
262 output= rmdir(string);
265 int symlink_test(void)
267 char string[FILE_NAME_LENGTH+strlen(ROOT_PATH)];
268 char string2[FILE_NAME_LENGTH+strlen(ROOT_PATH)];
270 strcpy(string,ROOT_PATH);
271 strcat(string,generate_random_string(FILE_NAME_LENGTH));
272 strcpy(string2,ROOT_PATH);
273 strcat(string2,generate_random_string(FILE_NAME_LENGTH));
274 sprintf(message,"\nsymlink from: %s, to %s\n",string,string2);
275 print_message(3,message);
276 output= symlink(string,string2);
279 int rename_test(void)
281 char string[FILE_NAME_LENGTH+strlen(ROOT_PATH)];
282 char string2[FILE_NAME_LENGTH+strlen(ROOT_PATH)];
284 strcpy(string,ROOT_PATH);
285 strcat(string,generate_random_string(FILE_NAME_LENGTH));
286 strcpy(string2,ROOT_PATH);
287 strcat(string2,generate_random_string(FILE_NAME_LENGTH));
288 sprintf(message,"\nrenaming from: %s, to %s\n",string,string2);
289 print_message(3,message);
290 output= rename(string,string2);
295 char string[FILE_NAME_LENGTH+strlen(ROOT_PATH)];
296 char string2[FILE_NAME_LENGTH+strlen(ROOT_PATH)];
298 strcpy(string,ROOT_PATH);
299 strcat(string,generate_random_string(FILE_NAME_LENGTH));
300 strcpy(string2,ROOT_PATH);
301 strcat(string2,generate_random_string(FILE_NAME_LENGTH));
302 sprintf(message,"\nlink from: %s, to %s\n",string,string2);
303 print_message(3,message);
304 output= link(string,string2);
309 char string[FILE_NAME_LENGTH+strlen(ROOT_PATH)];
310 int mode=0,dev=0,output=0;
311 strcpy(string,ROOT_PATH);
312 strcat(string,generate_random_string(FILE_NAME_LENGTH));
313 mode = ((S_IREAD|S_IWRITE)&random_int());
315 sprintf(message,"\nmaking node: %s, with mode %d, dev %d\n",string,mode,dev);
316 print_message(3,message);
317 output= mknod(string,mode,dev);