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 "mirror_tests.h"
17 int simulate_power_failure = 0;
19 int num_of_random_tests=1;
23 typedef struct test_list_temp2{
25 int (*test_pointer)(arg_temp *args_struct);
28 typedef struct test_temp2 {
30 test_list_temp test_list[];
33 test_temp yaffs_tests={
35 {{"yaffs_test_open",yaffs_test_open},
36 {"yaffs_test_truncate",yaffs_test_truncate},
37 {"yaffs_test_unlink",yaffs_test_unlink}
41 test_temp linux_tests={
43 {{"linux_test_open",linux_test_open},
44 {"linux_test_truncate",linux_test_truncate},
45 {"linux_test_unlink",linux_test_unlink}
50 int main(int argc, char *argv[])
54 // yaffs_tests.num_of_tests=(sizeof(yaffs_tests)/sizeof(test_temp));
55 // linux_tests.num_of_tests=(sizeof(linux_tests)/sizeof(test_temp));
58 print_message(1,"running mirror_tests\n");
59 sprintf(message,"linux_root_path: %s\n",linux_struct.root_path);
60 print_message(3,message);
61 sprintf(message,"yaffs_root_path: %s\n",yaffs_struct.root_path);
62 print_message(3,message);
63 sprintf(message,"linux_num_of_tests: %d\n",linux_tests.num_of_tests);
64 print_message(3,message);
65 sprintf(message,"yaffs_num_of_tests: %d\n",yaffs_tests.num_of_tests);
66 print_message(3,message);
67 for (x=0;x<num_of_random_tests;x++){
70 compare_linux_and_yaffs();
71 yaffs_unmount("yaffs2");
75 void init(int argc, char *argv[])
82 srand((unsigned)time(NULL));
84 linux_struct.type_of_test =LINUX;
85 yaffs_struct.type_of_test =YAFFS;
87 sprintf(message,"current absolute path is: %s\n",getcwd(dir,200));
88 print_message(3,message);
89 strcpy(dir,getcwd(dir,200));
92 printf("dir: %s\n",dir);
93 strcpy(linux_struct.root_path,dir);
94 strcpy(yaffs_struct.root_path,"yaffs2/test/");
98 if (strcmp(argv[x],"-h")==0){
99 printf("mirror_tests help\n");
100 printf("arguments:\n");
101 printf("\t-yaffs_path [PATH] //sets the path for yaffs.\n");
102 printf("\t-linux_path [PATH] //sets the path for linux.\n");
103 printf("\t-p [NUMBER] //sets the print level for mirror_tests.\n");
104 printf("\t-v //verbose mode everything is printed\n");
105 printf("\t-q //quiet mode nothing is printed.\n");
106 printf("\t-n [number] //sets the number of random tests to run.\n");
107 printf("\t-s [number] //seeds rand with the number\n");
108 printf("\t-t [number] //sets yaffs_trace to the number\n");
109 printf("\t-c //removes emfile and test dir\n");
111 } else if (strcmp(argv[x],"-yaffs_path")==0){
112 strcpy(yaffs_struct.root_path, argv[x+1]);
113 } else if (strcmp(argv[x],"-linux_path")==0){
114 strcpy(linux_struct.root_path, argv[x+1]);
115 } else if (strcmp(argv[x],"-p")==0){
116 set_print_level(atoi(argv[x+1]));
117 } else if (strcmp(argv[x],"-v")==0){
119 } else if (strcmp(argv[x],"-q")==0){
121 } else if (strcmp(argv[x],"-n")==0){
122 num_of_random_tests=atoi(argv[x+1]);
123 } else if (strcmp(argv[x],"-s")==0){
124 srand(atoi(argv[x+1]));
125 } else if (strcmp(argv[x],"-t")==0){
126 yaffs_set_trace(atoi(argv[x+1]));
127 } else if (strcmp(argv[x],"-c")==0){
134 print_message(2,"\nmounting yaffs\n");
135 x=yaffs_mount("yaffs2");
137 print_message(3,"failed to mount yaffs\n");
140 print_message(3,"mounted yaffs\n");
144 print_message(3,"\nmaking linux test dir\n");
145 x=mkdir(linux_struct.root_path,0777);
147 print_message(1,"failed to make dir\n");
150 print_message(3,"made dir\n");
153 print_message(3,"\nmaking yaffs test dir\n");
154 x=yaffs_mkdir(yaffs_struct.root_path,0777);
156 print_message(1,"failed to make dir\n");
159 print_message(3,"made dir\n");
163 int run_random_test(void)
170 arg_temp args_struct;
171 for (x=0;x<num_of_tests;x++) {
174 test_id = select_test_id(yaffs_tests.num_of_tests);
175 sprintf(message,"running test_id %d\n",test_id);
176 print_message(3,message);
177 generate_random_numbers(&args_struct);
178 run_yaffs_test(test_id, &args_struct);
179 run_linux_test(test_id, &args_struct);
180 if ((abs(yaffs_get_error())!=abs(errno)) &&
181 (abs(yaffs_get_error())!=EISDIR && abs(errno) != 0) &&
182 (abs(yaffs_get_error())!=ENOENT && abs(errno) != EACCES)
184 print_message(2,"\ndifference in returned errors######################################\n");
187 if (get_exit_on_error()){
192 compare_linux_and_yaffs();
195 int select_test_id(int test_len)
198 //printf("test_len = %d\n",test_len);
199 id=(rand() % test_len );
200 //printf("id %d\n",id);
205 int compare_linux_and_yaffs(void)
208 yaffs_DIR *yaffs_open_dir;
209 yaffs_dirent *yaffs_current_file;
212 struct dirent *linux_current_file;
214 yaffs_open_dir = yaffs_opendir(yaffs_struct.root_path);
216 for (x=0;NULL!=yaffs_readdir(yaffs_open_dir);x++){};
217 printf("number of files in yaffs dir= %d\n",x);
219 char yaffs_file_list[x][100];
220 yaffs_rewinddir(yaffs_open_dir);
222 for (x=0 ;NULL!=yaffs_current_file;x++)
224 yaffs_current_file =yaffs_readdir(yaffs_open_dir);
225 if (NULL!=yaffs_current_file){
226 strcpy(yaffs_file_list[x],yaffs_current_file->d_name);
230 linux_open_dir = opendir(linux_struct.root_path);
232 for (x=0;NULL!=readdir(linux_open_dir);x++){};
233 printf("number of files in linux dir= %d\n",(x-2)); //the -2 is because linux shows 2 extra files which are automaticly created.
235 //printf("file_name %s\n", yaffs_current_file->d_name);
236 // generate_array_of_objects_in_yaffs();
237 // generate_array_of_objects_in_linux();
238 //first do a check to see if both sides have the same objects on both sides.
239 //then stat all of the files and compare size and mode
240 //read the text of each file and compare them.
242 //show the diffrences by printing them.
246 void generate_random_numbers(arg_temp *args_struct)
249 args_struct->char1= (rand() % 255);
250 args_struct->char2= (rand() % 255);
251 args_struct->int1= (rand() % 100000);
252 args_struct->int2= (rand() % 100000);
253 generate_random_string(string,50);
254 strcpy(args_struct->string1, string);
255 generate_random_string(string,50);
256 strcpy(args_struct->string2, string);
259 void run_yaffs_test(int id,arg_temp *args_struct)
263 print_message(3,"\n");
264 //printf("id = %d\n",id);
265 sprintf(message,"running_test %s\n",yaffs_tests.test_list[id].test_name);
266 print_message(3,message);
267 output=yaffs_tests.test_list[id].test_pointer(args_struct);
269 sprintf(message,"test_failed %s\n",yaffs_tests.test_list[id].test_name);
270 print_message(3,message);
272 print_message(3,"test_passed\n");
276 void run_linux_test(int id,arg_temp *args_struct)
280 print_message(3,"\n");
281 //printf("id = %d\n",id);
282 sprintf(message,"running_test %s\n",linux_tests.test_list[id].test_name);
283 print_message(3,message);
284 output=linux_tests.test_list[id].test_pointer(args_struct);
286 sprintf(message,"test_failed %s\n",linux_tests.test_list[id].test_name);
287 print_message(3,message);
289 print_message(3,"test_passed\n");
293 void get_error_yaffs(void)
299 error_code=yaffs_get_error();
300 sprintf(message,"yaffs_error code %d\n",error_code);
301 print_message(1,message);
302 sprintf(message,"error is : %s\n",yaffs_error_to_str(error_code));
303 print_message(1,message);
306 void get_error_linux(void)
313 sprintf(message,"linux_error code %d\n",error_code);
314 print_message(1,message);
315 strcpy(message,"error code");
316 sprintf(message,"error is : %s\n",yaffs_error_to_str(error_code));
318 print_message(1,message);
327 struct dirent *linux_current_file;
331 strcat(string,"/emfile-2k-0");
332 sprintf(message,"\n\nunlinking emfile at this path: %s\n",string);
333 print_message(3,message);
337 linux_open_dir = opendir(linux_struct.root_path);
339 for (x=0 ;NULL!=linux_current_file ;x++)
341 linux_current_file =readdir(linux_open_dir);
342 if (NULL!=linux_current_file){
344 strcpy(file,linux_struct.root_path);
345 strcat(file,linux_current_file->d_name);
346 sprintf(message,"unlinking file %d\n",linux_current_file->d_name);
347 print_message(3,message);
351 unlink(linux_struct.root_path);