yaffs More tests for quick tests.
authorTimothy Manning <tfhmanning@gmail.com>
Wed, 10 Nov 2010 01:44:07 +0000 (14:44 +1300)
committerTimothy Manning <tfhmanning@gmail.com>
Wed, 10 Nov 2010 01:44:07 +0000 (14:44 +1300)
Signed-off-by: Timothy Manning <tfhmanning@gmail.com>
13 files changed:
direct/timothy_tests/quick_tests/Makefile
direct/timothy_tests/quick_tests/README.txt
direct/timothy_tests/quick_tests/current_bugs.txt
direct/timothy_tests/quick_tests/quick_tests.c
direct/timothy_tests/quick_tests/quick_tests.h
direct/timothy_tests/quick_tests/test_yaffs_read_EINVAL.c
direct/timothy_tests/quick_tests/test_yaffs_read_EINVAL.h
direct/timothy_tests/quick_tests/test_yaffs_unmount_EBUSY.c [new file with mode: 0644]
direct/timothy_tests/quick_tests/test_yaffs_unmount_EBUSY.h [new file with mode: 0644]
direct/timothy_tests/quick_tests/test_yaffs_write_EBADF.c [new file with mode: 0644]
direct/timothy_tests/quick_tests/test_yaffs_write_EBADF.h [new file with mode: 0644]
direct/timothy_tests/quick_tests/test_yaffs_write_EFBIG.c [new file with mode: 0644]
direct/timothy_tests/quick_tests/test_yaffs_write_EFBIG.h [new file with mode: 0644]

index 85aa36bda9647aee2e9fc514d055c2db3e79e29f..58dabc0c223ad063581ee4a1c07213eb33f6c167 100644 (file)
@@ -46,14 +46,14 @@ COMMONTESTOBJS = yaffscfg2k.o yaffs_ecc.o yaffs_fileem.o yaffs_fileem2k.o yaffsf
 
 TESTFILES =    quick_tests.o lib.o \
                test_yaffs_mount.o test_yaffs_mount_ENODEV.o test_yaffs_mount_ENAMETOOLONG.o test_yaffs_mount_ENOENT.o test_yaffs_mount_EBUSY.o \
-               test_yaffs_unmount.o test_yaffs_unmount_ENOENT.o test_yaffs_unmount_ENAMETOOLONG.o \
+               test_yaffs_unmount.o test_yaffs_unmount_ENOENT.o test_yaffs_unmount_ENAMETOOLONG.o test_yaffs_unmount_EBUSY.o \
                test_yaffs_open.o test_yaffs_open_ENOENT.o test_yaffs_open_ENOTDIR.o test_yaffs_open_EEXIST.o test_yaffs_open_EISDIR.o test_yaffs_open_ENAMETOOLONG.o \
                test_yaffs_open_EINVAL.o test_yaffs_open_EINVAL2.o \
                test_yaffs_unlink.o  test_yaffs_unlink_EISDIR.o test_yaffs_unlink_ENOENT.o test_yaffs_unlink_ENAMETOOLONG.o test_yaffs_unlink_ENOTDIR.o\
                test_yaffs_ftruncate.o test_yaffs_ftruncate_EBADF.o test_yaffs_ftruncate_EINVAL.o test_yaffs_ftruncate_EFBIG.o \
                test_yaffs_truncate.o test_yaffs_truncate_ENOTDIR.o test_yaffs_truncate_EISDIR.o test_yaffs_truncate_ENOENT.o test_yaffs_truncate_EINVAL.o \
                test_yaffs_truncate_EFBIG.o\
-               test_yaffs_write.o \
+               test_yaffs_write.o test_yaffs_write_EBADF.o test_yaffs_write_EFBIG.o \
                test_yaffs_read.o test_yaffs_read_EBADF.o test_yaffs_read_EINVAL.o\
                test_yaffs_lseek.o test_yaffs_lseek_EBADF.o test_yaffs_lseek_EINVAL.o test_yaffs_lseek_EFBIG.o \
                test_yaffs_access.o test_yaffs_access_EINVAL.o test_yaffs_access_ENOTDIR.o test_yaffs_access_ENOENT.o\
