git.iko.soy/typeable/nixpkgs
on master help sign in
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>

commit8be00dc71dbe409447feddc42d26bdfaf38703a4 authoraszlig <aszlig@redmoonstudios.org> dateFri 22 May 2015, 07:14 (12 years ago) parentefd4fcb
4 files changed+21−5
nixos/doc/manual/development/writing-nixos-tests.xml+6−2 nixos/lib/test-driver/Machine.pm+3 nixos/lib/testing.nix+9−2 nixos/tests/installer.nix+3−1
nixos/doc/manual/development/writing-nixos-tests.xml+6−2
@@ -158,7 +158,9 @@ startAll;
158158 <term><methodname>getScreenText</methodname></term>
159159 <listitem><para>Return a textual representation of what is currently
160160 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>
162164 </varlistentry>
163165
164166 <varlistentry>
@@ -248,7 +250,9 @@ startAll;
248250 <term><methodname>waitForText</methodname></term>
249251 <listitem><para>Wait until the supplied regular expressions matches
250252 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>
252256 </varlistentry>
253257
254258 <varlistentry>
nixos/lib/test-driver/Machine.pm+3
@@ -499,6 +499,9 @@ sub screenshot {
499499sub getScreenText {
500500 my ($self) = @_;
501501
502+ system("type -P tesseract &> /dev/null") == 0
503+ or die "getScreenText used but enableOCR is false";
504+
502505 my $text;
503506 $self->nest("performing optical character recognition", sub {
504507 my $tmpbase = Cwd::abs_path(".")."/ocr";
nixos/lib/testing.nix+9−2
@@ -27,7 +27,7 @@ rec {
2727 cp ${./test-driver/Logger.pm} $libDir/Logger.pm
2828
2929 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" \
3131 --prefix PERL5LIB : "${with perlPackages; lib.makePerlPath [ TermReadLineGnu XMLWriter IOTty FileSlurp ]}:$out/lib/perl5/site_perl"
3232 '';
3333 };
@@ -68,7 +68,12 @@ rec {
6868
6969
7070 makeTest =
71− { testScript, makeCoverageReport ? false, name ? "unnamed", ... } @ t:
71+ { testScript
72+ , makeCoverageReport ? false
73+ , enableOCR ? false
74+ , name ? "unnamed"
75+ , ...
76+ } @ t:
7277
7378 let
7479 testDriverName = "nixos-test-driver-${name}";
@@ -102,12 +107,14 @@ rec {
102107 vms="$(for i in ${toString vms}; do echo $i/bin/run-*-vm; done)"
103108 wrapProgram $out/bin/nixos-test-driver \
104109 --add-flags "$vms" \
110+ ${lib.optionalString enableOCR "--prefix PATH : '${tesseract}/bin'"} \
105111 --run "testScript=\"\$(cat $out/test-script)\"" \
106112 --set testScript '"$testScript"' \
107113 --set VLANS '"${toString vlans}"'
108114 ln -s ${testDriver}/bin/nixos-test-driver $out/bin/nixos-run-vms
109115 wrapProgram $out/bin/nixos-run-vms \
110116 --add-flags "$vms" \
117+ ${lib.optionalString enableOCR "--prefix PATH : '${tesseract}/bin'"} \
111118 --set tests '"startAll; joinAll;"' \
112119 --set VLANS '"${toString vlans}"' \
113120 ${lib.optionalString (builtins.length vms == 1) "--set USE_SERIAL 1"}
nixos/tests/installer.nix+3−1
@@ -252,12 +252,13 @@ let
252252 makeInstallerTest = name:
253253 { createPartitions, preBootCommands ? "", extraConfig ? ""
254254 , testChannel ? false, grubVersion ? 2, grubDevice ? "/dev/vda"
255− , grubIdentifier ? "uuid"
255+ , grubIdentifier ? "uuid", enableOCR ? false
256256 }:
257257 makeTest {
258258 inherit iso;
259259 name = "installer-" + name;
260260 nodes = if testChannel then { inherit webserver; } else { };
261+ inherit enableOCR;
261262 testScript = testScriptFun {
262263 inherit createPartitions preBootCommands testChannel grubVersion
263264 grubDevice grubIdentifier extraConfig;
@@ -364,6 +365,7 @@ in {
364365 preLVM = true;
365366 };
366367 '';
368+ enableOCR = true;
367369 preBootCommands = ''
368370 $machine->start;
369371 $machine->waitForText(qr/Enter passphrase/);