From 56435c140413ae43530d03ae1db3c8cdd43d3838 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Tue, 20 Jun 2017 19:53:25 -0400 Subject: [PATCH 1/4] nixos tests: retry: Count down to 0, and pass remaining attempts to the sub Allows test functions to output diagnostic information on failure. --- nixos/lib/test-driver/Machine.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nixos/lib/test-driver/Machine.pm b/nixos/lib/test-driver/Machine.pm index 6be119bbf33..c88f9f2bbbe 100644 --- a/nixos/lib/test-driver/Machine.pm +++ b/nixos/lib/test-driver/Machine.pm @@ -219,8 +219,8 @@ sub waitForMonitorPrompt { sub retry { my ($coderef) = @_; my $n; - for ($n = 0; $n < 900; $n++) { - return if &$coderef; + for ($n = 899; $n >=0; $n--) { + return if &$coderef($n); sleep 1; } die "action timed out after $n seconds"; From 348785eec0c499dc4f79943cedcd78be279ca41d Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Tue, 20 Jun 2017 20:55:52 -0400 Subject: [PATCH 2/4] nixos tests: waitUntilTTYMatches: Log TTY contents on last try If the test has not passed yet, on the last attempt it now outputs: machine: Last chance to match /logine: / on TTY2, which currently contains: machine: running command: fold -w$(stty -F /dev/tty2 size | awk '{print $2}') /dev/vcs2 machine: exit status 0 machine: <<< Welcome to NixOS 17.09.git.a804ef4 (x86_64) - tty2 >>> machine login: to help debug the problem. Notice the "logine" typo in my check. --- nixos/lib/test-driver/Machine.pm | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/nixos/lib/test-driver/Machine.pm b/nixos/lib/test-driver/Machine.pm index c88f9f2bbbe..973e05542d5 100644 --- a/nixos/lib/test-driver/Machine.pm +++ b/nixos/lib/test-driver/Machine.pm @@ -518,6 +518,12 @@ sub waitUntilTTYMatches { $self->nest("waiting for $regexp to appear on tty $tty", sub { retry sub { + my ($retries_remaining) = @_; + if ($retries_remaining == 0) { + $self->log("Last chance to match /$regexp/ on TTY$tty, which currently contains:"); + $self->log($self->getTTYText($tty)); + } + return 1 if $self->getTTYText($tty) =~ /$regexp/; } }); From 1b833015b72fa6ccf379c46706d1d645cd216f07 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Tue, 20 Jun 2017 21:10:34 -0400 Subject: [PATCH 3/4] nixos tests: waitForText: output the detected screen content prior to the last attempt machine: Last chance to match /(?^:BALICE)/ on the screen, which currently contains: machine: performing optical character recognition machine: sending monitor command: screendump /tmp/nix-build-vm-test-run-sddm.drv-0/ocrin.ppm machine: Session Layout O O 0 1 : 0 9 Wednesday, June 21, 2017 |_ I Select your user and enter password --- nixos/lib/test-driver/Machine.pm | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/nixos/lib/test-driver/Machine.pm b/nixos/lib/test-driver/Machine.pm index 973e05542d5..4a68e0cd9dc 100644 --- a/nixos/lib/test-driver/Machine.pm +++ b/nixos/lib/test-driver/Machine.pm @@ -572,6 +572,12 @@ sub waitForText { my ($self, $regexp) = @_; $self->nest("waiting for $regexp to appear on the screen", sub { retry sub { + my ($retries_remaining) = @_; + if ($retries_remaining == 0) { + $self->log("Last chance to match /$regexp/ on the screen, which currently contains:"); + $self->log($self->getScreenText); + } + return 1 if $self->getScreenText =~ /$regexp/; } }); From 3f40fcabbf692ac08cee390ac9b56650ca075630 Mon Sep 17 00:00:00 2001 From: Graham Christensen Date: Tue, 20 Jun 2017 21:16:35 -0400 Subject: [PATCH 4/4] nixos tests: waitForWindow: output a list of windows we see prior to the final check machine: must succeed: xwininfo -root -tree | sed 's/.*0x[0-9a-f]* \"\([^\"]*\)\".*/\1/; t; d' machine: exit status 0 machine: Last chance to match /(?^:dfiirst configuration)/ on the the window list, which currently contains: machine: [i3 con] container around 0xf8a5f0, i3: first configuration, [i3 con] floatingcon around 0xf8c260, [i3 con] container around 0xf8a380, i3bar for output Virtual-1, [i3 con] bottom dockarea Virtual-1, [i3 con] workspace 1, [i3 con] content Virtual-1, [i3 con] top dockarea Virtual-1, [i3 con] output Virtual-1, [i3 con] workspace __i3_scratch, [i3 con] content __i3, [i3 con] pseudo-output __i3, i3 --- nixos/lib/test-driver/Machine.pm | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/nixos/lib/test-driver/Machine.pm b/nixos/lib/test-driver/Machine.pm index 4a68e0cd9dc..cd375352c4c 100644 --- a/nixos/lib/test-driver/Machine.pm +++ b/nixos/lib/test-driver/Machine.pm @@ -612,6 +612,13 @@ sub waitForWindow { $self->nest("waiting for a window to appear", sub { retry sub { my @names = $self->getWindowNames; + + my ($retries_remaining) = @_; + if ($retries_remaining == 0) { + $self->log("Last chance to match /$regexp/ on the the window list, which currently contains:"); + $self->log(join(", ", @names)); + } + foreach my $n (@names) { return 1 if $n =~ /$regexp/; }