yaffs Working on timothy_tests and have updated yaffs_importer.py
[yaffs2.git] / direct / timothy_tests / yaffs_tester.c
1 /*yaffs_tester.c*/
2
3 #include "yaffs_tester.h"
4
5
6
7 int random_seed;
8 int simulate_power_failure = 0;
9
10
11 buffer message_buffer;  /*create  message_buffer */
12
13
14
15 int main(){     
16         char yaffs_test_dir[] ="/yaffs2/test_dir";      /*the path to the directory where all of the testing will take place*/
17         char yaffs_mount_dir[]="/yaffs2/";              /*the path to the mount point which yaffs will mount*/
18         
19         init(yaffs_test_dir,yaffs_mount_dir);
20         test(yaffs_test_dir);
21         yaffs_unmount(yaffs_mount_dir);
22         return 0;
23 }
24
25
26 void init(char *yaffs_test_dir,char *yaffs_mount_dir){
27         /*these variables are already set to zero, but it is better not to take chances*/
28         message_buffer.head=0;                           
29         message_buffer.tail=0;
30         
31         add_to_buffer(&message_buffer,"welcome to the yaffs tester",MESSAGE_LEVEL_BASIC_TASKS);/* print boot up message*/       
32         yaffs_start_up();
33         yaffs_mount(yaffs_mount_dir);
34
35         if (yaffs_access(yaffs_test_dir,0))
36         {
37                 yaffs_mkdir(yaffs_test_dir,S_IREAD | S_IWRITE);
38         }
39         
40 }
41 void join_paths(char *path1,char *path2,char *new_path ){
42
43 /*      printf("strlen path1:%d\n",strlen(path1));
44         printf("strlen path2:%d\n",strlen(path2));
45         printf("path1; %s\n",path1);
46 */
47         //add_to_buffer(&message_buffer, "joining paths\0",MESSAGE_LEVEL_BASIC_TASKS);
48         add_to_buffer(&message_buffer,path1,MESSAGE_LEVEL_BASIC_TASKS);
49         add_to_buffer(&message_buffer, path2,MESSAGE_LEVEL_BASIC_TASKS);
50         if ( (path1[(sizeof(path1)/sizeof(char))-2]=='/') && path2[0]!='/') {
51                 /*paths are compatiable. concatanate them. note -2 is because of \0*/  
52                 strcat(new_path,path1);
53                 strcat(new_path,path2);         
54                 //char new_path[(sizeof(path1)/sizeof(char))+(sizeof(path2)/sizeof(char))];
55                 //strcpy(new_path,strcat(path1,path2)); 
56                 //return new_path;
57         }       
58         else if ((path1[(sizeof(path1)/sizeof(char))-2]!='/') && path2[0]=='/') {
59                 /*paths are compatiable. concatanate them*/  
60                 strcat(new_path,path1);
61                 strcat(new_path,path2);         
62                 //char new_path[(sizeof(path1)/sizeof(char))+(sizeof(path2)/sizeof(char))];
63                 //strcpy(new_path,strcat(path1,path2)); 
64                 //return new_path;
65         }
66         else if ((path1[(sizeof(path1)/sizeof(char))-2]!='/') && path2[0]!='/') {
67                         /*need to add a "/". */  
68                 strcat(new_path,path1);
69                 strcat(new_path,"/");
70                 strcat(new_path,path2);
71                 //strcpy(new_path,strcat(path1,strcat("/\0",path2)));
72
73 #if 0
74                 copy_array(path1,new_path,0,0);
75                 copy_array('\0',new_path,0,(sizeof(path1)/sizeof(char)));
76                 copy_array(path2,new_path,0,(sizeof(path1)/sizeof(char))+1);
77  old method now trying to use copy_array
78                 //char new_path[(sizeof(path1)/sizeof(char))+(sizeof(path2)/sizeof(char))+1];
79                 for (x=0;x<=(sizeof(path1)/sizeof(char))-1;x++){ 
80                         new_path[x]=path1[x];
81                 }
82                 new_path[x+1]='/';
83                 for (x=(sizeof(path1)/sizeof(char)) ,i=0 ;i<=(sizeof(path2)/sizeof(char));x++,i++){ 
84                         new_path[x]=path2[i]; 
85                 }
86 #endif
87
88                 //return new_path;
89         }
90         else if ((path1[(sizeof(path1)/sizeof(char))-2]=='/') && path2[0]=='/') {
91                 /*need to remove a "/". */
92                 /*yaffs does not mind the extra slash. */
93                 //char new_path[(sizeof(path1)/sizeof(char))+(sizeof(path2)/sizeof(char))-1];
94                 
95                 strcat(new_path,path1);
96                 strcat(new_path,path2);
97                 //strcpy(new_path,strcat(path1,strncat("",path2,(sizeof(path1)/sizeof(char))-1))); 
98                 //return new_path;
99         } 
100         else{
101                 //error 
102                 //return -1;
103         }
104 }
105
106
107
108 void test(char*yaffs_test_dir){
109         char output=0;
110         char name[MAX_FILE_NAME_SIZE+3 ]="apple\0";
111         char path[MAX_FILE_NAME_SIZE];
112         join_paths(yaffs_test_dir,name,path);
113         while(1)
114         {
115                 path[0]='\0';// this should clear the path
116                 generate_random_string(name);
117                 join_paths(yaffs_test_dir,name,path);
118                 add_to_buffer(&message_buffer,"trying to open file",MESSAGE_LEVEL_BASIC_TASKS);
119                 add_to_buffer(&message_buffer,path,MESSAGE_LEVEL_BASIC_TASKS);
120                 output=yaffs_open(path,O_CREAT | O_TRUNC| O_RDWR, S_IREAD | S_IWRITE);
121                 yaffs_check_for_errors(output, &message_buffer,"failed to open file","opened file");
122         }
123 }
124 void  generate_random_string(char *ptr){
125         unsigned int x;
126         unsigned int length=((rand() %MAX_FILE_NAME_SIZE)+1);   /*creates a int with the number of charecters been between 1 and 51*/           
127         //printf("generating string\n");
128         //printf("string length is %d\n",length);
129         for (x=0; x <= (length-2) &&length>2 ; x++)
130         {
131                 //printf("x=%d\n",x);   
132                 ptr[x]=(rand() % 126-32)+32;    /*generate a number between 32 and 126 and uses it as a charecter (letter) */
133                 //printf("charecter generated is %c\n",ptr[x]);
134         }
135         ptr[x+1]='\0';  /*adds NULL charecter to turn it into a string*/
136         
137 }
138