2 * YAFFS: Yet another FFS. A NAND-flash specific file system.
4 * Copyright (C) 2002-2018 Aleph One Ltd.
6 * Created by Timothy Manning <timothy@yaffs.net>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #include "linux_test.h"
16 int simulate_power_failure = 1;
18 char message[400]; //this is used for storing print messages.
22 const struct option long_options[]={
26 {"print_level", 1,NULL,'p'},
27 {"quiet", 0,NULL,'q'},
31 {"verbose", 0,NULL,'v'}
34 const char short_options[]="hp:qs:v";
37 void init(int argc, char *argv[])
45 x=(unsigned)time(NULL);
46 sprintf(message,"seeding srand with: %d\n",x);
47 print_message(2,message);
53 new_option=getopt_long(argc,argv,short_options,long_options,NULL);
55 printf("mirror_tests help\n");
56 printf("arguments:\n");
57 printf("\t-p [NUMBER] //sets the print level for mirror_tests.\n");
58 printf("\t-v //verbose mode everything is printed\n");
59 printf("\t-q //quiet mode nothing is printed.\n");
60 printf("\t-s [number] //seeds rand with the number\n");
64 } else if (new_option=='p'){
65 set_print_level(atoi(optarg));
66 } else if (new_option=='v'){
68 } else if (new_option=='q'){
70 } else if (new_option=='s'){
71 srand(atoi(argv[x+1]));
73 } else if (new_option==-1){
75 } else if (new_option=='?') {
76 printf("bad argument\n");
79 }while(new_option!=-1);
82 int main(int argc, char *argv[])
84 dir_struct *scanned_dir=NULL;
91 while (break_bool!=1){
94 if (x<0 &&(break_bool!=1)){
99 if (x<0 &&(break_bool!=1)){
104 if (x<0 &&(break_bool!=1)){
109 if (x<0 &&(break_bool!=1)){
110 output=symlink_test();
114 if (x<0 &&(break_bool!=1)){
119 if (x<0 &&(break_bool!=1)){
120 output=rename_test();
124 if (x<0 &&(break_bool!=1)){
125 scanned_dir=scan_dir();
127 output=remount_test();
128 check_dir(scanned_dir);
129 scanned_dir=NULL; //the scanned dir has been freed in check_dir.
133 //printf("resetting x\n");
134 check_function(output);
141 dir_struct * scan_dir(void)
143 struct dirent *dir_data;
144 dir_struct *dir=NULL;
145 dir=malloc(sizeof(dir_struct));
146 memset(dir, 0, sizeof(dir_struct));
150 open_dir=opendir(ROOT_PATH);
152 sprintf(message,"failed to find the directory: %s",ROOT_PATH);
153 print_message(1,message);
155 dir_data=readdir(open_dir);
157 dir->path_list=linked_list_add_node(HEAD,dir->path_list);
158 dir->path_list->string=malloc(strlen(dir_data->d_name)+1);
159 strcpy(dir->path_list->string,dir_data->d_name);
160 sprintf(message,"opened file: %s\n",dir->path_list->string);
161 print_message(5,message);
162 dir_data=readdir(open_dir);
165 //node_print_pointers(dir->path_list);
169 int check_dir(dir_struct *old_dir)
171 print_message(3,"scanning new dir\n");
172 dir_struct *new_dir=scan_dir();
173 node *new_list=new_dir->path_list;
174 node *old_list=old_dir->path_list;
175 int exit_loop=0,error=0;
176 print_message(3,"checking dir\n");
177 for (;old_list!= NULL;old_list=old_list->next){
178 //sprintf(message,"new_list=!NULL= %d, exit_loop !=1 = %d\n",(new_list!=NULL),(exit_loop !=1));
179 //print_message(3,message);
180 for (;(new_list!=NULL) && (exit_loop !=1);new_list=new_list->next){
181 //sprintf(message,"comparing %s and %s\n",old_list->string,new_list->string);
182 //print_message(3,message);
183 if (strcmp( new_list->string ,old_list->string)==0){
184 //files match -now compare the modes and contents of the files.
185 //and set the paths to NULL.
188 /*if (new_list->next==NULL){
189 print_message(3,"next is null\n");
194 //failed to find a matching file
195 sprintf(message,"a file has disappeared: %s\n",old_list->string);
196 print_message(3,message);
200 new_list=new_dir->path_list;
203 //now check if there are any old unmatched files
205 //free both data structs
206 delete_linked_list(old_dir->path_list);
207 delete_linked_list(new_dir->path_list);
208 new_dir->path_list=NULL;
209 old_dir->path_list=NULL;
213 print_message(3,"checking dir failed\n");
214 if (get_exit_on_error()==1){
215 print_message(3,"exiting_program\n");
221 print_message(3,"checking dir passed\n");
226 int remount_test(void)
229 print_message(3,"\nunmounting\n");
230 output=umount2("/mnt/y",1);
231 check_function(output);
232 print_message(3,"mounting\n");
233 mount("/dev/mtdblock0","/mnt/y","yaffs2",0,NULL);
234 check_function(output);
241 char string[FILE_NAME_LENGTH+strlen(ROOT_PATH)];
243 strcpy(string,ROOT_PATH);
244 strcat(string,generate_random_string(FILE_NAME_LENGTH));
245 mode = ((S_IREAD|S_IWRITE)&random_int());
246 sprintf(message,"\nmaking directory: %s, with mode %d\n",string,mode);
247 print_message(3,message);
248 output= mkdir(string,mode);
254 char string[FILE_NAME_LENGTH+strlen(ROOT_PATH)];
256 strcpy(string,ROOT_PATH);
257 strcat(string,generate_random_string(FILE_NAME_LENGTH));
259 sprintf(message,"\nremoving directory: %s\n",string);
260 print_message(3,message);
261 output= rmdir(string);
264 int symlink_test(void)
266 char string[FILE_NAME_LENGTH+strlen(ROOT_PATH)];
267 char string2[FILE_NAME_LENGTH+strlen(ROOT_PATH)];
269 strcpy(string,ROOT_PATH);
270 strcat(string,generate_random_string(FILE_NAME_LENGTH));
271 strcpy(string2,ROOT_PATH);
272 strcat(string2,generate_random_string(FILE_NAME_LENGTH));
273 sprintf(message,"\nsymlink from: %s, to %s\n",string,string2);
274 print_message(3,message);
275 output= symlink(string,string2);
278 int rename_test(void)
280 char string[FILE_NAME_LENGTH+strlen(ROOT_PATH)];
281 char string2[FILE_NAME_LENGTH+strlen(ROOT_PATH)];
283 strcpy(string,ROOT_PATH);
284 strcat(string,generate_random_string(FILE_NAME_LENGTH));
285 strcpy(string2,ROOT_PATH);
286 strcat(string2,generate_random_string(FILE_NAME_LENGTH));
287 sprintf(message,"\nrenaming from: %s, to %s\n",string,string2);
288 print_message(3,message);
289 output= rename(string,string2);
294 char string[FILE_NAME_LENGTH+strlen(ROOT_PATH)];
295 char string2[FILE_NAME_LENGTH+strlen(ROOT_PATH)];
297 strcpy(string,ROOT_PATH);
298 strcat(string,generate_random_string(FILE_NAME_LENGTH));
299 strcpy(string2,ROOT_PATH);
300 strcat(string2,generate_random_string(FILE_NAME_LENGTH));
301 sprintf(message,"\nlink from: %s, to %s\n",string,string2);
302 print_message(3,message);
303 output= link(string,string2);
308 char string[FILE_NAME_LENGTH+strlen(ROOT_PATH)];
309 int mode=0,dev=0,output=0;
310 strcpy(string,ROOT_PATH);
311 strcat(string,generate_random_string(FILE_NAME_LENGTH));
312 mode = ((S_IREAD|S_IWRITE)&random_int());
314 sprintf(message,"\nmaking node: %s, with mode %d, dev %d\n",string,mode,dev);
315 print_message(3,message);
316 output= mknod(string,mode,dev);