Skip to content

Commit 06a45eb

Browse files
grahamcGraham Christensen
authored and
Graham Christensen
committedNov 30, 2016
login test: Create and use direct reads of the TTY contents.
(cherry picked from commit cb74fd7)
1 parent e360c72 commit 06a45eb

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed
 

‎nixos/lib/test-driver/Machine.pm

+25
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,31 @@ sub screenshot {
504504
}, { image => $name } );
505505
}
506506

507+
# 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+
}
507532

508533
# Take a screenshot and return the result as text using optical character
509534
# recognition.

‎nixos/tests/login.nix

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ import ./make-test.nix ({ pkgs, latestKernel ? false, ... }:
3333
3434
# Log in as alice on a virtual console.
3535
subtest "virtual console login", sub {
36-
$machine->sleep(2); # urgh: wait for username prompt
36+
$machine->waitUntilTTYMatches(2, "login: ");
3737
$machine->sendChars("alice\n");
38+
$machine->waitUntilTTYMatches(2, "login: alice");
3839
$machine->waitUntilSucceeds("pgrep login");
39-
$machine->sleep(2); # urgh: wait for `Password:'
40+
$machine->waitUntilTTYMatches(2, "Password: ");
4041
$machine->sendChars("foobar\n");
4142
$machine->waitUntilSucceeds("pgrep -u alice bash");
4243
$machine->sendChars("touch done\n");

0 commit comments

Comments
 (0)
Please sign in to comment.