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 */
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);
37 yaffs_unmount(yaffs_mount_dir);
42 void init(char *yaffs_test_dir,char *yaffs_mount_dir){
44 /*these variables are already set to zero, but it is better not to take chances*/
45 message_buffer.head=0;
46 message_buffer.tail=0;
48 add_to_buffer(&message_buffer,"welcome to the yaffs tester",MESSAGE_LEVEL_BASIC_TASKS,PRINT);/* print boot up message*/
50 yaffs_mount(yaffs_mount_dir);
52 if (yaffs_access(yaffs_test_dir,0))
54 add_to_buffer(&message_buffer,"creating dir: ",MESSAGE_LEVEL_BASIC_TASKS,NPRINT);
55 append_to_buffer(&message_buffer,yaffs_test_dir,MESSAGE_LEVEL_BASIC_TASKS,PRINT);
56 output=yaffs_mkdir(yaffs_test_dir,S_IREAD | S_IWRITE);
57 yaffs_check_for_errors(output, &message_buffer,"could not create dir","created dir\n\n");
61 void join_paths(char *path1,char *path2,char *new_path ){
63 /* printf("strlen path1:%d\n",strlen(path1));
64 printf("strlen path2:%d\n",strlen(path2));
65 printf("path1; %s\n",path1);
67 add_to_buffer(&message_buffer, "joining paths:",MESSAGE_LEVEL_BASIC_TASKS,NPRINT);
68 append_to_buffer(&message_buffer,path1,MESSAGE_LEVEL_BASIC_TASKS,NPRINT);
69 append_to_buffer(&message_buffer, " and ",MESSAGE_LEVEL_BASIC_TASKS,NPRINT);
70 append_to_buffer(&message_buffer, path2,MESSAGE_LEVEL_BASIC_TASKS,PRINT);
71 if ( (path1[(sizeof(path1)/sizeof(char))-2]=='/') && path2[0]!='/') {
72 /*paths are compatiable. concatanate them. note -2 is because of \0*/
73 strcat(new_path,path1);
74 strcat(new_path,path2);
75 //char new_path[(sizeof(path1)/sizeof(char))+(sizeof(path2)/sizeof(char))];
76 //strcpy(new_path,strcat(path1,path2));
79 else if ((path1[(sizeof(path1)/sizeof(char))-2]!='/') && path2[0]=='/') {
80 /*paths are compatiable. concatanate them*/
81 strcat(new_path,path1);
82 strcat(new_path,path2);
83 //char new_path[(sizeof(path1)/sizeof(char))+(sizeof(path2)/sizeof(char))];
84 //strcpy(new_path,strcat(path1,path2));
87 else if ((path1[(sizeof(path1)/sizeof(char))-2]!='/') && path2[0]!='/') {
88 /*need to add a "/". */
89 strcat(new_path,path1);
91 strcat(new_path,path2);
92 //strcpy(new_path,strcat(path1,strcat("/\0",path2)));
95 copy_array(path1,new_path,0,0);
96 copy_array('\0',new_path,0,(sizeof(path1)/sizeof(char)));
97 copy_array(path2,new_path,0,(sizeof(path1)/sizeof(char))+1);
98 old method now trying to use copy_array
99 //char new_path[(sizeof(path1)/sizeof(char))+(sizeof(path2)/sizeof(char))+1];
100 for (x=0;x<=(sizeof(path1)/sizeof(char))-1;x++){
101 new_path[x]=path1[x];
104 for (x=(sizeof(path1)/sizeof(char)) ,i=0 ;i<=(sizeof(path2)/sizeof(char));x++,i++){
105 new_path[x]=path2[i];
111 else if ((path1[(sizeof(path1)/sizeof(char))-2]=='/') && path2[0]=='/') {
112 /*need to remove a "/". */
113 /*yaffs does not mind the extra slash. */
114 //char new_path[(sizeof(path1)/sizeof(char))+(sizeof(path2)/sizeof(char))-1];
116 strcat(new_path,path1);
117 strcat(new_path,path2);
118 //strcpy(new_path,strcat(path1,strncat("",path2,(sizeof(path1)/sizeof(char))-1)));
129 void test(char*yaffs_test_dir){
131 char name[MAX_FILE_NAME_SIZE+3 ]="apple\0";
132 char path[MAX_FILE_NAME_SIZE];
133 join_paths(yaffs_test_dir,name,path);
136 path[0]='\0';// this should clear the path
137 generate_random_string(name);
138 join_paths(yaffs_test_dir,name,path);
139 add_to_buffer(&message_buffer,"trying to open file: ",MESSAGE_LEVEL_BASIC_TASKS,NPRINT);
140 append_to_buffer(&message_buffer,path,MESSAGE_LEVEL_BASIC_TASKS,PRINT);
141 output=yaffs_open(path,O_CREAT | O_TRUNC| O_RDWR, S_IREAD | S_IWRITE);
142 yaffs_check_for_errors(output, &message_buffer,"failed to open file","opened file");
145 void generate_random_string(char *ptr){
147 unsigned int length=((rand() %MAX_FILE_NAME_SIZE)+1); /*creates a int with the number of charecters been between 1 and 51*/
149 //printf("generating string\n");
150 //printf("string length is %d\n",length);
151 for (x=0; x <= (length-2) &&length>2 ; x++)
153 //printf("x=%d\n",x);
154 /* keep generating a charecter until the charecter is legal*/
155 while((letter=='\0' )||(letter=='/')||(letter=='\\')){
156 letter=(rand() % 126-32)+32; /*generate a number between 32 and 126 and uses it as a charecter (letter) */
159 //printf("charecter generated is %c\n",ptr[x]);
161 ptr[x+1]='\0'; /*adds NULL charecter to turn it into a string*/