From: Timothy Manning Date: Wed, 3 Nov 2010 00:55:42 +0000 (+1300) Subject: yaffs Are trapping a suspeced bug in quick_tests. X-Git-Tag: linux-mainline-patchset-4~122 X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs2.git;a=commitdiff_plain;h=6bdb202d06f1e3dc8cc00dea708ebbd7fb771342 yaffs Are trapping a suspeced bug in quick_tests. the bug is beleved to be when yaffs_read() is called on a 0 length file. Signed-off-by: Timothy Manning --- diff --git a/direct/timothy_tests/quick_tests/Makefile b/direct/timothy_tests/quick_tests/Makefile index cdde95c..f240695 100644 --- a/direct/timothy_tests/quick_tests/Makefile +++ b/direct/timothy_tests/quick_tests/Makefile @@ -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 diff --git a/direct/timothy_tests/quick_tests/lib.h b/direct/timothy_tests/quick_tests/lib.h index fe7a0bc..dee3a06 100644 --- a/direct/timothy_tests/quick_tests/lib.h +++ b/direct/timothy_tests/quick_tests/lib.h @@ -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 diff --git a/direct/timothy_tests/quick_tests/quick_tests.c b/direct/timothy_tests/quick_tests/quick_tests.c index 1c23eb2..6a65287 100644 --- a/direct/timothy_tests/quick_tests/quick_tests.c +++ b/direct/timothy_tests/quick_tests/quick_tests.c @@ -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"} diff --git a/direct/timothy_tests/quick_tests/quick_tests.h b/direct/timothy_tests/quick_tests/quick_tests.h index dbe60f5..70c9d06 100644 --- a/direct/timothy_tests/quick_tests/quick_tests.h +++ b/direct/timothy_tests/quick_tests/quick_tests.h @@ -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); diff --git a/direct/timothy_tests/quick_tests/test_open_file.c b/direct/timothy_tests/quick_tests/test_open_file.c index 30ff102..75a5f8c 100644 --- a/direct/timothy_tests/quick_tests/test_open_file.c +++ b/direct/timothy_tests/quick_tests/test_open_file.c @@ -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 index 0000000..a88664f --- /dev/null +++ b/direct/timothy_tests/quick_tests/test_yaffs_access.c @@ -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 index 0000000..181493d --- /dev/null +++ b/direct/timothy_tests/quick_tests/test_yaffs_access.h @@ -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 diff --git a/direct/timothy_tests/quick_tests/test_yaffs_lseek.c b/direct/timothy_tests/quick_tests/test_yaffs_lseek.c index 806699b..d84bd51 100644 --- a/direct/timothy_tests/quick_tests/test_yaffs_lseek.c +++ b/direct/timothy_tests/quick_tests/test_yaffs_lseek.c @@ -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"); diff --git a/direct/timothy_tests/quick_tests/test_yaffs_lseek.h b/direct/timothy_tests/quick_tests/test_yaffs_lseek.h index 1bd4ce7..772a0b4 100644 --- a/direct/timothy_tests/quick_tests/test_yaffs_lseek.h +++ b/direct/timothy_tests/quick_tests/test_yaffs_lseek.h @@ -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); diff --git a/direct/timothy_tests/quick_tests/test_yaffs_read.c b/direct/timothy_tests/quick_tests/test_yaffs_read.c index 9033107..d396ff6 100644 --- a/direct/timothy_tests/quick_tests/test_yaffs_read.c +++ b/direct/timothy_tests/quick_tests/test_yaffs_read.c @@ -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 index 0000000..d6c0eff --- /dev/null +++ b/direct/timothy_tests/quick_tests/test_yaffs_stat.c @@ -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 index 0000000..2072be4 --- /dev/null +++ b/direct/timothy_tests/quick_tests/test_yaffs_stat.h @@ -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 diff --git a/direct/timothy_tests/quick_tests/test_yaffs_unlinking.c b/direct/timothy_tests/quick_tests/test_yaffs_unlinking.c index 4972dfb..795c8d4 100644 --- a/direct/timothy_tests/quick_tests/test_yaffs_unlinking.c +++ b/direct/timothy_tests/quick_tests/test_yaffs_unlinking.c @@ -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){ diff --git a/direct/timothy_tests/quick_tests/test_yaffs_unlinking.h b/direct/timothy_tests/quick_tests/test_yaffs_unlinking.h index 7a385f8..34cf38c 100644 --- a/direct/timothy_tests/quick_tests/test_yaffs_unlinking.h +++ b/direct/timothy_tests/quick_tests/test_yaffs_unlinking.h @@ -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); diff --git a/direct/timothy_tests/quick_tests/test_yaffs_write.c b/direct/timothy_tests/quick_tests/test_yaffs_write.c index adee496..08ff765 100644 --- a/direct/timothy_tests/quick_tests/test_yaffs_write.c +++ b/direct/timothy_tests/quick_tests/test_yaffs_write.c @@ -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; }