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.
13 * yaffs_tester.c designed to stress test yaffs2 direct.
17 #include "yaffs_tester.h"
22 int simulate_power_failure = 0;
25 buffer message_buffer; /*create message_buffer */
30 char yaffs_test_dir[] ="/yaffs2/test_dir"; /*the path to the directory where all of the testing will take place*/
31 char yaffs_mount_dir[]="/yaffs2/"; /*the path to the mount point which yaffs will mount*/
33 init(yaffs_test_dir,yaffs_mount_dir);
35 yaffs_unmount(yaffs_mount_dir);
40 void init(char *yaffs_test_dir,char *yaffs_mount_dir){
42 /*these variables are already set to zero, but it is better not to take chances*/
43 message_buffer.head=0;
44 message_buffer.tail=0;
46 add_to_buffer(&message_buffer,"welcome to the yaffs tester",MESSAGE_LEVEL_BASIC_TASKS,PRINT);/* print boot up message*/
48 yaffs_mount(yaffs_mount_dir);
50 if (yaffs_access(yaffs_test_dir,0))
52 add_to_buffer(&message_buffer,"creating dir: ",MESSAGE_LEVEL_BASIC_TASKS,NPRINT);
53 append_to_buffer(&message_buffer,yaffs_test_dir,MESSAGE_LEVEL_BASIC_TASKS,PRINT);
54 output=yaffs_mkdir(yaffs_test_dir,S_IREAD | S_IWRITE);
55 yaffs_check_for_errors(output, &message_buffer,"could not create dir","created dir\n\n");
59 void join_paths(char *path1,char *path2,char *new_path ){
61 /* printf("strlen path1:%d\n",strlen(path1));
62 printf("strlen path2:%d\n",strlen(path2));
63 printf("path1; %s\n",path1);
65 add_to_buffer(&message_buffer, "joining paths:",MESSAGE_LEVEL_BASIC_TASKS,NPRINT);
66 append_to_buffer(&message_buffer,path1,MESSAGE_LEVEL_BASIC_TASKS,NPRINT);
67 append_to_buffer(&message_buffer, " and ",MESSAGE_LEVEL_BASIC_TASKS,NPRINT);
68 append_to_buffer(&message_buffer, path2,MESSAGE_LEVEL_BASIC_TASKS,PRINT);
69 if ( (path1[(sizeof(path1)/sizeof(char))-2]=='/') && path2[0]!='/') {
70 /*paths are compatiable. concatanate them. note -2 is because of \0*/
71 strcat(new_path,path1);
72 strcat(new_path,path2);
73 //char new_path[(sizeof(path1)/sizeof(char))+(sizeof(path2)/sizeof(char))];
74 //strcpy(new_path,strcat(path1,path2));
77 else if ((path1[(sizeof(path1)/sizeof(char))-2]!='/') && path2[0]=='/') {
78 /*paths are compatiable. concatanate them*/
79 strcat(new_path,path1);
80 strcat(new_path,path2);
81 //char new_path[(sizeof(path1)/sizeof(char))+(sizeof(path2)/sizeof(char))];
82 //strcpy(new_path,strcat(path1,path2));
85 else if ((path1[(sizeof(path1)/sizeof(char))-2]!='/') && path2[0]!='/') {
86 /*need to add a "/". */
87 strcat(new_path,path1);
89 strcat(new_path,path2);
90 //strcpy(new_path,strcat(path1,strcat("/\0",path2)));
93 copy_array(path1,new_path,0,0);
94 copy_array('\0',new_path,0,(sizeof(path1)/sizeof(char)));
95 copy_array(path2,new_path,0,(sizeof(path1)/sizeof(char))+1);
96 old method now trying to use copy_array
97 //char new_path[(sizeof(path1)/sizeof(char))+(sizeof(path2)/sizeof(char))+1];
98 for (x=0;x<=(sizeof(path1)/sizeof(char))-1;x++){
102 for (x=(sizeof(path1)/sizeof(char)) ,i=0 ;i<=(sizeof(path2)/sizeof(char));x++,i++){
103 new_path[x]=path2[i];
109 else if ((path1[(sizeof(path1)/sizeof(char))-2]=='/') && path2[0]=='/') {
110 /*need to remove a "/". */
111 /*yaffs does not mind the extra slash. */
112 //char new_path[(sizeof(path1)/sizeof(char))+(sizeof(path2)/sizeof(char))-1];
114 strcat(new_path,path1);
115 strcat(new_path,path2);
116 //strcpy(new_path,strcat(path1,strncat("",path2,(sizeof(path1)/sizeof(char))-1)));
127 void test(char*yaffs_test_dir){
129 char name[MAX_FILE_NAME_SIZE+3 ]="apple\0";
130 char path[MAX_FILE_NAME_SIZE];
131 join_paths(yaffs_test_dir,name,path);
134 path[0]='\0';// this should clear the path
135 generate_random_string(name);
136 join_paths(yaffs_test_dir,name,path);
137 add_to_buffer(&message_buffer,"trying to open file: ",MESSAGE_LEVEL_BASIC_TASKS,NPRINT);
138 append_to_buffer(&message_buffer,path,MESSAGE_LEVEL_BASIC_TASKS,PRINT);
139 output=yaffs_open(path,O_CREAT | O_TRUNC| O_RDWR, S_IREAD | S_IWRITE);
140 yaffs_check_for_errors(output, &message_buffer,"failed to open file","opened file");
143 void generate_random_string(char *ptr){
145 unsigned int length=((rand() %MAX_FILE_NAME_SIZE)+1); /*creates a int with the number of charecters been between 1 and 51*/
147 //printf("generating string\n");
148 //printf("string length is %d\n",length);
149 for (x=0; x <= (length-2) &&length>2 ; x++)
151 //printf("x=%d\n",x);
152 /* keep generating a charecter until the charecter is legal*/
153 while((letter=='\0' )||(letter=='/')||(letter=='\\')){
154 letter=(rand() % 126-32)+32; /*generate a number between 32 and 126 and uses it as a charecter (letter) */
157 //printf("charecter generated is %c\n",ptr[x]);
159 ptr[x+1]='\0'; /*adds NULL charecter to turn it into a string*/