about summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorGraham Christensen <graham@grahamc.com>2016-11-30 11:27:49 -0500
committerGitHub <noreply@github.com>2016-11-30 11:27:49 -0500
commitb28d21fd50e855a0c727a68e59f7049e58bcb3b4 (patch)
tree9856ff504968da15c0bb678579438074ec1cfcf2 /nixos
parent014a1b430a0e52ad75922109ae5bf171720b1cb8 (diff)
parentcb74fd75d700228b441b87a6dc46fba663821a97 (diff)
downloadnixlib-b28d21fd50e855a0c727a68e59f7049e58bcb3b4.tar
nixlib-b28d21fd50e855a0c727a68e59f7049e58bcb3b4.tar.gz
nixlib-b28d21fd50e855a0c727a68e59f7049e58bcb3b4.tar.bz2
nixlib-b28d21fd50e855a0c727a68e59f7049e58bcb3b4.tar.lz
nixlib-b28d21fd50e855a0c727a68e59f7049e58bcb3b4.tar.xz
nixlib-b28d21fd50e855a0c727a68e59f7049e58bcb3b4.tar.zst
nixlib-b28d21fd50e855a0c727a68e59f7049e58bcb3b4.zip
Merge pull request #20808 from grahamc/fancy-test-tty
login test: Create and use direct reads of the TTY contents.
Diffstat (limited to 'nixos')
-rw-r--r--nixos/lib/test-driver/Machine.pm25
-rw-r--r--nixos/tests/login.nix5
2 files changed, 28 insertions, 2 deletions
diff --git a/nixos/lib/test-driver/Machine.pm b/nixos/lib/test-driver/Machine.pm
index 1a243918c22f..274b16164db3 100644
--- a/nixos/lib/test-driver/Machine.pm
+++ b/nixos/lib/test-driver/Machine.pm
@@ -504,6 +504,31 @@ sub screenshot {
     }, { 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.
diff --git a/nixos/tests/login.nix b/nixos/tests/login.nix
index e793d89567bf..a6a460fb0a7d 100644
--- a/nixos/tests/login.nix
+++ b/nixos/tests/login.nix
@@ -33,10 +33,11 @@ import ./make-test.nix ({ pkgs, latestKernel ? false, ... }:
 
       # Log in as alice on a virtual console.
       subtest "virtual console login", sub {
-          $machine->sleep(2); # urgh: wait for username prompt
+          $machine->waitUntilTTYMatches(2, "login: ");
           $machine->sendChars("alice\n");
+          $machine->waitUntilTTYMatches(2, "login: alice");
           $machine->waitUntilSucceeds("pgrep login");
-          $machine->sleep(2); # urgh: wait for `Password:'
+          $machine->waitUntilTTYMatches(2, "Password: ");
           $machine->sendChars("foobar\n");
           $machine->waitUntilSucceeds("pgrep -u alice bash");
           $machine->sendChars("touch done\n");