···504504 }, { image => $name } );
505505}
506506507507+# Get the text of TTY<n>
508508+sub getTTYText {
509509+ my ($self, $tty) = @_;
510510+511511+ my ($status, $out) = $self->execute("fold -w 80 /dev/vcs${tty}");
512512+ return $out;
513513+}
514514+515515+# Wait until TTY<n>'s text matches a particular regular expression
516516+sub waitUntilTTYMatches {
517517+ my ($self, $tty, $regexp) = @_;
518518+519519+ $self->nest("waiting for $regexp to appear on tty $tty", sub {
520520+ retry sub {
521521+ return 1 if $self->getTTYText($tty) =~ /$regexp/;
522522+ }
523523+ });
524524+}
525525+526526+# Debugging: Dump the contents of the TTY<n>
527527+sub dumpTTYContents {
528528+ my ($self, $tty) = @_;
529529+530530+ $self->execute("fold -w 80 /dev/vcs${tty} | systemd-cat");
531531+}
507532508533# Take a screenshot and return the result as text using optical character
509534# recognition.
+3-2
nixos/tests/login.nix
···33333434 # Log in as alice on a virtual console.
3535 subtest "virtual console login", sub {
3636- $machine->sleep(2); # urgh: wait for username prompt
3636+ $machine->waitUntilTTYMatches(2, "login: ");
3737 $machine->sendChars("alice\n");
3838+ $machine->waitUntilTTYMatches(2, "login: alice");
3839 $machine->waitUntilSucceeds("pgrep login");
3939- $machine->sleep(2); # urgh: wait for `Password:'
4040+ $machine->waitUntilTTYMatches(2, "Password: ");
4041 $machine->sendChars("foobar\n");
4142 $machine->waitUntilSucceeds("pgrep -u alice bash");
4243 $machine->sendChars("touch done\n");