nixos/test-driver: Make tesseract OCR optional.

By default this is now enabled, and it has to be explicitely enabled
using "enableOCR = true". If it is set to false, any usage of
getScreenText or waitForText will fail with an error suggesting to pass
enableOCR.

This should get rid of the rather large dependency on tesseract which
we don't need for most tests.

Note, that I'm using system("type -P") here to check whether tesseract
is in PATH. I know it's a bashism but we already have other bashisms
within the test scripts and we also run it with bash, so IMHO it's not a
problem here.

Signed-off-by: aszlig <aszlig@redmoonstudios.org>

aszlig 8be00dc7 efd4fcbe

+21 -5
+6 -2
nixos/doc/manual/development/writing-nixos-tests.xml
··· 158 <term><methodname>getScreenText</methodname></term> 159 <listitem><para>Return a textual representation of what is currently 160 visible on the machine's screen using optical character 161 - recognition.</para></listitem> 162 </varlistentry> 163 164 <varlistentry> ··· 248 <term><methodname>waitForText</methodname></term> 249 <listitem><para>Wait until the supplied regular expressions matches 250 the textual contents of the screen by using optical character recognition 251 - (see <methodname>getScreenText</methodname>).</para></listitem> 252 </varlistentry> 253 254 <varlistentry>
··· 158 <term><methodname>getScreenText</methodname></term> 159 <listitem><para>Return a textual representation of what is currently 160 visible on the machine's screen using optical character 161 + recognition.</para> 162 + <note><para>This requires passing <option>enableOCR</option> to the test 163 + attribute set.</para></note></listitem> 164 </varlistentry> 165 166 <varlistentry> ··· 250 <term><methodname>waitForText</methodname></term> 251 <listitem><para>Wait until the supplied regular expressions matches 252 the textual contents of the screen by using optical character recognition 253 + (see <methodname>getScreenText</methodname>).</para> 254 + <note><para>This requires passing <option>enableOCR</option> to the test 255 + attribute set.</para></note></listitem> 256 </varlistentry> 257 258 <varlistentry>
+3
nixos/lib/test-driver/Machine.pm
··· 499 sub getScreenText { 500 my ($self) = @_; 501 502 my $text; 503 $self->nest("performing optical character recognition", sub { 504 my $tmpbase = Cwd::abs_path(".")."/ocr";
··· 499 sub getScreenText { 500 my ($self) = @_; 501 502 + system("type -P tesseract &> /dev/null") == 0 503 + or die "getScreenText used but enableOCR is false"; 504 + 505 my $text; 506 $self->nest("performing optical character recognition", sub { 507 my $tmpbase = Cwd::abs_path(".")."/ocr";
+9 -2
nixos/lib/testing.nix
··· 27 cp ${./test-driver/Logger.pm} $libDir/Logger.pm 28 29 wrapProgram $out/bin/nixos-test-driver \ 30 - --prefix PATH : "${qemu_kvm}/bin:${vde2}/bin:${netpbm}/bin:${coreutils}/bin:${tesseract}/bin" \ 31 --prefix PERL5LIB : "${with perlPackages; lib.makePerlPath [ TermReadLineGnu XMLWriter IOTty FileSlurp ]}:$out/lib/perl5/site_perl" 32 ''; 33 }; ··· 68 69 70 makeTest = 71 - { testScript, makeCoverageReport ? false, name ? "unnamed", ... } @ t: 72 73 let 74 testDriverName = "nixos-test-driver-${name}"; ··· 102 vms="$(for i in ${toString vms}; do echo $i/bin/run-*-vm; done)" 103 wrapProgram $out/bin/nixos-test-driver \ 104 --add-flags "$vms" \ 105 --run "testScript=\"\$(cat $out/test-script)\"" \ 106 --set testScript '"$testScript"' \ 107 --set VLANS '"${toString vlans}"' 108 ln -s ${testDriver}/bin/nixos-test-driver $out/bin/nixos-run-vms 109 wrapProgram $out/bin/nixos-run-vms \ 110 --add-flags "$vms" \ 111 --set tests '"startAll; joinAll;"' \ 112 --set VLANS '"${toString vlans}"' \ 113 ${lib.optionalString (builtins.length vms == 1) "--set USE_SERIAL 1"}
··· 27 cp ${./test-driver/Logger.pm} $libDir/Logger.pm 28 29 wrapProgram $out/bin/nixos-test-driver \ 30 + --prefix PATH : "${qemu_kvm}/bin:${vde2}/bin:${netpbm}/bin:${coreutils}/bin" \ 31 --prefix PERL5LIB : "${with perlPackages; lib.makePerlPath [ TermReadLineGnu XMLWriter IOTty FileSlurp ]}:$out/lib/perl5/site_perl" 32 ''; 33 }; ··· 68 69 70 makeTest = 71 + { testScript 72 + , makeCoverageReport ? false 73 + , enableOCR ? false 74 + , name ? "unnamed" 75 + , ... 76 + } @ t: 77 78 let 79 testDriverName = "nixos-test-driver-${name}"; ··· 107 vms="$(for i in ${toString vms}; do echo $i/bin/run-*-vm; done)" 108 wrapProgram $out/bin/nixos-test-driver \ 109 --add-flags "$vms" \ 110 + ${lib.optionalString enableOCR "--prefix PATH : '${tesseract}/bin'"} \ 111 --run "testScript=\"\$(cat $out/test-script)\"" \ 112 --set testScript '"$testScript"' \ 113 --set VLANS '"${toString vlans}"' 114 ln -s ${testDriver}/bin/nixos-test-driver $out/bin/nixos-run-vms 115 wrapProgram $out/bin/nixos-run-vms \ 116 --add-flags "$vms" \ 117 + ${lib.optionalString enableOCR "--prefix PATH : '${tesseract}/bin'"} \ 118 --set tests '"startAll; joinAll;"' \ 119 --set VLANS '"${toString vlans}"' \ 120 ${lib.optionalString (builtins.length vms == 1) "--set USE_SERIAL 1"}
+3 -1
nixos/tests/installer.nix
··· 252 makeInstallerTest = name: 253 { createPartitions, preBootCommands ? "", extraConfig ? "" 254 , testChannel ? false, grubVersion ? 2, grubDevice ? "/dev/vda" 255 - , grubIdentifier ? "uuid" 256 }: 257 makeTest { 258 inherit iso; 259 name = "installer-" + name; 260 nodes = if testChannel then { inherit webserver; } else { }; 261 testScript = testScriptFun { 262 inherit createPartitions preBootCommands testChannel grubVersion 263 grubDevice grubIdentifier extraConfig; ··· 364 preLVM = true; 365 }; 366 ''; 367 preBootCommands = '' 368 $machine->start; 369 $machine->waitForText(qr/Enter passphrase/);
··· 252 makeInstallerTest = name: 253 { createPartitions, preBootCommands ? "", extraConfig ? "" 254 , testChannel ? false, grubVersion ? 2, grubDevice ? "/dev/vda" 255 + , grubIdentifier ? "uuid", enableOCR ? false 256 }: 257 makeTest { 258 inherit iso; 259 name = "installer-" + name; 260 nodes = if testChannel then { inherit webserver; } else { }; 261 + inherit enableOCR; 262 testScript = testScriptFun { 263 inherit createPartitions preBootCommands testChannel grubVersion 264 grubDevice grubIdentifier extraConfig; ··· 365 preLVM = true; 366 }; 367 ''; 368 + enableOCR = true; 369 preBootCommands = '' 370 $machine->start; 371 $machine->waitForText(qr/Enter passphrase/);