yaffs working on the timothy_tests. just need to save the current state of the program.
authorTimothy Manning <tfhmanning@gmail.com>
Thu, 21 Oct 2010 20:26:31 +0000 (09:26 +1300)
committerTimothy Manning <tfhmanning@gmail.com>
Thu, 21 Oct 2010 20:26:31 +0000 (09:26 +1300)
Signed-off-by: Timothy Manning <tfhmanning@gmail.com>
direct/timothy_tests/Makefile
direct/timothy_tests/error_handler.c [new file with mode: 0644]
direct/timothy_tests/error_handler.h [new file with mode: 0644]
direct/timothy_tests/message_buffer.c [new file with mode: 0644]
direct/timothy_tests/message_buffer.h [new file with mode: 0644]
direct/timothy_tests/yaffs_tester.c
direct/timothy_tests/yaffs_tester.h

index 13371b2..c4accf5 100644 (file)
@@ -44,7 +44,7 @@ COMMONTESTOBJS = yaffscfg2k.o yaffs_ecc.o yaffs_fileem.o yaffs_fileem2k.o yaffsf
 
 #               yaffs_checkptrwtest.o\
 
-YAFFSTESTOBJS  = $(COMMONTESTOBJS) yaffs_tester.o
+YAFFSTESTOBJS  = $(COMMONTESTOBJS) yaffs_tester.o message_buffer.o error_handler.o
 
 
 ALLOBJS = $(sort $(YAFFSTESTOBJS))
diff --git a/direct/timothy_tests/error_handler.c b/direct/timothy_tests/error_handler.c
new file mode 100644 (file)
index 0000000..f060caf
--- /dev/null
@@ -0,0 +1,19 @@
+#include "error_handler.h"
+
+void yaffs_check_for_errors(char output, buffer *message_buffer,char error_message[],char success_message[])
+{
+       if (output==-1)
+       {
+               add_to_buffer(message_buffer, "error##########",MESSAGE_LEVEL_ERROR);
+               add_to_buffer(message_buffer, error_message,MESSAGE_LEVEL_ERROR);
+               add_to_buffer(message_buffer, "error_code",MESSAGE_LEVEL_ERROR);
+                printf("%d\n",yaffs_get_error());              
+
+               //print_buffer(message_buffer,PRINT_ALL);
+       
+       }
+       else{
+               add_to_buffer(message_buffer, success_message,MESSAGE_LEVEL_BASIC_TASKS);
+       }
+               
+}
diff --git a/direct/timothy_tests/error_handler.h b/direct/timothy_tests/error_handler.h
new file mode 100644 (file)
index 0000000..fad1ef8
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef __error_handler_h__
+#define __error_handler_h__
+#include <stdio.h>
+#include "message_buffer.h"
+#include "yaffsfs.h"
+#define DEBUG_LEVEL 5 /*set the debug level. this is used to display the relevent debug messages*/
+void yaffs_check_for_errors(char output, buffer *message_buffer, char error_message[], char success_message[]);
+#endif
diff --git a/direct/timothy_tests/message_buffer.c b/direct/timothy_tests/message_buffer.c
new file mode 100644 (file)
index 0000000..f8a9a8e
--- /dev/null
@@ -0,0 +1,61 @@
+#include "message_buffer.h"
+
+
+void add_to_buffer(buffer *p_Buffer, char message[],char message_level){
+       unsigned int x=0;
+
+       p_Buffer->head++;
+
+       printf("p_Buffer->tail=%d\n",p_Buffer->tail);
+       printf("p_Buffer->head=%d\n",p_Buffer->head);
+       if (p_Buffer->head >=BUFFER_SIZE) {
+               printf("buffer overflow\n");
+               p_Buffer->head -= BUFFER_SIZE;  /*wrap the head around the buffer*/
+               printf("new p_Buffer->head=%d\n",p_Buffer->head);
+               
+       /*if the buffer is full then delete last entry by moving the tail*/
+       if (p_Buffer->head==p_Buffer->tail){
+               printf("moving buffer tail from %d to ",p_Buffer->tail);
+               p_Buffer->tail++;
+               printf("%d\n",p_Buffer->tail);
+               if (p_Buffer->tail >=BUFFER_SIZE) p_Buffer->tail -= BUFFER_SIZE;/*wrap the tail around the buffer*/
+       }
+
+       /*move the head up one. the head always points at the last written data*/
+
+
+       
+       }
+
+       p_Buffer->message_level[p_Buffer->head]=message_level; /*copy the message level*/
+       x=p_Buffer->head;
+
+
+       
+       strcpy(p_Buffer->message[p_Buffer->head],message); /*copy the message*/
+/*     
+       //convert the message into a string so it can be printed cleanly
+       if (message[length_of_message-1]!='\0') p_Buffer->message[p_Buffer->head][x+1]='\0';    
+*/
+       if (p_Buffer->message_level[p_Buffer->head]<=DEBUG_LEVEL){
+//             printf("printing buffer 1\n");
+                print_buffer(p_Buffer,1); /*if the debug level is higher enough then print the new message*/
+       }
+}
+void print_buffer(buffer *p_Buffer, int number_of_messages_to_print){  
+/*     printf("print buffer\n");
+       printf("buffer head:%d\n",p_Buffer->head);
+       printf("buffer tail:%d\n",p_Buffer->tail);
+*/     int x;
+       int i;
+       if (number_of_messages_to_print==PRINT_ALL) number_of_messages_to_print=BUFFER_SIZE;
+//     printf("number_of_messages_to_print=%d\n",number_of_messages_to_print);
+       for (i=0,x=p_Buffer->head; (x>=p_Buffer->tail) && (i<number_of_messages_to_print); i++, x--){
+//             printf("printing bufer\n");
+               //printf("x:%d\n",x);
+               if (x<0) x = BUFFER_SIZE;               /*wrap x around buffer*/
+               printf("%s\n",p_Buffer->message[x]);
+       }
+
+}
+
diff --git a/direct/timothy_tests/message_buffer.h b/direct/timothy_tests/message_buffer.h
new file mode 100644 (file)
index 0000000..66cccae
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef __message_buffer__
+#define __message_buffer__
+
+#include <stdio.h>
+#include <string.h>
+
+#define PRINT_ALL -1                   /*this is used to print all of the messages in a buffer*/
+#define BUFFER_MESSAGE_LENGTH 60               /*number of char in message*/
+#define BUFFER_SIZE 50                 /*number of messages in buffer*/
+#define MESSAGE_LEVEL_ERROR 0
+#define MESSAGE_LEVEL_BASIC_TASKS 1
+typedef struct buffer_template{
+       char message[BUFFER_SIZE][BUFFER_MESSAGE_LENGTH];
+       int head;
+       int tail;
+       char message_level[BUFFER_SIZE];
+}buffer; 
+#include "error_handler.h"             /*include this for the debug level*/
+
+void add_to_buffer(buffer *p_Buffer, char message[],char message_level);               /*code for buffer*/
+void print_buffer(buffer *p_Buffer,int number_of_messages_to_print);           /*print messages in the buffer*/ 
+
+#endif
index 3c7c8ef..7aa97e2 100644 (file)
@@ -1,7 +1,9 @@
 /*yaffs_tester.c*/
