yaffs update to quick tests.
authorTimothy Manning <tfhmanning@gmail.com>
Tue, 2 Nov 2010 23:10:49 +0000 (12:10 +1300)
committerTimothy Manning <tfhmanning@gmail.com>
Wed, 3 Nov 2010 03:27:09 +0000 (16:27 +1300)
Signed-off-by: Timothy Manning <tfhmanning@gmail.com>
21 files changed:
direct/timothy_tests/quick_tests/Makefile
direct/timothy_tests/quick_tests/lib.c [new file with mode: 0644]
direct/timothy_tests/quick_tests/lib.h [new file with mode: 0644]
direct/timothy_tests/quick_tests/quick_tests.c
direct/timothy_tests/quick_tests/quick_tests.h
direct/timothy_tests/quick_tests/test_mount_yaffs.c
direct/timothy_tests/quick_tests/test_mount_yaffs.h
direct/timothy_tests/quick_tests/test_open_file.c [new file with mode: 0644]
direct/timothy_tests/quick_tests/test_open_file.h [new file with mode: 0644]
direct/timothy_tests/quick_tests/test_yaffs_ftruncate.c [new file with mode: 0644]
direct/timothy_tests/quick_tests/test_yaffs_ftruncate.h [new file with mode: 0644]
direct/timothy_tests/quick_tests/test_yaffs_lseek.c [new file with mode: 0644]
direct/timothy_tests/quick_tests/test_yaffs_lseek.h [new file with mode: 0644]
direct/timothy_tests/quick_tests/test_yaffs_read.c [new file with mode: 0644]
direct/timothy_tests/quick_tests/test_yaffs_read.h [new file with mode: 0644]
direct/timothy_tests/quick_tests/test_yaffs_truncate.c [new file with mode: 0644]
direct/timothy_tests/quick_tests/test_yaffs_truncate.h [new file with mode: 0644]
direct/timothy_tests/quick_tests/test_yaffs_unlinking.c [new file with mode: 0644]
direct/timothy_tests/quick_tests/test_yaffs_unlinking.h [new file with mode: 0644]
direct/timothy_tests/quick_tests/test_yaffs_write.c [new file with mode: 0644]
direct/timothy_tests/quick_tests/test_yaffs_write.h [new file with mode: 0644]

index dc52d49..cdde95c 100644 (file)
@@ -44,7 +44,9 @@ COMMONTESTOBJS = yaffscfg2k.o yaffs_ecc.o yaffs_fileem.o yaffs_fileem2k.o yaffsf
 
 #               yaffs_checkptrwtest.o\
 
-YAFFSTESTOBJS  = $(COMMONTESTOBJS) quick_tests.o test_mount_yaffs.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
+
 
 
 ALLOBJS = $(sort $(YAFFSTESTOBJS))
