yaffs Clean up test scripts a bit
[yaffs2.git] / linux-tests / stress_test.sh
index 2ec9739..6c531ab 100755 (executable)
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 # Do some random operations on a yaffs2 file system
 
 MTD="/dev/mtdblock0"
@@ -11,9 +11,16 @@ MAX_LOW_WATER=85
 MIN_HIGH_WATER=15
 MAX_HIGH_WATER=95
 
-let low_water=25
-let high_water=90
-let df_percent=50
+low_water=25
+high_water=90
+df_percent=50
+
+
+random_number(){
+ local val
+ val=$RANDOM
+ echo $val
+}
 
 
 update_df_percent(){
@@ -23,25 +30,25 @@ update_df_percent(){
 update_df_percent
 
 calc_low_water() {
-   let low_water=0
+   low_water=0
    while [ $low_water -lt $MIN_LOW_WATER ] ;
    do
-       let low_water=$RANDOM%100
+       low_water=$(($(random_number) % 100))
        while [[ $low_water -ge $df_percent  || $low_water -gt $MAX_LOW_WATER ]] ;
        do
-               let low_water=$RANDOM%100
+               low_water=$(($(random_number) % 100))
        done
    done
 }
 
 calc_high_water() {
-   let high_water=100
+   high_water=100
    while [ $high_water -gt $MAX_HIGH_WATER ] ;
    do
-       let high_water=$RANDOM%100
+       high_water=$(($(random_number) % 100))
        while [[ $high_water -le $df_percent || $high_water -lt $MIN_HIGH_WATER ]] ;
        do
-               let high_water=$RANDOM%100
+               high_water=$(($(random_number) % 100))
        done
    done
 }
@@ -50,9 +57,9 @@ calc_high_water() {
 
 maybe_sleep(){
   local val
-  let val=$RANDOM%10000
+  val=$(($(random_number) % 10000))
   if [ $val -le 1 ] ; then
-       let val=$RANDOM%100
+       val=$(($(random_number) % 100))
        echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
        echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
        echo "!!!!!!!!!                                                              !!!!!!!!!!!!!!!!!!!"
@@ -65,15 +72,20 @@ maybe_sleep(){
   fi
 }
 
+remount_count=0
+maybe_remount_count=0
+
 maybe_remount(){
   local val
-  let val=$RANDOM%10000
+  val=$(($(random_number) % 10000))
+  maybe_remount_count=$(($maybe_remount_count+1))
   
   if [ $val -le 1 ] ; then
+       remount_count=$(($remount_count+1))
        echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
        echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
        echo "!!!!!!!!!                                                              !!!!!!!!!!!!!!!!!!!"
-       echo "!!!!!!!!! R E M O U N T                                                !!!!!!!!!!!!!!!!!!!"
+       echo "!!!!!!!!! R E M O U N T $remount_count from $maybe_remount_count"
        echo "!!!!!!!!!                                                              !!!!!!!!!!!!!!!!!!!"
        echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
        echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
@@ -119,7 +131,7 @@ make_space_fast(){
    echo "!!!!!!"
    while [ $df_percent -ge $low_water ] ; do
 
-      let file_prefix=$RANDOM%100
+      file_prefix=$(($(random_number) % 100))
       rm -rf $TEST_DIR/dummy $TEST_DIR/$file_prefix*
 
       update_df_percent
@@ -130,7 +142,7 @@ make_space_fast(){
 
 make_space(){
    local xx
-   let xx=$RANDOM%100
+   xx=$(($(random_number) % 100))
    update_df_percent
 
    if [ $df_percent -gt $MIN_LOW_WATER ] ; then
@@ -149,11 +161,6 @@ periodic_action(){
   maybe_remount
 }
 
-random_number(){
- local val
- val=$RANDOM
- echo $val
-}
 
 
 drop_caches(){
@@ -166,7 +173,7 @@ drop_caches(){
 
 maybe_drop_caches(){
        local x
-       let x=$RANDOM%10000
+       x=$(($(random_number) % 10000))
        if [ $x -eq 99 ] ; then
                drop_caches
        fi
@@ -181,7 +188,7 @@ create_files(){
           calc_high_water
           
           rm -f $SUM_FILE
-          
+
           for i in $(find $TEST_DIR) ; do
                [ -f $i ] && md5sum $i >> $SUM_FILE
           done
@@ -189,42 +196,42 @@ create_files(){
           echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
           echo "!!!!! Fill from $df_percent percent to $high_water percent"
           echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
-          let chunks=$RANDOM%100
+          chunks=$(($(random_number) % 100))
 
        
           update_df_percent
           
-          let skip_file_create=0
-          let skip_dir_create=0
+          skip_file_create=0
+          skip_dir_create=0
 
           while [ $df_percent -le $high_water ] ; do
           
                if [ $skip_file_create -lt 1 ] ; then
-                       let fsize=$RANDOM*$chunks+1
+                       fsize=$(($(random_number)*$chunks+1))
                        echo "!!!!!! File size is $fsize"
                        dd if=/dev/urandom of=$REF_FILE bs=$fsize count=1
                        REF_SUM=$(md5sum $REF_FILE | cut -f1 -d" " )
-                       let skip_file_create=$RANDOM%50
+                       skip_file_create=$(($(random_number) % 50))
                else
-                       let skip_file_create=$skip_file_create-1
+                       skip_file_create=$(($skip_file_create-1))
                fi
 
                if [ $skip_dir_create -lt 1 ] ; then
-                       dir_name=$TEST_DIR/$RANDOM-dir
+                       dir_name=$TEST_DIR/$(random_number)-dir
                        mkdir -p $dir_name
                        echo "Creating in directory $dir_name"
-                       let skip_dir_create=$RANDOM%100
+                       skip_dir_create=$(($(random_number) % 100))
                else
-                       let skip_dir_create=$skip_dir_create-1
+                       skip_dir_create=$(($skip_dir_create-1))
                fi
           
-               FNAME=$dir_name/$RANDOM-$RANDOM-$RANDOM
+               FNAME=$dir_name/$(random_number)-$(random_number)-$(random_number)
                cp $REF_FILE $FNAME
                FILE_SUM=$(md5sum $FNAME | cut -f1 -d" ")
                md5sum $FNAME >> $SUM_FILE
 
                if [ "$FILE_SUM" != "$REF_SUM" ] ; then
-                       echo "File comparison failed $REF_SUM - $FILE_SUM"
+                       echo "File comparison between $REF_FILE and $FNAME failed $REF_SUM - $FILE_SUM"
                        exit 1
                fi
 
@@ -246,9 +253,9 @@ fill_disk(){
        echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
        echo "!!!!!!!!!!! F I L L   D I S K"
        echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
-       let full=0
+       full=0
        while [ $full -eq 0 ] ; do
-               dd if=/dev/urandom of=$TEST_DIR/$RANDOM-$RANDOM-fill bs=1000 count=50 2> /dev/null || let full=1 || true
+               dd if=/dev/urandom of=$TEST_DIR/$(random_number)-$(random_number)-fill bs=1000 count=50 2> /dev/null || full=1 || true
        done
                
 }
@@ -260,22 +267,22 @@ create_files
 
 while true ; do
 
-       let x=$RANDOM%100
+       x=$(($(random_number) % 100))
        if [ $x -lt 50 ] ; then
                create_files
        fi
 
-       let x=$RANDOM%100
+       x=$(($(random_number) % 100))
        if [ $x -lt 50 ] ; then
                make_space
        fi
 
-       let x=$RANDOM%100
+       x=$(($(random_number) % 100))
        if [ $x -lt 5 ] ; then 
                fill_disk
        fi
 
-       let x=$RANDOM%100
+       x=$(($(random_number) % 100))
        if [ $x -lt 1 ] ; then
                drop_caches
        fi