2024-01-05 18:42:15 +00:00
|
|
|
# Copyright (C) 2024 Umorpha Systems
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
2024-01-05 02:13:25 +00:00
|
|
|
bats_require_minimum_version 1.7.0
|
|
|
|
bats_load_library bats-support
|
|
|
|
bats_load_library bats-assert
|
2024-01-19 05:36:20 +00:00
|
|
|
bats_load_library bats-file
|
|
|
|
|
|
|
|
teardown() {
|
|
|
|
if [ -n "${tmpdir:-}" ]; then
|
2024-01-26 06:35:45 +00:00
|
|
|
if [[ -d "$tmpdir/tmp-dis" ]]; then
|
|
|
|
sudo fusermount -u "$tmpdir/tmp-dis" || true
|
2024-02-14 08:35:13 +00:00
|
|
|
rmdir "$tmpdir/tmp-dis"
|
|
|
|
fi
|
|
|
|
if [[ -d "$tmpdir/dir" ]]; then
|
|
|
|
sudo umount "$tmpdir/dir" || true
|
|
|
|
rmdir "$tmpdir/dir"
|
2024-01-26 06:35:45 +00:00
|
|
|
fi
|
2024-01-19 05:36:20 +00:00
|
|
|
temp_del "$tmpdir"
|
|
|
|
fi
|
|
|
|
}
|
2024-01-05 02:13:25 +00:00
|
|
|
|
|
|
|
@test "osi-mk needs arguments" {
|
|
|
|
LC_ALL=C run --separate-stderr osi-mk
|
|
|
|
assert_failure 2
|
|
|
|
assert_equal "$output" ''
|
|
|
|
assert [ ${#stderr_lines[@]} -gt 1 ]
|
|
|
|
assert_regex "${stderr_lines[-1]}" "^Try .*osi-mk --help' for more information\$"
|
|
|
|
}
|
2024-01-19 05:36:20 +00:00
|
|
|
|
2024-02-14 03:00:05 +00:00
|
|
|
@test "osi-mk shows help" {
|
|
|
|
LC_ALL=C run --separate-stderr osi-mk --help
|
|
|
|
assert_success
|
|
|
|
assert_equal "$stderr" ''
|
|
|
|
assert_regex "${lines[0]}" '^Usage: osi-mk '
|
|
|
|
|
|
|
|
LC_ALL=C run --separate-stderr osi-mk -h
|
|
|
|
assert_success
|
|
|
|
assert_equal "$stderr" ''
|
|
|
|
assert_regex "${lines[0]}" '^Usage: osi-mk'
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "osi-mk shows version" {
|
|
|
|
LC_ALL=C run --separate-stderr osi-mk --version
|
|
|
|
assert_success
|
|
|
|
assert_equal "$stderr" ''
|
|
|
|
assert_regex "${lines[0]}" '^osi-mk \(osi-tools\) '
|
|
|
|
|
|
|
|
LC_ALL=C run --separate-stderr osi-mk -V
|
|
|
|
assert_success
|
|
|
|
assert_equal "$stderr" ''
|
|
|
|
assert_regex "${lines[0]}" '^osi-mk \(osi-tools\) '
|
|
|
|
}
|
|
|
|
|
2024-02-14 08:35:01 +00:00
|
|
|
@test "osi-mk balks at invalid --conf=format=" {
|
|
|
|
tmpdir="$(temp_make)"
|
|
|
|
|
|
|
|
LC_ALL=C run --separate-stderr osi-mk --conf=format=blarg --conf=format.size=2G --package=base --package=linux-libre "$tmpdir/tst.img"
|
|
|
|
assert_failure 2
|
|
|
|
assert_equal "$output" ''
|
|
|
|
assert_regex "$stderr" '--conf=format='
|
|
|
|
assert_regex "${stderr_lines[-1]}" "^Try .*osi-mk --help' for more information\$"
|
|
|
|
}
|
|
|
|
|
2024-01-19 05:36:20 +00:00
|
|
|
@test "osi-mk builds base" {
|
|
|
|
tmpdir="$(temp_make)"
|
|
|
|
|
2024-01-26 07:20:35 +00:00
|
|
|
echo 'Building image...'
|
2024-02-14 15:46:22 +00:00
|
|
|
osi-mk --conf=format=btrfs --conf=format.size=2G --package=base --package=linux-libre "$tmpdir/tst.img"
|
2024-01-26 07:20:35 +00:00
|
|
|
|
|
|
|
echo 'Checking that mkinitcpio ran correctly...'
|
|
|
|
mkdir "$tmpdir/mnt"
|
|
|
|
sudo osi-mount --user "$tmpdir/tst.img" "$tmpdir/mnt" -- test -f "$tmpdir/mnt/boot/initramfs-linux-libre.img"
|
2024-01-19 05:36:20 +00:00
|
|
|
}
|
2024-01-26 06:35:45 +00:00
|
|
|
|
2024-01-19 05:37:09 +00:00
|
|
|
@test "osi-mk builds base x86_64" {
|
|
|
|
tmpdir="$(temp_make)"
|
|
|
|
|
2024-02-14 15:46:22 +00:00
|
|
|
osi-mk --conf=arch=x86_64 --conf=format=btrfs --conf=format.size=2G --package=base --package=linux-libre "$tmpdir/tst.img"
|
2024-01-19 05:37:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "osi-mk builds base armv7h" {
|
|
|
|
tmpdir="$(temp_make)"
|
|
|
|
|
2024-02-14 15:46:22 +00:00
|
|
|
osi-mk --conf=arch=armv7h --conf=format=btrfs --conf=format.size=2G --package=base --package=linux-libre "$tmpdir/tst.img"
|
2024-01-19 05:37:09 +00:00
|
|
|
}
|
|
|
|
|
2024-02-26 04:43:40 +00:00
|
|
|
@test "osi-mk builds existing dir" {
|
2024-02-14 08:35:13 +00:00
|
|
|
tmpdir="$(temp_make)"
|
|
|
|
|
|
|
|
mkdir "$tmpdir/dir"
|
|
|
|
sudo mount -t tmpfs tmpfs:osi-mk-bats "$tmpdir/dir"
|
|
|
|
|
|
|
|
echo 'Building image...'
|
|
|
|
osi-mk --conf=format=dir --conf=bootloader=none --edit --package=base --package=linux-libre "$tmpdir/dir"
|
|
|
|
|
|
|
|
echo 'Checking that mkinitcpio ran correctly...'
|
|
|
|
test -f "$tmpdir/dir/boot/initramfs-linux-libre.img"
|
|
|
|
}
|
|
|
|
|
2024-02-26 04:43:40 +00:00
|
|
|
@test "osi-mk builds new dir" {
|
|
|
|
tmpdir="$(temp_make)"
|
|
|
|
|
|
|
|
mkdir "$tmpdir/dir"
|
|
|
|
sudo mount -t tmpfs tmpfs:osi-mk-bats "$tmpdir/dir"
|
|
|
|
|
|
|
|
echo 'Building image...'
|
|
|
|
osi-mk --conf=format=dir --conf=bootloader=none --package=base --package=linux-libre "$tmpdir/dir/sub"
|
|
|
|
|
|
|
|
echo 'Checking permissions...'
|
|
|
|
assert_equal "$(stat --format='%u' "$tmpdir/dir/sub")" 0
|
|
|
|
|
|
|
|
echo 'Checking that mkinitcpio ran correctly...'
|
|
|
|
test -f "$tmpdir/dir/sub/boot/initramfs-linux-libre.img"
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "osi-mk builds copy dir" {
|
|
|
|
tmpdir="$(temp_make)"
|
|
|
|
|
|
|
|
mkdir "$tmpdir/dir"
|
|
|
|
sudo mount -t tmpfs tmpfs:osi-mk-bats "$tmpdir/dir"
|
|
|
|
|
|
|
|
sudo install -Dm444 --owner=123 /dev/null "$tmpdir/dir/base/file"
|
|
|
|
|
|
|
|
echo 'Building image...'
|
|
|
|
osi-mk --conf=format=dir --conf=bootloader=none --edit="$tmpdir/dir/base" --package=base --package=linux-libre "$tmpdir/dir/sub"
|
|
|
|
|
|
|
|
echo 'Checking permissions...'
|
|
|
|
assert_equal "$(stat --format='%u' "$tmpdir/dir/sub")" 0
|
|
|
|
assert_equal "$(stat --format='%u' "$tmpdir/dir/sub/file")" 123
|
|
|
|
assert_equal "$(stat --format='%a' "$tmpdir/dir/sub/file")" 444
|
|
|
|
|
|
|
|
echo 'Checking that mkinitcpio ran correctly...'
|
|
|
|
test -f "$tmpdir/dir/sub/boot/initramfs-linux-libre.img"
|
|
|
|
}
|
|
|
|
|
2024-02-14 08:35:13 +00:00
|
|
|
@test "osi-mk erofs is reproducible" {
|
2024-01-26 06:35:45 +00:00
|
|
|
tmpdir="$(temp_make)"
|
|
|
|
|
|
|
|
mkdir "$tmpdir/tmp-raw" "$tmpdir/tmp-dis"
|
|
|
|
sudo disorderfs --multi-user=yes --shuffle-dirents=yes "$tmpdir/tmp-raw" "$tmpdir/tmp-dis"
|
|
|
|
|
|
|
|
flags=(
|
|
|
|
--disorderfs
|
|
|
|
--conf=format=erofs --conf=bootloader=none
|
2024-02-14 15:46:22 +00:00
|
|
|
--conf=format.fsuuid="$(uuidgen)"
|
2024-01-30 06:43:51 +00:00
|
|
|
--conf=machine-id="$(uuidgen|tr -d -)"
|
2024-01-26 06:35:45 +00:00
|
|
|
--conf=SOURCE_DATE_EPOCH=auto
|
|
|
|
--package=base
|
|
|
|
|
|
|
|
# TODO: We simply delete the known non-reproducible
|
|
|
|
# files, to verify that we don't get *less*
|
|
|
|
# reproducible; but we aren't actually reproducible
|
|
|
|
# yet.
|
|
|
|
--module="$PWD/mod-reproducible.sh"
|
|
|
|
)
|
|
|
|
|
2024-02-14 08:35:13 +00:00
|
|
|
echo 'Building first image...'
|
|
|
|
TMPDIR="$tmpdir/tmp-dis" osi-mk "${flags[@]}" "$tmpdir/tst1.img"
|
|
|
|
echo 'Building second image...'
|
|
|
|
TMPDIR="$tmpdir/tmp-dis" osi-mk "${flags[@]}" "$tmpdir/tst2.img"
|
|
|
|
echo 'Comparing...'
|
|
|
|
cmp "$tmpdir/tst1.img" "$tmpdir/tst2.img"
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "osi-mk tar is reproducible" {
|
|
|
|
tmpdir="$(temp_make)"
|
|
|
|
|
|
|
|
mkdir "$tmpdir/tmp-raw" "$tmpdir/tmp-dis"
|
|
|
|
sudo disorderfs --multi-user=yes --shuffle-dirents=yes "$tmpdir/tmp-raw" "$tmpdir/tmp-dis"
|
|
|
|
|
|
|
|
flags=(
|
|
|
|
--disorderfs
|
|
|
|
--conf=format=tar --conf=bootloader=none
|
|
|
|
--conf=machine-id="$(uuidgen|tr -d -)"
|
|
|
|
--conf=SOURCE_DATE_EPOCH=auto
|
|
|
|
--package=base
|
|
|
|
|
|
|
|
# TODO: We simply delete the known non-reproducible
|
|
|
|
# files, to verify that we don't get *less*
|
|
|
|
# reproducible; but we aren't actually reproducible
|
|
|
|
# yet.
|
|
|
|
--module="$PWD/mod-reproducible.sh"
|
|
|
|
)
|
|
|
|
|
|
|
|
echo 'Building first image...'
|
2024-01-26 06:35:45 +00:00
|
|
|
TMPDIR="$tmpdir/tmp-dis" osi-mk "${flags[@]}" "$tmpdir/tst1.img"
|
2024-02-14 08:35:13 +00:00
|
|
|
echo 'Building second image...'
|
2024-01-26 06:35:45 +00:00
|
|
|
TMPDIR="$tmpdir/tmp-dis" osi-mk "${flags[@]}" "$tmpdir/tst2.img"
|
2024-02-14 08:35:13 +00:00
|
|
|
echo 'Comparing...'
|
2024-01-26 06:35:45 +00:00
|
|
|
cmp "$tmpdir/tst1.img" "$tmpdir/tst2.img"
|
|
|
|
}
|