diff --git a/direct/timothy_tests/quick_tests/lib.c b/direct/timothy_tests/quick_tests/lib.c
new file mode 100644 (file)
index 0000000..e5a8859
--- /dev/null
@@ -0,0 +1,41 @@
+#include "lib.h"
+
+
+void join_paths(char *path1,char *path2,char *new_path ){
+
+       //strcat(new_path,path1);       /*since all functions have this then pull it out*/
+       if ( (path1[(sizeof(path1)/sizeof(char))-2]=='/') && path2[0]!='/') {
+               /*paths are compatiable. concatanate them. note -2 is because of \0*/  
+               strcat(new_path,path1);
+               strcat(new_path,path2);         
+               //char new_path[(sizeof(path1)/sizeof(char))+(sizeof(path2)/sizeof(char))];
+               //strcpy(new_path,strcat(path1,path2)); 
+               //return new_path;
+       }       
+       else if ((path1[(sizeof(path1)/sizeof(char))-2]!='/') && path2[0]=='/') {
+               /*paths are compatiable. concatanate them*/  
+               strcat(new_path,path1);
+               strcat(new_path,path2);         
+
+       }
+       else if ((path1[(sizeof(path1)/sizeof(char))-2]!='/') && path2[0]!='/') {
+                       /*need to add a "/". */  
+               strcat(new_path,path1);
+               strcat(new_path,"/");
+               strcat(new_path,path2);
+
+
+       }
+       else if ((path1[(sizeof(path1)/sizeof(char))-2]=='/') && path2[0]=='/') {
+               /*need to remove a "/". */
+               /*yaffs does not mind the extra slash. */               
+               strcat(new_path,path1);
+               strcat(new_path,path2);
+
+       } 
+       else{
+               //error 
+               //return -1;
+       }
+}
+
diff --git a/direct/timothy_tests/quick_tests/lib.h b/direct/timothy_tests/quick_tests/lib.h
new file mode 100644 (file)
index 0000000..fe7a0bc
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef _lib_h__
+#define _lib_h__
+
+
+#include <string.h>
+#define YAFFS_MOUNT_POINT "/yaffs2/"
+#define FILE_NAME "foo"
+#define FILE_SIZE 9
+
+#define FILE_SIZE_TRUNCATED 100
+#define FILE_TEXT "file foo"
+#define FILE_TEXT_NBYTES 9
+
+/* warning do not define anything as FILE because there seems to be a conflict with stdio.h */ 
+#define FILE_PATH "/yaffs2/foo"
+
+void join_paths(char *path1,char *path2,char *new_path );
+#endif
index 125624d..1c23eb2 100644 (file)
@@ -8,7 +8,7 @@ int simulate_power_failure = 0;
 
 typedef struct test {
        int (*p_function)(void);        /*pointer to test function*/
-       void (*p_function_clean)(void);
+       int (*p_function_clean)(void);
        /*char pass_message[50]; will not need a pass message*/
        char *fail_message;     /*pointer to fail message, needs to include name of test*/
 }test_template;
@@ -23,32 +23,45 @@ void dummy_test_pass_clean(void){
 }
 int dummy_test_fail(void){
        //printf("running dummy_test_fail\n");
-       return 0;
+       return -1;
 }
 void dummy_test_fail_clean(void){
 }
 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_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_ftruncate,test_yaffs_ftruncate_clean,"test_yaffs_ftruncate"},
+       {test_yaffs_truncate,test_yaffs_truncate_clean,"test_yaffs_truncate"}
+
        };
 
