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},
38 {"yaffs_test_write",yaffs_test_write}
42 test_temp linux_tests={
44 {{"linux_test_open",linux_test_open},
45 {"linux_test_truncate",linux_test_truncate},
46 {"linux_test_unlink",linux_test_unlink},
47 {"linux_test_write",linux_test_write}
52 int main(int argc, char *argv[])
56 // yaffs_tests.num_of_tests=(sizeof(yaffs_tests)/sizeof(test_temp));
57 // linux_tests.num_of_tests=(sizeof(linux_tests)/sizeof(test_temp));
60 print_message(1,"running mirror_tests\n");
61 sprintf(message,"linux_root_path: %s\n",linux_struct.root_path);
62 print_message(3,message);
63 sprintf(message,"yaffs_root_path: %s\n",yaffs_struct.root_path);
64 print_message(3,message);
65 sprintf(message,"linux_num_of_tests: %d\n",linux_tests.num_of_tests);
66 print_message(3,message);
67 sprintf(message,"yaffs_num_of_tests: %d\n",yaffs_tests.num_of_tests);
68 print_message(3,message);
70 run_random_test(num_of_random_tests);
71 compare_linux_and_yaffs();
72 yaffs_unmount("yaffs2");
76 void init(int argc, char *argv[])
83 srand((unsigned)time(NULL));
85 linux_struct.type_of_test =LINUX;
86 yaffs_struct.type_of_test =YAFFS;
88 sprintf(message,"current absolute path is: %s\n",getcwd(dir,200));
89 print_message(3,message);
90 strcpy(dir,getcwd(dir,200));
93 printf("dir: %s\n",dir);
94 strcpy(linux_struct.root_path,dir);
95 strcpy(yaffs_struct.root_path,"yaffs2/test/");
99 if (strcmp(argv[x],"-h")==0){
100 printf("mirror_tests help\n");
101 printf("arguments:\n");
102 printf("\t-yaffs_path [PATH] //sets the path for yaffs.\n");
103 printf("\t-linux_path [PATH] //sets the path for linux.\n");
104 printf("\t-p [NUMBER] //sets the print level for mirror_tests.\n");
105 printf("\t-v //verbose mode everything is printed\n");
106 printf("\t-q //quiet mode nothing is printed.\n");
107 printf("\t-n [number] //sets the number of random tests to run.\n");
108 printf("\t-s [number] //seeds rand with the number\n");
109 printf("\t-t [number] //sets yaffs_trace to the number\n");
110 printf("\t-clean //removes emfile and test dir\n");
112 } else if (strcmp(argv[x],"-yaffs_path")==0){
113 strcpy(yaffs_struct.root_path, argv[x+1]);
114 } else if (strcmp(argv[x],"-linux_path")==0){
115 strcpy(linux_struct.root_path, argv[x+1]);
116 } else if (strcmp(argv[x],"-p")==0){
117 set_print_level(atoi(argv[x+1]));
118 } else if (strcmp(argv[x],"-v")==0){
120 } else if (strcmp(argv[x],"-q")==0){
122 } else if (strcmp(argv[x],"-n")==0){
123 num_of_random_tests=atoi(argv[x+1]);
124 } else if (strcmp(argv[x],"-s")==0){
125 srand(atoi(argv[x+1]));
126 } else if (strcmp(argv[x],"-t")==0){
127 yaffs_set_trace(atoi(argv[x+1]));
128 } else if (strcmp(argv[x],"-clean")==0){
135 print_message(2,"\nmounting yaffs\n");
136 x=yaffs_mount("yaffs2");
138 print_message(3,"failed to mount yaffs\n");
141 print_message(3,"mounted yaffs\n");
145 print_message(3,"\nmaking linux test dir\n");
146 x=mkdir(linux_struct.root_path,0777);
148 print_message(1,"failed to make dir\n");
151 print_message(3,"made dir\n");
154 print_message(3,"\nmaking yaffs test dir\n");
155 x=yaffs_mkdir(yaffs_struct.root_path,0777);
157 print_message(1,"failed to make dir\n");
160 print_message(3,"made dir\n");
164 int run_random_test(int num_of_random_tests)
170 int num_of_tests_before_check=1;
172 arg_temp args_struct;
173 for (y=0;(y*num_of_tests_before_check)<num_of_random_tests;y++){
174 for (x=0;x<num_of_tests_before_check && (x+(y*num_of_tests_before_check)<num_of_random_tests);x++) {
177 test_id = select_test_id(yaffs_tests.num_of_tests);
178 sprintf(message,"running test_id %d\n",test_id);
179 print_message(3,message);
180 generate_random_numbers(&args_struct);
181 run_yaffs_test(test_id, &args_struct);
182 run_linux_test(test_id, &args_struct);
183 if (get_print_level()>=4){
187 if ((abs(yaffs_get_error())!=abs(errno)) &&
188 (abs(yaffs_get_error())!=EISDIR && abs(errno) != 0) &&
189 (abs(yaffs_get_error())!=ENOENT && abs(errno) != EACCES)&&
190 (abs(yaffs_get_error())!=EINVAL && abs(errno) != EBADF)
192 print_message(2,"\ndifference in returned errors######################################\n");
195 if (get_exit_on_error()){
200 compare_linux_and_yaffs();
204 int select_test_id(int test_len)
207 //printf("test_len = %d\n",test_len);
208 id=(rand() % test_len );
209 //printf("id %d\n",id);
214 int compare_linux_and_yaffs(void)
218 int number_of_files_in_yaffs=0;
219 int number_of_files_in_linux=0;
222 yaffs_DIR *yaffs_open_dir;
223 yaffs_dirent *yaffs_current_file;
226 struct dirent *linux_current_file;
228 print_message(2,"\n\n comparing folders\n");
231 yaffs_open_dir = yaffs_opendir(yaffs_struct.root_path);
232 if (yaffs_open_dir) {
233 for (x=0;NULL!=yaffs_readdir(yaffs_open_dir);x++){}
234 number_of_files_in_yaffs=x;
235 sprintf(message,"number of files in yaffs dir= %d\n",number_of_files_in_yaffs);
236 print_message(2,message);
237 yaffs_rewinddir(yaffs_open_dir);
239 print_message(3,"failed to open yaffs test dir\n");
241 char yaffs_file_list[x][200];
246 for (x=0 ;NULL!=yaffs_current_file;x++)
248 yaffs_current_file =yaffs_readdir(yaffs_open_dir);
249 if (NULL!=yaffs_current_file){
250 strcpy(yaffs_file_list[x],yaffs_current_file->d_name);
253 yaffs_closedir(yaffs_open_dir);
255 print_message(3,"failed to populate yaffs test list\n");
258 linux_open_dir = opendir(linux_struct.root_path);
260 for (x=0;NULL!=readdir(linux_open_dir);x++){}
261 number_of_files_in_linux=x-2;
262 sprintf(message,"number of files in linux dir= %d\n",(number_of_files_in_linux));
263 print_message(2,message);
264 //the -2 is because linux shows 2 extra files which are automaticly created.
266 rewinddir(linux_open_dir);
268 print_message(3,"failed to open linux test dir\n");
270 char linux_file_list[x-2][200];
272 for (x=0, y=0 ;NULL!=linux_current_file;x++)
274 linux_current_file =readdir(linux_open_dir);
275 if (NULL!=linux_current_file){
276 strcpy(message,linux_current_file->d_name);
277 print_message(3,"opened file: ");
278 print_message(3,message);
279 print_message(3,"\n");
281 if (NULL!=linux_current_file &&
282 0!=strcmp(message,".")&&
283 0!=strcmp(message,"..")){
284 // strcpy(message,linux_current_file->d_name);
285 //sprintf("file opened: %s\n",linux_current_file->d_name);
286 //print_message(3,message);
287 print_message(3,"added file to list\n");
288 strcpy(linux_file_list[y],message);
290 sprintf(message,"file added to list: %s\n",linux_file_list[x]);
291 print_message(3,message);
294 closedir(linux_open_dir);
296 print_message(3,"failed to populate linux test dir\n");
301 for (x=0;x<number_of_files_in_yaffs;x++){
302 sprintf(message,"searching for yaffs file: %s\n",yaffs_file_list[x]);
303 print_message(3,message);
304 for (y=0;y<number_of_files_in_linux;y++){
305 sprintf(message,"comparing to linux file: %s\n",linux_file_list[y]);
306 print_message(3,message);
308 if (0==strcmp(yaffs_file_list[x],linux_file_list[y])){
309 sprintf(message,"file matched: %s\n",linux_file_list[y]);
310 print_message(3,message);
311 linux_file_list[y][0]=NULL;
312 yaffs_file_list[x][0]=NULL;
318 //print remaining files
319 for (x=0;x<number_of_files_in_linux;x++){
320 if (linux_file_list[x][0]!=NULL){
321 sprintf(message,"unmatched file in linux: %s\n",linux_file_list[x]);
322 print_message(2,message);
326 for (x=0;x<number_of_files_in_yaffs;x++){
327 if (yaffs_file_list[x][0]!=NULL){
328 sprintf(message,"unmatched file in yaffs: %s\n",yaffs_file_list[x]);
329 print_message(2,message);
334 print_message(2,"exiting program\n");
338 //printf("file_name %s\n", yaffs_current_file->d_name);
339 // generate_array_of_objects_in_yaffs();
340 // generate_array_of_objects_in_linux();
341 //first do a check to see if both sides have the same objects on both sides.
342 //then stat all of the files and compare size and mode
343 //read the text of each file and compare them.
345 //show the diffrences by printing them.
349 void generate_random_numbers(arg_temp *args_struct)
352 args_struct->char1= (rand() % 255);
353 args_struct->char2= (rand() % 255);
354 args_struct->int1= (rand() % 100000);
355 args_struct->int2= (rand() % 100000);
356 generate_random_string(string,50);
357 strcpy(args_struct->string1, string);
358 generate_random_string(string,50);
359 strcpy(args_struct->string2, string);
362 void run_yaffs_test(int id,arg_temp *args_struct)
366 print_message(3,"\n");
367 //printf("id = %d\n",id);
368 sprintf(message,"running_test %s\n",yaffs_tests.test_list[id].test_name);
369 print_message(3,message);
370 output=yaffs_tests.test_list[id].test_pointer(args_struct);
372 sprintf(message,"test_failed %s\n",yaffs_tests.test_list[id].test_name);
373 print_message(3,message);
375 print_message(3,"test_passed\n");
379 void run_linux_test(int id,arg_temp *args_struct)
383 print_message(3,"\n");
384 //printf("id = %d\n",id);
385 sprintf(message,"running_test %s\n",linux_tests.test_list[id].test_name);
386 print_message(3,message);
387 output=linux_tests.test_list[id].test_pointer(args_struct);
389 sprintf(message,"test_failed %s\n",linux_tests.test_list[id].test_name);
390 print_message(3,message);
392 print_message(3,"test_passed\n");
396 void get_error_yaffs(void)
402 error_code=yaffs_get_error();
403 sprintf(message,"yaffs_error code %d\n",error_code);
404 print_message(1,message);
405 sprintf(message,"error is : %s\n",yaffs_error_to_str(error_code));
406 print_message(1,message);
409 void get_error_linux(void)
416 sprintf(message,"linux_error code %d\n",error_code);
417 print_message(1,message);
418 strcpy(message,"error code");
419 sprintf(message,"error is : %s\n",yaffs_error_to_str(error_code));
421 print_message(1,message);
430 struct dirent *linux_current_file;
434 strcat(string,"/emfile-2k-0");
435 sprintf(message,"\n\nunlinking emfile at this path: %s\n",string);
436 print_message(3,message);
440 linux_open_dir = opendir(linux_struct.root_path);
442 for (x=0 ;NULL!=linux_current_file ;x++)
444 linux_current_file =readdir(linux_open_dir);
445 if (NULL!=linux_current_file){
447 strcpy(file,linux_struct.root_path);
448 strcat(file,linux_current_file->d_name);
449 sprintf(message,"unlinking file %d\n",linux_current_file->d_name);
450 print_message(3,message);
454 closedir(linux_open_dir);
455 rmdir(linux_struct.root_path);