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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
#!/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_func_setup_partitions_dos \
setup_disk_func_setup_partitions_gpt \
setup_disk_func_find_efi_size \
setup_disk_non_existing_block_dev
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() {
local dev="$1"
local size="${2:-1000}" # size in MiB
local blocksize="${3:-512}"
mkdir -p dev \
sys/block/$dev/device \
sys/block/$dev/holders \
sys/block/$dev/queue
echo $(( $size * 1000000 / $blocksize )) > sys/block/$dev/size
echo $(( $blocksize )) > sys/block/$dev/queue/logical_block_size
}
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
}
setup_disk_func_setup_partitions_dos_body() {
atf_require_prog sfdisk
init_env
mkdir -p dev
truncate -s 100M dev/vda
SETUP_DISK_TESTFUNC=setup_partitions \
atf_check -s exit:0 \
-o match:"mdev" \
setup-disk dev/vda "0M," "10M,83,*", "10M,82", "10M,fd", ",8e"
SETUP_DISK_TESTFUNC=find_partitions \
atf_check -s exit:0 \
-o match:"dev/vda1" \
setup-disk dev/vda "boot"
SETUP_DISK_TESTFUNC=find_partitions \
atf_check -s exit:0 \
-o match:"dev/vda1" \
setup-disk dev/vda "linux"
SETUP_DISK_TESTFUNC=find_partitions \
atf_check -s exit:0 \
-o match:"dev/vda2" \
setup-disk dev/vda "swap"
SETUP_DISK_TESTFUNC=find_partitions \
atf_check -s exit:0 \
-o match:"dev/vda3" \
setup-disk dev/vda "raid"
SETUP_DISK_TESTFUNC=find_partitions \
atf_check -s exit:0 \
-o match:"dev/vda4" \
setup-disk dev/vda "lvm"
}
setup_disk_func_setup_partitions_gpt_body() {
atf_require_prog sfdisk
init_env
mkdir -p dev
truncate -s 200M dev/vda
swap=0657FD6D-A4AB-43C4-84E5-0933C84B4F4F
linux=0FC63DAF-8483-4772-8E79-3D69D8477DE4
raid=A19D880F-05FC-4D3B-A006-743F0F84911E
lvm=E6D6D379-F507-44C2-A23C-238F2A3DF928
prep=9E1A2d38-C612-4316-AA26-8B49521E5A8B
esp=C12A7328-F81F-11D2-BA4B-00A0C93EC93B
SETUP_DISK_TESTFUNC=setup_partitions DISKLABEL=gpt \
atf_check -s exit:0 \
-o match:"mdev" \
setup-disk dev/vda "0M," "30M,$esp" "30M,$swap" "30M,$linux" "30M,$raid" "30M,$lvm"
sfdisk -d dev/vda
SETUP_DISK_TESTFUNC=find_partitions DISKLABEL=gpt USE_EFI=1 \
atf_check -s exit:0 \
-o match:"dev/vda1" \
setup-disk dev/vda "boot"
SETUP_DISK_TESTFUNC=find_partitions DISKLABEL=gpt \
atf_check -s exit:0 \
-o match:"dev/vda2" \
setup-disk dev/vda "swap"
SETUP_DISK_TESTFUNC=find_partitions DISKLABEL=gpt \
atf_check -s exit:0 \
-o match:"dev/vda3" \
setup-disk dev/vda "linux"
SETUP_DISK_TESTFUNC=find_partitions DISKLABEL=gpt \
atf_check -s exit:0 \
-o match:"dev/vda4" \
setup-disk dev/vda "raid"
SETUP_DISK_TESTFUNC=find_partitions DISKLABEL=gpt \
atf_check -s exit:0 \
-o match:"dev/vda5" \
setup-disk dev/vda "lvm"
}
setup_disk_func_find_efi_size_body() {
init_env
# size:blocksize:expected
for i in 10000::512 4000::264 1000::160 \
10000:4096:512 4000:4096:264 1000:4096:264; do
local diskdata=${i%:*}
local disksize=${diskdata%:*}
local blocksize=${diskdata#*:}
local expected=${i##*:}
fake_disk vda $disksize $blocksize
SETUP_DISK_TESTFUNC=find_efi_size \
atf_check -s exit:0 \
-o match:"^$expected$" \
setup-disk /dev/vda
done
}
setup_disk_non_existing_block_dev_body() {
init_env
atf_check -s not-exit:0 \
-e match:"/dev/vda is not a block device suitable for partitioning" \
-o match:"swapoff" \
setup-disk -m sys /dev/vda
}
|