]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - test
test: ensure testing uses correct mdmon
[thirdparty/mdadm.git] / test
diff --git a/test b/test
index ca7643fff2c4ccd32c549f0adfdf892804092b0e..8e8d1df3612202fbcbc14c74f6adc99d295997f1 100755 (executable)
--- a/test
+++ b/test
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 #
 # run test suite for mdadm
 user=`id -un`
@@ -8,9 +8,6 @@ then echo >&2 "test: testing can only be done as 'root'."
 fi
 
 prefix='[0-9][0-9]'
-if [ -n "$1" ]
-then prefix=$1
-fi
 
 dir=`pwd`
 mdadm=$dir/mdadm
@@ -19,6 +16,23 @@ then
    echo >&2 "test: $mdadm isn't usable."
 fi
 
+testdir="tests"
+logdir="$testdir/logs"
+logsave=0
+exitonerror=1
+
+echo "Testing on linux-$(uname -r) kernel"
+
+# Check whether to run multipath tests
+modprobe multipath 2> /dev/null
+if grep -s 'Personalities : .*multipath' > /dev/null /proc/mdstat ; then
+    MULTIPATH="yes"
+fi
+INTEGRITY=yes
+
+# make sure to test local mdmon, not system one
+export MDADM_NO_SYSTEMCTL=1
+
 # assume md0, md1, md2 exist in /dev
 md0=/dev/md0 md1=/dev/md1 md2=/dev/md2
 mdp0=/dev/md_d0
@@ -37,58 +51,64 @@ mdsize1=19992
 mdsize1a=19988
 mdsize12=19988
 # super1.2 for linear: round to multiple of 2, subtract 4
-mdsize1_l=18976
-mdsize2_l=18976
+mdsize1_l=19996
+mdsize2_l=19996
 # subtract another 4 for bitmaps
 mdsize1b=19988
 mdsize11=19992
-mdsize11a=18944
+mdsize11a=19456
 mdsize12=19988
 
 # ddf needs bigger devices as 32Meg is reserved!
 ddfsize=65536
 
+config=/tmp/mdadm.conf
+
 cleanup() {
        udevadm settle
        $mdadm -Ssq 2> /dev/null
-       for d in 0 1 2 3 4 5 6 7  8 9 10 11 12
+       for d in 0 1 2 3 4 5 6 7  8 9 10 11 12 13
        do
            losetup -d /dev/loop$d ; # rm -f $targetdir/mdtest$d
            rm -f /dev/disk/by-path/loop*
        done
 }
 
-trap cleanup 0 1 2 3 15
+ctrl_c() {
+       exitonerror=1
+}
 
