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 cdde95c..f240695 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 \
-               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 fe7a0bc..dee3a06 100644 (file)
@@ -7,6 +7,7 @@
 #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
index 1c23eb2..6a65287 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"},
-
        {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_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"}
 
index dbe60f5..70c9d06 100644 (file)
@@ -10,6 +10,8 @@
 #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);
index 30ff102..75a5f8c 100644 (file)
@@ -9,7 +9,7 @@ int test_open_file(void){
        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;
 }
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 806699b..d84bd51 100644 (file)
@@ -5,19 +5,12 @@ int test_yaffs_lseek(void){
        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");
@@ -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){
-               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");
index 1bd4ce7..772a0b4 100644 (file)
@@ -3,6 +3,7 @@
 #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);
index 9033107..d396ff6 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);
-               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");
+                               return -1;
                        }
                }
                else{
-                       printf("error reading file");
+                       printf("error reading file\n");
+                       return -1;
                }
        }
        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 4972dfb..795c8d4 100644 (file)
@@ -2,7 +2,13 @@
 
 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){
index 7a385f8..34cf38c 100644 (file)
@@ -4,6 +4,7 @@
 #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);
index adee496..08ff765 100644 (file)
@@ -6,12 +6,13 @@ int test_yaffs_write(void){
                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){
+       test_yaffs_lseek_to_beginning();
        return 1;
 }