summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2022-11-11 15:04:57 +0100
committerNatanael Copa <ncopa@alpinelinux.org>2022-11-11 15:04:57 +0100
commit2c507187be2be177c730758b2ca21ebe06d4ae61 (patch)
tree1600b79f11f3399d46f06e347572736453a6c207
parent48291cdfd804ea69b23cfddcd87589634cd1d7da (diff)
downloadalpine-conf-2c507187be2be177c730758b2ca21ebe06d4ae61.zip
setup-disk: add tests for find_efi_size
-rw-r--r--setup-disk.in4
-rwxr-xr-xtests/setup_disk_test34
2 files changed, 34 insertions, 4 deletions
diff --git a/setup-disk.in b/setup-disk.in
index b178ff0..ad92426 100644
--- a/setup-disk.in
+++ b/setup-disk.in
@@ -731,9 +731,9 @@ find_swap_size() {
find_efi_size() {
local diskdevs="$*"
- local blocksize=$(cat "$(echo "$diskdevs" | sed -E 's:/dev/([^ ]+):/sys/block/\1/queue/logical_block_size:g')" \
+ local blocksize=$(cat "$(echo "$diskdevs" | sed -E "s:/?dev/([^ ]+):$ROOT/sys/block/\1/queue/logical_block_size:g")" \
| sort -n | tail -n 1 || echo 512)
- local disksize_blk=$(cat "$(echo "$diskdevs" | sed -E 's:/dev/([^ ]+):/sys/block/\1/size:g')" \
+ local disksize_blk=$(cat "$(echo "$diskdevs" | sed -E "s:/?dev/([^ ]+):$ROOT/sys/block/\1/size:g")" \
| sort -n | tail -n 1 || echo 0)
local disksize_mb=$(( blocksize * disksize_blk / 1024 / 1024 ))
diff --git a/tests/setup_disk_test b/tests/setup_disk_test
index f935796..1fee4aa 100755
--- a/tests/setup_disk_test
+++ b/tests/setup_disk_test
@@ -8,6 +8,7 @@ init_tests \
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() {
@@ -27,10 +28,20 @@ setup_disk_none_body() {
}
fake_disk() {
- mkdir -p sys/block/$1/device \
- sys/block/$1/holders
+ 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
}
@@ -160,6 +171,25 @@ setup_disk_func_setup_partitions_gpt_body() {
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 \