From 17c2897913447766bfd88fd49ca897821a3d2205 Mon Sep 17 00:00:00 2001 From: Timothy Manning Date: Thu, 17 Jan 2013 11:54:46 +1300 Subject: [PATCH] working on the quick tests Signed-off-by: Timothy Manning --- .../timothy_tests/quick_tests/lib.c | 50 ++++++++++++++++++- .../timothy_tests/quick_tests/lib.h | 26 +++++----- .../timothy_tests/quick_tests/quick_tests.c | 31 ++++++------ .../quick_tests/test_yaffs_open_EACCES.c | 5 +- .../quick_tests/test_yaffs_open_EEXIST.c | 1 + .../quick_tests/test_yaffs_open_EINVAL.c | 1 + .../quick_tests/test_yaffs_open_ENOTDIR.c | 3 +- .../quick_tests/test_yaffs_rename_dir.c | 2 +- .../test_yaffs_rename_dir_ENOENT.c | 2 +- .../test_yaffs_rename_dir_not_empty.c | 2 +- .../test_yaffs_rename_dir_to_file.c | 4 +- .../test_yaffs_rename_file_to_dir.c | 7 +++ 12 files changed, 96 insertions(+), 38 deletions(-) diff --git a/direct/test-framework/timothy_tests/quick_tests/lib.c b/direct/test-framework/timothy_tests/quick_tests/lib.c index 50723c3..25a7942 100644 --- a/direct/test-framework/timothy_tests/quick_tests/lib.c +++ b/direct/test-framework/timothy_tests/quick_tests/lib.c @@ -125,9 +125,55 @@ void join_paths(char *path1,char *path2,char *new_path ) void print_message(char *message,char print_level) { if (print_level <= PRINT_LEVEL){ - printf(message); + printf("%s",message); } } - +/*same as forcing the rmdir of a directory*/ +int delete_dir(char *dir_name) +{ + yaffs_DIR *d; + struct yaffs_dirent *de; + struct yaffs_stat s; + char str[100]; + d = yaffs_opendir(dir_name); + printf("%s\n",dir_name); + if(!d) + { + printf("%s\n",dir_name); + print_message("failed to open dir\n",2); + get_error(); + return -1; + } + + while((de = yaffs_readdir(d)) != NULL) { + //stats the file + sprintf(str,"%s/%s",dir_name,de->d_name); + yaffs_lstat(str,&s); + + if ((s.st_mode & S_IFMT) == S_IFDIR){ + //it is a directory. call the function recursivly. + delete_dir(str); + yaffs_rmdir(str); + }else{ + yaffs_unlink(str); + } + } + yaffs_rmdir(dir_name); + yaffs_closedir(d); + return 1; +} + +void get_error(void) +{ + int error_code=0; + char message[30]; + message[0]='\0'; + + error_code=yaffs_get_error(); + sprintf(message,"yaffs_error code %d\n",error_code); + print_message(message,1); + sprintf(message,"error is : %s\n",yaffs_error_to_str(error_code)); + print_message(message,1); +} diff --git a/direct/test-framework/timothy_tests/quick_tests/lib.h b/direct/test-framework/timothy_tests/quick_tests/lib.h index c7d67d2..094db3b 100644 --- a/direct/test-framework/timothy_tests/quick_tests/lib.h +++ b/direct/test-framework/timothy_tests/quick_tests/lib.h @@ -22,33 +22,33 @@ #define YAFFS_MOUNT_POINT "/yaffs2/" -#define FILE_NAME "foo" +#define FILE_NAME "test_dir/foo" #define FILE_SIZE 10 #define FILE_MODE (S_IREAD | S_IWRITE) #define FILE_SIZE_TRUNCATED 100 #define FILE_TEXT "file foo " /* keep space at end of string */ #define FILE_TEXT_NBYTES 10 +#define TEST_DIR "/yaffs2/test_dir" +#define DIR_PATH "/yaffs2/test_dir/new_directory" -#define DIR_PATH "/yaffs2/new_directory" +#define SYMLINK_PATH "/yaffs2/test_dir/sym_foo" -#define SYMLINK_PATH "/yaffs2/sym_foo" +#define HARD_LINK_PATH "/yaffs2/test_dir/hard_link" -#define HARD_LINK_PATH "/yaffs2/hard_link" +#define NODE_PATH "/yaffs2/test_dir/node" -#define NODE_PATH "/yaffs2/node" +#define RENAME_PATH "/yaffs2/test_dir/foo2" -#define RENAME_PATH "/yaffs2/foo2" +#define RENAME_DIR_PATH "/yaffs2/test_dir/dir2" -#define RENAME_DIR_PATH "/yaffs2/dir2" +#define ELOOP_PATH "/yaffs2/test_dir/ELOOP" +#define ELOOP2_PATH "/yaffs2/test_dir/ELOOP2" -#define ELOOP_PATH "/yaffs2/ELOOP" -#define ELOOP2_PATH "/yaffs2/ELOOP2" - -#define RMDIR_PATH "/yaffs2/RM_DIR" +#define RMDIR_PATH "/yaffs2/test_dir/RM_DIR" /* warning do not define anything as FILE because there seems to be a conflict with stdio.h */ -#define FILE_PATH "/yaffs2/foo" +#define FILE_PATH "/yaffs2/test_dir/foo" void join_paths(char *path1,char *path2,char *new_path ); void print_message(char *message,char print_level); @@ -58,4 +58,6 @@ int get_exit_on_error(void); int set_up_ELOOP(void); int EROFS_setup(void); int EROFS_clean(void); +int delete_dir(char *dir_name); +void get_error(void); #endif diff --git a/direct/test-framework/timothy_tests/quick_tests/quick_tests.c b/direct/test-framework/timothy_tests/quick_tests/quick_tests.c index a3f6463..6f91ffa 100644 --- a/direct/test-framework/timothy_tests/quick_tests/quick_tests.c +++ b/direct/test-framework/timothy_tests/quick_tests/quick_tests.c @@ -50,14 +50,15 @@ int main(int argc, char *argv[]) } /*this is where the loop should break to*/ quit_quick_tests(0); + } void run_random_test_loop(void) { int id=0; - int x=0; - int run_list[total_number_of_tests]; + unsigned int x=0; + //int run_list[total_number_of_tests]; for (x=0;x