-devlist=
-for d in 0 1 2 3 4 5 6 7 8 9 10 11 12
-do
-   sz=$size
-   if [ $d -gt 7 ]; then sz=$ddfsize ; fi
-   [ -f $targetdir/mdtest$d ] || dd if=/dev/zero of=$targetdir/mdtest$d count=$sz bs=1K > /dev/null 2>&1
-   [ -b /dev/loop$d ] || mknod /dev/loop$d b 7 $d
-   if [ $d -eq 7 ]
-   then
-     losetup /dev/loop$d $targetdir/mdtest6 # for multipath use
-   else
-     losetup /dev/loop$d $targetdir/mdtest$d
-   fi
-   eval dev$d=/dev/loop$d
-   eval file$d=$targetdir/mdtest$d
-   eval devlist=\"\$devlist \$dev$d\"
-   #" <-- add this quote to un-confuse vim syntax highlighting
-done
-path0=$dev6
-path1=$dev7
+do_setup() {
+  trap cleanup 0 1 3 15
+  trap ctrl_c 2
 
-ulimit -c unlimited
-[ -f /proc/mdstat ] || modprobe md_mod
-echo 2000 > /proc/sys/dev/raid/speed_limit_max
-echo 0 > /sys/module/md_mod/parameters/start_ro
+  devlist=
+  for d in 0 1 2 3 4 5 6 7 8 9 10 11 12 13
+  do
+    sz=$size
+    if [ $d -gt 7 ]; then sz=$ddfsize ; fi
+    [ -f $targetdir/mdtest$d ] || dd if=/dev/zero of=$targetdir/mdtest$d count=$sz bs=1K > /dev/null 2>&1
+    [ -b /dev/loop$d ] || mknod /dev/loop$d b 7 $d
+    if [ $d -eq 7 ]
+    then
+      losetup /dev/loop$d $targetdir/mdtest6 # for multipath use
+    else
+      losetup /dev/loop$d $targetdir/mdtest$d
+    fi
+    eval dev$d=/dev/loop$d
+    eval file$d=$targetdir/mdtest$d
+    eval devlist=\"\$devlist \$dev$d\"
+    eval devlist$d=\"\$devlist\"
+   #" <-- add this quote to un-confuse vim syntax highlighting
+  done
+  path0=$dev6
+  path1=$dev7
 
-if [ " $1" = " setup" ]
-then trap 0 ; exit 0
-fi
+  ulimit -c unlimited
+  [ -f /proc/mdstat ] || modprobe md_mod
+  echo 2000 > /proc/sys/dev/raid/speed_limit_max
+  echo 0 > /sys/module/md_mod/parameters/start_ro
+}
 
 # mdadm always adds --quiet, and we want to see any unexpected messages
 mdadm() {
@@ -122,6 +142,10 @@ check() {
       grep -s "active $1 " /proc/mdstat > /dev/null || {
                echo >&2 "ERROR active $1 not found" ; cat /proc/mdstat ; exit 1;}
      ;;
+    algorithm )
+      grep -s " algorithm $2 " /proc/mdstat > /dev/null || {
+         echo >&2 "ERROR algorithm $2 not found"; cat /proc/mdstat; exit 1;}
+     ;;
     resync | recovery | reshape)
       sleep 0.5
       grep -s $1 /proc/mdstat > /dev/null || {
@@ -136,10 +160,13 @@ check() {
      ;;
 
     wait )
+      p=`cat /proc/sys/dev/raid/speed_limit_max`
+      echo 2000000 > /proc/sys/dev/raid/speed_limit_max
       sleep 0.1
       while grep -E '(resync|recovery|reshape|check|repair) *=' > /dev/null /proc/mdstat
-      do sleep 2;
+      do sleep 0.5;
       done
+      echo $p > /proc/sys/dev/raid/speed_limit_max
       ;;
 
     state )
@@ -188,35 +215,145 @@ testdev() {
       rasize=$[rasize*DEV_ROUND_K*2]
    fi
    if [ `/sbin/blockdev --getsize $dev` -eq 0 ]; then sleep 2 ; fi
-   if [ $rasize -ne `/sbin/blockdev --getsize $dev` ]
+   _sz=`/sbin/blockdev --getsize $dev`
+   if [ $rasize -lt $_sz -o $[rasize*4/5] -gt $_sz ]
    then
-     echo "ERROR: size is wrong for $dev: $cnt * $dvsize (chunk=$chunk) = $rasize, not `/sbin/blockdev --getsize $dev`"
+     echo "ERROR: size is wrong for $dev: $cnt * $dvsize (chunk=$chunk) = $rasize, not $_sz"
      exit 1
    fi
 }
 
+fast_sync() {
+  echo 200000 > /proc/sys/dev/raid/speed_limit_max
+}
+
 rotest() {
   dev=$1
   fsck -fn $dev >&2
 }
 
