yaffs Commiting yaffs_tester.c and coresponding files
[yaffs2.git] / direct / timothy_tests / yaffs_tester.c
1 /*yaffs_tester.c*/
2 #include "yaffs_tester.h"
3
4
5 int random_seed;
6 int simulate_power_failure = 0;
7
8
9 buffer message_buffer;  /*create  message_buffer */
10
11
12
13 int main()
14 {       
15         char yaffs_test_dir[]="/yaffs2/test_dir";
16         char yaffs_mount_dir[]="/yaffs2/";
17         printf("welcome to the yaffs tester\n");
18         init(yaffs_test_dir,yaffs_mount_dir);
19         test(yaffs_test_dir);
20
21         yaffs_unmount(yaffs_mount_dir);
22         return 0;
23 }
24
25 void add_to_buffer(buffer *p_Buffer, char message[])
26 {
27         if (p_Buffer->head+1==p_Buffer->tail)
28         {
29                 p_Buffer->tail++;
30                 if (p_Buffer->tail >BUFFER_SIZE-1) p_Buffer->tail -= BUFFER_SIZE-1;
31                 
32         }
33         /*move the head up one. the head always points at the last witten data*/
34         p_Buffer->head++;
35         if (p_Buffer->head >BUFFER_SIZE) p_Buffer->head -= BUFFER_SIZE;
36
37         strcpy(p_Buffer->buffer[p_Buffer->head],message);
38
39 }
40 void print_buffer(buffer *p_Buffer)
41 {
42         for (x=p_Buffer->head; x>=p_Buffer->tail; x--)
43         {
44                 
45         }
46
47 }
48
49
50 void init(char yaffs_test_dir[],char yaffs_mount_dir[])
51 {
52         yaffs_StartUp();
53         yaffs_mount(yaffs_mount_dir);
54         if (yaffs_access(yaffs_test_dir,0))
55         {
56                 yaffs_mkdir(yaffs_test_dir,S_IREAD | S_IWRITE);
57         }
58 }
59
60 void yaffs_check_for_errors(char output)
61 {
62         if (output==-1)
63         {
64                 printf("error####");
65                 print_buffer(message_buffer);
66         }
67 }
68
69 void test(char yaffs_test_dir[])
70 {
71         char name[MAX_FILE_NAME_SIZE +3];
72         unsigned int x;
73         while(1)
74         {
75
76                 generate_random_string(name);
77                 printf("the length of the string is %d \n",strlen(name)); 
78                 printf("generated string is:");
79                 for (x=0; x <= (strlen(name)-1)&&x<=MAX_FILE_NAME_SIZE ; x++)
80                 {
81 //                      printf("x=%d\n",x);
82                         printf("%c ",name[x]);
83                 }
84                 printf("\n");
85         }
86 }
87 void  generate_random_string(char *ptr)
88 {
89         unsigned int x;
90         unsigned int length=((rand() %MAX_FILE_NAME_SIZE)+1);   /*creates a int with the number of charecters been between 1 and 51*/           
91         printf("generating string\n");
92         printf("string length is %d\n",length);
93         for (x=0; x <= (length-2) &&length>2 ; x++)
94         {
95 //              printf("x=%d\n",x);     
96                 ptr[x]=(rand() % 126-32)+32;    /*generate a number between 32 and 126 and uses it as a charecter (letter) */
97 //              printf("charecter generated is %c\n",ptr[x]);
98         }
99         ptr[x+1]=0;     /*adds NULL charecter to turn it into a string*/
100         
101 }
102