mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-22 23:13:19 +00:00
login test: Create and use direct reads of the TTY contents.
This commit is contained in:
parent
b09435ea51
commit
cb74fd75d7
@ -504,6 +504,31 @@ sub screenshot {
|
||||
}, { 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
|
||||
# recognition.
|
||||
|
@ -33,10 +33,11 @@ import ./make-test.nix ({ pkgs, latestKernel ? false, ... }:
|
||||
|
||||
# Log in as alice on a virtual console.
|
||||
subtest "virtual console login", sub {
|
||||
$machine->sleep(2); # urgh: wait for username prompt
|
||||
$machine->waitUntilTTYMatches(2, "login: ");
|
||||
$machine->sendChars("alice\n");
|
||||
$machine->waitUntilTTYMatches(2, "login: alice");
|
||||
$machine->waitUntilSucceeds("pgrep login");
|
||||
$machine->sleep(2); # urgh: wait for `Password:'
|
||||
$machine->waitUntilTTYMatches(2, "Password: ");
|
||||
$machine->sendChars("foobar\n");
|
||||
$machine->waitUntilSucceeds("pgrep -u alice bash");
|
||||
$machine->sendChars("touch done\n");
|
||||
|
Loading…
Reference in New Issue
Block a user