Merge pull request #20808 from grahamc/fancy-test-tty
login test: Create and use direct reads of the TTY contents.
This commit is contained in:
commit
b28d21fd50
@ -504,6 +504,31 @@ sub screenshot {
|
|||||||
}, { image => $name } );
|
}, { image => $name } );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Get the text of TTY<n>
|
||||||
|
sub getTTYText {
|
||||||
|
my ($self, $tty) = @_;
|
||||||
|
|
||||||
|
my ($status, $out) = $self->execute("fold -w 80 /dev/vcs${tty}");
|
||||||
|
return $out;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Wait until TTY<n>'s text matches a particular regular expression
|
||||||
|
sub waitUntilTTYMatches {
|
||||||
|
my ($self, $tty, $regexp) = @_;
|
||||||
|
|
||||||
|
$self->nest("waiting for $regexp to appear on tty $tty", sub {
|
||||||
|
retry sub {
|
||||||
|
return 1 if $self->getTTYText($tty) =~ /$regexp/;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
# Debugging: Dump the contents of the TTY<n>
|
||||||
|
sub dumpTTYContents {
|
||||||
|
my ($self, $tty) = @_;
|
||||||
|
|
||||||
|
$self->execute("fold -w 80 /dev/vcs${tty} | systemd-cat");
|
||||||
|
}
|
||||||
|
|
||||||
# Take a screenshot and return the result as text using optical character
|
# Take a screenshot and return the result as text using optical character
|
||||||
# recognition.
|
# recognition.
|
||||||
|
@ -33,10 +33,11 @@ import ./make-test.nix ({ pkgs, latestKernel ? false, ... }:
|
|||||||
|
|
||||||
# Log in as alice on a virtual console.
|
# Log in as alice on a virtual console.
|
||||||
subtest "virtual console login", sub {
|
subtest "virtual console login", sub {
|
||||||
$machine->sleep(2); # urgh: wait for username prompt
|
$machine->waitUntilTTYMatches(2, "login: ");
|
||||||
$machine->sendChars("alice\n");
|
$machine->sendChars("alice\n");
|
||||||
|
$machine->waitUntilTTYMatches(2, "login: alice");
|
||||||
$machine->waitUntilSucceeds("pgrep login");
|
$machine->waitUntilSucceeds("pgrep login");
|
||||||
$machine->sleep(2); # urgh: wait for `Password:'
|
$machine->waitUntilTTYMatches(2, "Password: ");
|
||||||
$machine->sendChars("foobar\n");
|
$machine->sendChars("foobar\n");
|
||||||
$machine->waitUntilSucceeds("pgrep -u alice bash");
|
$machine->waitUntilSucceeds("pgrep -u alice bash");
|
||||||
$machine->sendChars("touch done\n");
|
$machine->sendChars("touch done\n");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user