Merge pull request #20808 from grahamc/fancy-test-tty

login test: Create and use direct reads of the TTY contents.

Changed files
+28 -2
nixos
lib
test-driver
tests
+25
nixos/lib/test-driver/Machine.pm
···
}, { image => $name } );
}
# Take a screenshot and return the result as text using optical character
# recognition.
···
}, { 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.
+3 -2
nixos/tests/login.nix
···
# Log in as alice on a virtual console.
subtest "virtual console login", sub {
-
$machine->sleep(2); # urgh: wait for username prompt
$machine->sendChars("alice\n");
$machine->waitUntilSucceeds("pgrep login");
-
$machine->sleep(2); # urgh: wait for `Password:'
$machine->sendChars("foobar\n");
$machine->waitUntilSucceeds("pgrep -u alice bash");
$machine->sendChars("touch done\n");
···
# Log in as alice on a virtual console.
subtest "virtual console login", sub {
+
$machine->waitUntilTTYMatches(2, "login: ");
$machine->sendChars("alice\n");
+
$machine->waitUntilTTYMatches(2, "login: alice");
$machine->waitUntilSucceeds("pgrep login");
+
$machine->waitUntilTTYMatches(2, "Password: ");
$machine->sendChars("foobar\n");
$machine->waitUntilSucceeds("pgrep -u alice bash");
$machine->sendChars("touch done\n");