Add --without-activation option for luksOpen (check passphrase only).
[platform/upstream/cryptsetup.git] / tests / align-test
index 41ecd52..a764a44 100755 (executable)
@@ -2,9 +2,11 @@
 
 CRYPTSETUP="../src/cryptsetup"
 DEV=""
+DEV_STACKED="luks0xbabe"
 
 cleanup() {
-       udevadm settle
+       udevadm settle >/dev/null 2>&1
+       [ -b /dev/mapper/$DEV_STACKED ] && dmsetup remove $DEV_STACKED >/dev/null 2>&1
        rmmod scsi_debug 2>/dev/null
        sleep 2
 }
@@ -18,6 +20,11 @@ fail()
 
 add_device() {
        modprobe scsi_debug $@
+       if [ $? -ne 0 ] ; then
+               echo "This kernel seems to not support proper scsi_debug module, test skipped."
+               exit 0
+       fi
+
        sleep 2
        DEV=$(grep scsi_debug /sys/block/*/device/model | cut -f4 -d /)
 
@@ -36,20 +43,34 @@ format() # key_bits expected [forced]
 {
        if [ -z "$3" ] ; then
                echo -n "Formatting using topology info ($1 bits key)...."
-               echo xxx| $CRYPTSETUP luksFormat $DEV -q -s $1
+               echo xxx| $CRYPTSETUP luksFormat $DEV -q -i1 -c aes-cbc-essiv:sha256 -s $1
        else
-               echo -n "Formatting using forced offset $3 ($1 bits key)..."
-               echo xxx| $CRYPTSETUP luksFormat $DEV -q -s $1 --align-payload=$2
+               echo -n "Formatting using forced sector alignment $3 ($1 bits key)..."
+               echo xxx| $CRYPTSETUP luksFormat $DEV -q -i1 -s $1 -c aes-cbc-essiv:sha256 --align-payload=$2
        fi
 
        ALIGN=$($CRYPTSETUP luksDump $DEV |grep "Payload offset" | sed -e s/.*\\t//)
        #echo "ALIGN = $ALIGN"
 
-       if [ $ALIGN -ne $2 ] ; then
+       if [ -z "$ALIGN" ] ; then
+               fail "FAIL"
+       elif [ $ALIGN -ne $2 ] ; then
                echo "FAIL"
-               echo "Expected alignment differs: expected $2 != detected $ALIGN"
-               fail
+               fail "Expected alignment differs: expected $2 != detected $ALIGN"
        fi
+
+       # test some operation, just in case
+       echo -e "xxx\naaa" | $CRYPTSETUP luksAddKey $DEV -i1 --key-slot 1
+       if [ $? -ne 0 ] ; then
+               echo "FAIL"
+               fail "Keyslot add failed."
+       fi
+       $CRYPTSETUP -q luksKillSlot $DEV 1
+       if [ $? -ne 0 ] ; then
+               echo "FAIL"
+               fail "Keyslot removal failed."
+       fi
+
        echo "PASSED"
 }
 
@@ -64,8 +85,10 @@ cleanup
 echo "# Create desktop-class 4K drive"
 echo "# (logical_block_size=512, physical_block_size=4096, alignment_offset=0)"
 add_device dev_size_mb=16 sector_size=512 physblk_exp=3 num_tgts=1
-format 256 2112
-format 128 1088
+format 256 4096
+format 256 2112 8
+format 128 2048
+format 128 1088 8
 format 256 8192 8192
 format 128 8192 8192
 cleanup
@@ -73,25 +96,30 @@ cleanup
 echo "# Create desktop-class 4K drive w/ 63-sector DOS partition compensation"
 echo "# (logical_block_size=512, physical_block_size=4096, alignment_offset=3584)"
 add_device dev_size_mb=16 sector_size=512 physblk_exp=3 lowest_aligned=7 num_tgts=1
-format 256 2119
-format 128 1095
+format 256 4103
+format 256 2119 8
+format 128 2055
+format 128 1095 8
 cleanup
 
 echo "# Create enterprise-class 4K drive"
 echo "# (logical_block_size=4096, physical_block_size=4096, alignment_offset=0)"
 add_device dev_size_mb=16 sector_size=4096 num_tgts=1
-format 256 2560
-format 128 1536 
+format 256 4096
+format 256 2560 8
+format 128 2048
+format 128 1536 8
 cleanup
 
 echo "# Create classic 512b drive and stack dm-linear"
 echo "# (logical_block_size=512, physical_block_size=512, alignment_offset=0)"
 add_device dev_size_mb=16 sector_size=512 num_tgts=1
 DEV2=$DEV
-DEV=/dev/mapper/luks0xbabe
-dmsetup create luks0xbabe --table "0 32768 linear $DEV2 0"
-format 256 2112
-format 128 1088
+DEV=/dev/mapper/$DEV_STACKED
+dmsetup create $DEV_STACKED --table "0 32768 linear $DEV2 0"
+format 256 4096
+format 256 2112 8
+format 128 2048
+format 128 1088 8
 format 128 8192 8192
-dmsetup remove luks0xbabe
 cleanup