···504 }, { image => $name } );
505}
5060000000000000000000000000507508# Take a screenshot and return the result as text using optical character
509# recognition.
···504 }, { image => $name } );
505}
506507+# Get the text of TTY<n>
508+sub getTTYText {
509+ my ($self, $tty) = @_;
510+511+ my ($status, $out) = $self->execute("fold -w 80 /dev/vcs${tty}");
512+ return $out;
513+}
514+515+# Wait until TTY<n>'s text matches a particular regular expression
516+sub waitUntilTTYMatches {
517+ my ($self, $tty, $regexp) = @_;
518+519+ $self->nest("waiting for $regexp to appear on tty $tty", sub {
520+ retry sub {
521+ return 1 if $self->getTTYText($tty) =~ /$regexp/;
522+ }
523+ });
524+}
525+526+# Debugging: Dump the contents of the TTY<n>
527+sub dumpTTYContents {
528+ my ($self, $tty) = @_;
529+530+ $self->execute("fold -w 80 /dev/vcs${tty} | systemd-cat");
531+}
532533# Take a screenshot and return the result as text using optical character
534# recognition.
+3-2
nixos/tests/login.nix
···3334 # Log in as alice on a virtual console.
35 subtest "virtual console login", sub {
36- $machine->sleep(2); # urgh: wait for username prompt
37 $machine->sendChars("alice\n");
038 $machine->waitUntilSucceeds("pgrep login");
39- $machine->sleep(2); # urgh: wait for `Password:'
40 $machine->sendChars("foobar\n");
41 $machine->waitUntilSucceeds("pgrep -u alice bash");
42 $machine->sendChars("touch done\n");
···3334 # Log in as alice on a virtual console.
35 subtest "virtual console login", sub {
36+ $machine->waitUntilTTYMatches(2, "login: ");
37 $machine->sendChars("alice\n");
38+ $machine->waitUntilTTYMatches(2, "login: alice");
39 $machine->waitUntilSucceeds("pgrep login");
40+ $machine->waitUntilTTYMatches(2, "Password: ");
41 $machine->sendChars("foobar\n");
42 $machine->waitUntilSucceeds("pgrep -u alice bash");
43 $machine->sendChars("touch done\n");