1
0
Fork 0
cryptsetup/debian/tests/cryptroot-lvm.d/mock
Daniel Baumann 74b680e410
Adding debian version 2:2.7.5-2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
2025-06-21 10:45:48 +02:00

54 lines
1.7 KiB
Perl
Executable file

#!/usr/bin/perl -T
BEGIN {
require "./debian/tests/utils/mock.pm";
CryptrootTest::Mock::->import();
}
my $POWERCYCLE_COUNT = $ARGV[0];
unlock_disk("topsecret");
if ($POWERCYCLE_COUNT == 0) {
login("root");
# make sure the root FS and swap are help by dm-crypt devices
shell(q{cryptsetup luksOpen --test-passphrase /dev/vda3 <<<topsecret}, rv => 0);
my $out = shell(q{lsblk -in -oNAME,TYPE,MOUNTPOINT /dev/vda3});
die unless $out =~ m#^`-vda3_crypt\s+crypt\s*$#m;
die unless $out =~ m#^\s{2}[`|]-cryptvg-root\s+lvm\s+/\s*$#m;
die unless $out =~ m#^\s{2}[`|]-cryptvg-swap\s+lvm\s+\[SWAP\]\s*$#m;
# create a stamp in memory, hibernate (suspend on disk) and thaw
shell(q{echo hello >/dev/shm/foo.stamp});
hibernate();
}
else {
expect($SERIAL => qr/(?:^|\s)?PM: (?:hibernation: )?hibernation exit\r\n/m);
# no need to relogin, we get the shell as we left it
shell(q{grep -Fx hello </dev/shm/foo.stamp}, rv => 0);
# briefly suspend
suspend();
# make sure wakeup yields a cryptsetup prompt
wakeup();
expect($SERIAL => qr/(?:^|\s)?PM: suspend exit\r\n/m);
unlock_disk("topsecret");
# suspend() leaves clutter in the console due to the retries
# that prevents test from succeeding.
consume($CONSOLE);
# ensure that shell is available
shell(q{echo ready}, rv => 0);
my $out = shell(q{dmsetup info -c --noheadings -omangled_name,suspended --separator ' '});
die if grep !/[:[:blank:]]Active$/i, split(/\r?\n/, $out);
# test I/O on the root file system
shell(q{cp -vT /dev/shm/foo.stamp /cryptroot.stamp});
shell(q{grep -Fx hello </cryptroot.stamp}, rv => 0);
QMP::quit();
}