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\0"; /*the path to the directory where all of the testing will take place*/
17 char yaffs_mount_dir[]="/yaffs2/\0"; /*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\0",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 ){
44 printf("strlen path1:%d\n",strlen(path1));
45 printf("strlen path2:%d\n",strlen(path2));
46 printf("path1; %s\n",path1);
48 //add_to_buffer(&message_buffer, "joining paths\0",MESSAGE_LEVEL_BASIC_TASKS);
51 add_to_buffer(&message_buffer,path1,MESSAGE_LEVEL_BASIC_TASKS);
52 add_to_buffer(&message_buffer, path2,MESSAGE_LEVEL_BASIC_TASKS);
53 if ( (path1[(sizeof(path1)/sizeof(char))-2]=='/') && path2[0]!='/') {
54 /*paths are compatiable. concatanate them. note -2 is because of \0*/
55 //char new_path[(sizeof(path1)/sizeof(char))+(sizeof(path2)/sizeof(char))];
56 strcpy(new_path,strcat(path1,path2));
59 else if ((path1[(sizeof(path1)/sizeof(char))-2]!='/') && path2[0]=='/') {
60 /*paths are compatiable. concatanate them*/
61 //char new_path[(sizeof(path1)/sizeof(char))+(sizeof(path2)/sizeof(char))];
62 strcpy(new_path,strcat(path1,path2));
65 else if ((path1[(sizeof(path1)/sizeof(char))-2]!='/') && path2[0]!='/') {
66 /*need to add a "/". */
67 strcat(new_path,path1);
69 strcat(new_path,path2);
70 //strcpy(new_path,strcat(path1,strcat("/\0",path2)));
72 /* copy_array(path1,new_path,0,0);
73 copy_array('\0',new_path,0,(sizeof(path1)/sizeof(char)));
74 copy_array(path2,new_path,0,(sizeof(path1)/sizeof(char))+1);
75 old method now trying to use copy_array
76 //char new_path[(sizeof(path1)/sizeof(char))+(sizeof(path2)/sizeof(char))+1];
77 for (x=0;x<=(sizeof(path1)/sizeof(char))-1;x++){
81 for (x=(sizeof(path1)/sizeof(char)) ,i=0 ;i<=(sizeof(path2)/sizeof(char));x++,i++){
87 else if ((path1[(sizeof(path1)/sizeof(char))-2]=='/') && path2[0]=='/') {
88 /*need to remove a "/". */
89 //char new_path[(sizeof(path1)/sizeof(char))+(sizeof(path2)/sizeof(char))-1];
90 strcpy(new_path,strcat(path1,strncat("",path2,(sizeof(path1)/sizeof(char))-1)));
99 void copy_array(char from[],char *to, unsigned int from_offset,unsigned int to_offset){
101 for (x=0+from_offset; x<(sizeof(from)/sizeof(char));x++){
102 //add_to_buffer(&message_buffer, x,MESSAGE_LEVEL_BASIC_TASKS);
103 //add_to_buffer(&message_buffer,from[x],MESSAGE_LEVEL_BASIC_TASKS);
105 printf("char in from: %c\n\n",from[x]);
107 to[x+to_offset]=from[x];
111 void test(char yaffs_test_dir[]){
113 char name[MAX_FILE_NAME_SIZE+3 ]="apple\0";
114 char path[MAX_FILE_NAME_SIZE+strlen(yaffs_test_dir)];
115 join_paths(yaffs_test_dir,name,path);
118 path[0]='\0';// this should clear the path
119 generate_random_string(name);
120 join_paths(yaffs_test_dir,name,path);
121 add_to_buffer(&message_buffer,"trying to open file",MESSAGE_LEVEL_BASIC_TASKS);
122 add_to_buffer(&message_buffer,path,MESSAGE_LEVEL_BASIC_TASKS);
123 output=yaffs_open(path,O_CREAT | O_TRUNC| O_RDWR, S_IREAD | S_IWRITE);
124 yaffs_check_for_errors(output, &message_buffer,"failed to open file","opened file");
127 void generate_random_string(char *ptr){
129 unsigned int length=((rand() %MAX_FILE_NAME_SIZE)+1); /*creates a int with the number of charecters been between 1 and 51*/
130 //printf("generating string\n");
131 //printf("string length is %d\n",length);
132 for (x=0; x <= (length-2) &&length>2 ; x++)
134 //printf("x=%d\n",x);
135 ptr[x]=(rand() % 126-32)+32; /*generate a number between 32 and 126 and uses it as a charecter (letter) */
136 //printf("charecter generated is %c\n",ptr[x]);
138 ptr[x+1]='\0'; /*adds NULL charecter to turn it into a string*/