working on the quick tests
authorTimothy Manning <tfhmanning@gmail.com>
Wed, 16 Jan 2013 22:54:46 +0000 (11:54 +1300)
committerTimothy Manning <tfhmanning@gmail.com>
Wed, 16 Jan 2013 22:54:46 +0000 (11:54 +1300)
Signed-off-by: Timothy Manning <tfhmanning@gmail.com>
12 files changed:
direct/test-framework/timothy_tests/quick_tests/lib.c
direct/test-framework/timothy_tests/quick_tests/lib.h
direct/test-framework/timothy_tests/quick_tests/quick_tests.c
direct/test-framework/timothy_tests/quick_tests/test_yaffs_open_EACCES.c
direct/test-framework/timothy_tests/quick_tests/test_yaffs_open_EEXIST.c
direct/test-framework/timothy_tests/quick_tests/test_yaffs_open_EINVAL.c
direct/test-framework/timothy_tests/quick_tests/test_yaffs_open_ENOTDIR.c
direct/test-framework/timothy_tests/quick_tests/test_yaffs_rename_dir.c
direct/test-framework/timothy_tests/quick_tests/test_yaffs_rename_dir_ENOENT.c
direct/test-framework/timothy_tests/quick_tests/test_yaffs_rename_dir_not_empty.c
direct/test-framework/timothy_tests/quick_tests/test_yaffs_rename_dir_to_file.c
direct/test-framework/timothy_tests/quick_tests/test_yaffs_rename_file_to_dir.c

index 50723c3..25a7942 100644 (file)
@@ -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);
+}
 
index c7d67d2..094db3b 100644 (file)
 
 
 #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
index a3f6463..6f91ffa 100644 (file)
@@ -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<total_number_of_tests;x++){ 
                id = (rand() % (total_number_of_tests-1));
                run_test(id);   
@@ -77,8 +78,10 @@ void logical_run_of_tests(void)
 void run_test(int x)
 {
        int output=0;
+       int y= 0;
        char message[200];
        message[0]='\0';
+       printf ("making test dir %d\n",yaffs_mkdir(TEST_DIR,S_IWRITE | S_IREAD));
 
        yaffs_set_error(0);     /*reset the last error to 0 */
        //printf("foo exists %d\n",test_yaffs_open());
@@ -121,12 +124,18 @@ void run_test(int x)
                sprintf(message,"\ttest clean: %s passed\n",test_list[x].name_of_test);
                print_message(message,3);
        }
+       /* close all open handles */
+       for (y=0; y<100;y++){
+               yaffs_close(y);
+       }
+       delete_dir(TEST_DIR);
 }
 
 void quit_quick_tests(int exit_code)
 {
-       char message[30];
-       message[0]='\0';        
+       /*char message[30];
+       message[0]='\0';
+       */      
        if (num_of_tests_pass==total_number_of_tests &&  num_of_tests_failed==0){
                printf("\t OK --all tests passed\n");
        }
@@ -135,24 +144,12 @@ void quit_quick_tests(int exit_code)
        exit(exit_code);
 }
 
-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);
-}
 
 void init_quick_tests(int argc, char *argv[])
 {
        int trace=0;
        int new_option;
-       int x=0;        
+       //int x=0;      
        do{
                new_option=getopt_long(argc,argv,short_options,long_options,NULL);              
                if (new_option=='h'){
index c3d9a71..c333c3f 100644 (file)
@@ -20,7 +20,10 @@ int test_yaffs_open_EACCES(void)
        int error_code=0;
        int output =-1;
        if (yaffs_access(FILE_PATH,0)!=0){
-               output=yaffs_close(test_yaffs_open());
+               
+               handle = yaffs_open(FILE_PATH, O_CREAT | O_RDWR, FILE_MODE);
+
+               output=yaffs_close(handle);
                if (output<0){
                        print_message("failed to open file\n",2);
                        return -1;
index 922f431..4e5a2a4 100644 (file)
@@ -18,6 +18,7 @@ static int handle = -1;
 int test_yaffs_open_EEXIST(void)
 {
        int error_code = 0;
+       handle = yaffs_open(FILE_PATH, O_CREAT | O_EXCL | O_TRUNC| O_RDWR ,FILE_MODE );
 
        handle = yaffs_open(FILE_PATH, O_CREAT | O_EXCL | O_TRUNC| O_RDWR ,FILE_MODE );
        if (handle == -1){
index c1f6c90..7729369 100644 (file)
@@ -18,6 +18,7 @@ static int handle = -1;
 int test_yaffs_open_EINVAL(void)
 {
        int error_code = 0;
+       handle = yaffs_open(FILE_PATH, O_CREAT | O_RDWR, FILE_MODE);
 
        handle=yaffs_open(FILE_PATH, 255,FILE_MODE);
        if (handle == -1){
index 4ec6a74..6b0fc98 100644 (file)
@@ -18,8 +18,9 @@ static int handle = -1;
 int test_yaffs_open_ENOTDIR(void)
 {
        int error_code=0;
+       handle = yaffs_open(FILE_PATH,O_CREAT | O_RDWR, FILE_MODE);
 
-       handle=yaffs_open("/yaffs2/foo/file", O_TRUNC| O_RDWR,FILE_MODE );
+       handle=yaffs_open("/yaffs2/test_dir/foo/file", O_TRUNC| O_RDWR,FILE_MODE );
        if (handle <0){
                error_code=yaffs_get_error();
                if (abs(error_code)==ENOTDIR){
index 70e3db7..18a28e6 100644 (file)
@@ -13,7 +13,7 @@
 
 #include "test_yaffs_rename_dir.h"
 
-
+/*creates a new directory and renames it*/
 int test_yaffs_rename_dir(void)
 {
        int output=0;
index f86b705..059e0b9 100644 (file)
@@ -13,7 +13,7 @@
 
 #include "test_yaffs_rename_dir_ENOENT.h"
 
-
+/*tries to rename a nonexisting directory */
 int test_yaffs_rename_dir_ENOENT(void)
 {
        int output=0;
index b191dbb..02a068d 100644 (file)
@@ -13,7 +13,7 @@
 
 #include "test_yaffs_rename_dir_to_file.h"
 
-
+/*tries to rename a directory over an existing file */
 int test_yaffs_rename_dir_to_file(void)
 {
        int output=0;
@@ -21,7 +21,7 @@ int test_yaffs_rename_dir_to_file(void)
        if (0 !=  yaffs_access(DIR_PATH,0)) {
                output= yaffs_mkdir(DIR_PATH,(S_IREAD | S_IWRITE));
                if (output<0) {
-                       print_message("failed to remove directory\n",2);
+                       print_message("failed to create directory\n",2);
                        return -1;
                }
        }
index efc87d0..f4bd775 100644 (file)
@@ -31,6 +31,13 @@ int test_yaffs_rename_file_to_dir(void)
                        }
                }
        }
+       if (0 !=  yaffs_access(RENAME_DIR_PATH,0)) {
+               output = yaffs_mkdir(RENAME_DIR_PATH,S_IWRITE | S_IREAD);
+               if (output < 0) {
+                       print_message("failed to create directory\n",2);
+                       return -1;
+               }
+       }
        output = yaffs_rename( "/yaffs2/foo" , RENAME_DIR_PATH);
        if (output<0){ 
                print_message("failed to rename a file over an empty directory\n",2);