3 #include "yaffs_tester.h"
8 int simulate_power_failure = 0;
11 buffer message_buffer; /*create message_buffer */
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*/
19 init(yaffs_test_dir,yaffs_mount_dir);
21 yaffs_unmount(yaffs_mount_dir);
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;
31 add_to_buffer(&message_buffer,"welcome to the yaffs tester",MESSAGE_LEVEL_BASIC_TASKS);/* print boot up message*/
33 yaffs_mount(yaffs_mount_dir);
35 if (yaffs_access(yaffs_test_dir,0))
37 yaffs_mkdir(yaffs_test_dir,S_IREAD | S_IWRITE);
41 void join_paths(char *path1,char *path2,char *new_path ){
43 /* printf("strlen path1:%d\n",strlen(path1));
44 printf("strlen path2:%d\n",strlen(path2));
45 printf("path1; %s\n",path1);
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));
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));
66 else if ((path1[(sizeof(path1)/sizeof(char))-2]!='/') && path2[0]!='/') {
67 /*need to add a "/". */
68 strcat(new_path,path1);
70 strcat(new_path,path2);
71 //strcpy(new_path,strcat(path1,strcat("/\0",path2)));
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++){
83 for (x=(sizeof(path1)/sizeof(char)) ,i=0 ;i<=(sizeof(path2)/sizeof(char));x++,i++){
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];
95 strcat(new_path,path1);
96 strcat(new_path,path2);
97 //strcpy(new_path,strcat(path1,strncat("",path2,(sizeof(path1)/sizeof(char))-1)));
108 void test(char*yaffs_test_dir){
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);
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");
124 void generate_random_string(char *ptr){
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++)
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]);
135 ptr[x+1]='\0'; /*adds NULL charecter to turn it into a string*/