-for script in tests/$prefix tests/$prefix*[^~]
-do
-  if [ -f "$script" ]
+do_test() {
+  _script=$1
+  _basename=`basename $_script`
+  if [ -f "$_script" ]
   then
-   rm -f $targetdir/stderr
-   # stop all arrays, just incase some script left an array active.
-   $mdadm -Ssq 2> /dev/null
-   mdadm --zero $devlist 2> /dev/null
-   mdadm --zero $devlist 2> /dev/null
-   # source script in a subshell, so it has access to our
-   # namespace, but cannot change it.
-   echo -ne "$script... "
-   if ( set -ex ; . $script )  2> $targetdir/log
-   then echo "succeeded"
-   else echo "FAILED - see $targetdir/log for details"
-       exit 1
-   fi
+    rm -f $targetdir/stderr
+    # stop all arrays, just incase some script left an array active.
+    $mdadm -Ssq 2> /dev/null
+    mdadm --zero $devlist 2> /dev/null
+    mdadm --zero $devlist 2> /dev/null
+    # this might have been reset: restore the default.
+    echo 2000 > /proc/sys/dev/raid/speed_limit_max
+    # source script in a subshell, so it has access to our
+    # namespace, but cannot change it.
+    echo -ne "$_script... "
+    if ( set -ex ; . $_script ) &> $targetdir/log
+    then
+      echo "succeeded"
+      _fail=0
+    else
+      log=log
+      cat $targetdir/stderr >> $targetdir/log
+      if [ $exitonerror == 0 ]; then
+         log=log-`basename $_script`
+         mv $targetdir/log $targetdir/$log
+      fi
+      echo "FAILED - see $targetdir/$log for details"
+      _fail=1
+    fi
+    if [ "$savelogs" == "1" ]; then
+      cp $targetdir/log $logdir/$_basename.log
+    fi
+    if [ "$_fail" == "1" -a "$exitonerror" == "1" ]; then
+      exit 1
+    fi
   fi
+}
+
+do_help() {
+  echo "Usage: $0 [options]"
+  echo " Options:"
+  echo "    --tests=<test1,test2,..>    Comma separated list of tests to run"
+  echo "    --disable-multipath         Disable any tests involving multipath"
+  echo "    --disable-integrity         Disable slow tests of RAID[56] consistency"
+  echo "    --logdir=<directory>        Directory to save logfiles in"
+  echo "    --save-logs                 Save all logs in <logdir>"
+  echo "    --keep-going                Don't stop on error, ie. run all tests"
+  echo "    setup                       Setup test environment and exit"
+  echo "    cleanup                     Cleanup test environment"
+  echo "    <prefix>                    Run tests with <prefix>"
+}
+
+parse_args() {
+  for i in $*
+  do
+    case $i in
+    [0-9]*)
+      prefix=$i
+      ;;
+    setup)
+      echo "mdadm test environment setup"
+      do_setup
+      trap 0; exit 0
+      ;;
+    cleanup)
+      cleanup
+      exit 0
+      ;;
+    --tests=*)
+      TESTLIST=`expr "x$i" : 'x[^=]*=\(.*\)' | sed -e 's/,/ /g'`
+      ;;
+    --logdir=*)
+      logdir=`expr "x$i" : 'x[^=]*=\(.*\)'`
+      ;;
+    --save-logs)
+      savelogs=1
+      if [ ! -d $logdir ] ; then
+        mkdir $logdir
+        if [ $? -ne 0 ] ; then
+         exit 1;
+       fi
+      fi
+      ;;
+    --keep-going | --no-error)
+      exitonerror=0
+      ;;
+    --disable-multipath)
+      unset MULTIPATH
+      ;;
+    --disable-integrity)
+      unset INTEGRITY
+      ;;
+    --help)
+      do_help
+      exit 0;
+      ;;
+    -*)
+      echo " $0: Unknown argument: $i"
+      do_help
+      exit 0;
+      ;;
+    esac
 done
+}
+
+parse_args $@
+
+do_setup
+
+if [ "$savelogs" == "1" ]; then
+  echo "Saving logs to $logdir"
+fi
+
+if [ "x$TESTLIST" != "x" ]; then
+  for script in $TESTLIST
+  do
+    do_test $testdir/$script
+  done
+else
+  for script in $testdir/$prefix $testdir/$prefix*[^~]
+  do
+    do_test $script
+  done
+fi
 exit 0