yaffs Implement phase 1 fuzz testing.
authorCharles Manning <cdhmanning@gmail.com>
Fri, 2 Jul 2010 04:46:47 +0000 (16:46 +1200)
committerCharles Manning <cdhmanning@gmail.com>
Wed, 4 Aug 2010 00:24:14 +0000 (12:24 +1200)
Signed-off-by: Charles Manning <cdhmanning@gmail.com>
direct/tests/nor_stress.c
direct/tests/nor_stress.h
direct/tests/run_fuzz_test_nand.sh [new file with mode: 0755]
direct/tests/yaffs_test.c

index 349ecbe..bb614d8 100644 (file)
@@ -49,6 +49,8 @@ static unsigned cycleEnds;
 
 static int interleave_fsx;
 
+static int no_verification;
 char fullPathName[100];
 char fullPowerUpName[100];
 char fullStartName[100];
@@ -119,8 +121,9 @@ static void UpdateCounter(const char *name, unsigned *val,  int initialise)
       yaffs_close(inh);
     }
 
-    if(nread != sizeof(x) ||
-       x[0] + 1 != x[1]){
+    if(!no_verification &&
+      (nread != sizeof(x) ||
+       x[0] + 1 != x[1])){
       printf("Error reading counter %s handle %d, x[0] %u x[1] %u last error %d\n",
               name, inh, x[0], x[1],yaffsfs_GetLastError());
       FatalError(__LINE__);
@@ -220,7 +223,7 @@ static void dump_directory_tree_worker(const char *dname,int recursive)
                                                        
                }
                
-               if(error_line)
+               if(error_line && !no_verification)
                        FatalError(error_line);
                
                yaffs_closedir(d);
@@ -312,6 +315,8 @@ static int yVerifyFile(const char *fName)
        int i;
        int retval = 0;
 
+       if(no_verification)
+               return 0;
 
         printf("Verifying file %s\n",fName);
                
@@ -384,7 +389,7 @@ static void DoUpdateMainFile(void)
         
        result = yWriteFile(fullTempMainName,sz32);
        FSX();
-       if(result)
+       if(!no_verification && result)
            FatalError(__LINE__);
        printf("Raname file %s to %s\n",fullTempMainName,fullMainName);
        yaffs_rename(fullTempMainName,fullMainName);
@@ -394,6 +399,8 @@ static void DoUpdateMainFile(void)
 static void DoVerifyMainFile(void)
 {
         int result;
+       if(no_verification)
+               return;
        result = yVerifyFile(fullMainName);
        if(result)
            FatalError(__LINE__);
@@ -414,10 +421,12 @@ void NorStressTestInitialise(const char *prefix)
 }
 
 
-void NorStressTestRun(const char *prefix, int n_cycles, int do_fsx)
+void NorStressTestRun(const char *prefix, int n_cycles, int do_fsx, int skip_verification)
 {
 
   interleave_fsx = do_fsx;
+  no_verification = skip_verification;
   MakeFullNames(prefix);
   dump_directory_tree(fullPathName);
   FSX_INIT(prefix);
index 7c4274e..7ebef78 100644 (file)
@@ -16,7 +16,7 @@
 #define __NOR_STRESS_H__
 
 void NorStressTestInitialise(const char *path);
-void NorStressTestRun(const char *path, int n_cycles, int do_fsx);
+void NorStressTestRun(const char *path, int n_cycles, int do_fsx, int no_verification);
 
 #endif
 
diff --git a/direct/tests/run_fuzz_test_nand.sh b/direct/tests/run_fuzz_test_nand.sh
new file mode 100755 (executable)
index 0000000..b9473fc
--- /dev/null
@@ -0,0 +1,50 @@
+#!/bin/bash
+
+iterations=100000
+
+[ -z $1 ]  || iterations=$1
+
+
+rm iteration-max-*
+touch iteration-max-$iterations
+
+echo " Running $iterations iterations"
+sleep 2
+
+for ((i=0; i < $iterations; i++))  
+do
+
+   seed=$RANDOM   
+   j=$(( $i % 10 ))
+
+   rm -f log-nand-*$j
+   rm -f seed-nand-*$j
+   echo $seed>seed-nand-for-run-$i
+
+   rm -f emfile-2k-0-*$j
+   rm -f emfile-2k-1-*$j
+   rm -f emfile-2k-2-*$j
+   rm -f emfile-2k-3-*$j
+
+   echo "fuzz"
+   [ -e emfile-2k-0 ] && ./fuzzer -p 10000 emfile-2k-0 
+   [ -e emfile-2k-1 ] && ./fuzzer -p 10000 emfile-2k-1 
+   [ -e emfile-2k-2 ] && ./fuzzer -p 10000 emfile-2k-2 
+   [ -e emfile-2k-3 ] && ./fuzzer -p 10000 emfile-2k-3 
+
+   cp emfile-2k-0 emfile-2k-0-$i
+   cp emfile-2k-1 emfile-2k-1-$i
+   cp emfile-2k-2 emfile-2k-2-$i
+   cp emfile-2k-3 emfile-2k-3-$i
+
+   echo "#########"
+   echo "#########"
+   echo "#########"
+   echo "######### Run $i of $iterations with seed $seed"
+   echo "#########"
+   echo "#########"
+   echo "#########"
+   ./yaffs_test -u  -p -s$seed -t 8 -z yaffs2 
+   # >log-nand-$i
+done
index 520626a..825cf18 100644 (file)
@@ -42,6 +42,9 @@ int do_bash_around;
 int init_test;
 int do_upgrade;
 int n_cycles = -1;
+int fuzz_test=0;
+
+
 int yaffs_test_maxMallocs;
 
 extern int ops_multiplier;
@@ -74,7 +77,7 @@ void yaffs_bash_around(const char *mountpt, int n_cycles)
        while(n_cycles){
                if(cycle % 100 == 0){
                        printf("CYCLE %8d mo %2d inodes %d space %d ",cycle,op_max,
-                               yaffs_inodecount(mountpt),yaffs_freespace(mountpt));
+                               yaffs_inodecount(mountpt),(int)yaffs_freespace(mountpt));
                        for(i = 0; i < BASH_HANDLES; i++)
                                printf("%2d ",h[i]);
                        printf("\n");
@@ -155,6 +158,7 @@ void BadUsage(void)
        printf(" s sss: set seed\n");
        printf(" u: do upgrade test\n");
        printf(" b: bash-about test\n");
+       printf(" z: fuzz test - ignore verification errors\n");
        exit(2);
 }
 
@@ -192,7 +196,7 @@ int main(int argc, char **argv)
        signal(SIGBUS,bad_ptr_handler);
        signal(SIGABRT,bad_ptr_handler);
 #endif 
-       while ((ch = getopt(argc,argv, "bfilmn:ps:t:u"))
+       while ((ch = getopt(argc,argv, "bfilmn:ps:t:uz"))
               != EOF)
                switch (ch) {
                case 's':
@@ -225,6 +229,8 @@ int main(int argc, char **argv)
                case 't':
                        yaffs_traceMask = strtol(optarg,NULL,0);
                        break;
+               case 'z':fuzz_test=1;
+                       break;
                default:
                        BadUsage();
                        /* NOTREACHED */
@@ -237,19 +243,31 @@ int main(int argc, char **argv)
        }
        
        if(argc == 1) {
+               int result;
+
                strcpy(mount_point,argv[0]);
                
                if(simulate_power_failure)
                        n_cycles = -1;
-               printf("Running test %s %s %s %s seed %d cycles %d\n",
+               printf("Running test %s %s %s %s %s seed %d cycles %d\n",
                        do_upgrade ? "fw_upgrade" : "",
                        init_test ? "initialise":"",
+                       fuzz_test ? "fuzz-test" : "",
                        do_fsx ? "fsx" :"",
                        simulate_power_failure ? "power_fail" : "",
                        random_seed, n_cycles);
 
                yaffs_StartUp();
-               yaffs_mount(mount_point);
+               result = yaffs_mount(mount_point);
+               if(result < 0){
+                       printf("Mount of %s failed\n",mount_point);
+                       printf("pid %d sleeping\n",getpid());
+                       
+                       while(!sleep_exit){
+                               sleep(1);
+                               sleep_time++;
+                       }
+               }
                printf("Mount complete\n");
                        
                if(do_upgrade && init_test){
@@ -257,7 +275,7 @@ int main(int argc, char **argv)
                        NorStressTestInitialise(mount_point);
                } else if(do_upgrade){
                        printf("Running stress on %s with seed %d\n",mount_point,random_seed);
-                       NorStressTestRun(mount_point,n_cycles,do_fsx);
+                       NorStressTestRun(mount_point,n_cycles,do_fsx,fuzz_test);
                } else if(do_fsx){
                        yaffs_fsx_main(mount_point,n_cycles);
                } else if(do_bash_around){