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