From 6939873412c0a08368f5f57147ee7c1e4b413b93 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Fri, 10 Jul 2020 10:30:33 +0100 Subject: [PATCH] test: exercise systemd-dissect --mount in TEST-50-DISSECT --- test/TEST-50-DISSECT/test.sh | 2 ++ test/units/testsuite-50.sh | 35 +++++++++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/test/TEST-50-DISSECT/test.sh b/test/TEST-50-DISSECT/test.sh index cfe97aaa2da..28a7f986bfe 100755 --- a/test/TEST-50-DISSECT/test.sh +++ b/test/TEST-50-DISSECT/test.sh @@ -25,7 +25,9 @@ test_create_image() { instmods loop =block instmods squashfs =squashfs instmods dm_verity =md + install_dmevent generate_module_dependencies + inst_binary md5sum inst_binary mksquashfs inst_binary veritysetup ) diff --git a/test/units/testsuite-50.sh b/test/units/testsuite-50.sh index 9f35ffd653f..131893ff839 100755 --- a/test/units/testsuite-50.sh +++ b/test/units/testsuite-50.sh @@ -4,27 +4,50 @@ set -ex set -o pipefail +cleanup() +{ + if [ -z "${image_dir}" ]; then + return + fi + rm -rf "${image_dir}" +} + cd /tmp -image=$(mktemp -d -t -p /tmp tmp.XXXXXX) -if [ -z "${image}" ] || [ ! -d "${image}" ]; then - echo "Could not create temporary directory with mktemp under /tmp" - exit 1 +image_dir="$(mktemp -d -t -p /tmp tmp.XXXXXX)" +if [ -z "${image_dir}" ] || [ ! -d "${image_dir}" ]; then + echo "mktemp under /tmp failed" + exit 1 fi +trap cleanup EXIT + +image="${image_dir}/img" mkdir -p ${image}/usr/lib ${image}/etc cp /usr/lib/os-release ${image}/usr/lib/ cp /etc/machine-id /etc/os-release ${image}/etc/ mksquashfs ${image} ${image}.raw veritysetup format ${image}.raw ${image}.verity | grep '^Root hash:' | cut -f2 | tr -d '\n' > ${image}.roothash +roothash="$(cat ${image}.roothash)" /usr/lib/systemd/systemd-dissect ${image}.raw | grep -q -F "Found read-only 'root' partition of type squashfs with verity" /usr/lib/systemd/systemd-dissect ${image}.raw | grep -q -F -f /usr/lib/os-release mv ${image}.verity ${image}.fooverity mv ${image}.roothash ${image}.foohash -/usr/lib/systemd/systemd-dissect ${image}.raw --root-hash=`cat ${image}.foohash` --verity-data=${image}.fooverity | grep -q -F "Found read-only 'root' partition of type squashfs with verity" -/usr/lib/systemd/systemd-dissect ${image}.raw --root-hash=`cat ${image}.foohash` --verity-data=${image}.fooverity | grep -q -F -f /usr/lib/os-release +/usr/lib/systemd/systemd-dissect ${image}.raw --root-hash=${roothash} --verity-data=${image}.fooverity | grep -q -F "Found read-only 'root' partition of type squashfs with verity" +/usr/lib/systemd/systemd-dissect ${image}.raw --root-hash=${roothash} --verity-data=${image}.fooverity | grep -q -F -f /usr/lib/os-release +mv ${image}.fooverity ${image}.verity +mv ${image}.foohash ${image}.roothash + +mkdir -p ${image_dir}/mount +/usr/lib/systemd/systemd-dissect --mount ${image}.raw ${image_dir}/mount +pushd ${image_dir}/mount/etc/ +(cd /etc; md5sum os-release) | md5sum -c +cd ../usr/lib +(cd /usr/lib; md5sum os-release) | md5sum -c +popd +umount ${image_dir}/mount echo OK > /testok -- 2.39.2