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.
15 * yaffs_tester.c designed to stress test yaffs2 direct.
19 #include "yaffs_tester.h"
24 int simulate_power_failure = 0;
27 buffer message_buffer; /*create message_buffer */
31 int main(int argc, char *argv[]){
32 char yaffs_test_dir[] ="/yaffs2/test_dir"; /*the path to the directory where all of the testing will take place*/
33 char yaffs_mount_dir[]="/yaffs2/"; /*the path to the mount point which yaffs will mount*/
35 init(yaffs_test_dir,yaffs_mount_dir,argc,argv);
37 yaffs_unmount(yaffs_mount_dir);
43 void init(char *yaffs_test_dir,char *yaffs_mount_dir,int argc, char *argv[]){
48 /*these variables are already set to zero, but it is better not to take chances*/
49 message_buffer.head=0;
50 message_buffer.tail=0;
53 log_handle=fopen(LOG_FILE,"w");
54 if (log_handle!=NULL){
55 fputs("log file for yaffs tester\n",log_handle);
58 add_to_buffer(&message_buffer,"welcome to the yaffs tester",MESSAGE_LEVEL_BASIC_TASKS,PRINT);/* print boot up message*/
60 yaffs_mount(yaffs_mount_dir);
62 // add_to_buffer(&message_buffer,"argv ",MESSAGE_LEVEL_BASIC_TASKS,PRINT);
63 // add_to_buffer(&message_buffer,argv[x],MESSAGE_LEVEL_BASIC_TASKS,PRINT);
64 if (strcmp("-seed",argv[x])==0){ /*warning only compares the length of the strings, quick fix*/
65 seed= atoi(argv[x+1]);
66 /*add_to_buffer(&message_buffer,"setting seed to ",MESSAGE_LEVEL_BASIC_TASKS,NPRINT);
67 append_int_to_buffer(&message_buffer,seed,MESSAGE_LEVEL_BASIC_TASKS,NPRINT);
68 append_to_buffer(&message_buffer,"\n",MESSAGE_LEVEL_BASIC_TASKS,PRINT);*/
78 add_to_buffer(&message_buffer,"setting seed to ",MESSAGE_LEVEL_BASIC_TASKS,NPRINT);
79 append_int_to_buffer(&message_buffer,seed,MESSAGE_LEVEL_BASIC_TASKS,PRINT);/* print boot up message*/
81 if (yaffs_access(yaffs_test_dir,0)) /* if the test folder does not exist then create it */
83 add_to_buffer(&message_buffer,"creating dir: ",MESSAGE_LEVEL_BASIC_TASKS,NPRINT);
84 append_to_buffer(&message_buffer,yaffs_test_dir,MESSAGE_LEVEL_BASIC_TASKS,PRINT);
85 output=yaffs_mkdir(yaffs_test_dir,S_IREAD | S_IWRITE);
86 yaffs_check_for_errors(output, &message_buffer,"could not create dir","created dir\n\n");
90 void join_paths(char *path1,char *path2,char *new_path ){
92 /* printf("strlen path1:%d\n",strlen(path1));
93 printf("strlen path2:%d\n",strlen(path2));
94 printf("path1; %s\n",path1);
96 add_to_buffer(&message_buffer, "joining paths:",MESSAGE_LEVEL_BASIC_TASKS,NPRINT);
97 append_to_buffer(&message_buffer,path1,MESSAGE_LEVEL_BASIC_TASKS,NPRINT);
98 append_to_buffer(&message_buffer, " and ",MESSAGE_LEVEL_BASIC_TASKS,NPRINT);
99 append_to_buffer(&message_buffer, path2,MESSAGE_LEVEL_BASIC_TASKS,PRINT);
100 if ( (path1[(sizeof(path1)/sizeof(char))-2]=='/') && path2[0]!='/') {
101 /*paths are compatiable. concatanate them. note -2 is because of \0*/
102 strcat(new_path,path1);
103 strcat(new_path,path2);
104 //char new_path[(sizeof(path1)/sizeof(char))+(sizeof(path2)/sizeof(char))];
105 //strcpy(new_path,strcat(path1,path2));
108 else if ((path1[(sizeof(path1)/sizeof(char))-2]!='/') && path2[0]=='/') {
109 /*paths are compatiable. concatanate them*/
110 strcat(new_path,path1);
111 strcat(new_path,path2);
112 //char new_path[(sizeof(path1)/sizeof(char))+(sizeof(path2)/sizeof(char))];
113 //strcpy(new_path,strcat(path1,path2));
116 else if ((path1[(sizeof(path1)/sizeof(char))-2]!='/') && path2[0]!='/') {
117 /*need to add a "/". */
118 strcat(new_path,path1);
119 strcat(new_path,"/");
120 strcat(new_path,path2);
121 //strcpy(new_path,strcat(path1,strcat("/\0",path2)));
124 copy_array(path1,new_path,0,0);
125 copy_array('\0',new_path,0,(sizeof(path1)/sizeof(char)));
126 copy_array(path2,new_path,0,(sizeof(path1)/sizeof(char))+1);
127 old method now trying to use copy_array
128 //char new_path[(sizeof(path1)/sizeof(char))+(sizeof(path2)/sizeof(char))+1];
129 for (x=0;x<=(sizeof(path1)/sizeof(char))-1;x++){
130 new_path[x]=path1[x];
133 for (x=(sizeof(path1)/sizeof(char)) ,i=0 ;i<=(sizeof(path2)/sizeof(char));x++,i++){
134 new_path[x]=path2[i];
140 else if ((path1[(sizeof(path1)/sizeof(char))-2]=='/') && path2[0]=='/') {
141 /*need to remove a "/". */
142 /*yaffs does not mind the extra slash. */
143 //char new_path[(sizeof(path1)/sizeof(char))+(sizeof(path2)/sizeof(char))-1];
145 strcat(new_path,path1);
146 strcat(new_path,path2);
147 //strcpy(new_path,strcat(path1,strncat("",path2,(sizeof(path1)/sizeof(char))-1)));
158 void test(char*yaffs_test_dir){
160 char name[MAX_FILE_NAME_SIZE+3 ]="apple\0";
161 char path[MAX_FILE_NAME_SIZE];
162 join_paths(yaffs_test_dir,name,path);
165 path[0]='\0';// this should clear the path
166 generate_random_string(name);
167 join_paths(yaffs_test_dir,name,path);
168 add_to_buffer(&message_buffer,"trying to open file: ",MESSAGE_LEVEL_BASIC_TASKS,NPRINT);
169 append_to_buffer(&message_buffer,path,MESSAGE_LEVEL_BASIC_TASKS,PRINT);
170 output=yaffs_open(path,O_CREAT | O_TRUNC| O_RDWR, S_IREAD | S_IWRITE);
171 yaffs_check_for_errors(output, &message_buffer,"failed to open file","opened file");
174 void generate_random_string(char *ptr){
176 unsigned int length=((rand() %MAX_FILE_NAME_SIZE)+1); /*creates a int with the number of charecters been between 1 and 51*/
178 //printf("generating string\n");
179 //printf("string length is %d\n",length);
180 for (x=0; x <= (length-2) &&length>2 ; x++)
182 //printf("x=%d\n",x);
183 /* keep generating a charecter until the charecter is legal*/
184 while((letter=='\0' )||(letter=='/')||(letter=='\\')){
185 letter=(rand() % 126-32)+32; /*generate a number between 32 and 126 and uses it as a charecter (letter) */
188 //printf("charecter generated is %c\n",ptr[x]);
190 ptr[x+1]='\0'; /*adds NULL charecter to turn it into a string*/