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++) {
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)
210 yaffs_DIR *yaffs_open_dir;
211 yaffs_dirent *yaffs_current_file;
214 struct dirent *linux_current_file;
216 yaffs_open_dir = yaffs_opendir(yaffs_struct.root_path);
217 if (yaffs_open_dir) {
218 for (x=0;NULL!=yaffs_readdir(yaffs_open_dir);x++){}
219 printf("number of files in yaffs dir= %d\n",x);
221 char yaffs_file_list[x][100];
222 yaffs_rewinddir(yaffs_open_dir);
224 for (x=0 ;NULL!=yaffs_current_file;x++)
226 yaffs_current_file =yaffs_readdir(yaffs_open_dir);
227 if (NULL!=yaffs_current_file){
228 strcpy(yaffs_file_list[x],yaffs_current_file->d_name);
231 yaffs_closedir(yaffs_open_dir);
234 linux_open_dir = opendir(linux_struct.root_path);
236 for (x=0;NULL!=readdir(linux_open_dir);x++){}
237 printf("number of files in linux dir= %d\n",(x-2));
238 //the -2 is because linux shows 2 extra files which are automaticly created.
240 char linux_file_list[x][100];
242 for (x=0 ;NULL!=linux_current_file;x++)
244 linux_current_file =readdir(linux_open_dir);
245 if (NULL!=linux_current_file){
246 strcpy(linux_file_list[x],linux_current_file->d_name);
249 closedir(linux_open_dir);
256 //printf("file_name %s\n", yaffs_current_file->d_name);
257 // generate_array_of_objects_in_yaffs();
258 // generate_array_of_objects_in_linux();
259 //first do a check to see if both sides have the same objects on both sides.
260 //then stat all of the files and compare size and mode
261 //read the text of each file and compare them.
263 //show the diffrences by printing them.
267 void generate_random_numbers(arg_temp *args_struct)
270 args_struct->char1= (rand() % 255);
271 args_struct->char2= (rand() % 255);
272 args_struct->int1= (rand() % 100000);
273 args_struct->int2= (rand() % 100000);
274 generate_random_string(string,50);
275 strcpy(args_struct->string1, string);
276 generate_random_string(string,50);
277 strcpy(args_struct->string2, string);
280 void run_yaffs_test(int id,arg_temp *args_struct)
284 print_message(3,"\n");
285 //printf("id = %d\n",id);
286 sprintf(message,"running_test %s\n",yaffs_tests.test_list[id].test_name);
287 print_message(3,message);
288 output=yaffs_tests.test_list[id].test_pointer(args_struct);
290 sprintf(message,"test_failed %s\n",yaffs_tests.test_list[id].test_name);
291 print_message(3,message);
293 print_message(3,"test_passed\n");
297 void run_linux_test(int id,arg_temp *args_struct)
301 print_message(3,"\n");
302 //printf("id = %d\n",id);
303 sprintf(message,"running_test %s\n",linux_tests.test_list[id].test_name);
304 print_message(3,message);
305 output=linux_tests.test_list[id].test_pointer(args_struct);
307 sprintf(message,"test_failed %s\n",linux_tests.test_list[id].test_name);
308 print_message(3,message);
310 print_message(3,"test_passed\n");
314 void get_error_yaffs(void)
320 error_code=yaffs_get_error();
321 sprintf(message,"yaffs_error code %d\n",error_code);
322 print_message(1,message);
323 sprintf(message,"error is : %s\n",yaffs_error_to_str(error_code));
324 print_message(1,message);
327 void get_error_linux(void)
334 sprintf(message,"linux_error code %d\n",error_code);
335 print_message(1,message);
336 strcpy(message,"error code");
337 sprintf(message,"error is : %s\n",yaffs_error_to_str(error_code));
339 print_message(1,message);
348 struct dirent *linux_current_file;
352 strcat(string,"/emfile-2k-0");
353 sprintf(message,"\n\nunlinking emfile at this path: %s\n",string);
354 print_message(3,message);
358 linux_open_dir = opendir(linux_struct.root_path);
360 for (x=0 ;NULL!=linux_current_file ;x++)
362 linux_current_file =readdir(linux_open_dir);
363 if (NULL!=linux_current_file){
365 strcpy(file,linux_struct.root_path);
366 strcat(file,linux_current_file->d_name);
367 sprintf(message,"unlinking file %d\n",linux_current_file->d_name);
368 print_message(3,message);
372 closedir(linux_open_dir);
373 rmdir(linux_struct.root_path);