yaffs Are trapping a suspeced bug in quick_tests.
authorTimothy Manning <tfhmanning@gmail.com>
Wed, 3 Nov 2010 00:55:42 +0000 (13:55 +1300)
committerTimothy Manning <tfhmanning@gmail.com>
Wed, 3 Nov 2010 03:27:09 +0000 (16:27 +1300)
the bug is beleved to be when yaffs_read() is called on a 0 length file.
Signed-off-by: Timothy Manning <tfhmanning@gmail.com>
15 files changed:
direct/timothy_tests/quick_tests/Makefile
direct/timothy_tests/quick_tests/lib.h
direct/timothy_tests/quick_tests/quick_tests.c
direct/timothy_tests/quick_tests/quick_tests.h
direct/timothy_tests/quick_tests/test_open_file.c
direct/timothy_tests/quick_tests/test_yaffs_access.c [new file with mode: 0644]
direct/timothy_tests/quick_tests/test_yaffs_access.h [new file with mode: 0644]
direct/timothy_tests/quick_tests/test_yaffs_lseek.c
direct/timothy_tests/quick_tests/test_yaffs_lseek.h
direct/timothy_tests/quick_tests/test_yaffs_read.c
direct/timothy_tests/quick_tests/test_yaffs_stat.c [new file with mode: 0644]
direct/timothy_tests/quick_tests/test_yaffs_stat.h [new file with mode: 0644]
direct/timothy_tests/quick_tests/test_yaffs_unlinking.c
direct/timothy_tests/quick_tests/test_yaffs_unlinking.h
direct/timothy_tests/quick_tests/test_yaffs_write.c

index cdde95c75cf6ac9ee1ef386dc5c06c13608b515e..f240695630bc735860c7dd74a1dfe071fe1103ec 100644 (file)
@@ -45,7 +45,7 @@ COMMONTESTOBJS = yaffscfg2k.o yaffs_ecc.o yaffs_fileem.o yaffs_fileem2k.o yaffsf
 #               yaffs_checkptrwtest.o\
 
 YAFFSTESTOBJS  = $(COMMONTESTOBJS) quick_tests.o lib.o test_mount_yaffs.o   test_yaffs_unlinking.o test_open_file.o test_yaffs_ftruncate.o test_yaffs_truncate.o \
 #               yaffs_checkptrwtest.o\
 
 YAFFSTESTOBJS  = $(COMMONTESTOBJS) quick_tests.o lib.o test_mount_yaffs.o   test_yaffs_unlinking.o test_open_file.o test_yaffs_ftruncate.o test_yaffs_truncate.o \
-               test_yaffs_write.o test_yaffs_read.o test_yaffs_lseek.o
+               test_yaffs_write.o test_yaffs_read.o test_yaffs_lseek.o test_yaffs_access.o test_yaffs_stat.o
 
 
 
 
 
 
index fe7a0bc0c765febeab1048f5cc94271bc02c28c2..dee3a068ec825b186d5461d8ad8a5e92420ff3f4 100644 (file)
@@ -7,6 +7,7 @@
 #define FILE_NAME "foo"
 #define FILE_SIZE 9
 
 #define FILE_NAME "foo"
 #define FILE_SIZE 9
 
+#define FILE_MODE (S_IREAD | S_IWRITE)
 #define FILE_SIZE_TRUNCATED 100
 #define FILE_TEXT "file foo"
 #define FILE_TEXT_NBYTES 9
 #define FILE_SIZE_TRUNCATED 100
 #define FILE_TEXT "file foo"
 #define FILE_TEXT_NBYTES 9
