]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - test
fix: segfault when killing subarray of non-existent container
[thirdparty/mdadm.git] / test
diff --git a/test b/test
old mode 100644 (file)
new mode 100755 (executable)
index a31ad40..1aaf3c1
--- a/test
+++ b/test
@@ -48,13 +48,16 @@ mdsize12=19988
 # ddf needs bigger devices as 32Meg is reserved!
 ddfsize=65536
 
+config=/tmp/mdadm.conf
+
 cleanup() {
        udevadm settle
-       $mdadm -Ssq
+       $mdadm -Ssq 2> /dev/null
        for d in 0 1 2 3 4 5 6 7  8 9 10 11 12
        do
-           losetup -d /dev/loop$d ; # rm -f $targetdir/mdtest$d
-        done
+           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
@@ -100,6 +103,9 @@ mdadm() {
         * )   $mdadm 2> $targetdir/stderr --quiet "$@"
     esac
     rv=$?
+    case $* in
+       *-S* ) udevadm settle;;
+    esac
     cat >&2 $targetdir/stderr
     return $rv
 }
@@ -116,45 +122,45 @@ check() {
       ;;
     raid* | linear )
       grep -s "active $1 " /proc/mdstat > /dev/null || {
-               echo >&2 "ERROR active $1 not found" ; cat /proc/mdstat ; exit 1;}
+               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; }
+               echo >&2 ERROR no $1 happening; cat /proc/mdstat; exit 1; }
      ;;
-   
+
      nosync )
        sleep 0.5
-       if grep -s -E '(resync|recovery|reshape) =' > /dev/null /proc/mdstat ; then
-          echo >&2 "ERROR resync or recovery is happening!"; cat /proc/mdstat ; exit 1; 
+       if grep -s -E '(resync|recovery|reshape) *=' > /dev/null /proc/mdstat ; then
+               echo >&2 "ERROR resync or recovery is happening!"; cat /proc/mdstat ; exit 1;
        fi
      ;;
-   
+
     wait )
       sleep 0.1
-      while grep -E '(resync|recovery|reshape|check|repair) =' > /dev/null /proc/mdstat
+      while grep -E '(resync|recovery|reshape|check|repair) *=' > /dev/null /proc/mdstat
       do sleep 2;
       done
       ;;
-   
+
     state )
        grep -s "blocks.*\[$2\]\$" /proc/mdstat > /dev/null || {
-               echo >&2 "ERROR state $2 not found!"; cat /proc/mdstat ; exit 1; }
+               echo >&2 "ERROR state $2 not found!"; cat /proc/mdstat ; exit 1; }
        sleep 0.5
       ;;
 
     bitmap )
        grep -s bitmap > /dev/null /proc/mdstat || {
-          echo >&2 ERROR no bitmap ; cat /proc/mdstat ; exit 1; }
+               echo >&2 ERROR no bitmap ; cat /proc/mdstat ; exit 1; }
       ;;
     nobitmap )
-       if grep -s "bitmap" > /dev/null /proc/mdstat 
+       if grep -s "bitmap" > /dev/null /proc/mdstat
        then
-          echo >&2 ERROR bitmap present ; cat /proc/mdstat ; exit 1;
+               echo >&2 ERROR bitmap present ; cat /proc/mdstat ; exit 1;
        fi
       ;;
-   
+
     * ) echo >&2 ERROR unknown check $1 ; exit 1;
    esac
 }
@@ -196,42 +202,23 @@ rotest() {
   fsck -fn $dev >&2
 }
 
-setup_environment() {
-   if [ -f $1 ]; then
-      . $environment
-      setup_env
-   fi
-}
-
-reset_environment() {
-   if [ -f $1 ]; then
-      reset_env
-      unset setup_env
-      unset reset_env
-   fi
-}
-
 for script in tests/$prefix tests/$prefix*[^~]
 do
   if [ -f "$script" ]
   then
    rm -f $targetdir/stderr
    # stop all arrays, just incase some script left an array active.
-   mdadm -Ssq
+   $mdadm -Ssq 2> /dev/null
    mdadm --zero $devlist 2> /dev/null
    mdadm --zero $devlist 2> /dev/null
-   environment="tests/env-`basename $script`"
-   setup_environment $environment
    # 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 "$script succeeded" 
-   else cat $targetdir/log ; cat $targetdir/stderr
-        echo "$script failed"
-       reset_environment $environment
+   then echo "succeeded"
+   else echo "FAILED - see $targetdir/log for details"
        exit 1
    fi
-   reset_environment $environment
   fi
 done
 exit 0