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 50723c3e1e6efbb907f64e836757706e51479a4e..25a7942514ac8f2672a75060523bbb5d85199409 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 c7d67d28ebb095ea359be04a1da8154497c1a5f8..094db3b95983dc53c34e53f36f4b132a9b4760b1 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 a3f6463304d3ec866645db8e413ee90fb8dd83ee..6f91ffa2ab4491c63ad012018ba2714fce34feee 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 c3d9a71957d43a9aebbb35d2db8dd00a5452856d..c333c3f90bedcccd9f190b8b0ddde68a8c937096 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 922f4312a566e057e35abfa2361792572ead026e..4e5a2a497b4ede65fb87b5a876501891d87efc8b 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 c1f6c90fd8ab71bd053acd577acf380f43205506..7729369ea333d56486b7801039fb1ac4f48e05de 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 4ec6a7467fbfaa54c8c7b2cda0cdb8762b909109..6b0fc98cfebb56d4c639e92ec2cc6840ea80ba6f 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 70e3db7a495d84d9f9a146cec7ace8a52b24adeb..18a28e6bb1c626b3cfde4c10acc10db80dacf2fb 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 f86b705b7d685654f7a57382045eb0fae746a792..059e0b9ef32b9044283541a9c5acd59492ead726 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 9b37209fd835119c098a2faa92e130b1ed6d84e9..bc6f01f55b7de101132dd195b670ea80d8732033 100644 (file)
@@ -13,7 +13,7 @@
 
 #include "test_yaffs_rename_dir.h"
 
-
+/*tests renaming a non empty file */
 int test_yaffs_rename_dir(void)
 {
        int output=0;
index b191dbb9d18839ec4febbcb0fa830e733ebfd9cb..02a068dacb084e12f66819d372db2f54c43f98f4 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 efc87d0f2405c031e10a5f4e284b4d1618632405..f4bd775dc259e5b592989404bf322f8f2a684841 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);