index 1c23eb2f6b48c323f9988970866db96a486f9498..6a65287109fff15bf258917c3a809e8900f39f16 100644 (file)
@@ -31,14 +31,16 @@ test_template test_list[]={
        //{dummy_test_pass,dummy_test_pass_clean,"dummy_test_pass"},
        //{dummy_test_fail,dummy_test_fail_clean,"dummy_test_fail"},
        {mount_yaffs_test,mount_yaffs_test_clean,"mount_yaffs_test"},
        //{dummy_test_pass,dummy_test_pass_clean,"dummy_test_pass"},
        //{dummy_test_fail,dummy_test_fail_clean,"dummy_test_fail"},
        {mount_yaffs_test,mount_yaffs_test_clean,"mount_yaffs_test"},
-
        {test_open_file,test_open_file_clean,"test_open_file"},
        {test_open_file,test_open_file_clean,"test_open_file"},
+       
+       {test_yaffs_access,test_yaffs_access_clean,"test_yaffs_access"},
        {test_yaffs_unlinking, test_yaffs_unlinking_clean,"test_yaffs_unlinking"},
 
        {test_yaffs_lseek,test_yaffs_lseek_clean,"test_yaffs_lseek"},
        {test_yaffs_read,test_yaffs_read_clean,"test_yaffs_read"},
        {test_yaffs_write,test_yaffs_write_clean,"test_yaffs_write"},
 
        {test_yaffs_unlinking, test_yaffs_unlinking_clean,"test_yaffs_unlinking"},
 
        {test_yaffs_lseek,test_yaffs_lseek_clean,"test_yaffs_lseek"},
        {test_yaffs_read,test_yaffs_read_clean,"test_yaffs_read"},
        {test_yaffs_write,test_yaffs_write_clean,"test_yaffs_write"},
 
+       {test_yaffs_stat,test_yaffs_stat_clean,"test_yaffs_stat"},
        {test_yaffs_ftruncate,test_yaffs_ftruncate_clean,"test_yaffs_ftruncate"},
        {test_yaffs_truncate,test_yaffs_truncate_clean,"test_yaffs_truncate"}
 
        {test_yaffs_ftruncate,test_yaffs_ftruncate_clean,"test_yaffs_ftruncate"},
        {test_yaffs_truncate,test_yaffs_truncate_clean,"test_yaffs_truncate"}
 
index dbe60f57b80fbbaa9e186923de212c7ab18a7e93..70c9d06207a40f51f53a53a312113d914e112947 100644 (file)
@@ -10,6 +10,8 @@
 #include "test_yaffs_write.h"
 #include "test_yaffs_read.h"
 #include "test_yaffs_lseek.h"
 #include "test_yaffs_write.h"
 #include "test_yaffs_read.h"
 #include "test_yaffs_lseek.h"
+#include "test_yaffs_access.h"
+#include "test_yaffs_stat.h"
 #define YAFFS_MOUNT_POINT "/yaffs2/"
 
 void init_quick_tests(void);
 #define YAFFS_MOUNT_POINT "/yaffs2/"
 
 void init_quick_tests(void);
index 30ff1020e7637e781d3e468daa56dc9ca4c36355..75a5f8c110adb633ac1f899b1c245abb111c2cb0 100644 (file)
@@ -9,7 +9,7 @@ int test_open_file(void){
        int output=0;
 
        /*printf("path %s\n",path); */
        int output=0;
 
        /*printf("path %s\n",path); */
-       output=yaffs_open(FILE_PATH,O_CREAT | O_TRUNC| O_RDWR, S_IREAD | S_IWRITE);
+       output=yaffs_open(FILE_PATH,O_CREAT | O_TRUNC| O_RDWR, FILE_MODE);
 
        return output;
 }
 
        return output;
 }