index 58536c97fe6b8d65b76648290478a9fcf701cef5..2a5892fa76f55ddb1faf27fbe770a4ee4f1f4e86 100644 (file)
@@ -39,6 +39,7 @@ Tests made
        test_yaffs_read_EBADF
        test_yaffs_read_EINVAL
 
+
        test_yaffs_stat
 
        test_yaffs_truncate
@@ -58,8 +59,10 @@ Tests made
        test_yaffs_unmount
        test_yaffs_unmount_ENOENT
        test_yaffs_unmount_ENAMETOOLONG
+       test_yaffs_umount_EBUSY //cause by having a file handle open and then trying to unmount yaffs.
 
        test_yaffs_write
+       test_yaffs_write_EBADF
 
        
 
@@ -72,7 +75,7 @@ Tests to add
 
        test_yaffs_umount_ENODEV        //Cannot be generated with yaffs.
        test_yaffs_umount_ENOENT        //Cannot be generated with yaffs.
-       test_yaffs_umount_EBUSY         //when files are open and yaffs is unmounted.
+                       
 
        test_yaffs_open_EACCES
        test_yaffs_open_ENOSPC
@@ -88,9 +91,9 @@ Tests to add
        test_yaffs_stat_ENOTDIR
         
        test_yaffs_read_EISDIR          //Cannot be generated with yaffs.
+       test_yaffs_read_EFBIG
        test what happens if you read off the end of the file?
 
-       test_yaffs_write_EBADF
        test_yaffs_write_EFBIG
        test_yaffs_write_EINVAL
        What happens when you run out of space?
index f2a81c9a4dd23258a2a9098d9add7b68eaafb143..64a7bde760c46a381def678ccef6b4a2db7ea687 100644 (file)
@@ -41,6 +41,7 @@ Current BUGS
 
        Unmount2 forcing the unmount needs to break the handles so they return EBADF.
 
+       A read of -1 bytes tries to read 4 gig of data 
 
 Current WARNINGS
        
