From df369209e1ee1d05eba9527b1e6447e8e78d0988 Mon Sep 17 00:00:00 2001 From: Timothy Manning Date: Mon, 13 Dec 2010 15:23:16 +1300 Subject: [PATCH] yaffs Working on mirror_tests Signed-off-by: Timothy Manning --- direct/timothy_tests/mirror_tests/lib.c | 22 ++++++++ direct/timothy_tests/mirror_tests/lib.h | 2 +- .../mirror_tests/linux_test_open.c | 19 +++++-- .../timothy_tests/mirror_tests/mirror_tests.c | 50 +++++++++++++------ .../timothy_tests/mirror_tests/mirror_tests.h | 2 + .../mirror_tests/yaffs_test_open.c | 9 ++-- 6 files changed, 82 insertions(+), 22 deletions(-) diff --git a/direct/timothy_tests/mirror_tests/lib.c b/direct/timothy_tests/mirror_tests/lib.c index 4b9ebd6..0d14430 100644 --- a/direct/timothy_tests/mirror_tests/lib.c +++ b/direct/timothy_tests/mirror_tests/lib.c @@ -37,6 +37,28 @@ void display_error(void) { } + +void generate_random_string(char *ptr,int length_of_str){ + unsigned int x; + unsigned int length=((rand() %length_of_str)+1); /*creates a int with the number of charecters been between 1 and 51*/ + char letter='\0'; + strcpy(ptr,""); + //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); + /* keep generating a charecter until the charecter is legal*/ + while((letter=='\0' )||(letter=='/')||(letter=='\\')){ + letter=(rand() % 125-59)+58; /*generate a number between 32 and 126 and uses it as a charecter (letter) */ + } + ptr[x]=letter; + //printf("charecter generated is %c\n",ptr[x]); + } + ptr[x+1]='\0'; /*adds NULL charecter to turn it into a string*/ + +} + void join_paths(char *path1,char *path2,char *new_path ) { char message[100]; diff --git a/direct/timothy_tests/mirror_tests/lib.h b/direct/timothy_tests/mirror_tests/lib.h index 2e03573..99c2763 100644 --- a/direct/timothy_tests/mirror_tests/lib.h +++ b/direct/timothy_tests/mirror_tests/lib.h @@ -40,7 +40,7 @@ test_dir yaffs_struct,linux_struct; - +void generate_random_string(char *ptr,int length_of_str); void join_paths(char *path1,char *path2,char *new_path ); void print_message(char print_level, char *message); void set_print_level(int new_level); diff --git a/direct/timothy_tests/mirror_tests/linux_test_open.c b/direct/timothy_tests/mirror_tests/linux_test_open.c index 7817c3a..0f90039 100644 --- a/direct/timothy_tests/mirror_tests/linux_test_open.c +++ b/direct/timothy_tests/mirror_tests/linux_test_open.c @@ -15,11 +15,24 @@ int linux_test_open(arg_temp *args_struct) { - char path[200]; - char message[100]; + char path[250]; + char message[150]; + int output; join_paths(linux_struct.root_path,args_struct->string1, path ); sprintf(message,"file path: %s\n",path); print_message(3,message); - return open(path,args_struct->char1,args_struct->char2); + output= open(path,args_struct->char1 & (O_TRUNC|O_EXCL|O_CREAT|O_APPEND) ,args_struct->char2& (S_IREAD|S_IWRITE)); + if (output>=0){ + output=close(output); + if (output<0) { + print_message(3,"failed to close handle\n"); + return -1; + } else { + return 1; + } + } else { + print_message(3,"failed to open file\n"); + return -1; + } } diff --git a/direct/timothy_tests/mirror_tests/mirror_tests.c b/direct/timothy_tests/mirror_tests/mirror_tests.c index 319eb93..79c4dad 100644 --- a/direct/timothy_tests/mirror_tests/mirror_tests.c +++ b/direct/timothy_tests/mirror_tests/mirror_tests.c @@ -16,7 +16,7 @@ int random_seed; int simulate_power_failure = 0; - +int num_of_random_tests=1; @@ -46,7 +46,7 @@ test_temp linux_tests={ int main(int argc, char *argv[]) { char message[100]; - + int x; yaffs_tests.num_of_tests=(sizeof(yaffs_tests)/sizeof(test_temp)); linux_tests.num_of_tests=(sizeof(linux_tests)/sizeof(test_temp)); @@ -60,8 +60,9 @@ int main(int argc, char *argv[]) print_message(3,message); sprintf(message,"yaffs_num_of_tests: %d\n",yaffs_tests.num_of_tests); print_message(3,message); - + for (x=0;xchar1= (rand() % 255); args_struct->char2= (rand() % 255); args_struct->int1= (rand() % 100000); args_struct->int2= (rand() % 100000); - strcpy(args_struct->string1, "apple"); - strcpy(args_struct->string2, "apple"); + generate_random_string(string,50); + strcpy(args_struct->string1, string); + generate_random_string(string,50); + strcpy(args_struct->string2, string); } void run_yaffs_test(int id,arg_temp *args_struct) { char message[30]; int output =0; - print_message(2,"\n"); + print_message(3,"\n"); sprintf(message,"running_test %s\n",yaffs_tests.test_list[id].test_name); print_message(3,message); output=yaffs_tests.test_list[id].test_pointer(args_struct); if (output<0) { sprintf(message,"test_failed %s\n",yaffs_tests.test_list[id].test_name); - print_message(1,message); - get_error_yaffs(); + print_message(3,message); } else { print_message(3,"test_passed\n"); } @@ -207,14 +230,13 @@ void run_linux_test(int id,arg_temp *args_struct) { char message[30]; int output =0; - print_message(2,"\n"); + print_message(3,"\n"); sprintf(message,"running_test %s\n",linux_tests.test_list[id].test_name); print_message(3,message); output=linux_tests.test_list[id].test_pointer(args_struct); if (output<0) { sprintf(message,"test_failed %s\n",linux_tests.test_list[id].test_name); - print_message(1,message); - get_error_linux(); + print_message(3,message); } else { print_message(3,"test_passed\n"); } diff --git a/direct/timothy_tests/mirror_tests/mirror_tests.h b/direct/timothy_tests/mirror_tests/mirror_tests.h index 8c8b820..5493900 100644 --- a/direct/timothy_tests/mirror_tests/mirror_tests.h +++ b/direct/timothy_tests/mirror_tests/mirror_tests.h @@ -22,6 +22,7 @@ #include #include "yaffsfs.h" #include "lib.h" +#include #include "linux_test_open.h" #include "yaffs_test_open.h" @@ -38,6 +39,7 @@ void init(int argc, char *argv[]); int run_random_test(void); int compare_linux_and_yaffs(void); void get_error_yaffs(void); +void get_error_linux(void); int select_test_id(int test_len); void generate_random_numbers(arg_temp *args_struct); void run_yaffs_test(int id,arg_temp *args_struct); diff --git a/direct/timothy_tests/mirror_tests/yaffs_test_open.c b/direct/timothy_tests/mirror_tests/yaffs_test_open.c index e8b72b4..87a824b 100644 --- a/direct/timothy_tests/mirror_tests/yaffs_test_open.c +++ b/direct/timothy_tests/mirror_tests/yaffs_test_open.c @@ -17,21 +17,22 @@ int yaffs_test_open(arg_temp *args_struct) { char path[200]; char message[100]; + int output=0; join_paths(yaffs_struct.root_path,args_struct->string1, path ); sprintf(message,"file path: %s\n",path); print_message(3,message); - output=yaffs_open(path,args_struct->char1,args_struct->char2); + output=yaffs_open(path,args_struct->char1 &(O_TRUNC|O_EXCL|O_CREAT|O_APPEND),args_struct->char2&(S_IREAD|S_IWRITE)); if (output>=0){ output= yaffs_close(output); if (output<0) { - print_message(1,"failed to close handle\n"); - return -1 + print_message(3,"failed to close handle\n"); + return -1; } else { return 1; } } else { - print_message(1,"failed to close handle\n"); + print_message(3,"failed to open file\n"); return -1; } } -- 2.30.2