test: exercise systemd-dissect --mount in TEST-50-DISSECT
authorLuca Boccassi <luca.boccassi@microsoft.com>
Fri, 10 Jul 2020 09:30:33 +0000 (10:30 +0100)
committerLuca Boccassi <luca.boccassi@microsoft.com>
Wed, 15 Jul 2020 18:35:40 +0000 (19:35 +0100)
test/TEST-50-DISSECT/test.sh
test/units/testsuite-50.sh

index cfe97aaa2da48df6a029984f6e93788d1ebc271d..28a7f986bfe41b13ca5d26ffe368502ebb943ff6 100755 (executable)
@@ -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
     )
index 9f35ffd653fc54af200258ad96fdee6e263dd41b..131893ff839ba387883386475a1580720a64ba3a 100755 (executable)
@@ -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