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);
68 run_random_test(num_of_random_tests);
69 compare_linux_and_yaffs();
70 yaffs_unmount("yaffs2");
74 void init(int argc, char *argv[])
81 srand((unsigned)time(NULL));
83 linux_struct.type_of_test =LINUX;
84 yaffs_struct.type_of_test =YAFFS;
86 sprintf(message,"current absolute path is: %s\n",getcwd(dir,200));
87 print_message(3,message);
88 strcpy(dir,getcwd(dir,200));
91 printf("dir: %s\n",dir);
92 strcpy(linux_struct.root_path,dir);
93 strcpy(yaffs_struct.root_path,"yaffs2/test/");
97 if (strcmp(argv[x],"-h")==0){
98 printf("mirror_tests help\n");
99 printf("arguments:\n");
100 printf("\t-yaffs_path [PATH] //sets the path for yaffs.\n");
101 printf("\t-linux_path [PATH] //sets the path for linux.\n");
102 printf("\t-p [NUMBER] //sets the print level for mirror_tests.\n");
103 printf("\t-v //verbose mode everything is printed\n");
104 printf("\t-q //quiet mode nothing is printed.\n");
105 printf("\t-n [number] //sets the number of random tests to run.\n");
106 printf("\t-s [number] //seeds rand with the number\n");
107 printf("\t-t [number] //sets yaffs_trace to the number\n");
108 printf("\t-clean //removes emfile and test dir\n");
110 } else if (strcmp(argv[x],"-yaffs_path")==0){
111 strcpy(yaffs_struct.root_path, argv[x+1]);
112 } else if (strcmp(argv[x],"-linux_path")==0){
113 strcpy(linux_struct.root_path, argv[x+1]);
114 } else if (strcmp(argv[x],"-p")==0){
115 set_print_level(atoi(argv[x+1]));
116 } else if (strcmp(argv[x],"-v")==0){
118 } else if (strcmp(argv[x],"-q")==0){
120 } else if (strcmp(argv[x],"-n")==0){
121 num_of_random_tests=atoi(argv[x+1]);
122 } else if (strcmp(argv[x],"-s")==0){
123 srand(atoi(argv[x+1]));
124 } else if (strcmp(argv[x],"-t")==0){
125 yaffs_set_trace(atoi(argv[x+1]));
126 } else if (strcmp(argv[x],"-clean")==0){
133 print_message(2,"\nmounting yaffs\n");
134 x=yaffs_mount("yaffs2");
136 print_message(3,"failed to mount yaffs\n");
139 print_message(3,"mounted yaffs\n");
143 print_message(3,"\nmaking linux test dir\n");
144 x=mkdir(linux_struct.root_path,0777);
146 print_message(1,"failed to make dir\n");
149 print_message(3,"made dir\n");
152 print_message(3,"\nmaking yaffs test dir\n");
153 x=yaffs_mkdir(yaffs_struct.root_path,0777);
155 print_message(1,"failed to make dir\n");
158 print_message(3,"made dir\n");
162 int run_random_test(int num_of_random_tests)
168 int num_of_tests_before_check=10;
170 arg_temp args_struct;
171 for (y=0;(y*num_of_tests_before_check)<num_of_random_tests;y++){
172 for (x=0;x<num_of_tests_before_check && (x+(y*num_of_tests_before_check)<num_of_random_tests);x++) {
175 test_id = select_test_id(yaffs_tests.num_of_tests);
176 sprintf(message,"running test_id %d\n",test_id);
177 print_message(3,message);
178 generate_random_numbers(&args_struct);
179 run_yaffs_test(test_id, &args_struct);
180 run_linux_test(test_id, &args_struct);
181 if ((abs(yaffs_get_error())!=abs(errno)) &&
182 (abs(yaffs_get_error())!=EISDIR && abs(errno) != 0) &&
183 (abs(yaffs_get_error())!=ENOENT && abs(errno) != EACCES)
185 print_message(2,"\ndifference in returned errors######################################\n");
188 if (get_exit_on_error()){
193 compare_linux_and_yaffs();
197 int select_test_id(int test_len)
200 //printf("test_len = %d\n",test_len);
201 id=(rand() % test_len );
202 //printf("id %d\n",id);
207 int compare_linux_and_yaffs(void)
211 int number_of_files_in_yaffs=0;
212 int number_of_files_in_linux=0;
215 yaffs_DIR *yaffs_open_dir;
216 yaffs_dirent *yaffs_current_file;
219 struct dirent *linux_current_file;
221 print_message(2,"\n\n comparing folders\n");
224 yaffs_open_dir = yaffs_opendir(yaffs_struct.root_path);
225 if (yaffs_open_dir) {
226 for (x=0;NULL!=yaffs_readdir(yaffs_open_dir);x++){}
227 number_of_files_in_yaffs=x;
228 sprintf(message,"number of files in yaffs dir= %d\n",number_of_files_in_yaffs);
229 print_message(2,message);
230 yaffs_rewinddir(yaffs_open_dir);
232 print_message(3,"failed to open yaffs test dir\n");
234 char yaffs_file_list[x][200];
239 for (x=0 ;NULL!=yaffs_current_file;x++)
241 yaffs_current_file =yaffs_readdir(yaffs_open_dir);
242 if (NULL!=yaffs_current_file){
243 strcpy(yaffs_file_list[x],yaffs_current_file->d_name);
246 yaffs_closedir(yaffs_open_dir);
248 print_message(3,"failed to populate yaffs test list\n");
251 linux_open_dir = opendir(linux_struct.root_path);
253 for (x=0;NULL!=readdir(linux_open_dir);x++){}
254 number_of_files_in_linux=x-2;
255 sprintf(message,"number of files in linux dir= %d\n",(number_of_files_in_linux));
256 print_message(2,message);
257 //the -2 is because linux shows 2 extra files which are automaticly created.
259 rewinddir(linux_open_dir);
261 print_message(3,"failed to open linux test dir\n");
263 char linux_file_list[x-2][200];
265 for (x=0, y=0 ;NULL!=linux_current_file;x++)
267 linux_current_file =readdir(linux_open_dir);
268 if (NULL!=linux_current_file){
269 strcpy(message,linux_current_file->d_name);
270 print_message(3,"opened file: ");
271 print_message(3,message);
272 print_message(3,"\n");
274 if (NULL!=linux_current_file &&
275 0!=strcmp(message,".")&&
276 0!=strcmp(message,"..")){
277 // strcpy(message,linux_current_file->d_name);
278 //sprintf("file opened: %s\n",linux_current_file->d_name);
279 //print_message(3,message);
280 print_message(3,"added file to list\n");
281 strcpy(linux_file_list[y],message);
283 sprintf(message,"file added to list: %s\n",linux_file_list[x]);
284 print_message(3,message);
287 closedir(linux_open_dir);
289 print_message(3,"failed to populate linux test dir\n");
294 for (x=0;x<number_of_files_in_yaffs;x++){
295 sprintf(message,"searching for yaffs file: %s\n",yaffs_file_list[x]);
296 print_message(3,message);
297 for (y=0;y<number_of_files_in_linux;y++){
298 sprintf(message,"comparing to linux file: %s\n",linux_file_list[x]);
299 print_message(3,message);
301 if (0==strcmp(yaffs_file_list[x],linux_file_list[y])){
302 sprintf(message,"file matched: %s\n",linux_file_list[y]);
303 print_message(3,message);
304 linux_file_list[y][0]=NULL;
305 yaffs_file_list[x][0]=NULL;
311 //print remaining files
312 for (x=0;x<number_of_files_in_linux;x++){
313 if (linux_file_list[x][0]!=NULL){
314 sprintf(message,"unmatched file in linux: %s\n",linux_file_list[x]);
315 print_message(2,message);
319 for (x=0;x<number_of_files_in_yaffs;x++){
320 if (yaffs_file_list[x][0]!=NULL){
321 sprintf(message,"unmatched file in yaffs: %s\n",yaffs_file_list[x]);
322 print_message(2,message);
327 print_message(2,"exiting program\n");
331 //printf("file_name %s\n", yaffs_current_file->d_name);
332 // generate_array_of_objects_in_yaffs();
333 // generate_array_of_objects_in_linux();
334 //first do a check to see if both sides have the same objects on both sides.
335 //then stat all of the files and compare size and mode
336 //read the text of each file and compare them.
338 //show the diffrences by printing them.
342 void generate_random_numbers(arg_temp *args_struct)
345 args_struct->char1= (rand() % 255);
346 args_struct->char2= (rand() % 255);
347 args_struct->int1= (rand() % 100000);
348 args_struct->int2= (rand() % 100000);
349 generate_random_string(string,50);
350 strcpy(args_struct->string1, string);
351 generate_random_string(string,50);
352 strcpy(args_struct->string2, string);
355 void run_yaffs_test(int id,arg_temp *args_struct)
359 print_message(3,"\n");
360 //printf("id = %d\n",id);
361 sprintf(message,"running_test %s\n",yaffs_tests.test_list[id].test_name);
362 print_message(3,message);
363 output=yaffs_tests.test_list[id].test_pointer(args_struct);
365 sprintf(message,"test_failed %s\n",yaffs_tests.test_list[id].test_name);
366 print_message(3,message);
368 print_message(3,"test_passed\n");
372 void run_linux_test(int id,arg_temp *args_struct)
376 print_message(3,"\n");
377 //printf("id = %d\n",id);
378 sprintf(message,"running_test %s\n",linux_tests.test_list[id].test_name);
379 print_message(3,message);
380 output=linux_tests.test_list[id].test_pointer(args_struct);
382 sprintf(message,"test_failed %s\n",linux_tests.test_list[id].test_name);
383 print_message(3,message);
385 print_message(3,"test_passed\n");
389 void get_error_yaffs(void)
395 error_code=yaffs_get_error();
396 sprintf(message,"yaffs_error code %d\n",error_code);
397 print_message(1,message);
398 sprintf(message,"error is : %s\n",yaffs_error_to_str(error_code));
399 print_message(1,message);
402 void get_error_linux(void)
409 sprintf(message,"linux_error code %d\n",error_code);
410 print_message(1,message);
411 strcpy(message,"error code");
412 sprintf(message,"error is : %s\n",yaffs_error_to_str(error_code));
414 print_message(1,message);
423 struct dirent *linux_current_file;
427 strcat(string,"/emfile-2k-0");
428 sprintf(message,"\n\nunlinking emfile at this path: %s\n",string);
429 print_message(3,message);
433 linux_open_dir = opendir(linux_struct.root_path);
435 for (x=0 ;NULL!=linux_current_file ;x++)
437 linux_current_file =readdir(linux_open_dir);
438 if (NULL!=linux_current_file){
440 strcpy(file,linux_struct.root_path);
441 strcat(file,linux_current_file->d_name);
442 sprintf(message,"unlinking file %d\n",linux_current_file->d_name);
443 print_message(3,message);
447 closedir(linux_open_dir);
448 rmdir(linux_struct.root_path);