diff --git a/direct/timothy_tests/quick_tests/test_yaffs_access.c b/direct/timothy_tests/quick_tests/test_yaffs_access.c
new file mode 100644 (file)
index 0000000..a88664f
--- /dev/null
@@ -0,0 +1,9 @@
+#include "test_yaffs_access.h"
+
+int test_yaffs_access(void){
+               return yaffs_access(FILE_PATH,0);
+}
+
+int test_yaffs_access_clean(void){
+       return 1;
+}
diff --git a/direct/timothy_tests/quick_tests/test_yaffs_access.h b/direct/timothy_tests/quick_tests/test_yaffs_access.h
new file mode 100644 (file)
index 0000000..181493d
--- /dev/null
@@ -0,0 +1,9 @@
+#ifndef __test_yaffs_access_h__
+#define __test_yaffs_access_h__
+#include "lib.h"
+#include "yaffsfs.h"
+#include "test_open_file.h"
+#include "test_yaffs_lseek.h"
+int test_yaffs_access(void);
+int test_yaffs_access_clean(void);
+#endif
index 806699b57fbd8f71bce1306b83148e0be20f4054..d84bd512949921074e225afcbdce7ef95a75003f 100644 (file)
@@ -5,19 +5,12 @@ int test_yaffs_lseek(void){
        char text[20]="\0";
        int output=0;
        if (handle>0){
        char text[20]="\0";
        int output=0;
        if (handle>0){
-               return yaffs_lseek(handle, 0, SEEK_SET);
-               /*
-               if (output>0){
-                       if (text==FILE_TEXT){
-                               return 1;
-                       }
-                       else {
-                               printf("text does not match the the text that should be in the file\n");
-                       }
+               if (0==yaffs_lseek(handle, 0, SEEK_SET)){
+                       return 1;
+               }
+               else {
+                       printf("lseek returned a different position to the expeced position\n");
                }
                }
-               else{
-                       printf("error reading file");
-               } */
        }
        else {
                printf("error opening file\n");
        }
        else {
                printf("error opening file\n");
@@ -33,7 +26,12 @@ int test_yaffs_lseek_clean(void){
 int test_yaffs_lseek_to_beginning(void){
        int handle=test_open_file();
        if (handle>0){
 int test_yaffs_lseek_to_beginning(void){
        int handle=test_open_file();
        if (handle>0){
-               return yaffs_lseek(handle, 0, SEEK_SET);
+               if (0==yaffs_lseek(handle, 0, SEEK_SET)){       /*lseek returns the position of the seeker */
+                       return 1;
+               }
+               else {
+                       printf("lseek returned a different position to the expeced position\n");
+               } 
        }
        else {
                printf("error opening file\n");
        }
        else {
                printf("error opening file\n");
index 1bd4ce7def6eaed74fac35f40d1ea94e28ef574d..772a0b47b5152a10993ab16a43b3469bd95ee1fe 100644 (file)
@@ -3,6 +3,7 @@
 #include "lib.h"
 #include "yaffsfs.h"
 #include "test_open_file.h"
 #include "lib.h"
 #include "yaffsfs.h"
 #include "test_open_file.h"
+
 int test_yaffs_lseek(void);
 int test_yaffs_lseek_clean(void);
 int test_yaffs_lseek_to_beginning(void);
 int test_yaffs_lseek(void);
 int test_yaffs_lseek_clean(void);
 int test_yaffs_lseek_to_beginning(void);
index 9033107d9f5762e59870e54eec38662a9c6d9573..d396ff607efa8075169568411b2b55dfb0bf9724 100644 (file)
@@ -6,16 +6,19 @@ int test_yaffs_read(void){
        int output=0;
        if (handle>0){
                output=yaffs_read(handle, text, FILE_TEXT_NBYTES);
        int output=0;
        if (handle>0){
                output=yaffs_read(handle, text, FILE_TEXT_NBYTES);
-               if (output>0){
+               printf("output: %d\n",output);
+               if (output>0){ 
                        if (text==FILE_TEXT){
                                return 1;
                        }
                        else {
                                printf("text does not match the the text that should be in the file\n");
                        if (text==FILE_TEXT){
                                return 1;
                        }
                        else {
                                printf("text does not match the the text that should be in the file\n");
+                               return -1;
                        }
                }
                else{
                        }
                }
                else{
-                       printf("error reading file");
+                       printf("error reading file\n");
+                       return -1;
                }
        }
        else {
                }
        }
        else {
diff --git a/direct/timothy_tests/quick_tests/test_yaffs_stat.c b/direct/timothy_tests/quick_tests/test_yaffs_stat.c
new file mode 100644 (file)
index 0000000..d6c0eff
--- /dev/null
@@ -0,0 +1,67 @@
+#include "test_yaffs_stat.h"
+
+int test_yaffs_stat(void){
+       int mode=0;
+       int size=0;
+       mode =yaffs_test_stat_mode();
+       printf("\nmode %o\n",mode);
+       printf("expected mode %o \n",FILE_MODE);
+       printf("anding together %o\n",FILE_MODE & mode);
+       printf("%d\n",FILE_MODE == (FILE_MODE & mode));
+       if (FILE_MODE == (FILE_MODE & mode)){
+               mode=1;
+       }
+       else {
+               printf("mode did not match expected file mode\n");
+               return -1;
+       }
+       if (yaffs_test_stat_size()==FILE_SIZE){
+               size=1;
+       }
+       else {
+               printf("mode did not match expected file mode\n");
+               return -1;
+       }
+       
+       if (mode && size){
+               return 1;
+       }
+       else {
+               /* a test failed*/
+               return -1;
+       }
+
+}
+
+int test_yaffs_stat_clean(void){
+       return test_open_file();
+}
+
+int yaffs_test_stat_mode(void){
+       struct yaffs_stat stat;
+       int output=0;
+       output=yaffs_stat(FILE_PATH, &stat);
+       printf("output: %d\n",output);
+       if (output>=0){
+               return stat.st_mode;    
+       }
+       else {
+               printf("failed to stat file\n") ;
+               return -1;
+       }
+}
+
+int yaffs_test_stat_size(void){
+       struct yaffs_stat stat;
+       int output=0;
+       output=yaffs_stat(FILE_PATH, &stat); 
+       if (output>=0){
+               return stat.st_size;    
+       }
+       else {
+               printf("failed to stat file\n") ;
+               return -1;
+       }
+}
+
+
diff --git a/direct/timothy_tests/quick_tests/test_yaffs_stat.h b/direct/timothy_tests/quick_tests/test_yaffs_stat.h
new file mode 100644 (file)
index 0000000..2072be4
--- /dev/null
@@ -0,0 +1,11 @@
+#ifndef __test_yaffs_stat_h__
+#define __test_yaffs_stat_h__
+#include "lib.h"
+#include "yaffsfs.h"
+#include "test_open_file.h"
+#include "test_yaffs_lseek.h"
+int test_yaffs_stat(void);
+int test_yaffs_stat_clean(void);
+int yaffs_test_stat_mode(void);
+int yaffs_test_stat_size(void);
+#endif
index 4972dfb10f5f3a37abe38685e6161d4e14b678c6..795c8d4cccc47ad55d0a530ff8f23b9335c12392 100644 (file)
@@ -2,7 +2,13 @@
 
 int test_yaffs_unlinking(void){
        int output=yaffs_unlink(FILE_PATH);
 
 int test_yaffs_unlinking(void){
        int output=yaffs_unlink(FILE_PATH);
-       return output;
+       if (output>=0){
+               return (-test_yaffs_access());  /*return negative access. we do not want the file to be there*/
+       }
+       else {
+               printf("failed to unlink file\n") ;
+               return -1;
+       }
 }
 
 int test_yaffs_unlinking_clean(void){
 }
 
 int test_yaffs_unlinking_clean(void){
index 7a385f8985f330b9486c353b364ea6d569f83aef..34cf38cea414270caa44f267c8bbbd8a3b13c7ce 100644 (file)
@@ -4,6 +4,7 @@
 #include "lib.h"
 #include "yaffsfs.h"
 #include "test_open_file.h"
 #include "lib.h"
 #include "yaffsfs.h"
 #include "test_open_file.h"
+#include "test_yaffs_access.h"
 
 int test_yaffs_unlinking(void);
 int test_yaffs_unlinking_clean(void);
 
 int test_yaffs_unlinking(void);
 int test_yaffs_unlinking_clean(void);
index adee496718d7de05db0076d1655cefe53f8f87cc..08ff7659aee5fe0ea27a950fb82fd1fb7469776e 100644 (file)
@@ -6,12 +6,13 @@ int test_yaffs_write(void){
                return yaffs_write(handle, FILE_TEXT, FILE_TEXT_NBYTES);
        }
        else {
                return yaffs_write(handle, FILE_TEXT, FILE_TEXT_NBYTES);
        }
        else {
-               printf("error opening file");
+               printf("error opening file\n");
                return -1;
        }
        
 }
 
 int test_yaffs_write_clean(void){
                return -1;
        }
        
 }
 
 int test_yaffs_write_clean(void){
+       test_yaffs_lseek_to_beginning();
        return 1;
 }
        return 1;
 }