about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--nixos/doc/manual/development/writing-nixos-tests.xml8
-rw-r--r--nixos/lib/test-driver/Machine.pm3
-rw-r--r--nixos/lib/testing.nix11
-rw-r--r--nixos/tests/installer.nix4
4 files changed, 21 insertions, 5 deletions
diff --git a/nixos/doc/manual/development/writing-nixos-tests.xml b/nixos/doc/manual/development/writing-nixos-tests.xml
index 322778d1c209..b9da712b86f0 100644
--- a/nixos/doc/manual/development/writing-nixos-tests.xml
+++ b/nixos/doc/manual/development/writing-nixos-tests.xml
@@ -158,7 +158,9 @@ startAll;
     <term><methodname>getScreenText</methodname></term>
     <listitem><para>Return a textual representation of what is currently
     visible on the machine's screen using optical character
-    recognition.</para></listitem>
+    recognition.</para>
+    <note><para>This requires passing <option>enableOCR</option> to the test
+    attribute set.</para></note></listitem>
   </varlistentry>
 
   <varlistentry>
@@ -248,7 +250,9 @@ startAll;
     <term><methodname>waitForText</methodname></term>
     <listitem><para>Wait until the supplied regular expressions matches
     the textual contents of the screen by using optical character recognition
-    (see <methodname>getScreenText</methodname>).</para></listitem>
+    (see <methodname>getScreenText</methodname>).</para>
+    <note><para>This requires passing <option>enableOCR</option> to the test
+    attribute set.</para></note></listitem>
   </varlistentry>
 
   <varlistentry>
diff --git a/nixos/lib/test-driver/Machine.pm b/nixos/lib/test-driver/Machine.pm
index d149634e9e62..824f23bcc4bb 100644
--- a/nixos/lib/test-driver/Machine.pm
+++ b/nixos/lib/test-driver/Machine.pm
@@ -499,6 +499,9 @@ sub screenshot {
 sub getScreenText {
     my ($self) = @_;
 
+    system("type -P tesseract &> /dev/null") == 0
+        or die "getScreenText used but enableOCR is false";
+
     my $text;
     $self->nest("performing optical character recognition", sub {
         my $tmpbase = Cwd::abs_path(".")."/ocr";
diff --git a/nixos/lib/testing.nix b/nixos/lib/testing.nix
index 431e3de6a8ce..2039740a4578 100644
--- a/nixos/lib/testing.nix
+++ b/nixos/lib/testing.nix
@@ -27,7 +27,7 @@ rec {
         cp ${./test-driver/Logger.pm} $libDir/Logger.pm
 
         wrapProgram $out/bin/nixos-test-driver \
-          --prefix PATH : "${qemu_kvm}/bin:${vde2}/bin:${netpbm}/bin:${coreutils}/bin:${tesseract}/bin" \
+          --prefix PATH : "${qemu_kvm}/bin:${vde2}/bin:${netpbm}/bin:${coreutils}/bin" \
           --prefix PERL5LIB : "${with perlPackages; lib.makePerlPath [ TermReadLineGnu XMLWriter IOTty FileSlurp ]}:$out/lib/perl5/site_perl"
       '';
   };
@@ -68,7 +68,12 @@ rec {
 
 
   makeTest =
-    { testScript, makeCoverageReport ? false, name ? "unnamed", ... } @ t:
+    { testScript
+    , makeCoverageReport ? false
+    , enableOCR ? false
+    , name ? "unnamed"
+    , ...
+    } @ t:
 
     let
       testDriverName = "nixos-test-driver-${name}";
@@ -102,12 +107,14 @@ rec {
           vms="$(for i in ${toString vms}; do echo $i/bin/run-*-vm; done)"
           wrapProgram $out/bin/nixos-test-driver \
             --add-flags "$vms" \
+            ${lib.optionalString enableOCR "--prefix PATH : '${tesseract}/bin'"} \
             --run "testScript=\"\$(cat $out/test-script)\"" \
             --set testScript '"$testScript"' \
             --set VLANS '"${toString vlans}"'
           ln -s ${testDriver}/bin/nixos-test-driver $out/bin/nixos-run-vms
           wrapProgram $out/bin/nixos-run-vms \
             --add-flags "$vms" \
+            ${lib.optionalString enableOCR "--prefix PATH : '${tesseract}/bin'"} \
             --set tests '"startAll; joinAll;"' \
             --set VLANS '"${toString vlans}"' \
             ${lib.optionalString (builtins.length vms == 1) "--set USE_SERIAL 1"}
diff --git a/nixos/tests/installer.nix b/nixos/tests/installer.nix
index f491b0460330..64f98141cc0e 100644
--- a/nixos/tests/installer.nix
+++ b/nixos/tests/installer.nix
@@ -252,12 +252,13 @@ let
   makeInstallerTest = name:
     { createPartitions, preBootCommands ? "", extraConfig ? ""
     , testChannel ? false, grubVersion ? 2, grubDevice ? "/dev/vda"
-    , grubIdentifier ? "uuid"
+    , grubIdentifier ? "uuid", enableOCR ? false
     }:
     makeTest {
       inherit iso;
       name = "installer-" + name;
       nodes = if testChannel then { inherit webserver; } else { };
+      inherit enableOCR;
       testScript = testScriptFun {
         inherit createPartitions preBootCommands testChannel grubVersion
                 grubDevice grubIdentifier extraConfig;
@@ -364,6 +365,7 @@ in {
           preLVM = true;
         };
       '';
+      enableOCR = true;
       preBootCommands = ''
         $machine->start;
         $machine->waitForText(qr/Enter passphrase/);