]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - test
change back 0644 permission for Grow.c
[thirdparty/mdadm.git] / test
diff --git a/test b/test
index 788258649256db43189d20e0c2a27e136435a5fc..13f1bda71d0ae0ef1dae9a8c2492cfd60b07d00e 100755 (executable)
--- a/test
+++ b/test
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
 #
 # run test suite for mdadm
 user=`id -un`
@@ -16,11 +16,24 @@ 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
+DEVTYPE=loop
+LVM_VOLGROUP=mdtest
+
+# 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
@@ -56,54 +69,103 @@ 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
-       do
+        case $DEVTYPE in
+        loop)
+         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
+         done
+          ;;
+        lvm)
+         for d in 0 1 2 3 4 5 6 7  8 9 10 11 12 13
+         do
+           eval "lvremove --quiet -f \$dev$d"
+         done
+          ;;
+        esac
 }
 
-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\"
+do_setup() {
+  trap cleanup 0 1 3 15
+  trap ctrl_c 2
+
+  # make sure there are no loop devices remaining.
+  # udev started things can sometimes prevent them being stopped
+  # immediately
+  while grep loop /proc/partitions > /dev/null 2>&1
+  do
+    mdadm -Ss
+    losetup -d /dev/loop[0-9]* 2> /dev/null
+    sleep 1
+  done
+  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
+    case $DEVTYPE in
+    loop)
+      [ -f $targetdir/mdtest$d ] || dd if=/dev/zero of=$targetdir/mdtest$d count=$sz bs=1K > /dev/null 2>&1
+      # make sure udev doesn't touch
+      mdadm --zero $targetdir/mdtest$d 2> /dev/null
+      [ -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
+      ;;
+    lvm)
+      unset MULTIPATH
+      eval dev$d=/dev/mapper/${LVM_VOLGROUP}-mdtest$d
+      if ! lvcreate --quiet -L ${sz}K -n mdtest$d $LVM_VOLGROUP; then
+         trap '' 0 # make sure lvremove is not called
+         eval echo error creating \$dev$d
+         exit 129
+      fi
+      ;;
+    ram)
+      unset MULTIPATH
+      eval dev$d=/dev/ram$d
+      ;;
+    esac
+    eval devlist=\"\$devlist \$dev$d\"
+    eval devlist$d=\"\$devlist\"
    #" <-- add this quote to un-confuse vim syntax highlighting
-done
-path0=$dev6
-path1=$dev7
+  done
+  path0=$dev6
+  path1=$dev7
 
-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
+  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() {
     rm -f $targetdir/stderr
     case $* in
-       *-S* ) udevadm settle;;
+       *-S* ) udevadm settle
+              p=`cat /proc/sys/dev/raid/speed_limit_max`
+              echo 20000 > /proc/sys/dev/raid/speed_limit_max
     esac
     case $* in
-       *-C* ) $mdadm 2> $targetdir/stderr --quiet "$@" --auto=yes;;
-        * )   $mdadm 2> $targetdir/stderr --quiet "$@"
+       *-C* ) $mdadm 2> $targetdir/stderr --quiet "$@" --auto=yes;;
+       * )    $mdadm 2> $targetdir/stderr --quiet "$@"
     esac
     rv=$?
     case $* in
-       *-S* ) udevadm settle;;
+       *-S* ) udevadm settle
+              echo $p > /proc/sys/dev/raid/speed_limit_max
     esac
     cat >&2 $targetdir/stderr
     return $rv
@@ -123,24 +185,48 @@ check() {
       grep -s "active $1 " /proc/mdstat > /dev/null || {
                echo >&2 "ERROR active $1 not found" ; cat /proc/mdstat ; exit 1;}
      ;;
-    resync | recovery | reshape)
-      sleep 0.5
-      grep -s $1 /proc/mdstat > /dev/null || {
-               echo >&2 ERROR no $1 happening; 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)
+       cnt=5
+       while ! grep -s $1 /proc/mdstat > /dev/null
+       do
+           if [ $cnt -gt 0 ] && grep -v idle /sys/block/md*/md/sync_action > /dev/null
+           then # Something isn't idle - wait a bit
+               sleep 0.5
+               cnt=$[cnt-1]
+           else
+               echo >&2 ERROR no $1 happening; cat /proc/mdstat; exit 1
+           fi
+       done
+       ;;
 
      nosync )
        sleep 0.5
+       # Since 4.2 we delay the close of recovery until there has been a chance for
+       # spares to be activated.  That means that a recovery that finds nothing
+       # to do can still take a little longer than expected.
+       # add an extra check: is sync_completed shows the end is reached, assume
+       # there is no recovery.
        if grep -s -E '(resync|recovery|reshape) *=' > /dev/null /proc/mdstat ; then
