git.iko.soy/typeable/nixpkgs
on master help sign in
login test: Create and use direct reads of the TTY contents.
commitcb74fd75d700228b441b87a6dc46fba663821a97 authorGraham Christensen <graham@grahamc.com> dateTue 29 Nov 2016, 23:58 (10 years ago) parentb09435e
2 files changed+28−2
nixos/lib/test-driver/Machine.pm+25 nixos/tests/login.nix+3−2
nixos/lib/test-driver/Machine.pm+25
@@ -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
@@ -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");