index e057f1237fa331b0acf849b38c0fb4fb8489e037..720fdee55a7dceaf3a67a7955f077f57ae65d47c 100644 (file)
@@ -38,6 +38,7 @@ int main(){
        for (x=0;x<total_number_of_tests;x++){
                //printf("x %d\n",x);
                yaffs_set_error(0);     /*reset the last error to 0 */
+               printf("\nrunning test: %s \n",test_list[x].name_of_test);
                output=test_list[x].p_function();       /*run test*/
                if (output>=0){
                        /*test has passed*/
@@ -60,6 +61,7 @@ int main(){
                                printf("\n\n");
                        }
                }
+               output=0;
                output=test_list[x].p_function_clean(); /*clean the test*/
                if (output <0){
                        /* if the test failed to clean it's self then */
@@ -72,8 +74,9 @@ int main(){
                                quit_quick_tests(1);
                        }
                        
+               } else {
+                       printf("\ttest clean: %s passed\n",test_list[x].name_of_test);
                }
-                       
        }
        /*this is where the loop should break to*/
        quit_quick_tests(0);
index b1fb094dc3c8541eb4940786ca243cd1b7c51611..32745401c65b2a960bb8b1bdbdf2257d2bff7d8f 100644 (file)
@@ -26,6 +26,7 @@
 #include "test_yaffs_unmount.h"
 #include "test_yaffs_unmount_ENOENT.h"
 #include "test_yaffs_unmount_ENAMETOOLONG.h"
+#include "test_yaffs_unmount_EBUSY.h"
 
 #include "test_yaffs_open.h"
 #include "test_yaffs_open_EISDIR.h"
@@ -60,6 +61,8 @@
 #include "test_yaffs_truncate_EFBIG.h"
 
 #include "test_yaffs_write.h"
+#include "test_yaffs_write_EBADF.h"
+#include "test_yaffs_write_EFBIG.h"
 
 #include "test_yaffs_read.h"
 #include "test_yaffs_read_EBADF.h"
@@ -92,7 +95,7 @@ typedef struct test {
 
 
 test_template test_list[]={
-/*     {test_yaffs_mount,test_yaffs_mount_clean,"test_yaffs_mount"},
+       {test_yaffs_mount,test_yaffs_mount_clean,"test_yaffs_mount"},
        {test_yaffs_mount_ENODEV,test_yaffs_mount_ENODEV_clean,"test_yaffs_mount_ENODEV"},
        {test_yaffs_mount_ENAMETOOLONG,test_yaffs_mount_ENAMETOOLONG_clean,"test_yaffs_mount_ENAMETOOLONG"},
        {test_yaffs_mount_ENOENT,test_yaffs_mount_ENOENT_clean,"test_yaffs_mount_ENOENT"},
@@ -101,7 +104,8 @@ test_template test_list[]={
        {test_yaffs_unmount,test_yaffs_unmount_clean,"test_yaffs_unmount"},
        {test_yaffs_unmount_ENOENT,test_yaffs_unmount_ENOENT_clean,"test_yaffs_unmount_ENOENT"},
        {test_yaffs_unmount_ENAMETOOLONG,test_yaffs_unmount_ENAMETOOLONG_clean,"test_yaffs_unmount_ENAMETOOLONG"},
-*/
+       {test_yaffs_unmount_EBUSY,test_yaffs_unmount_EBUSY_clean,"test_yaffs_unmount_EBUSY"},
+
        {test_yaffs_open,test_yaffs_open_clean,"test_yaffs_open"},
        {test_yaffs_open_EISDIR,test_yaffs_open_EISDIR_clean,"test_yaffs_open_EISDIR"},
        {test_yaffs_open_EEXIST,test_yaffs_open_EEXIST_clean,"test_yaffs_open_EEXIST"},
@@ -132,6 +136,8 @@ test_template test_list[]={
        {test_yaffs_lseek_EFBIG,test_yaffs_lseek_EFBIG_clean,"test_yaffs_lseek_EFBIG"},
 
        {test_yaffs_write,test_yaffs_write_clean,"test_yaffs_write"},
+       {test_yaffs_write_EBADF,test_yaffs_write_EBADF_clean,"test_yaffs_write_EBADF"},
+       {test_yaffs_write_EFBIG,test_yaffs_write_EFBIG_clean,"test_yaffs_write_EFBIG"},
 
        {test_yaffs_read,test_yaffs_read_clean,"test_yaffs_read"},
        {test_yaffs_read_EBADF,test_yaffs_read_EBADF_clean,"test_yaffs_read_EBADF"},
index f11e3adbf8b6f4432d44ed54ad761637fdce8548..46e11f78c2936f1e13540a6eb4ce71ab52af6327 100644 (file)
 
 static int handle=0;
 
+static char *file_name = NULL;
 int test_yaffs_read_EINVAL(void){
        int error_code=0;
        handle=test_yaffs_open();
-       char text[20]="\0";
-       int output=0;
+       char text[2000000]="\0";
+       int output=0;   
+       
+       if (handle<0){
+               printf("could not open file\n");
+               return -1;
+       }       
+
+       /*there needs a large amout of test in the file in order to trigger EINVAL */
+       output=test_yaffs_read_EINVAL_init();
+       if (output<0){
+               printf("could not write text to the file\n");
+               return -1; 
+       }
 
        if (handle>=0){
                output=yaffs_read(handle, text, -1);
@@ -35,7 +48,7 @@ int test_yaffs_read_EINVAL(void){
                        }
                }
                else{
-                       printf("read a non-existing file (which is a bad thing)\n");
+                       printf("read a negative number of bytes (which is a bad thing)\n");
                        return -1;
                }
        }
@@ -47,10 +60,86 @@ int test_yaffs_read_EINVAL(void){
 }
 
 int test_yaffs_read_EINVAL_clean(void){
+       int output=0;
        if (handle>=0){
-               return yaffs_close(handle);
+               output=test_yaffs_read_EINVAL_init_clean();
+               if(output>=0){
+                       output=yaffs_close(handle);
+                       if (output>=0){
+                               return 1;
+                       } else {
+                               printf("could not close the handle\n");
+                               return -1;
+                       }
+               } else {
+                       printf("failed to fix the file\n");
+                       return -1;
+               }
        }
-       else {
-               return 1; /* no handle was opened so there is no need to close a handle */
-       }       
+
 }
+
+int test_yaffs_read_EINVAL_init(void)
+{
+       int output=0;
+       int error_code=0;
+       int x=0;
+       
+       int file_name_length=1000000;
+
+       file_name = malloc(file_name_length);
+       if(!file_name){
+               printf("unable to create file text\n");
+               return -1;
+       }
+       
+       strcat(file_name,YAFFS_MOUNT_POINT);
+       for (x=strlen(YAFFS_MOUNT_POINT); x<file_name_length -1; x++){
+               file_name[x]='a';
+       }
+       file_name[file_name_length-2]='\0';
+
+
+
+       if (handle>=0){
+               output= yaffs_write(handle, file_name, file_name_length-1);
+               if (output<0){
+                       printf("could not write text to file\n");
+                       return -1;
+               } else {
+                       
+                       return 1;
+               }
+
+       } else {
+               printf("error opening file\n");
+               return -1;
+       }
+       
+}
+
+int test_yaffs_read_EINVAL_init_clean(void)
+{
+       int output=1;
+       if(file_name){
+               free(file_name);
+               file_name = NULL;
+       }
+
+       
+       output= yaffs_truncate(FILE_PATH,FILE_SIZE );   
+       if (output>=0){
+               output=test_yaffs_write();
+               if (output>=0){
+                       return 1;
+               } else {
+                       printf("failed to write to file\n");
+                       return -1;
+               }
+       } else {
+               printf("failed to truncate file\n");
+               return -1;
+       }
+
+}
+
index b9650580f0c52e712da6c9e5d9c98afdac6c6a8d..c2c54b7729fb96a89b4222fa8a5331f183da7b5b 100644 (file)
 #include "lib.h"
 #include "yaffsfs.h"
 #include "test_yaffs_open.h"
+#include "test_yaffs_write.h"
+#include "test_yaffs_truncate.h"
 
 
 int test_yaffs_read_EINVAL(void);
 int test_yaffs_read_EINVAL_clean(void);
+int test_yaffs_read_EINVAL_init(void);
+int test_yaffs_read_EINVAL_init_clean(void);
 #endif
diff --git a/direct/timothy_tests/quick_tests/test_yaffs_unmount_EBUSY.c b/direct/timothy_tests/quick_tests/test_yaffs_unmount_EBUSY.c
new file mode 100644 (file)
index 0000000..2c6145b
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * YAFFS: Yet another FFS. A NAND-flash specific file system.
+ *
+ * Copyright (C) 2002-2010 Aleph One Ltd.
+ *   for Toby Churchill Ltd and Brightstar Engineering
+ *
+ * Created by Timothy Manning <timothy@yaffs.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include "test_yaffs_mount_EBUSY.h"
+
+static int handle=-1;
+int test_yaffs_unmount_EBUSY(void){
+       int output=0;
+       int error_code=0;
+       /*printf("path %s\n",path); */
+       handle=yaffs_open(FILE_PATH,O_CREAT | O_RDWR, FILE_MODE);
+       if (handle<0){
+               printf("failed to open file\n");
+               return -1;
+       }
+
+
+       output=yaffs_unmount(YAFFS_MOUNT_POINT);
+       if (output==-1){
+               error_code=yaffs_get_error();
+               if (abs(error_code)==EBUSY){
+                       return 1;
+               }
+               else {
+                       printf("different error than expected\n");
+                       return -1;
+               }
+       }
+       else {
+               printf("non existant mount point unmounted.(which is a bad thing)\n");
+               return -1;
+       }
+
+}
+int test_yaffs_unmount_EBUSY_clean(void){
+       if (handle>=0){
+               return yaffs_close(handle);     
+       }
+       else {
+               return 1;
+       }
+}
+
diff --git a/direct/timothy_tests/quick_tests/test_yaffs_unmount_EBUSY.h b/direct/timothy_tests/quick_tests/test_yaffs_unmount_EBUSY.h
new file mode 100644 (file)
index 0000000..fc41645
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * YAFFS: Yet another Flash File System . A NAND-flash specific file system. 
+ *
+ * Copyright (C) 2002-2010 Aleph One Ltd.
+ *   for Toby Churchill Ltd and Brightstar Engineering
+ *
+ * Created by Timothy Manning <timothy@yaffs.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1 as
+ * published by the Free Software Foundation.
+ *
+ * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL.
+ */
+
+#ifndef __test_yaffs_unmount_EBUSY_h__
+#define __test_yaffs_unmount_EBUSY_h__
+
+#include "lib.h"
+#include "yaffsfs.h"
+#include "test_yaffs_unmount.h"
+#include "test_yaffs_mount.h"
+
+int test_yaffs_unmount_EBUSY(void);
+int test_yaffs_unmount_EBUSY_clean(void);
+#endif
diff --git a/direct/timothy_tests/quick_tests/test_yaffs_write_EBADF.c b/direct/timothy_tests/quick_tests/test_yaffs_write_EBADF.c
new file mode 100644 (file)
index 0000000..a889b34
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * YAFFS: Yet another FFS. A NAND-flash specific file system.
+ *
+ * Copyright (C) 2002-2010 Aleph One Ltd.
+ *   for Toby Churchill Ltd and Brightstar Engineering
+ *
+ * Created by Timothy Manning <timothy@yaffs.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include "test_yaffs_write_EBADF.h"
+
+static int handle=0;
+int test_yaffs_write_EBADF(void){
+       int output=0;
+       int error_code=0;
+       handle=test_yaffs_open();
+       if (handle>=0){
+               output= yaffs_write(-1, FILE_TEXT, FILE_TEXT_NBYTES);
+               if (output<0){
+                       error_code=yaffs_get_error();
+                       //printf("EISDIR def %d, Error code %d\n", ENOTDIR,error_code);
+                       if (abs(error_code)==EBADF){
+                               return 1;
+                       }
+                       else {
+                               printf("different error than expected\n");
+                               return -1;
+                       }
+               }
+               else {
+                       printf("wrote to a bad handle.(which is a bad thing)\n");
+                       return -1;
+               }
+
+       }
+       else {
+               printf("error opening file\n");
+               return -1;
+       }
+       
+}
+
+int test_yaffs_write_EBADF_clean(void){
+       if (handle>=0){
+               return yaffs_close(handle);
+       }
+       else {
+               return 1; /* no handle was opened so there is no need to close a handle */
+       }       
+}
diff --git a/direct/timothy_tests/quick_tests/test_yaffs_write_EBADF.h b/direct/timothy_tests/quick_tests/test_yaffs_write_EBADF.h
new file mode 100644 (file)
index 0000000..6b427fb
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * YAFFS: Yet another Flash File System . A NAND-flash specific file system. 
+ *
+ * Copyright (C) 2002-2010 Aleph One Ltd.
+ *   for Toby Churchill Ltd and Brightstar Engineering
+ *
+ * Created by Timothy Manning <timothy@yaffs.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1 as
+ * published by the Free Software Foundation.
+ *
+ * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL.
+ */
+
+#ifndef __test_yaffs_write_EBADF_h__
+#define __test_yaffs_write_EBADF_h__
+#include "lib.h"
+#include "yaffsfs.h"
+#include "test_yaffs_open.h"
+int test_yaffs_write_EBADF(void);
+int test_yaffs_write_EBADF_clean(void);
+#endif
diff --git a/direct/timothy_tests/quick_tests/test_yaffs_write_EFBIG.c b/direct/timothy_tests/quick_tests/test_yaffs_write_EFBIG.c
new file mode 100644 (file)
index 0000000..a61d3df
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * YAFFS: Yet another FFS. A NAND-flash specific file system.
+ *
+ * Copyright (C) 2002-2010 Aleph One Ltd.
+ *   for Toby Churchill Ltd and Brightstar Engineering
+ *
+ * Created by Timothy Manning <timothy@yaffs.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include "test_yaffs_write_EFBIG.h"
+
+static int handle=0;
+static char *file_name = NULL;
+int test_yaffs_write_EFBIG(void)
+{
+       int output=0;
+       int error_code=0;
+       handle=test_yaffs_open();
+       int x=0;
+       
+       long int file_name_length=100000000000;
+
+       file_name = malloc(file_name_length);
+       if(!file_name){
+               printf("unable to create file text\n");
+               return -1;
+       }
+       
+       strcat(file_name,YAFFS_MOUNT_POINT);
+       for (x=strlen(YAFFS_MOUNT_POINT); x<file_name_length -1; x++){
+               file_name[x]='a';
+       }
+       file_name[file_name_length-2]='\0';
+
+
+
+       if (handle>=0){
+               output= yaffs_write(handle, file_name, file_name_length-1);
+               if (output<0){
+                       error_code=yaffs_get_error();
+                       //printf("EISDIR def %d, Error code %d\n", ENOTDIR,error_code);
+                       if (abs(error_code)==EINVAL){
+                               return 1;
+                       } else {
+                               printf("different error than expected\n");
+                               return -1;
+                       }
+               } else {
+                       printf("wrote a large amount of text to a file.(which is a bad thing)\n");
+                       return -1;
+               }
+
+       } else {
+               printf("error opening file\n");
+               return -1;
+       }
+       
+}
+
+int test_yaffs_write_EFBIG_clean(void)
+{
+       int output=1;
+       if(file_name){
+               free(file_name);
+               file_name = NULL;
+       }
+
+       if (handle>=0){ 
+               output=yaffs_close(handle);
+       }
+
+       
+       output= test_yaffs_truncate_clean();    
+       if (output>=0){
+               output=test_yaffs_write();
+               if (output>=0){
+                       return 1;
+               } else {
+                       printf("failed to write to file\n");
+                       return -1;
+               }
+       } else {
+               printf("failed to truncate file\n");
+               return -1;
+       }
+
+}
diff --git a/direct/timothy_tests/quick_tests/test_yaffs_write_EFBIG.h b/direct/timothy_tests/quick_tests/test_yaffs_write_EFBIG.h
new file mode 100644 (file)
index 0000000..cb2a9b2
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * YAFFS: Yet another Flash File System . A NAND-flash specific file system. 
+ *
+ * Copyright (C) 2002-2010 Aleph One Ltd.
+ *   for Toby Churchill Ltd and Brightstar Engineering
+ *
+ * Created by Timothy Manning <timothy@yaffs.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 2.1 as
+ * published by the Free Software Foundation.
+ *
+ * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL.
+ */
+
+#ifndef __test_yaffs_write_EFBIG_h__
+#define __test_yaffs_write_EFBIG_h__
+#include "lib.h"
+#include "yaffsfs.h"
+#include "test_yaffs_open.h"
+#include "test_yaffs_write.h"
+#include "test_yaffs_truncate.h"
+
+int test_yaffs_write_EFBIG(void);
+int test_yaffs_write_EFBIG_clean(void);
+#endif