dm-cmd-test.sh 19.5 KB
Newer Older
Helen Koike's avatar
Helen Koike committed
1 2 3 4 5 6 7 8 9 10 11
#!/bin/bash

#set -eo pipefail

if [ "$#" -ne 1 ]; then
    echo "Illegal number of parameters"
    echo "Usage: $0 <path-to-kernel-bzimage>"
    exit 1
fi
KERNEL=$1

Helen Koike's avatar
Helen Koike committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
fill_rootfs()
{
	MSG=${1-""}
	# Add busybox and init script
	if [ ! -f busybox ]; then
		wget https://busybox.net/downloads/binaries/1.21.1/busybox-x86_64 -O busybox
		chmod +x busybox
	fi
	sudo mkdir dm-mount/bin
	sudo cp busybox dm-mount/bin/busybox

	sudo bash -c 'cat > dm-mount/bin/init.sh' <<- EOF
	#!/bin/busybox sh
	busybox echo "System Booted $MSG"
	busybox poweroff -f
	EOF
	sudo chmod +x dm-mount/bin/init.sh
}

Helen Koike's avatar
Helen Koike committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
create_snap()
{
	# Create disk
	DISK=$1
	PREFIX=$2
	DM_DEV=dm-snap
	if [ -f $DISK -a -f ${DISK}.info ]; then
		echo "$DISK already exist, not creating it"
		return
	else
		echo "creating $DISK"
	fi

	dd if=/dev/zero of=$DISK bs=256M count=2
	# Partition 1
	sudo sgdisk -n 1:0:+200M -t 1:7f01 "$DISK"
	# Partition 2
	sudo sgdisk -n 2:0:+200M -t 2:7f01 "$DISK"

	LOOP_DEV=$(sudo losetup -fP --show $DISK)
	sectors=$(sudo blockdev --getsz "${LOOP_DEV}"p1)
	bash -c "cat > ${DISK}.info" <<- EOF
	${PREFIX}sectors=${sectors}
	EOF

	sudo mkfs.ext4 -L ROOT-SNAP ${LOOP_DEV}p1
	mkdir -p dm-mount
	sudo mount ${LOOP_DEV}p1 dm-mount

	fill_rootfs  "snap disk $DISK"

	# Umount disk/dm/loopback
	sudo umount dm-mount
	rm -r dm-mount
}

Helen Koike's avatar
Helen Koike committed
67
create_raid()
Helen Koike's avatar
Helen Koike committed
68 69 70 71
{
	# Create disk
	DISK=$1
	PREFIX=$2
Helen Koike's avatar
Helen Koike committed
72 73
	TYPE=${3-raid4}
	DM_DEV=dm-raid
Helen Koike's avatar
Helen Koike committed
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
	if [ -f $DISK -a -f ${DISK}.info ]; then
		echo "$DISK already exist, not creating it"
		return
	else
		echo "creating $DISK"
	fi

	dd if=/dev/zero of=$DISK bs=256M count=4
	# Partition 1
	sudo sgdisk -n 1:0:+200M -t 1:7f01 "$DISK"
	# Partition 2
	sudo sgdisk -n 2:0:+200M -t 2:7f01 "$DISK"
	# Partition 3
	sudo sgdisk -n 3:0:+200M -t 3:7f01 "$DISK"
	# Partition 4
	sudo sgdisk -n 4:0:+200M -t 4:7f01 "$DISK"

	LOOP_DEV=$(sudo losetup -fP --show $DISK)

	sectors=$(sudo blockdev --getsz "${LOOP_DEV}"p1)
	sectors=$(($(sudo blockdev --getsz "${LOOP_DEV}"p2) + $sectors))
Helen Koike's avatar
Helen Koike committed
95 96 97
	if [ "$TYPE" != "raid6_zr" ]; then
		sectors=$(($(sudo blockdev --getsz "${LOOP_DEV}"p3) + $sectors))
	fi
Helen Koike's avatar
Helen Koike committed
98

Helen Koike's avatar
Helen Koike committed
99
	table="0 $sectors raid ${TYPE} 3 64 region_size 1024 4 - ${LOOP_DEV}p1 - ${LOOP_DEV}p2 - ${LOOP_DEV}p3 - ${LOOP_DEV}p4"
Helen Koike's avatar
Helen Koike committed
100 101 102 103 104 105 106 107 108 109 110
	echo "$table"
	echo "$table" | sudo dmsetup create $DM_DEV

	bash -c "cat > ${DISK}.info" <<- EOF
	${PREFIX}sectors=${sectors}
	EOF

	echo "concise table (with loopback device)"
	sudo dmsetup table --concise /dev/mapper/$DM_DEV

	# Format
Helen Koike's avatar
Helen Koike committed
111
	sudo mkfs.ext4 -L ROOT-RAID /dev/mapper/$DM_DEV
Helen Koike's avatar
Helen Koike committed
112 113 114
	mkdir -p dm-mount
	sudo mount /dev/mapper/$DM_DEV dm-mount

Helen Koike's avatar
Helen Koike committed
115
	fill_rootfs "raid disk $DISK"
Helen Koike's avatar
Helen Koike committed
116 117 118 119 120 121 122 123

	# Umount disk/dm/loopback
	sudo umount dm-mount
	rm -r dm-mount
	sudo dmsetup remove $DM_DEV
	sudo losetup -d $LOOP_DEV
}