+
 #include "yaffs_tester.h"
 
 
+
 int random_seed;
 int simulate_power_failure = 0;
 
@@ -10,106 +12,130 @@ buffer message_buffer;    /*create  message_buffer */
 
 
 
-int main()
-{      
-       char yaffs_test_dir[]="/yaffs2/test_dir";
-       char yaffs_mount_dir[]="/yaffs2/";
-       printf("welcome to the yaffs tester\n");
+int main(){    
+       char yaffs_test_dir[]="/yaffs2/test_dir\0";     /*the path to the directory where all of the testing will take place*/
+       char yaffs_mount_dir[]="/yaffs2/\0";            /*the path to the mount point which yaffs will mount*/
+       
        init(yaffs_test_dir,yaffs_mount_dir);
-       //test(yaffs_test_dir);
-       add_to_buffer(&message_buffer,"message1\0");
-       add_to_buffer(&message_buffer,"message2\0");
-       add_to_buffer(&message_buffer,"message3\0");
-       add_to_buffer(&message_buffer,"message4\0");
-       add_to_buffer(&message_buffer,"message5\0");
-       print_buffer(&message_buffer);
+       test(yaffs_test_dir);
        yaffs_unmount(yaffs_mount_dir);
        return 0;
 }
 
-void add_to_buffer(buffer *p_Buffer, char message[])
-{
-       //add a thing to add \0 on the end of the message
-       if (p_Buffer->head+1==p_Buffer->tail)
-       {
-               p_Buffer->tail++;
-               if (p_Buffer->tail >BUFFER_SIZE-1) p_Buffer->tail -= BUFFER_SIZE-1;
-               
-       }
-       /*move the head up one. the head always points at the last witten data*/
-       p_Buffer->head++;
-       if (p_Buffer->head >BUFFER_SIZE) p_Buffer->head -= BUFFER_SIZE;
-
-       strcpy(p_Buffer->message[p_Buffer->head],message);
-
-}
-void print_buffer(buffer *p_Buffer)
-{
-       printf("print buffer\n");
-       printf("buffer head:%d\n",p_Buffer->head);
-       printf("buffer tail:%d\n",p_Buffer->tail);
-       int x;
-       for (x=p_Buffer->head; x>=p_Buffer->tail; x--)
-       {
-               printf("x:%d\n",x);
-               if (x<0) x = BUFFER_SIZE;
-               printf("%s",p_Buffer->message[x]);
-               
-       }
-
-}
-
 
-void init(char yaffs_test_dir[],char yaffs_mount_dir[])
-{
-       yaffs_StartUp();
+void init(char yaffs_test_dir[],char yaffs_mount_dir[]){
+       /*these variables are already set to zero, but it is better not to take chances*/
+       message_buffer.head=0;                           
+       message_buffer.tail=0;
+       
+       add_to_buffer(&message_buffer,"welcome to the yaffs tester\0",MESSAGE_LEVEL_BASIC_TASKS);/* print boot up message*/     
+       yaffs_start_up();
        yaffs_mount(yaffs_mount_dir);
+
        if (yaffs_access(yaffs_test_dir,0))
        {
                yaffs_mkdir(yaffs_test_dir,S_IREAD | S_IWRITE);
        }
+       
 }
-
-void yaffs_check_for_errors(char output)
-{
-       if (output==-1)
-       {
-               printf("error####");
-               print_buffer(&message_buffer);
+void join_paths(char path1[],char path2[],char *new_path ){
+       unsigned int i=0;
+       unsigned int x=0;
+       printf("strlen path1:%d\n",strlen(path1));
+       printf("strlen path2:%d\n",strlen(path2));
+       printf("path1; %s\n",path1);
+
+       //add_to_buffer(&message_buffer, "joining paths\0",MESSAGE_LEVEL_BASIC_TASKS);
+       char cat[10]="cat\0";
+       strcat(cat,"dog\0");
+       add_to_buffer(&message_buffer,path1,MESSAGE_LEVEL_BASIC_TASKS);
+       add_to_buffer(&message_buffer, path2,MESSAGE_LEVEL_BASIC_TASKS);
+       if ( (path1[(sizeof(path1)/sizeof(char))-2]=='/') && path2[0]!='/') {
+               /*paths are compatiable. concatanate them. note -2 is because of \0*/  
+               //char new_path[(sizeof(path1)/sizeof(char))+(sizeof(path2)/sizeof(char))];
+               strcpy(new_path,strcat(path1,path2)); 
+               //return new_path;
+       }       
+       else if ((path1[(sizeof(path1)/sizeof(char))-2]!='/') && path2[0]=='/') {
+               /*paths are compatiable. concatanate them*/  
+               //char new_path[(sizeof(path1)/sizeof(char))+(sizeof(path2)/sizeof(char))];
+               strcpy(new_path,strcat(path1,path2)); 
+               //return new_path;
+       }
+       else if ((path1[(sizeof(path1)/sizeof(char))-2]!='/') && path2[0]!='/') {
+                       /*need to add a "/". */  
+               strcat(new_path,path1);
+               strcat(new_path,"/");
+               strcat(new_path,path2);
+               //strcpy(new_path,strcat(path1,strcat("/\0",path2)));
+
+/*             copy_array(path1,new_path,0,0);
+               copy_array('\0',new_path,0,(sizeof(path1)/sizeof(char)));
+               copy_array(path2,new_path,0,(sizeof(path1)/sizeof(char))+1);
+ old method now trying to use copy_array
+               //char new_path[(sizeof(path1)/sizeof(char))+(sizeof(path2)/sizeof(char))+1];
+               for (x=0;x<=(sizeof(path1)/sizeof(char))-1;x++){ 
+                       new_path[x]=path1[x];
+               }
+               new_path[x+1]='/';
+               for (x=(sizeof(path1)/sizeof(char)) ,i=0 ;i<=(sizeof(path2)/sizeof(char));x++,i++){ 
+                       new_path[x]=path2[i]; 
+               }
+*/
+               //return new_path;
+       }
+       else if ((path1[(sizeof(path1)/sizeof(char))-2]=='/') && path2[0]=='/') {
+               /*need to remove a "/". */  
+               //char new_path[(sizeof(path1)/sizeof(char))+(sizeof(path2)/sizeof(char))-1];
+               strcpy(new_path,strcat(path1,strncat("",path2,(sizeof(path1)/sizeof(char))-1))); 
+               //return new_path;
+       } 
+       else{
+               //error 
+               //return -1;
        }
 }
-
-void test(char yaffs_test_dir[])
-{
-       char name[MAX_FILE_NAME_SIZE +3];
-       unsigned int x;
+/*
+void copy_array(char from[],char *to, unsigned int from_offset,unsigned int to_offset){        
+       unsigned int x=0;
+       for (x=0+from_offset; x<(sizeof(from)/sizeof(char));x++){
+               //add_to_buffer(&message_buffer, x,MESSAGE_LEVEL_BASIC_TASKS);
+               //add_to_buffer(&message_buffer,from[x],MESSAGE_LEVEL_BASIC_TASKS);
+               printf("x=%d\n",x);
+               printf("char in from: %c\n\n",from[x]);
+               
+               to[x+to_offset]=from[x];
+       }
+}
+*/
+void test(char yaffs_test_dir[]){
+       char output=0;
+       char name[MAX_FILE_NAME_SIZE+3 ]="apple\0";
+       char path[MAX_FILE_NAME_SIZE+strlen(yaffs_test_dir)];
+       join_paths(yaffs_test_dir,name,path);
        while(1)
        {
-
+               path[0]='\0';// this should clear the path
                generate_random_string(name);
-               printf("the length of the string is %d \n",strlen(name)); 
-               printf("generated string is:");
-               for (x=0; x <= (strlen(name)-1)&&x<=MAX_FILE_NAME_SIZE ; x++)
-               {
-//                     printf("x=%d\n",x);
-                       printf("%c ",name[x]);
-               }
-               printf("\n");
+               join_paths(yaffs_test_dir,name,path);
+               add_to_buffer(&message_buffer,"trying to open file",MESSAGE_LEVEL_BASIC_TASKS);
+               add_to_buffer(&message_buffer,path,MESSAGE_LEVEL_BASIC_TASKS);
+               output=yaffs_open(path,O_CREAT | O_TRUNC| O_RDWR, S_IREAD | S_IWRITE);
+               yaffs_check_for_errors(output, &message_buffer,"failed to open file","opened file");
        }
 }
-void  generate_random_string(char *ptr)
-{
+void  generate_random_string(char *ptr){
        unsigned int x;
        unsigned int length=((rand() %MAX_FILE_NAME_SIZE)+1);   /*creates a int with the number of charecters been between 1 and 51*/           
-       printf("generating string\n");
-       printf("string length is %d\n",length);
+       //printf("generating string\n");
+       //printf("string length is %d\n",length);
        for (x=0; x <= (length-2) &&length>2 ; x++)
        {
-//             printf("x=%d\n",x);     
+               //printf("x=%d\n",x);   
                ptr[x]=(rand() % 126-32)+32;    /*generate a number between 32 and 126 and uses it as a charecter (letter) */
-//             printf("charecter generated is %c\n",ptr[x]);
+               //printf("charecter generated is %c\n",ptr[x]);
        }
-       ptr[x+1]=0;     /*adds NULL charecter to turn it into a string*/
+       ptr[x+1]='\0';  /*adds NULL charecter to turn it into a string*/
        
 }
 
index 1f96591..712563f 100644 (file)
@@ -2,24 +2,19 @@
 #ifndef __YAFFS_TESTER_H__
        #define __YAFFS_TESTER_H__
 
-       #include <stdio.h>
+#include <string.h>
+#include <stdio.h>
        
-       #include "yaffsfs.h"    /* it is in "yaffs2/direct/" link it in the Makefile */
+#include "yaffsfs.h"   /* it is in "yaffs2/direct/" link it in the Makefile */
+#include "message_buffer.h"
+#include "error_handler.h"
        
 
-       #define MAX_FILE_NAME_SIZE 51
-       #define BUFFER_MESSAGE_LENGTH 50                /*number of char in message*/
-       #define BUFFER_SIZE 50                  /*number of messages in buffer*/
-       typedef struct buffer_template
-       {
-               char message[BUFFER_SIZE][BUFFER_MESSAGE_LENGTH];
-               char head;
-               char tail;
-       }buffer; 
+#define MAX_FILE_NAME_SIZE 51
 
-       void init(char yaffs_test_dir[],char yaffs_mount_dir[]);        /*sets up yaffs and mounts yaffs */
-       void test(char yaffs_test_dir[]);                               /*contains the test code*/
-       void generate_random_string(char *ptr);                         /*generates a random string of letters to be used for a name*/
-       void add_to_buffer(buffer *p_Buffer, char message[]);           /*code for buffer*/
-       void print_buffer(buffer *p_Buffer);                            /*print all of the messages in the buffer*/ 
+void init(char yaffs_test_dir[],char yaffs_mount_dir[]);       /*sets up yaffs and mounts yaffs */
+void test(char yaffs_test_dir[]);                              /*contains the test code*/
+void generate_random_string(char *ptr);                                /*generates a random string of letters to be used for a name*/
+void join_paths(char path1[],char path2[],char *newpath );
+void copy_array(char from[],char *to, unsigned int from_offset,unsigned int to_offset);
 #endif