Skip to content

Commit

Permalink
fix: Add a verity_cleanup function to test helpers.bash
Browse files Browse the repository at this point in the history
The atomfs bad verity test case ends up leaving verity and loop
devices which then break other test cases.  Tearing a bad verity
device down requires more inspection of the system to determine the
correct verity hash device name and the loop device in use.  Add
the verity_cleanup to the teardown() method in atomfs and squashfs
tests.

Fixes: #541

Signed-off-by: Ryan Harper <rharper@woxford.com>
  • Loading branch information
raharper committed Nov 29, 2023
1 parent 3897848 commit d894e7f
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/atomfs.bats
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ function setup() {

function teardown() {
cleanup
verity_cleanup
}

function basic_test() {
Expand Down
36 changes: 36 additions & 0 deletions test/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,42 @@ function cleanup() {
rm -rf "$TEST_TMPDIR" || true
}

function verity_cleanup() {
# search for loopdevices which have backing files with the current BATS_TEST_NAME value
# if we find them, we can use them to tear down the verity device, and cleanup the loopdev
# normally, on verity close, the loop dev is removed as well, but on the bad test, it does
# not, so we have to clean that up here.

usedloop=$(losetup -a | grep "$BATS_TEST_NAME")
if [ -n "$usedloop" ]; then
echo "found a used loop device $usedloop"

loopdev=$(echo "$usedloop" | cut -d: -f1)
loopname=${loopdev##*/}
echo "loopdev=$loopdev loopname=$loopname"

badloop_hash=$(basename "$(<"/sys/class/block/$loopname/loop/backing_file")")
echo "badloop_hash=$badloop_hash"

bad_devname="/dev/mapper/${badloop_hash}-verity"
echo "Checking if bad verity device $bad_devname exists..."

while [ -b "$bad_devname" ]; do
echo "closing verity device $bad_devname"
veritysetup close "$bad_devname" || true
udevadm settle
sleep 1
done

while [ -e "/sys/class/block/$loopname/loop" ]; do
echo "closing loop device $loopdev"
losetup -d "$loopdev" || true
udevadm settle
sleep 1
done
fi
}

function run_as {
if [ "$PRIVILEGE_LEVEL" = "priv" ]; then
"$@"
Expand Down
1 change: 1 addition & 0 deletions test/squashfs.bats
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function teardown() {
umount layer1 || true
rm -rf layer0 layer1 || true
cleanup
verity_cleanup
}

@test "squashfs + derivative build only layers" {
Expand Down

0 comments on commit d894e7f

Please sign in to comment.