Helen Koike's avatar
Helen Koike committed
124 125 126 127 128 129 130 131 132 133 134 135 136
create_crypt()
{
	# Create disk
	DISK=$1
	PREFIX=$2
	DM_DEV=dm-crypt
	if [ -f $DISK -a -f ${DISK}.info ]; then
		echo "$DISK already exist, not creating it"
		return
	else
		echo "creating $DISK"
	fi

Helen Koike's avatar
Helen Koike committed
137
	dd if=/dev/zero of=$DISK bs=256M count=2
Helen Koike's avatar
Helen Koike committed
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
	LOOP_DEV=$(sudo losetup -fP --show $DISK)
	sectors=$(sudo blockdev --getsz "${LOOP_DEV}")
	key=babebabebabebabebabebabebabebabebabebabebabebabebabebabebabebabe
	table="0 $sectors crypt aes-xts-plain64 $key 0 ${LOOP_DEV} 0 1 allow_discards"
	echo "$table" | sudo dmsetup create $DM_DEV

	bash -c "cat > ${DISK}.info" <<- EOF
	${PREFIX}sectors=${sectors}
	${PREFIX}key=${key}
	EOF

	echo "concise table (with loopback device)"
	sudo dmsetup table --concise /dev/mapper/$DM_DEV

	# Format
	sudo mkfs.ext4 -L ROOT-CRYPT /dev/mapper/$DM_DEV
	mkdir -p dm-mount
	sudo mount /dev/mapper/$DM_DEV dm-mount

	fill_rootfs  "crypt disk $DISK"

	# Umount disk/dm/loopback
	sudo umount dm-mount
	rm -r dm-mount
	sudo dmsetup remove $DM_DEV
	sudo losetup -d $LOOP_DEV
}

Helen Koike's avatar
Helen Koike committed
166 167 168 169 170 171 172 173 174 175 176 177 178
create_striped()
{
	# Create disk
	DISK=$1
	PREFIX=$2
	DM_DEV=dm-striped
	if [ -f $DISK -a -f ${DISK}.info ]; then
		echo "$DISK already exist, not creating it"
		return
	else
		echo "creating $DISK"
	fi

Helen Koike's avatar
Helen Koike committed
179
	dd if=/dev/zero of=$DISK bs=256M count=4
Helen Koike's avatar
Helen Koike committed
180
	# Partition 1
Helen Koike's avatar
Helen Koike committed
181
	sudo sgdisk -n 1:0:+200M -t 1:7f01 "$DISK"
Helen Koike's avatar
Helen Koike committed
182
	# Partition 2
Helen Koike's avatar
Helen Koike committed
183
	sudo sgdisk -n 2:0:+200M -t 2:7f01 "$DISK"
Helen Koike's avatar
Helen Koike committed
184
	# Partition 3
Helen Koike's avatar
Helen Koike committed
185
	sudo sgdisk -n 3:0:+200M -t 3:7f01 "$DISK"
Helen Koike's avatar
Helen Koike committed
186
	# Partition 4
Helen Koike's avatar
Helen Koike committed
187
	sudo sgdisk -n 4:0:+200M -t 4:7f01 "$DISK"
Helen Koike's avatar
Helen Koike committed
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222

	LOOP_DEV=$(sudo losetup -fP --show $DISK)

	sectors=$(sudo blockdev --getsz "${LOOP_DEV}"p1)
	sectors=$(($(sudo blockdev --getsz "${LOOP_DEV}"p2) + $sectors))
	sectors=$(($(sudo blockdev --getsz "${LOOP_DEV}"p3) + $sectors))
	sectors=$(($(sudo blockdev --getsz "${LOOP_DEV}"p4) + $sectors))

	PAGESIZE=$(getconf PAGESIZE)

	table="0 $sectors striped 4 $PAGESIZE ${LOOP_DEV}p1 0 ${LOOP_DEV}p2 0 ${LOOP_DEV}p3 0 ${LOOP_DEV}p4 0"
	echo "$table" | sudo dmsetup create $DM_DEV

	bash -c "cat > ${DISK}.info" <<- EOF
	${PREFIX}sectors=${sectors}
	${PREFIX}PAGESIZE=${PAGESIZE}
	EOF

	echo "concise table (with loopback device)"
	sudo dmsetup table --concise /dev/mapper/$DM_DEV

	# Format
	sudo mkfs.ext4 -L ROOT-STRIPED /dev/mapper/$DM_DEV
	mkdir -p dm-mount
	sudo mount /dev/mapper/$DM_DEV dm-mount

	fill_rootfs  "striped disk $DISK"

	# Umount disk/dm/loopback
	sudo umount dm-mount
	rm -r dm-mount
	sudo dmsetup remove $DM_DEV
	sudo losetup -d $LOOP_DEV
}