+unsigned int num_of_tests_pass=0;
+unsigned int num_of_tests_failed=0;
+unsigned int total_number_of_tests=(sizeof(test_list)/sizeof(test_template));
 
 int main(){
        int output=0;
-       unsigned int num_of_tests_pass=0;
-       int num_of_tests_failed=0;
-       unsigned int total_number_of_tests=(sizeof(test_list)/sizeof(test_template));
+
+
        unsigned int x=0;       
        init_quick_tests();
-       printf("quick tests for yaffs\n");
+       printf("\n\nrunning quick tests for yaffs\n");
        //printf("testing yaffs\n");
 
        //printf("len function %d",(sizeof(test_list)/sizeof(test_template)));
        for (x=0;x<total_number_of_tests;x++){
                //printf("x %d\n",x);
                output=test_list[x].p_function();       /*run test*/
-               if (output>0){
+               if (output>=0){
                        /*test has passed*/
                        num_of_tests_pass++;
                }
@@ -57,19 +70,35 @@ int main(){
                        //printf("test failed\n");
                        printf("test: %s failed\n",test_list[x].fail_message);          
                        num_of_tests_failed ++; 
+                       quit_quick_tests(1);
+                       
+               }
+               output=test_list[x].p_function_clean(); /*clean the test*/
+               if (output <0){
+                       /* if the test failed to clean it's self then */
+                       printf("test: %s failed to clean\n",test_list[x].fail_message);         
+                       num_of_tests_failed ++; 
+                       num_of_tests_pass--;
+                       quit_quick_tests(1);
                }
-               test_list[x].p_function_clean();        /*run test*/
                        
        }
-       if (num_of_tests_pass==total_number_of_tests){
+       /*this is where the loop should break to*/
+       quit_quick_tests(0);
+       /* the progame should never get here*/  
+       return 0;
+}
+
+void quit_quick_tests(int exit_code){
+       if (num_of_tests_pass==total_number_of_tests &&  num_of_tests_failed==0){
                printf("\t OK \n");
        }
-       printf("tests: %d passed %d failed\n",num_of_tests_pass,num_of_tests_failed);
-       return 0;
+       printf("tests: %d passed %d failed\n\n\n",num_of_tests_pass,num_of_tests_failed);
+       exit(exit_code);
 }
 
 void init_quick_tests(void){
        yaffs_start_up();;
-       //yaffs_set_trace(0);
+       yaffs_set_trace(0);
 
 }
index 3c811a8..dbe60f5 100644 (file)
@@ -1,12 +1,19 @@
 #ifndef __quick_tests_h__
 #define __quick_tests_h__
 #include <stdio.h>
-#include "test_mount_yaffs.h"
-
 
+#include "test_mount_yaffs.h"
+#include "test_open_file.h"
+#include "test_yaffs_unlinking.h"
+#include "test_yaffs_ftruncate.h"
+#include "test_yaffs_truncate.h"
+#include "test_yaffs_write.h"
+#include "test_yaffs_read.h"
+#include "test_yaffs_lseek.h"
 #define YAFFS_MOUNT_POINT "/yaffs2/"
 
 void init_quick_tests(void);
 int dummy_test_pass(void);
-int dummy_test_pass(void);
+int dummy_test_fail(void);
+void quit_quick_tests(int exit_code);
 #endif
index 9746864..b74cba3 100644 (file)
@@ -1,11 +1,15 @@
 #include "test_mount_yaffs.h"
 #include "yaffsfs.h"
+#include "lib.h"
+
 int mount_yaffs_test(void){
        int output=0;
        output=yaffs_mount(YAFFS_MOUNT_POINT);
+       /*printf("output %d",output);*/
        return output;
 }
 
-void mount_yaffs_test_clean(void){
-       yaffs_unmount(YAFFS_MOUNT_POINT);
+int mount_yaffs_test_clean(void){
+       return 1;
+       
 }
index e922474..c0fa817 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef __mount_yaffs_test__
 #define __mount_yaffs_test__
 
-#define YAFFS_MOUNT_POINT "/yaffs2/"
+
 int mount_yaffs_test(void);
-void mount_yaffs_test_clean(void);
+int mount_yaffs_test_clean(void);
 #endif
diff --git a/direct/timothy_tests/quick_tests/test_open_file.c b/direct/timothy_tests/quick_tests/test_open_file.c
new file mode 100644 (file)
index 0000000..30ff102
--- /dev/null
@@ -0,0 +1,19 @@
+#include "test_open_file.h"
+#include "lib.h"
+#include "yaffsfs.h"
+
+
+
+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);
+
+       return output;
+}
+int test_open_file_clean(void){
+       return 1;
+}
+
diff --git a/direct/timothy_tests/quick_tests/test_open_file.h b/direct/timothy_tests/quick_tests/test_open_file.h
new file mode 100644 (file)
index 0000000..4202558
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef __test_open_file_h__
+#define __test_open_file_h__
+
+int test_open_file(void);
+int test_open_file_clean(void);
+#endif
diff --git a/direct/timothy_tests/quick_tests/test_yaffs_ftruncate.c b/direct/timothy_tests/quick_tests/test_yaffs_ftruncate.c
new file mode 100644 (file)
index 0000000..26a89a7
--- /dev/null
@@ -0,0 +1,25 @@
+#include "test_yaffs_ftruncate.h"
+
+int test_yaffs_ftruncate(void){
+       int handle=test_open_file();
+       if (handle>0){
+               return yaffs_ftruncate(handle,FILE_SIZE_TRUNCATED );
+       }
+       else {
+               printf("error opening file");
+               return -1;
+       }
+}
+
+int test_yaffs_ftruncate_clean(void){
+       /* change file size back to orignal size */
+       int handle=test_open_file();
+       if (handle>0){
+               return yaffs_ftruncate(handle,FILE_SIZE );
+       }
+       else {
+               printf("error opening file in clean function");
+               return -1;
+       }
+
+}
diff --git a/direct/timothy_tests/quick_tests/test_yaffs_ftruncate.h b/direct/timothy_tests/quick_tests/test_yaffs_ftruncate.h
new file mode 100644 (file)
index 0000000..68f9e43
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef __test_yaffs_ftruncate_h__
+#define __test_yaffs_ftruncate_h__
+#include "lib.h"
+#include "yaffsfs.h"
+#include "test_open_file.h"
+int test_yaffs_ftruncate(void);
+int test_yaffs_ftruncate_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
new file mode 100644 (file)
index 0000000..806699b
--- /dev/null
@@ -0,0 +1,42 @@
+#include "test_yaffs_lseek.h"
+
+int test_yaffs_lseek(void){
+       int handle=test_open_file();
+       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");
+                       }
+               }
+               else{
+                       printf("error reading file");
+               } */
+       }
+       else {
+               printf("error opening file\n");
+               return -1;
+       }
+       
+}
+
+int test_yaffs_lseek_clean(void){
+       /* need to reset the seek position*/
+       return test_yaffs_lseek_to_beginning(); 
+}
+int test_yaffs_lseek_to_beginning(void){
+       int handle=test_open_file();
+       if (handle>0){
+               return yaffs_lseek(handle, 0, SEEK_SET);
+       }
+       else {
+               printf("error opening file\n");
+               return -1;
+       }
+}
diff --git a/direct/timothy_tests/quick_tests/test_yaffs_lseek.h b/direct/timothy_tests/quick_tests/test_yaffs_lseek.h
new file mode 100644 (file)
index 0000000..1bd4ce7
--- /dev/null
@@ -0,0 +1,9 @@
+#ifndef __test_yaffs_lseek_h__
+#define __test_yaffs_lseek_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);
+#endif
diff --git a/direct/timothy_tests/quick_tests/test_yaffs_read.c b/direct/timothy_tests/quick_tests/test_yaffs_read.c
new file mode 100644 (file)
index 0000000..9033107
--- /dev/null
@@ -0,0 +1,32 @@
+#include "test_yaffs_write.h"
+
+int test_yaffs_read(void){
+       int handle=test_open_file();
+       char text[20]="\0";
+       int output=0;
+       if (handle>0){
+               output=yaffs_read(handle, text, FILE_TEXT_NBYTES);
+               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");
+                       }
+               }
+               else{
+                       printf("error reading file");
+               }
+       }
+       else {
+               printf("error opening file\n");
+               return -1;
+       }
+       
+}
+
+int test_yaffs_read_clean(void){
+       /* need to reset the seek position*/
+       
+       return test_yaffs_lseek_to_beginning();
+}
diff --git a/direct/timothy_tests/quick_tests/test_yaffs_read.h b/direct/timothy_tests/quick_tests/test_yaffs_read.h
new file mode 100644 (file)
index 0000000..972fb31
--- /dev/null
@@ -0,0 +1,9 @@
+#ifndef __test_yaffs_read_h__
+#define __test_yaffs_read_h__
+#include "lib.h"
+#include "yaffsfs.h"
+#include "test_open_file.h"
+#include "test_yaffs_lseek.h"
+int test_yaffs_read(void);
+int test_yaffs_read_clean(void);
+#endif
diff --git a/direct/timothy_tests/quick_tests/test_yaffs_truncate.c b/direct/timothy_tests/quick_tests/test_yaffs_truncate.c
new file mode 100644 (file)
index 0000000..300c340
--- /dev/null
@@ -0,0 +1,25 @@
+#include "test_yaffs_truncate.h"
+
+int test_yaffs_truncate(void){
+       int handle=test_open_file();
+       if (handle>0){
+               return yaffs_truncate(FILE_PATH,FILE_SIZE_TRUNCATED );
+       }
+       else {
+               printf("error opening file");
+               return -1;
+       }
+}
+
+int test_yaffs_truncate_clean(void){
+       /* change file size back to orignal size */
+       int handle=test_open_file();
+       if (handle>0){
+               return yaffs_truncate(FILE_PATH,FILE_SIZE );
+       }
+       else {
+               printf("error opening file in clean function");
+               return -1;
+       }
+
+}
diff --git a/direct/timothy_tests/quick_tests/test_yaffs_truncate.h b/direct/timothy_tests/quick_tests/test_yaffs_truncate.h
new file mode 100644 (file)
index 0000000..8bc8669
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef __test_yaffs_truncate_h__
+#define __test_yaffs_truncate_h__
+#include "lib.h"
+#include "yaffsfs.h"
+#include "test_open_file.h"
+int test_yaffs_truncate(void);
+int test_yaffs_truncate_clean(void); 
+#endif
diff --git a/direct/timothy_tests/quick_tests/test_yaffs_unlinking.c b/direct/timothy_tests/quick_tests/test_yaffs_unlinking.c
new file mode 100644 (file)
index 0000000..4972dfb
--- /dev/null
@@ -0,0 +1,10 @@
+#include "test_yaffs_unlinking.h"
+
+int test_yaffs_unlinking(void){
+       int output=yaffs_unlink(FILE_PATH);
+       return output;
+}
+
+int test_yaffs_unlinking_clean(void){
+       return test_open_file();
+}
diff --git a/direct/timothy_tests/quick_tests/test_yaffs_unlinking.h b/direct/timothy_tests/quick_tests/test_yaffs_unlinking.h
new file mode 100644 (file)
index 0000000..7a385f8
--- /dev/null
@@ -0,0 +1,10 @@
+#ifndef __test_yaffs_unlinking_h__
+#define __test_yaffs_unlinking_h__
+
+#include "lib.h"
+#include "yaffsfs.h"
+#include "test_open_file.h"
+
+int test_yaffs_unlinking(void);
+int test_yaffs_unlinking_clean(void);
+#endif
diff --git a/direct/timothy_tests/quick_tests/test_yaffs_write.c b/direct/timothy_tests/quick_tests/test_yaffs_write.c
new file mode 100644 (file)
index 0000000..adee496
--- /dev/null
@@ -0,0 +1,17 @@
+#include "test_yaffs_write.h"
+
+int test_yaffs_write(void){
+       int handle=test_open_file();
+       if (handle>0){
+               return yaffs_write(handle, FILE_TEXT, FILE_TEXT_NBYTES);
+       }
+       else {
+               printf("error opening file");
+               return -1;
+       }
+       
+}
+
+int test_yaffs_write_clean(void){
+       return 1;
+}
diff --git a/direct/timothy_tests/quick_tests/test_yaffs_write.h b/direct/timothy_tests/quick_tests/test_yaffs_write.h
new file mode 100644 (file)
index 0000000..671ed96
--- /dev/null
@@ -0,0 +1,9 @@
+#ifndef __test_yaffs_write_h__
+#define __test_yaffs_write_h__
+#include "lib.h"
+#include "yaffsfs.h"
+#include "test_open_file.h"
+#include "test_yaffs_lseek.h"
+int test_yaffs_write(void);
+int test_yaffs_write_clean(void);
+#endif