summaryrefslogtreecommitdiff
path: root/tests/setup_disk_test
blob: 65b7ada52a3ab29d80239c2e294b12408c6df110 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
67
68
69
70
71
72
73
74
#!/usr/bin/env atf-sh

. $(atf_get_srcdir)/test_env.sh
init_tests \
	setup_disk_usage \
	setup_disk_mode_none \
	setup_disk_none \
	setup_disk_func_find_disks

setup_disk_usage_body() {
	test_usage setup-disk
}

setup_disk_mode_none_body() {
	init_env
	atf_check -s exit:0 \
		setup-disk -m none
}

setup_disk_none_body() {
	init_env
	atf_check -s exit:0 \
		setup-disk none
}

fake_disk() {
	mkdir -p sys/block/$1/device \
		sys/block/$1/holders
}

fake_partition() {
	mkdir -p sys/block/$1/$1$2/holders
}

fake_mount() {
	mkdir -p proc
	echo "$1" >> proc/mounts
}

fake_raid() {
	local md="$1"
	shift
	for dev; do
		for p in sys/block/*/$dev/holders sys/block/$dev/holders; do
			if [ -d "$p" ]; then
				touch "$p"/$md
			fi
		done
	done
}

setup_disk_func_find_disks_body() {
	init_env
	fake_disk vda
	fake_disk vdb
	fake_partition vdb 1
	fake_disk sda
	fake_disk nvme0n1
	fake_partition nvme0n1 p2

	# simulate vda and vdb1 being part of md0 raid
	fake_raid md0 vda vdb1

	# simulate nvme0n1p2 being mounted
	fake_mount '/dev/nvme0n1p2 /boot vfat rw,relatime,fmask=0022 0 0'

	SETUP_DISK_TESTFUNC=find_disks USE_RAID=1 \
		atf_check -s exit:0 \
		-o match:"^ sda$" \
		-e match:"vda is part of a running raid" \
		-e match:"vdb is part of a running raid" \
		setup-disk
}