Helen Koike's avatar
Helen Koike committed
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269
# Create a simple rootfs - target verity
create_verity()
{
	# Create disk
	DISK=$1
	PREFIX=$2
	if [ -f $DISK -a -f ${DISK}.info ]; then
		echo "$DISK already exist, not creating it"
		return
	else
		echo "creating $DISK"
	fi

	dd if=/dev/zero of=$DISK bs=512M count=3
	# Partition 1
	sudo sgdisk -n 1:0:+800M -t 1:7f01 "$DISK"
	# Partition 2
	sudo sgdisk -n 2:0:+500M -t 2:7f01 "$DISK"

	# Format and mount partition 1
	LOOP_DEV=$(sudo losetup -fP --show $DISK)
	sudo mkfs.ext4 -L ROOT-VERITY ${LOOP_DEV}p1
	mkdir -p dm-mount
	sudo mount ${LOOP_DEV}p1 dm-mount

	fill_rootfs  "verity disk $DISK"

	# Umount partition
	sudo umount dm-mount
	rm -r dm-mount

	# Format verity
	sudo veritysetup format ${LOOP_DEV}p1 ${LOOP_DEV}p2 > ${DISK}.info
	sed -i -e '1d' ${DISK}.info
	sed -i -e 's/./\L&/g' ${DISK}.info
	sed -i -e 's/[[:space:]]\+/_/g' ${DISK}.info
	sed -i -e "s/:_/=/g" ${DISK}.info
	sectors=$(sudo blockdev --getsz "${LOOP_DEV}"p1)
	echo "sectors=${sectors}" >> ${DISK}.info

	# Add prefix to variables in file
	sed -i -e "s/^/$PREFIX/" ${DISK}.info

	# Umount loopback
	sudo losetup -d $LOOP_DEV
}

