summaryrefslogtreecommitdiff
path: root/direct
diff options
context:
space:
mode:
authorTimothy Manning <tfhmanning@gmail.com>2010-12-13 15:23:16 +1300
committerTimothy Manning <tfhmanning@gmail.com>2010-12-15 11:32:30 +1300
commitdf369209e1ee1d05eba9527b1e6447e8e78d0988 (patch)
treed3028c6ab6e656dc403534d636481a8a79769bf1 /direct
parent137f935f6d622bffdef2fece0c5194e85f5174e9 (diff)
yaffs Working on mirror_tests
Signed-off-by: Timothy Manning <tfhmanning@gmail.com>
Diffstat (limited to 'direct')
-rw-r--r--direct/timothy_tests/mirror_tests/lib.c22
-rw-r--r--direct/timothy_tests/mirror_tests/lib.h2
-rw-r--r--direct/timothy_tests/mirror_tests/linux_test_open.c19
-rw-r--r--direct/timothy_tests/mirror_tests/mirror_tests.c50
-rw-r--r--direct/timothy_tests/mirror_tests/mirror_tests.h2
-rw-r--r--direct/timothy_tests/mirror_tests/yaffs_test_open.c9
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;x<num_of_random_tests;x++){
run_random_test();
+ }
return 0;
}
@@ -71,6 +72,8 @@ void init(int argc, char *argv[])
dir[0]='\0';
int x=-1;
char message[100];
+
+ srand(time(NULL));
linux_struct.type_of_test =LINUX;
yaffs_struct.type_of_test =YAFFS;
@@ -78,7 +81,7 @@ void init(int argc, char *argv[])
print_message(3,message);
strcpy(dir,getcwd(dir,200));
- strcat(dir,"/test");
+ strcat(dir,"/test/");
printf("dir: %s\n",dir);
strcpy(linux_struct.root_path,dir);
strcpy(yaffs_struct.root_path,"yaffs2/test/");
@@ -93,6 +96,8 @@ void init(int argc, char *argv[])
printf("\t-p [NUMBER] //sets the print level for mirror_tests.\n");
printf("\t-v //verbose mode everything is printed\n");
printf("\t-q //quiet mode nothing is printed.\n");
+ printf("\t-n [number] //sets the number of random tests to run.\n");
+ printf("\t-s [number] //seeds rand with the number\n");
exit(0);
} else if (strcmp(argv[x],"-yaffs_path")==0){
strcpy(yaffs_struct.root_path, argv[x+1]);
@@ -104,7 +109,11 @@ void init(int argc, char *argv[])
set_print_level(5);
} else if (strcmp(argv[x],"-q")==0){
set_print_level(-1);
- }
+ } else if (strcmp(argv[x],"-n")==0){
+ num_of_random_tests=atoi(argv[x+1]);
+ } else if (strcmp(argv[x],"-n")==0){
+ srand(atoi(argv[x+1]));
+ }
}
yaffs_start_up();
@@ -146,12 +155,24 @@ int run_random_test(void)
char message[15];
arg_temp args_struct;
for (x=0;x<num_of_tests;x++) {
+ errno=0;
+ yaffs_set_error(0);
test_id = select_test_id(yaffs_tests.num_of_tests);
sprintf(message,"test_id %d\n",test_id);
- print_message(2,message);
+ print_message(3,message);
generate_random_numbers(&args_struct);
run_yaffs_test(id, &args_struct);
run_linux_test(id, &args_struct);
+ if ((abs(yaffs_get_error())!=abs(errno)) &&
+ (abs(yaffs_get_error())!=EISDIR && abs(errno) != 0)
+ ){
+ print_message(2,"\ndiffrence in returned errors######################################\n");
+ get_error_yaffs();
+ get_error_linux();
+ if (get_exit_on_error()){
+ exit(0);
+ }
+ }
}
compare_linux_and_yaffs();
}
@@ -178,26 +199,28 @@ int compare_linux_and_yaffs(void)
void generate_random_numbers(arg_temp *args_struct)
{
+ char string[51];
args_struct->char1= (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 <errno.h>
#include "yaffsfs.h"
#include "lib.h"
+#include <time.h>
#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;
}
}