diff options
Diffstat (limited to 'nixos/lib/test-driver/Machine.pm')
-rw-r--r-- | nixos/lib/test-driver/Machine.pm | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/nixos/lib/test-driver/Machine.pm b/nixos/lib/test-driver/Machine.pm index e0791692d3ef..0dddc1dc14b1 100644 --- a/nixos/lib/test-driver/Machine.pm +++ b/nixos/lib/test-driver/Machine.pm @@ -9,6 +9,7 @@ use FileHandle; use Cwd; use File::Basename; use File::Path qw(make_path); +use File::Slurp; my $showGraphics = defined $ENV{'DISPLAY'}; @@ -493,6 +494,30 @@ sub screenshot { } +# Take a screenshot and return the result as text using optical character +# recognition. +sub getScreenText { + my ($self) = @_; + + my $text; + $self->nest("performing optical character recognition", sub { + my $tmpbase = Cwd::abs_path(".")."/ocr"; + my $tmpin = $tmpbase."in.ppm"; + my $tmpout = "$tmpbase.ppm"; + + $self->sendMonitorCommand("screendump $tmpin"); + system("ppmtopgm $tmpin | pamscale 4 -filter=lanczos > $tmpout") == 0 + or die "cannot scale screenshot"; + unlink $tmpin; + system("tesseract $tmpout $tmpbase") == 0 or die "OCR failed"; + unlink $tmpout; + $text = read_file("$tmpbase.txt"); + unlink "$tmpbase.txt"; + }); + return $text; +} + + # Wait until it is possible to connect to the X server. Note that # testing the existence of /tmp/.X11-unix/X0 is insufficient. sub waitForX { |