Helen Koike's avatar
Helen Koike committed
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
# Create a simple rootfs - target linear from 4 joined partitions
create_linear()
{
	# Create 1g disk
	DISK=$1
	PREFIX=$2
	DM_DEV=dm-linear
	if [ -f $DISK -a -f ${DISK}.info ]; then
		echo "$DISK already exist, not creating it"
		return
	else
		echo "creating $DISK"
	fi

	dd if=/dev/zero of=$DISK bs=512M count=2
	# Partition 1 - bootable
	sudo sgdisk -n 1:0:+16M -t 1:7f00 "$DISK"
	# Partition 2
	sudo sgdisk -n 2:0:+500M -t 2:7f01 "$DISK"
	# Partition 3
	sudo sgdisk -n 3:0:+100M -t 3:7f01 "$DISK"
	# Partition 4
	sudo sgdisk -n 4:0:+250M -t 4:7f01 "$DISK"

	# Create linear device
	LOOP_DEV=$(sudo losetup -fP --show $DISK)
	S1=$(sudo blockdev --getsz ${LOOP_DEV}p1)
	S2=$(sudo blockdev --getsz ${LOOP_DEV}p2)
	S3=$(sudo blockdev --getsz ${LOOP_DEV}p3)
	S4=$(sudo blockdev --getsz ${LOOP_DEV}p4)

	bash -c "cat > ${DISK}.info" <<- EOF
	P1_START=0
	P1_SIZE=$S1
	P2_START=$S1
	P2_SIZE=$S2
	P3_START=$(($S1 + $S2))
	P3_SIZE=$S3
	P4_START=$(($S1 + $S2 + $S3))
	P4_SIZE=$S4
	EOF

	source ${DISK}.info

	# Add prefix to variables in file
	sed -i -e "s/^/$PREFIX/" ${DISK}.info

Helen Koike's avatar
Helen Koike committed
317
	table="$P1_START $P1_SIZE linear ${LOOP_DEV}p1 0
Helen Koike's avatar
Helen Koike committed
318 319
	$P2_START $P2_SIZE linear ${LOOP_DEV}p2 0
	$P3_START $P3_SIZE linear ${LOOP_DEV}p3 0
Helen Koike's avatar
Helen Koike committed
320 321
	$P4_START $P4_SIZE linear ${LOOP_DEV}p4 0"
	echo "$table" | sudo dmsetup create $DM_DEV
Helen Koike's avatar
Helen Koike committed
322 323 324 325 326 327 328 329 330

	echo "concise table (with loopback device)"
	sudo dmsetup table --concise /dev/mapper/$DM_DEV

	# Format
	sudo mkfs.ext4 -L ROOT-LINEAR /dev/mapper/$DM_DEV
	mkdir -p dm-mount
	sudo mount /dev/mapper/$DM_DEV dm-mount

Helen Koike's avatar
Helen Koike committed
331
	fill_rootfs  "linear disk $DISK"
Helen Koike's avatar
Helen Koike committed
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347

	# Umount disk/dm/loopback
	sudo umount dm-mount
	rm -r dm-mount
	sudo dmsetup remove $DM_DEV
	sudo losetup -d $LOOP_DEV
}

launch_test()
{
	DESC=$1
	KVM_PARAM=$2
	ROOT_DEV=$3
	DM_BOOT_PARAM=$4
	EXPECT_RESULT=${5-0}
	LOG_N=${LOG_N-0}
Helen Koike's avatar
Helen Koike committed
348 349
	N_SUCCESS=${N_SUCCESS-0}
	N_FAIL=${N_FAIL-0}
Helen Koike's avatar
Helen Koike committed
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370

	LOG_N=$((LOG_N+1))

	args="loglevel=15 nokaslr printk.synchronous=1 console=ttyS0 dm=\"${DM_BOOT_PARAM}\" root=${ROOT_DEV} ro init=/bin/init.sh"

	mkdir -p logs/${LOG_N}

	echo ""
	echo "=== Test $LOG_N ($(date)):" | tee logs/${LOG_N}/info
	echo "description:: $DESC" | tee -a logs/${LOG_N}/info
	echo "kernel: $KERNEL" | tee -a logs/${LOG_N}/info
	echo "kvm_param: $KVM_PARAM" | tee -a logs/${LOG_N}/info
	echo "dm_param: $DM_BOOT_PARAM" | tee -a logs/${LOG_N}/info
	echo "root_dev: $ROOT_DEV" | tee -a logs/${LOG_N}/info

	cmd="timeout --foreground 15 kvm ${KVM_PARAM} -smp 1 -m 2g -nographic -kernel ${KERNEL} -append '${args}' > logs/${LOG_N}/qemu 2>&1"
	echo "$cmd" >> logs/${LOG_N}/info
	eval "$cmd"
	ret=$?
	if [ "$ret" == "${EXPECT_RESULT}" ]; then
		echo "> Result: SUCCESS ($ret)"
Helen Koike's avatar
Helen Koike committed
371
		N_SUCCESS=$((N_SUCCESS+1))
Helen Koike's avatar
Helen Koike committed
372 373
	else
		echo "> Result: FAIL ($ret)"
Helen Koike's avatar
Helen Koike committed
374
		N_FAIL=$((N_FAIL+1))
Helen Koike's avatar
Helen Koike committed
375
	fi
Helen Koike's avatar
Helen Koike committed
376 377
	echo ""
	echo "Total successes: ${N_SUCCESS}. Total failures: ${N_FAIL}"
Helen Koike's avatar
Helen Koike committed
378 379
}

Helen Koike's avatar
Helen Koike committed
380 381 382 383 384 385
# -----------------------
# Linear and parser tests
# -----------------------

