the bug is beleved to be when yaffs_read() is called on a 0 length file.
Signed-off-by: Timothy Manning <tfhmanning@gmail.com>
# 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
#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
//{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"}
#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);
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;
}
--- /dev/null
+#include "test_yaffs_access.h"
+
+int test_yaffs_access(void){
+ return yaffs_access(FILE_PATH,0);
+}
+
+int test_yaffs_access_clean(void){
+ return 1;
+}
--- /dev/null
+#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
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");
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");
#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 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 {
--- /dev/null
+#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;
+ }
+}
+
+
--- /dev/null
+#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
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){
#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);
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;
}