+          incomplete=`grep / /sys/block/md*/md/sync_completed 2> /dev/null | sed '/^ *\([0-9]*\) \/ \1/d'`
+          if [ -n "$incomplete" ]; then
                echo >&2 "ERROR resync or recovery is happening!"; cat /proc/mdstat ; exit 1;
+          fi
        fi
      ;;
 
     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;
+      while grep -E '(resync|recovery|reshape|check|repair) *=' > /dev/null /proc/mdstat ||
+             grep -v idle > /dev/null /sys/block/md*/md/sync_action
+      do sleep 0.5;
       done
+      echo $p > /proc/sys/dev/raid/speed_limit_max
       ;;
 
     state )
@@ -160,6 +246,15 @@ check() {
        fi
       ;;
 
+    readonly )
+       grep -s "read-only" > /dev/null /proc/mdstat || {
+                echo >&2 "ERROR array is not read-only!"; cat /proc/mdstat ; exit 1; }
+      ;;
+
+    inactive )
+       grep -s "inactive" > /dev/null /proc/mdstat || {
+                echo >&2 "ERROR array is not inactive!"; cat /proc/mdstat ; exit 1; }
+      ;;
     * ) echo >&2 ERROR unknown check $1 ; exit 1;
    esac
 }
@@ -178,7 +273,7 @@ testdev() {
    dvsize=$3
    chunk=$4
    if [ -z "$5" ]; then
-      mkfs -j $dev > /dev/null 2>&1 && fsck -fn $dev >&2
+      mkfs.ext3 -F -j $dev > /dev/null 2>&1 && fsck -fn $dev >&2
    fi
    dsize=$[dvsize/chunk]
    dsize=$[dsize*chunk]
@@ -197,6 +292,10 @@ testdev() {
    fi
 }
 
+fast_sync() {
+  echo 200000 > /proc/sys/dev/raid/speed_limit_max
+}
+
 rotest() {
   dev=$1
   fsck -fn $dev >&2
@@ -204,6 +303,7 @@ rotest() {
 
 do_test() {
   _script=$1
+  _basename=`basename $_script`
   if [ -f "$_script" ]
   then
     rm -f $targetdir/stderr
@@ -211,20 +311,50 @@ do_test() {
     $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 )  2> $targetdir/log
-    then echo "succeeded"
-    else echo "FAILED - see $targetdir/log for details"
+    if ( set -ex ; . $_script ) &> $targetdir/log
+    then
+      echo "succeeded"
+      _fail=0
+    else
+      log=log
+      cat $targetdir/stderr >> $targetdir/log
+      echo "=======================dmesg=================" >> $targetdir/log
+      dmesg | tail -n 200 >> $targetdir/log
+      if [ $exitonerror == 0 ]; then
+         log=log-`basename $_script`
+         mv $targetdir/log $logdir/$log
+      fi
+      echo "FAILED - see $logdir/$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: "
-  echo " $0 [--tests=<test1,test2,..>] [--disable-multipath] [setup] [prefix]"
+  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 "    --dev=[loop|lvm|ram]        Use loop devices (default), LVM, or RAM disk"
+  echo "    --volgroup=<name>           LVM volume group for LVM test"
+  echo "    setup                       Setup test environment and exit"
+  echo "    cleanup                     Cleanup test environment"
+  echo "    <prefix>                    Run tests with <prefix>"
 }
 
 parse_args() {
@@ -236,14 +366,43 @@ parse_args() {
       ;;
     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
+      ;;
+    --keep-going | --no-error)
+      exitonerror=0
+      ;;
     --disable-multipath)
       unset MULTIPATH
       ;;
+    --disable-integrity)
+      unset INTEGRITY
+      ;;
+    --dev=loop)
+      DEVTYPE=loop
+      ;;
+    --dev=lvm)
+      DEVTYPE=lvm
+      ;;
+    --dev=ram)
+      DEVTYPE=ram
+      ;;
+    --volgroup=*)
+      LVM_VOLGROUP=`expr "x$i" : 'x[^=]*=\(.*\)'`
+      ;;
     --help)
       do_help
       exit 0;
@@ -257,15 +416,23 @@ parse_args() {
 done
 }
 
+logdir=$targetdir
 parse_args $@
 
+do_setup
+mkdir -p $logdir
+
+if [ "$savelogs" == "1" ]; then
+  echo "Saving logs to $logdir"
+fi
+
 if [ "x$TESTLIST" != "x" ]; then
   for script in $TESTLIST
   do
-    do_test tests/$script
+    do_test $testdir/$script
   done
 else
-  for script in tests/$prefix tests/$prefix*[^~]
+  for script in $testdir/$prefix $testdir/$prefix*[^~]
   do
     do_test $script
   done