linear_parser_tests()
{
Helen Koike's avatar
Helen Koike committed
386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
launch_test \
	"linear: should fail (test the test)" \
	"-hda ${DL1}" \
	/dev/dm-0 \
	"dm-linear,,0,rw,0 0 linear 8:1 0,0 0 linear 8:2 0,0 0 linear 8:3 0,0 0 linear 8:4 0" \
	124

launch_test \
	"linear: with minor" \
	"-hda ${DL1}" \
	/dev/dm-4 \
	"dm-linear,,4,rw,$DL1_P1_START $DL1_P1_SIZE linear 8:1 0,$DL1_P2_START $DL1_P2_SIZE linear 8:2 0,$DL1_P3_START $DL1_P3_SIZE linear 8:3 0,$DL1_P4_START $DL1_P4_SIZE linear 8:4 0"

UUID=123123123123
launch_test \
	"linear: with uuid (but booting from /dev/dm-0)" \
	"-hda ${DL1}" \
	"/dev/dm-0" \
	"dm-linear,${UUID},,rw,$DL1_P1_START $DL1_P1_SIZE linear 8:1 0,$DL1_P2_START $DL1_P2_SIZE linear 8:2 0,$DL1_P3_START $DL1_P3_SIZE linear 8:3 0,$DL1_P4_START $DL1_P4_SIZE linear 8:4 0"

launch_test \
	"linear: with device path" \
	"-hda ${DL1}" \
	/dev/dm-4 \
	"dm-linear,,4,rw,$DL1_P1_START $DL1_P1_SIZE linear /dev/sda1 0,$DL1_P2_START $DL1_P2_SIZE linear /dev/sda2 0,$DL1_P3_START $DL1_P3_SIZE linear /dev/sda3 0,$DL1_P4_START $DL1_P4_SIZE linear /dev/sda4 0"

launch_test \
	"linear: No minor" \
	"-hda ${DL1}" \
	/dev/dm-0 \
	"dm-linear,,,rw,$DL1_P1_START $DL1_P1_SIZE linear 8:1 0,$DL1_P2_START $DL1_P2_SIZE linear 8:2 0,$DL1_P3_START $DL1_P3_SIZE linear 8:3 0,$DL1_P4_START $DL1_P4_SIZE linear 8:4 0"

launch_test \
	"linear: minor to 0" \
	"-hda ${DL1}" \
	/dev/dm-0 \
	"dm-linear,,0,rw,$DL1_P1_START $DL1_P1_SIZE linear 8:1 0,$DL1_P2_START $DL1_P2_SIZE linear 8:2 0,$DL1_P3_START $DL1_P3_SIZE linear 8:3 0,$DL1_P4_START $DL1_P4_SIZE linear 8:4 0"

args="dm-linear1,,4,rw,$DL1_P1_START $DL1_P1_SIZE linear /dev/sda1 0,$DL1_P2_START $DL1_P2_SIZE linear /dev/sda2 0,$DL1_P3_START $DL1_P3_SIZE linear /dev/sda3 0,$DL1_P4_START $DL1_P4_SIZE linear /dev/sda4 0"
args+=";dm-linear2,,5,rw,$DL2_P1_START $DL2_P1_SIZE linear /dev/sdb1 0,$DL2_P2_START $DL2_P2_SIZE linear /dev/sdb2 0,$DL2_P3_START $DL2_P3_SIZE linear /dev/sdb3 0,$DL2_P4_START $DL2_P4_SIZE linear /dev/sdb4 0"
launch_test \
	"linear: multiple disks (boot sda)" \
	"-hda ${DL1} -hdb ${DL2} " \
	/dev/dm-4 \
	"$args"

args="dm-linear1,,4,rw,$DL1_P1_START $DL1_P1_SIZE linear /dev/sda1 0,$DL1_P2_START $DL1_P2_SIZE linear /dev/sda2 0,$DL1_P3_START $DL1_P3_SIZE linear /dev/sda3 0,$DL1_P4_START $DL1_P4_SIZE linear /dev/sda4 0"
args+=";dm-linear2,,5,rw,$DL2_P1_START $DL2_P1_SIZE linear /dev/sdb1 0,$DL2_P2_START $DL2_P2_SIZE linear /dev/sdb2 0,$DL2_P3_START $DL2_P3_SIZE linear /dev/sdb3 0,$DL2_P4_START $DL2_P4_SIZE linear /dev/sdb4 0"
launch_test \
	"linear: multiple disks (boot sdb)" \
	"-hda ${DL1} -hdb ${DL2} " \
	/dev/dm-5 \
	"$args"

args="   dm-linear  ,  ,   100  ,  rw  ,  $DL1_P1_START   $DL1_P1_SIZE   linear   8:1   0  ,  $DL1_P2_START $DL1_P2_SIZE   linear   8:2    0  ,   $DL1_P3_START    $DL1_P3_SIZE    linear    8:3   0   ,    $DL1_P4_START $DL1_P4_SIZE    linear    8:4    0   "
args+="  ;   dm-linear2 ,   , ,ro,   $DL2_P1_START $DL2_P1_SIZE   linear /dev/sdb1 0,$DL2_P2_START $DL2_P2_SIZE linear /dev/sdb2 0,$DL2_P3_START $DL2_P3_SIZE linear /dev/sdb3 0,$DL2_P4_START $DL2_P4_SIZE linear /dev/sdb4 0   "
launch_test \
	"linear: spaces" \
	"-hda ${DL1} -hdb ${DL2} " \
	/dev/dm-0 \
	"$args"

launch_test \
	"linear: name with space" \
	"-hda ${DL1}" \
	/dev/dm-4 \
	"this is a name,,4,rw,$DL1_P1_START $DL1_P1_SIZE linear 8:1 0,$DL1_P2_START $DL1_P2_SIZE linear 8:2 0,$DL1_P3_START $DL1_P3_SIZE linear 8:3 0,$DL1_P4_START $DL1_P4_SIZE linear 8:4 0" \

launch_test \
	"linear: bad argument: bad name" \
	"-hda ${DL1}" \
	/dev/dm-4 \
	"/dev/asdf,,4,rw,$DL1_P1_START $DL1_P1_SIZE linear 8:1 0,$DL1_P2_START $DL1_P2_SIZE linear 8:2 0,$DL1_P3_START $DL1_P3_SIZE linear 8:3 0,$DL1_P4_START $DL1_P4_SIZE linear 8:4 0" \
	124

launch_test \
	"linear: bad argument: bad minor" \
	"-hda ${DL1}" \
	/dev/dm-4 \
	"dm-linear,,BAD,rw,$DL1_P1_START $DL1_P1_SIZE linear 8:1 0,$DL1_P2_START $DL1_P2_SIZE linear 8:2 0,$DL1_P3_START $DL1_P3_SIZE linear 8:3 0,$DL1_P4_START $DL1_P4_SIZE linear 8:4 0" \
	124

launch_test \
	"linear: bad argument: bad read/write" \
	"-hda ${DL1}" \
	/dev/dm-4 \
	"dm-linear,,,BAD,$DL1_P1_START $DL1_P1_SIZE linear 8:1 0,$DL1_P2_START $DL1_P2_SIZE linear 8:2 0,$DL1_P3_START $DL1_P3_SIZE linear 8:3 0,$DL1_P4_START $DL1_P4_SIZE linear 8:4 0" \
	124

launch_test \
	"linear: bad argument: missing field" \
	"-hda ${DL1}" \
	/dev/dm-4 \
	"dm-linear,,,rw" \
	124

launch_test \
	"linear: bad argument: empty" \
	"-hda ${DL1}" \
	/dev/dm-4 \
	"" \
	124

launch_test \
	"linear: bad argument: negative minor number" \
	"-hda ${DL1}" \
	/dev/dm-4 \
	"dm-linear,,-4,ro,$DL1_P1_START $DL1_P1_SIZE linear 8:1 0,$DL1_P2_START $DL1_P2_SIZE linear 8:2 0,$DL1_P3_START $DL1_P3_SIZE linear 8:3 0,$DL1_P4_START $DL1_P4_SIZE linear 8:4 0" \
	124

launch_test \
	"linear: ending with semi-colon (empty device)" \
	"-hda ${DL1}" \
	/dev/dm-4 \
	"dm-linear,,4,rw,$DL1_P1_START $DL1_P1_SIZE linear /dev/sda1 0,$DL1_P2_START $DL1_P2_SIZE linear /dev/sda2 0,$DL1_P3_START $DL1_P3_SIZE linear /dev/sda3 0,$DL1_P4_START $DL1_P4_SIZE linear /dev/sda4 0;" \
	124

name="this is a really loooooooooooong name for a deviceeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee - reaaaaaaaaaly loooooooooooooooooooooooooong nnnnnnnnnnnnnnnnnnnname"
name+=" this is a really loooooooooooong name for a deviceeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee - reaaaaaaaaaly loooooooooooooooooooooooooong nnnnnnnnnnnnnnnnnnnname"
name+=" this is a really loooooooooooong name for a deviceeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee - reaaaaaaaaaly loooooooooooooooooooooooooong nnnnnnnnnnnnnnnnnnnname"
name+=" this is a really loooooooooooong name for a deviceeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee - reaaaaaaaaaly loooooooooooooooooooooooooong nnnnnnnnnnnnnnnnnnnname"
name+=" this is a really loooooooooooong name for a deviceeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee - reaaaaaaaaaly loooooooooooooooooooooooooong nnnnnnnnnnnnnnnnnnnname"
name+=" this is a really loooooooooooong name for a deviceeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee - reaaaaaaaaaly loooooooooooooooooooooooooong nnnnnnnnnnnnnnnnnnnname"
name+=" this is a really loooooooooooong name for a deviceeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee - reaaaaaaaaaly loooooooooooooooooooooooooong nnnnnnnnnnnnnnnnnnnname"
name+=" this is a really loooooooooooong name for a deviceeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee - reaaaaaaaaaly loooooooooooooooooooooooooong nnnnnnnnnnnnnnnnnnnname"
name+=" this is a really loooooooooooong name for a deviceeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee - reaaaaaaaaaly loooooooooooooooooooooooooong nnnnnnnnnnnnnnnnnnnname"
name+=" this is a really loooooooooooong name for a deviceeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee - reaaaaaaaaaly loooooooooooooooooooooooooong nnnnnnnnnnnnnnnnnnnname"
name+=" this is a really loooooooooooong name for a deviceeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee - reaaaaaaaaaly loooooooooooooooooooooooooong nnnnnnnnnnnnnnnnnnnname"
launch_test \
	"linear: bad argument: too long name" \
	"-hda ${DL1}" \
	/dev/dm-4 \
	"$name,,4,rw,$DL1_P1_START $DL1_P1_SIZE linear 8:1 0,$DL1_P2_START $DL1_P2_SIZE linear 8:2 0,$DL1_P3_START $DL1_P3_SIZE linear 8:3 0,$DL1_P4_START $DL1_P4_SIZE linear 8:4 0" \
	124
Helen Koike's avatar
Helen Koike committed
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537
}

# --------------
# Verity
# --------------

verity_tests()
{
launch_test \
	"verity: with minor" \
	"-hda ${DV1}" \
	/dev/dm-4 \
	"dm-verity,,4,ro,0 $DV1_sectors verity $DV1_hash_type 8:1 8:2 $DV1_data_block_size $DV1_hash_block_size $DV1_data_blocks 1 $DV1_hash_algorithm $DV1_root_hash $DV1_salt"

UUID=CRYPT-VERITY-543c115f6fb048e2bd7ecbb5960aae4d-verity-test
launch_test \
	"verity: with uuid" \
	"-hda ${DV1}" \
Helen Koike's avatar
Helen Koike committed
538
	/dev/dm-4 \
Helen Koike's avatar
Helen Koike committed
539 540
	"dm-verity,${UUID},4,ro,0 $DV1_sectors verity $DV1_hash_type 8:1 8:2 $DV1_data_block_size $DV1_hash_block_size $DV1_data_blocks 1 $DV1_hash_algorithm $DV1_root_hash $DV1_salt"
}
Helen Koike's avatar
Helen Koike committed
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560

# --------------
# Striped
# --------------

striped_tests()
{
launch_test \
	"striped: with minor" \
	"-hda ${DS1}" \
	/dev/dm-4 \
	"dm-striped,,4,ro,0 $DS1_sectors striped 4 $DS1_PAGESIZE 8:1 0 8:2 0 8:3 0 8:4 0"

UUID=123123123
launch_test \
	"striped: with uuid" \
	"-hda ${DS1}" \
	/dev/dm-4 \
	"dm-striped,${UUID},4,ro,0 $DS1_sectors striped 4 $DS1_PAGESIZE 8:1 0 8:2 0 8:3 0 8:4 0"
}
Helen Koike's avatar
Helen Koike committed
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588

# --------------
# Crypt
# --------------

crypt_tests()
{
launch_test \
	"crypt: with minor" \
	"-hda ${DC1}" \
	/dev/dm-4 \
	"dm-crypt,,4,ro,0 $DC1_sectors crypt aes-xts-plain64 $DC1_key 0 /dev/sda 0 1 allow_discards"

UUID=123123123
launch_test \
	"crypt: with uuid" \
	"-hda ${DC1}" \
	/dev/dm-4 \
	"dm-crypt,${UUID},4,ro,0 $DC1_sectors crypt aes-xts-plain64 $DC1_key 0 /dev/sda 0 1 allow_discards"

launch_test \
	"crypt: wrong key" \
	"-hda ${DC1}" \
	/dev/dm-4 \
	"dm-crypt,,4,ro,0 $DC1_sectors crypt aes-xts-plain64 123123123123 0 /dev/sda 0 1 allow_discards" \
	124
}

Helen Koike's avatar
Helen Koike committed
589 590 591 592 593 594 595 596 597 598
# --------------
# Raid
# --------------

raid_tests()
{
launch_test \
	"raid4: with minor" \
	"-hda ${DR41}" \
	/dev/dm-4 \
Helen Koike's avatar
Helen Koike committed
599 600 601 602 603 604 605 606 607 608 609 610 611
	"dm-raid,,4,ro,0 $DR41_sectors raid raid4 3 64 region_size 1024 4 - 8:1 - 8:2 - 8:3 - 8:4"

launch_test \
	"raid5: no minor" \
	"-hda ${DR51}" \
	/dev/dm-0 \
	"dm-raid,,,ro,0 $DR51_sectors raid raid5_ls 3 64 region_size 1024 4 - 8:1 - 8:2 - 8:3 - 8:4"

launch_test \
	"raid6: no minor" \
	"-hda ${DR61}" \
	/dev/dm-0 \
	"dm-raid,,,ro,0 $DR61_sectors raid raid6_zr 3 64 region_size 1024 4 - 8:1 - 8:2 - 8:3 - 8:4"
Helen Koike's avatar
Helen Koike committed
612 613
}

Helen Koike's avatar
Helen Koike committed
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634
snap_tests()
{
launch_test \
	"snap: snapshot-origin" \
	"-hda ${DSN1}" \
	/dev/dm-4 \
	"dm-snap-orig,,4,ro,0 ${DSN1_sectors} snapshot-origin 8:1"

launch_test \
	"snap: snapshot-origin" \
	"-hda ${DSN1}" \
	/dev/dm-0 \
	"dm-snap,,,ro,0 ${DSN1_sectors} snapshot 8:1 8:2 P 8"

launch_test \
	"snap: snapshot-merge" \
	"-hda ${DSN1}" \
	/dev/dm-0 \
	"dm-snap,,,ro,0 ${DSN1_sectors} snapshot-merge 8:1 8:2 P 8"
}

Helen Koike's avatar
Helen Koike committed
635
DR41=disk-raid4-1.img
Helen Koike's avatar
Helen Koike committed
636
create_raid $DR41 DR41_ raid4
Helen Koike's avatar
Helen Koike committed
637 638 639
# Load disk info
source ${DR41}.info

Helen Koike's avatar
Helen Koike committed
640 641 642 643 644 645 646 647 648 649
DR51=disk-raid5-1.img
create_raid $DR51 DR51_ raid5_ls
# Load disk info
source ${DR51}.info

DR61=disk-raid6-1.img
create_raid $DR61 DR61_ raid6_zr
# Load disk info
source ${DR61}.info

Helen Koike's avatar
Helen Koike committed
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674
DS1=disk-striped-1.img
create_striped $DS1 DS1_
# Load disk info
source ${DS1}.info

DL1=disk-linear-1.img
create_linear $DL1 DL1_
# Load disk info
source ${DL1}.info

DL2=disk-linear-2.img
create_linear $DL2 DL2_
# Load disk info
source ${DL2}.info

DV1=disk-verity-1.img
create_verity $DV1 DV1_
# Load disk info
source ${DV1}.info

DC1=disk-crypt-1.img
create_crypt $DC1 DC1_
# Load disk info
source ${DC1}.info

Helen Koike's avatar
Helen Koike committed
675 676 677 678 679
DSN1=disk-snap-1.img
create_snap $DSN1 DSN1_
# Load disk info
source ${DSN1}.info

Helen Koike's avatar
Helen Koike committed
680 681
verity_tests
linear_parser_tests
Helen Koike's avatar
Helen Koike committed
682
striped_tests
Helen Koike's avatar
Helen Koike committed
683
crypt_tests
Helen Koike's avatar
Helen Koike committed
684
raid_tests
Helen Koike's avatar
Helen Koike committed
685
snap_tests