Debian Codegraph @

src/testpattern/run-testpattern-2.in

raw
1 #!@PERL@
2
3 # Featureful driver for test pattern generator
4 #
5 # Copyright 2006-2017 Robert Krawitz ([email protected]) and other
6 # members of the Gutenprint project.
7 #
8 # This program is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by the Free
10 # Software Foundation; either version 2 of the License, or (at your option)
11 # any later version.
12 #
13 # This program is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 # for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <https://www.gnu.org/licenses/>.
20
21 use Getopt::Long;
22 Getopt::Long::Configure("bundling", "no_ignore_case", "pass_through");
23
24 use strict;
25 use POSIX ":sys_wait_h";
26
27 my $valgrind = 0;
28 my $callgrind = 0;
29 my $gdb_attach = 0;
30 my $compress_checksums = 0;
31 my $csum_file = undef;
32 my $csum_dir = undef;
33 my $csum_type = 'sha512';
34 my $dontrun = 0;
35 my $retval = 0;
36 my $halt_on_error = 0;
37 my $testpattern_command;
38 my @printer_list = ();
39 my @exclude_list = ();
40 my @include_patterns = ();
41 my @exclude_patterns = ();
42 my @special_options = ();
43 my $include_pattern = '';
44 my $exclude_pattern = '';
45 my %exclude_list = ();
46 my @standard_options = ("InkType",
47 "Resolution",
48 "InkSet,RawChannels",
49 "DitherAlgorithm",
50 "Duplex",
51 "MediaType",
52 "InputSlot",
53 "ColorCorrection",
54 "TPMode",
55 "ImageType",
56 "FullBleed",
57 "Quality",
58 "UseGloss",
59 "Weave",
60 "PrintingDirection",
61 "Density",
62 "CyanDensity",
63 "Orientation",
64 "LabelSeparator");
65 my @tp_modes = ("cmyk8",
66 "cmyk16",
67 "kcmy8",
68 "kcmy16",
69 "rgb8",
70 "rgb16",
71 "cmy8",
72 "cmy16",
73 "gray8",
74 "gray16",
75 "white8",
76 "white16");
77 my $global_status = 1;
78 my $run_installed = 0;
79 my $use_min_res = 0;
80 my $use_min_pagesize = 0;
81 my $help = 0;
82 my $output = undef;
83 my $hsize = 0.1;
84 my $vsize = 0.1;
85 my $left = 0.15;
86 my $top = 0.15;
87 my $geometry = "";
88 my $restart = 1;
89 my $global_fh;
90 my $error = 0;
91 my $global_printer;
92 my $global_messages;
93 my $global_page;
94 my $global_case;
95
96 my @extras = ();
97 my @job_extras = ();
98 my @messages = ();
99 my @global_messages = ();
100 my @families = ();
101 my %stpdata = ();
102 my %resolutions = ();
103 my %models_found = ();
104 my %models;
105 my %families;
106 my %defaults;
107 my $skip_duplicate_printers = 0;
108 my $std_pages = 1;
109 my $duplex_pages = 4;
110 my $skip_resolutions = 0;
111 my $quiet = 0;
112 my $single = 0;
113 my $rerun = 0;
114 my $list_printers = 0;
115 my $list_options = 0;
116 my $verbose = 0;
117 my $use_unused_options = 0;
118 my $proc_count = 1;
119 my $round = 0;
120 my $print_family = 0;
121 my $res_limit = 0;
122 my $proc_rotor = 0;
123 my $case_no = -1;
124 my $vg = "libtool --mode=execute valgrind";
125
126 my @default_options = ();
127 my %base_settings = ("DitherAlgorithm" => "Fast");
128
129 my %param_types;
130 my %stp_dimension_values;
131 my %stp_float_values;
132 my %stp_int_values;
133 my %min_page_size;
134 my %max_page_size;
135 my %stp_bools;
136 my %rerun_cases;
137 my $stp_test_rotor=0;
138 my $stp_test_rotor_circumference=1;
139
140 if (defined $ENV{"STP_PARALLEL"}) {
141 $proc_count = $ENV{"STP_PARALLEL"};
142 if ($proc_count < 1) {
143 $proc_count = 1;
144 } elsif ($proc_count > 1) {
145 $quiet = 1;
146 }
147 }
148 if (defined $ENV{"STP_TEST_ROTOR"} && defined $ENV{"STP_TEST_ROTOR_CIRCUMFERENCE"}) {
149 $stp_test_rotor=$ENV{"STP_TEST_ROTOR"};
150 $stp_test_rotor_circumference=$ENV{"STP_TEST_ROTOR_CIRCUMFERENCE"};
151 }
152
153
154 if (defined $ENV{"STP_TEST_FAMILY"}) {
155 @families = split(/ +/, $ENV{"STP_TEST_FAMILY"});
156 }
157
158 GetOptions("C=s" => \$csum_type,
159 "F" => \$print_family,
160 "G=s" => \$geometry,
161 "H!" => \$halt_on_error,
162 "L" => \$list_options,
163 "M:s" => \$csum_file,
164 "O=s" => \$output,
165 "P:i" => \$duplex_pages,
166 "R+" => \$use_min_res,
167 "S+" => \$single,
168 "T:i" => \$res_limit,
169 "V+" => \$verbose,
170 "X" => \$rerun,
171 "Y=s" => \@include_patterns,
172 "c" => \$callgrind,
173 "d=s" => \@default_options,
174 "f=s" => \@families,
175 "g" => \$gdb_attach,
176 "h" => \$help,
177 "i!" => \$run_installed,
178 "l" => \$list_printers,
179 "m:s" => \$csum_dir,
180 "n" => \$dontrun,
181 "o=s" => \@special_options,
182 "p:i" => \$std_pages,
183 "q+" => \$quiet,
184 "r!" => \$skip_resolutions,
185 "s!" => \$skip_duplicate_printers,
186 "N!" => \$use_unused_options,
187 "v+" => \$valgrind,
188 "x=s" => \@exclude_list,
189 "y=s" => \@exclude_patterns,
190 "u" => \$round,
191 "t:i" => \$proc_count);
192
193 sub print_help_and_exit() {
194 my $options = join("\n ", sort @standard_options);
195 print STDERR <<EOF;
196 Usage: run-testpattern-2 [opts] [model ...]
197
198 Printer selection options:
199 -f family Test printers only in the specified family. Multiple
200 families may be tested. By default, all printer families
201 are tested.
202 -s Skip duplicate printers (with the same model number
203 in printers.xml).
204 -x printer Do not test the specified printer.
205 -y pattern Do not test printers matching the specified pattern(s).
206 -Y pattern Only test printers matching the specified pattern(s).
207
208 Logging options:
209 -C csum_type Generate specified checksum type (default $csum_type). Options:
210 - md5
211 - sha
212 - sha1
213 - sha224
214 - ssh256
215 - sha384
216 - sha512
217 -m csum_dir Generate checksums and place them in the specified
218 directory, one file per run. Directory will be created
219 if necessary.
220 -M csum_file Generate checksums and place them in the specified
221 file, one line per run.
222 -O out_dir Generate actual output and place it in the specified
223 directory, one file per run. Directory will be created
224 if necessary.
225 -F Report printer name as "family_modelno" rather than
226 model ID.
227
228 Control options:
229 -H Halt on any error.
230 -S Run a separate testpattern command for each printer.
231 -SS Run a separate testpattern command for each case (slow).
232
233 Debugging options:
234 -c Use callgrind (incompatible with -v).
235 -g Attach testpattern job to gdb.
236 -v[v[v[v]]] Use valgrind. Number of -v options controls usage:
237 -v Basic valgrind checking, no leak checking
238 -vv Additional leak checking
239 -vvv Show reachable data also
240 -vvvv Minimal checks only
241
242 Test selection/control options:
243 -d option=value Test this option with only the specified (default) value,
244 if available. For Resolution and PageSize the special
245 values MIN and MAX can be used to specify the
246 lowest/smallest and highest/largest respectively.
247 -G geometry Specify geometry (=(HxV)(+L+T), as fractions of page).
248 -o option Test this option. Multiple -o options may be specified.
249 option1,option2... tests all combinations of each
250 option. For floating point and integer options, a
251 selection of values is tested.
252 To remove an option from the list tested, specify
253 -o -option
254 Default:
255 $options
256 -o+ Any options specified with -o will be tested in addition
257 to those specified (or omitted if -o -option is used)
258 -p page count Specify number of pages to print per printer. Default $std_pages.
259 -P page count Specify number of pages to print per printer when testing
260 duplex mode. Default $duplex_pages.
261 -R Use the minimum resolution (rather than the default)
262 to test other options. Equivalent to -dResolution=MIN.
263 -T maxres Limit the tested resolutions to a maximum of maxres in
264 both dimensions; use the lowest resolution available
265 if none meet the criterion.
266 -X Repeat specified cases listed on standard input.
267 -N Supply all requested options, even if unused.
268 -u Round all dimensions to the lower point (for
269 regression testing against Gutenprint 5.2).
270
271 Miscellaneous options:
272 -i Use the installed Gutenprint libraries rather than
273 from source tree.
274 -q Only list each printer as it is tested.
275 -qq Print one dot for every printer.
276 -qqq Do not report any output.
277
278 Information options (do not run tests):
279 -l List available printers.
280 -L List available options for specified printer.
281 -n Do not actually run test (write out input that
282 would be passed to testpattern).
283 -V List available values for each option.
284 EOF
285 exit 1;
286 }
287
288 if ($help) {
289 print_help_and_exit();
290 }
291
292 if ($use_min_res) {
293 $base_settings{"Resolution"} = "MIN";
294 }
295
296 if (@special_options) {
297 my (%options);
298 my ($optseq) = 1;
299 if ((scalar grep { /^\+$/ } @special_options) ||
300 (! scalar grep { /^[^-]/ } @special_options)) {
301 map { $options{$_} = $optseq++; } @standard_options;
302 }
303 if (scalar grep { /^\-$/ } @special_options) {
304 %options = ();
305 }
306 foreach my $opt (@special_options) {
307 next if $opt eq '+';
308 if ($opt =~ /^-/) {
309 $opt = substr($opt, 1);
310 delete $options{$opt};
311 } else {
312 if ($opt =~ /^\+/) {
313 $opt = substr($opt, 1);
314 }
315 if (! defined $options{$opt}) {
316 $options{$opt} = $optseq++;
317 }
318 }
319 }
320 my (%ropt) = reverse %options;
321 @special_options = map { $ropt{$_} } sort { $a <=> $b } keys %ropt;
322 } else {
323 @special_options = @standard_options;
324 }
325
326 my $bad_opt = 0;
327
328 foreach my $opt (@default_options) {
329 if (! ($opt =~ /=/)) {
330 print STDERR "Malformed default option `$opt'\n";
331 $bad_opt = 1;
332 }
333 my ($option, $value) = split(/=/, $opt);
334 if (! $value) {
335 delete $base_settings{$option};
336 } else {
337 $base_settings{$option} = $value;
338 }
339 }
340
341 if ($bad_opt) {
342 print_help_and_exit();
343 }
344
345 my $pwd = `pwd`;
346 chomp $pwd;
347
348 my $srcdir = $ENV{"srcdir"};
349 my $sdir;
350
351 $geometry =~ s/^=*//;
352 if ($geometry =~ /^(([01]?(\.[0-9]*)?)(x([01]?(\.[0-9]*)?))?)?(\+([01]?(\.[0-9]*)?)(\+([01]?(\.[0-9]*)?))?)?$/) {
353 my ($H) = $2;
354 my ($V) = $5;
355 my ($L) = $8;
356 my ($T) = $11;
357 if ($H) {
358 $hsize = $H;
359 if (not $V) {
360 $V=$H;
361 }
362 if ($hsize > 1) {
363 $hsize = 1;
364 }
365 }
366 if ($V) {
367 $vsize = $V;
368 if ($vsize > 1) {
369 $vsize = 1;
370 }
371 }
372 if ($L) {
373 if (not $T) {
374 $T=$L;
375 }
376 $left = $L;
377 }
378 if ($T) {
379 $top = $T;
380 }
381 if ($left + $hsize > 1) {
382 $left = 1 - $hsize;
383 }
384 if ($top + $vsize > 1) {
385 $top = 1 - $vsize;
386 }
387 }
388
389 if ("$srcdir" eq "" || "$srcdir" eq ".") {
390 $sdir = $pwd;
391 } elsif ($srcdir =~ /^\//) {
392 $sdir = "$srcdir";
393 } else {
394 $sdir = "$pwd/$srcdir";
395 }
396
397 if (! $run_installed && ! defined $ENV{"STP_DATA_PATH"}) {
398 $ENV{"STP_DATA_PATH"} = "${sdir}/../xml";
399 }
400
401 if (! defined $ENV{"STP_MODULE_PATH"}) {
402 $ENV{"STP_MODULE_PATH"} = "${sdir}/../main:${sdir}/../main/.libs";
403 }
404
405 sub set_opt($$$) {
406 my ($opt, $val, $printer) = @_;
407 my ($type) = $param_types{$printer}{$opt};
408 if ($type == 1) {
409 push @extras, "parameter_int \"$opt\" $val;\n";
410 } elsif ($type == 2) {
411 my ($xval) = $val;
412 if ($val =~ /true/i) {
413 $xval = 1;
414 } elsif ($val =~ /false/i) {
415 $xval = 0;
416 }
417 push @extras, "parameter_bool \"$opt\" $xval;\n";
418 } elsif ($type == 3) {
419 push @extras, "parameter_float \"$opt\" $val;\n";
420 } elsif ($type == 4) {
421 push @extras, "parameter_curve \"$opt\" \"$val\";\n";
422 } else {
423 if ($opt eq "PageSize" && $val =~ /^([^.]+)\.([0-9]+)x([0-9]+)$/) {
424 push @extras, "parameter \"PageSize\" \"$1\";\n";
425 push @extras, "page_size $2 $3;\n";
426 } else {
427 push @extras, "parameter \"$opt\" \"$val\";\n";
428 }
429 }
430 }
431
432 sub set_message($) {
433 my ($message) = @_;
434 push @messages, "message \"$message\";\n" if (! $quiet);
435 }
436
437 sub set_global_message($) {
438 my ($message) = @_;
439 push @global_messages, "message \"$message\";\n"
440 }
441
442 sub print_one_testpattern($$$;$) {
443 my ($printer, $pages, $tp_mode, $raw) = @_;
444 my $stuff = join "", @global_messages;
445 $stuff .= join "", @job_extras;
446 $global_printer = $printer;
447 foreach my $page (0..$pages - 1) {
448 $global_page = $page;
449 $stuff .= "printer \"$printer\";\n";
450 $stuff .= "parameter \"PageSize\" \"Auto\";\n";
451 $stuff .= join "", @messages, @extras;
452 if (! $quiet && $pages > 1) {
453 $stuff .= "message \"(page $page)\";\n";
454 }
455 $stuff .= "parameter_int \"PageNumber\" $page;\n";
456 if ($page == 0) {
457 $stuff .= "start_job;\n";
458 }
459 if ($page == $pages - 1) {
460 $stuff .= "end_job;\n";
461 }
462 $stuff .= sprintf("hsize %f;\n", $hsize);
463 $stuff .= sprintf("vsize %f;\n", $vsize);
464 $stuff .= sprintf("left %f;\n", $left);
465 $stuff .= sprintf("top %f;\n", $top);
466 $stuff .= "blackline 0;\n";
467 $stuff .= "steps 16;\n";
468 if ($round) {
469 $stuff .= "round;\n";
470 }
471 if ($raw > 0) {
472 $stuff .= "mode extended $raw 16;\n";
473 $stuff .= "xpattern ";
474 for (my $i = 0; $i < $raw; $i++) {
475 $stuff .= "0.0 0.0 1.0 ";
476 }
477 $stuff .= ";\n";
478 for (my $i = 0; $i < $raw; $i++) {
479 $stuff .= "xpattern ";
480 for (my $j = 0; $j < $raw; $j++) {
481 if ($i == $j) {
482 $stuff .= "0.0 1.0 1.0 ";
483 } else {
484 $stuff .= "0.0 0.0 1.0 ";
485 }
486 }
487 $stuff .= ";\n";
488 }
489 $stuff .= "xpattern ";
490 for (my $i = 0; $i < $raw; $i++) {
491 $stuff .= "0.0 0.0 1.0 ";
492 }
493 $stuff .= ";\n";
494 $stuff .= "end;\n";
495 } else {
496 $tp_mode =~ s/([81]+)/ $1/;
497 $stuff .= << "EOF";
498 mode $tp_mode;
499 pattern 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 1.0 0.0 0.0 1.0 0.0 0.0 1.0 ;
500 pattern 1.0 1.0 1.0 1.0 1.0 0.0 0.0 1.0 0.0 1.0 1.0 0.0 0.0 1.0 0.0 0.0 1.0;
501 pattern 1.0 1.0 1.0 1.0 1.0 0.0 0.0 1.0 0.0 0.0 1.0 0.0 1.0 1.0 0.0 0.0 1.0;
502 pattern 1.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0.0 1.0 0.0 0.0 1.0 0.0 0.0 1.0;
516 pattern 0.3 0.999 -2.0 -2.0 -2.0 0.0 1.0 1.0 0.0 0.0 1.0 0.0 0.0 1.0 0.0 0.0 1.0;
517 pattern 0.5 0.999 -2.0 -2.0 -2.0 0.0 1.0 1.0 0.0 0.0 1.0 0.0 0.0 1.0 0.0 0.0 1.0;
518 pattern 1.0 1.0 1.0 1.0 1.0 0.0 0.0 1.0 0.0 0.0 1.0 0.0 1.0 1.0 0.0 1.0 1.0;
519 pattern 1.0 1.0 1.0 1.0 1.0 0.0 0.25 1.0 0.0 0.0 1.0 0.0 0.75 1.0 0.0 0.75 1.0;
520 pattern 0.0 0.0 1.0 1.0 1.0 0.0 0.25 1.0 0.0 0.0 1.0 0.0 0.75 1.0 0.0 0.75 1.0;
521 pattern 1.0 1.0 1.0 1.0 1.0 0.0 0.5 1.0 0.0 0.0 1.0 0.0 0.5 1.0 0.0 0.5 1.0;
522 pattern 0.0 0.0 1.0 1.0 1.0 0.0 0.5 1.0 0.0 0.0 1.0 0.0 0.5 1.0 0.0 0.5 1.0;
523 pattern 1.0 1.0 1.0 1.0 1.0 0.0 0.75 1.0 0.0 0.0 1.0 0.0 0.25 1.0 0.0 0.25 1.0;
524 pattern 0.0 0.0 1.0 1.0 1.0 0.0 0.75 1.0 0.0 0.0 1.0 0.0 0.25 1.0 0.0 0.25 1.0;
525 pattern 1.0 1.0 1.0 1.0 1.0 0.0 0.9 1.0 0.0 0.0 1.0 0.0 0.1 1.0 0.0 0.1 1.0;
526 pattern 0.0 0.0 1.0 1.0 1.0 0.0 0.9 1.0 0.0 0.0 1.0 0.0 0.1 1.0 0.0 0.1 1.0;
527 pattern 1.0 1.0 1.0 1.0 1.0 0.0 0.0 1.0 0.0 1.0 1.0 0.0 0.0 1.0 0.0 1.0 1.0;
528 pattern 1.0 1.0 1.0 1.0 1.0 0.0 0.25 1.0 0.0 0.75 1.0 0.0 0.0 1.0 0.0 0.75 1.0;
529 pattern 0.0 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.0 0.0 0.0 1.0;
543 pattern 1.0 1.0 1.0 1.0 1.0 0.0 0.9 1.0 0.0 0.1 1.0 0.0 0.1 1.0 0.0 0.0 1.0;
544 pattern 0.0 0.0 1.0 1.0 1.0 0.0 0.9 1.0 0.0 0.1 1.0 0.0 0.1 1.0 0.0 0.0 1.0;
545 end;
546 EOF
547 }
548 }
549 return $stuff;
550 }
551
552 sub get_printers() {
553 map { $exclude_list{$_} = 1; } @exclude_list;
554 $include_pattern = join("|", map {"($_)"} @include_patterns);
555 $exclude_pattern = join("|", map {"($_)"} @exclude_patterns);
556 my (@nprinter_list);
557 my $extra_arg = "";
558 my (%families);
559 my (%model_families);
560 my (%printer_models);
561 map { $families{$_} = 1; } @families;
562 open PIPE, "./printers|" or die "Cannot run printers: $!\n";
563 my ($line_count);
564 while(<PIPE>) {
565 next if m!^#!;
566 chomp;
567 $line_count++;
568 my ($model, $family, $printer) = split;
569 my ($model_family) = "${model}_${family}";
570 $printer_models{$printer} = $model_family;
571 if (! defined $model_families{$model_family}) {
572 $model_families{$model_family} = $printer;
573 }
574 next if @families && ! defined $families{$family};
575 next if $exclude_list{$printer};
576 next if $exclude_pattern ne '' && $printer =~ /$exclude_pattern/;
577 next if $include_pattern ne '' && ! $printer =~ /$include_pattern/;
578 next if $skip_duplicate_printers && $model_families{$model_family} ne $printer;
579 push @nprinter_list, $printer;
580 }
581 close PIPE;
582 if ($#ARGV >= 0) {
583 my ($bad_printers_found) = 0;
584 @nprinter_list = grep { defined $_ } map {
585 if (defined $printer_models{$_}) {
586 $_;
587 } elsif (defined $model_families{$_}) {
588 $model_families{$_};
589 } else {
590 print STDERR "Unknown printer ${_}!\n";
591 $bad_printers_found = 1;
592 undef;
593 }
594 } @ARGV;
595 }
596 exit 1 if (! scalar @nprinter_list);
597 return @nprinter_list;
598 }
599
600 sub load_printer_data() {
601 my ($extra_arg) = join(" ", @printer_list);
602 open PIPE, "./printer_options $extra_arg|" or die "Cannot run printer_options: $!\n";
603 while(<PIPE>) {
604 next if m!^#!;
605 eval $_;
606 }
607 close PIPE or die "Cannot run printer_options: $!\n";
608 if ($rerun) {
609 while (<>) {
610 chomp;
611 s/^[^a-zA-Z]*//;
612 s/\..*//;
613 $rerun_cases{$_} = 1;
614 }
615 }
616
617 my (@nprinter_list);
618 foreach my $printer (@printer_list) {
619 my $model_id = $models{$printer};
620 my $family_id = $families{$printer};
621 if (($skip_duplicate_printers && $models_found{$family_id}{$model_id}) ||
622 (@families && ! grep { $family_id eq $_ } @families)) {
623 } else {
624 $models_found{$family_id}{$model_id} = 1;
625 push @nprinter_list, $printer;
626 }
627 }
628 @printer_list = @nprinter_list;
629 }
630
631 sub do_print($$) {
632 my ($output, $fh) = @_;
633 if ($dontrun) {
634 print $output;
635 } elsif (! $fh) {
636 restart_testpattern(1);
637 print $global_fh $output;
638 my ($status) = close $global_fh;
639 if (!$status) {
640 if ($? == 2) {
641 stopit();
642 }
643 $error++;
644 if ($single > 1) {
645 warn("\n*** FAIL $global_case ($?)\n");
646 } else {
647 warn("\n*** FAIL ($?)\n");
648 }
649 if ($halt_on_error) { # SIGINT
650 stopit();
651 }
652 }
653 } else {
654 print $fh $output;
655 }
656 }
657
658 sub do_output($) {
659 my ($outkey) = @_;
660 if (defined $output || defined $csum_dir ||
661 defined $csum_file) {
662 my $checksum_cmd;
663 my $outbase = "${outkey}.prn";
664 my $outfile = "$output/$outbase";
665 if (defined $csum_file) {
666 $checksum_cmd = "${csum_type}sum -b | sed 's/-/$outbase/'";
667 if ($csum_file =~ /^\:([0-9]+)$/) {
668 $checksum_cmd .= " 1>&$1";
669 } elsif ($csum_file ne '' && $csum_file ne '-') {
670 $checksum_cmd .= " >> '$csum_file'";
671 }
672 } elsif (defined $csum_dir) {
673 my $checksum_dir = $csum_dir;
674 if (defined $csum_dir && $csum_dir eq "") {
675 $checksum_dir = $output;
676 }
677 my $checksumfile = "$checksum_dir/${outkey}.checksum";
678 if (! $checksum_dir) {
679 $checksumfile = "${outkey}.checksum";
680 }
681 $checksum_cmd = "${csum_type}sum -b | sed 's/-/$outbase/' > '$checksumfile'";
682 }
683 if ($output && $checksum_cmd ne "") {
684 push @job_extras, "output \"|tee '$outfile' | $checksum_cmd\";\n";
685 } elsif ($output) {
686 push @job_extras, "output \"$outfile\";\n";
687 } else {
688 push @job_extras, "output \"|$checksum_cmd\";\n";
689 }
690 }
691 }
692
693 sub build_list($$$$) {
694 my ($keys, $printer, $min_res, $max_res) = @_;
695 my (@keys) = split (/,/, $keys);
696 my ($key) = $keys[0];
697 my ($rest);
698 my (@stuff);
699 if ($#keys > 0) {
700 $rest = join ",", @keys[1..$#keys];
701 @stuff = build_list($rest, $printer, $min_res, $max_res);
702 }
703 my (@tmp);
704 if ($key =~ /=/) {
705 my (@values);
706 my ($vlist);
707 ($key, $vlist) = split(/=/, $key);
708 @tmp = split(/;/, $vlist);
709 if ($key eq 'Resolution') {
710 @tmp = map {
711 if ($_ eq 'MIN') {
712 $min_res;
713 } elsif ($_ eq 'MAX') {
714 $max_res;
715 } else {
716 $_
717 }
718 } @tmp;
719 } elsif ($key eq 'PageSize') {
720 @tmp = map {
721 if ($_ eq 'MIN') {
722 $min_page_size{$printer}
723 } elsif ($_ eq 'MAX') {
724 $max_page_size{$printer}
725 } else {
726 $_
727 }
728 } @tmp;
729 }
730 } elsif ($param_types{$printer}{$key} == 3) {
731 my (@vals) = @{$stp_float_values{$printer}{$key}};
732 my ($minv) = $vals[2];
733 my ($defv) = $vals[1];
734 my ($maxv) = $vals[3];
735 push @tmp, $minv;
736 push @tmp, ($minv + $defv) / 2.0;
737 push @tmp, $defv;
738 push @tmp, ($defv + $maxv) / 2.0;
739 push @tmp, $maxv;
740 } elsif ($param_types{$printer}{$key} == 1) {
741 my (@vals) = @{$stp_int_values{$printer}{$key}};
742 my ($minv) = $vals[2];
743 my ($maxv) = $vals[3];
744 push @tmp, ($minv..$maxv);
745 } elsif ($param_types{$printer}{$key} == 2) {
746 push @tmp, 0;
747 push @tmp, 1;
748 } elsif ($key eq "TPMode") {
749 push @tmp, @tp_modes;
750 } elsif ($key eq "Resolution") {
751 @tmp = sort keys %{$resolutions{$printer}};
752 if ($res_limit > 0) {
753 @tmp = grep { $resolutions{$printer}{$_}[0] <= $res_limit &&
754 $resolutions{$printer}{$_}[1] <= $res_limit} @tmp;
755 }
756 if (! @tmp) {
757 push @tmp, $min_res;
758 }
759 } elsif (defined($param_types{$printer}{$key})) {
760 @tmp = @{$stpdata{$printer}{$key}};
761 }
762 if (! @tmp) {
763 return @stuff;
764 } elsif (! @stuff) {
765 return @tmp;
766 } else {
767 my (@answer);
768 foreach my $i (@tmp) {
769 foreach my $j (@stuff) {
770 push @answer, "$i,$j";
771 }
772 }
773 return @answer;
774 }
775 return @tmp;
776 }
777
778 sub build_key($$) {
779 my ($keys, $printer) = @_;
780 my (@keys) = split (/,/, $keys);
781 my (@answer) = grep { $_ eq "TPMode" || defined $param_types{$printer}{$_} || /=/ } @keys;
782 return join ",", @answer;
783 }
784
785 sub get_min_max_res($) {
786 my ($printer) = @_;
787 my (%reslist) = %{$resolutions{$printer}};
788 my $min_res_name;
789 my $min_res_value = 5760*5760;
790 my $max_res_name;
791 my $max_res_value = 0;
792 # We want to get the same named resolution each time.
793 foreach my $resid (sort keys %reslist) {
794 my ($res) = $reslist{$resid};
795 my ($res_value) = $$res[0] * $$res[1];
796 if ($res_value < $min_res_value) {
797 $min_res_value = $res_value;
798 $min_res_name = $resid;
799 }
800 if ($res_value > $max_res_value) {
801 $max_res_value = $res_value;
802 $max_res_name = $resid;
803 }
804 }
805 return ($min_res_name, $max_res_name);
806 }
807
808 sub get_printing_modes($) {
809 my ($printer) = @_;
810 my (@printing_modes) = grep {$_ ne 'None' } @{$stpdata{$printer}{'PrintingMode'}};
811 if ($base_settings{'PrintingMode'}) {
812 if ($base_settings{'PrintingMode'} eq 'Color' &&
813 grep { $_ eq 'Color' } @printing_modes) {
814 return ('Color');
815 } elsif ($base_settings{'PrintingMode'} eq 'BW' &&
816 grep { $_ eq 'BW' } @printing_modes) {
817 return ('BW');
818 } else {
819 return ();
820 }
821 } else {
822 return @printing_modes;
823 }
824 }
825
826 sub get_optvals($$$) {
827 my ($printer, $min_res_name, $max_res_name) = @_;
828 my (%opt_vals);
829 if (! @special_options) {
830 $opt_vals{"Default"} = ['all'];
831 } else {
832 foreach my $key (@special_options) {
833 my (@subkeys) = (split(/,/, $key));
834 my $nkey = build_key($key, $printer);
835 if ($nkey ne "") {
836 my (@vals) = build_list($nkey, $printer, $min_res_name, $max_res_name);
837 $nkey =~ s/=[^,]*//g;
838 $opt_vals{$nkey} = \@vals;
839 }
840 }
841 }
842 return %opt_vals;
843 }
844
845 sub setup_printer_params($) {
846 my ($printer) = @_;
847 if ($stpdata{$printer}) {
848 foreach my $k (sort keys %{$stpdata{$printer}}) {
849 my ($vals) = $stpdata{$printer}{$k};
850 foreach my $v (0..@$vals) {
851 if (substr($$vals[$v], 0, 1) eq '+') {
852 $$vals[$v] = substr($$vals[$v], 1);
853 $defaults{$printer}{$k} = $$vals[$v];
854 last;
855 }
856 }
857 }
858 map { $param_types{$printer}{$_} = 0 } keys %{$stpdata{$printer}};
859 }
860 $param_types{$printer}{"Resolution"} = 0;
861 if ($stp_int_values{$printer}) {
862 map { $param_types{$printer}{$_} = 1 } keys %{$stp_int_values{$printer}};
863 }
864 if ($stp_bools{$printer}) {
865 map { $param_types{$printer}{$_} = 2 } keys %{$stp_bools{$printer}};
866 }
867 if ($stp_float_values{$printer}) {
868 map { $param_types{$printer}{$_} = 3 } keys %{$stp_float_values{$printer}};
869 }
870 if ($stp_dimension_values{$printer}) {
871 map { $param_types{$printer}{$_} = 8 } keys %{$stp_dimension_values{$printer}};
872 }
873 # curve = 4
874 # file = 5
875 # raw = 6
876 # array = 7
877 }
878
879 # Resolution and PageSize need special handling because of MIN and MAX
880 # Duplex needs special handling because of printing multiple pages, and
881 # need to set JobMode
882 # RawChannels needs special handling because it's handled specially by
883 # the underlying testpattern command.
884 sub do_printer($$) {
885 my ($printer, $global_fh) = @_;
886 my $first_time = 1;
887 my %opt_vals = {};
888
889 setup_printer_params($printer);
890 my (@printing_modes) = get_printing_modes($printer);
891 return if (! @printing_modes);
892 my ($min_res, $max_res) = get_min_max_res($printer);
893 my (%opt_vals) = get_optvals($printer, $min_res, $max_res);
894 foreach my $pmode (sort @printing_modes) {
895 foreach my $key (sort keys %opt_vals) {
896 next if ($key eq "RawChannels" && $pmode ne "Color");
897 next if (! defined $opt_vals{$key} || $opt_vals{$key} < 1);
898 my (@opts) = sort @{$opt_vals{$key}};
899 my (@subkeys) = split (/,/, $key);
900 my (%subkeys);
901 map {$subkeys{$_} = 1} @subkeys;
902 my $opt;
903 foreach $opt (@opts) {
904 @messages = ();
905 @global_messages = ();
906 $case_no++;
907 next if (($case_no % $stp_test_rotor_circumference) != $stp_test_rotor);
908 my ($pname) = $print_family ?
909 "${models{$printer}}-$families{$printer}" : $printer;
910 if ($first_time) {
911 if ($quiet < 2) {
912 set_global_message("$pname\n");
913 } elsif ($quiet == 2) {
914 set_global_message(".");
915 }
916 $first_time = 0;
917 }
918 next if ($proc_count > 0 && ($case_no % $proc_count) != $proc_rotor);
919 my ($tp_mode) = "rgb8";
920 @extras = ();
921 @job_extras = ();
922 my (@ovals);
923 my $rawval;
924 my (@subopts) = split (/,/, $opt);
925 map {
926 my $k = $subkeys[$_];
927 my $v = $subopts[$_];
928 next if ($k eq "RawChannels" && $v ne "None" && $pmode ne "Color");
929 if ($k eq "RawChannels") {
930 $rawval = $v;
931 } elsif ($k eq "TPMode") {
932 $tp_mode = $v;
933 } else {
934 set_opt($k, $v, $printer);
935 }
936 push @ovals, "${k}=${v}";
937 } (0..$#subkeys);
938 map {
939 if ($key ne $_) {
940 my $setting = $base_settings{$_};
941 if ($_ eq "Resolution" && $setting eq "MIN") {
942 $setting = $min_res;
943 } elsif ($_ eq "Resolution" && $setting eq "MAX") {
944 $setting = $max_res;
945 } elsif ($_ eq "PageSize" && $setting eq "MIN") {
946 $setting = $min_page_size{$printer};
947 } elsif ($_ eq "PageSize" && $setting eq "MAX") {
948 $setting = $max_page_size{$printer};
949 }
950 set_opt($_, $setting, $printer);
951 push @ovals, "${_}=$setting";
952 }
953 } grep { ! defined $subkeys{$_} &&
954 ($use_unused_options || $_ eq "Resolution" ||
955 $_ eq "TPMode" ||
956 defined $stpdata{$printer}{$_})} (sort keys %base_settings);
957 my $pages = $std_pages;
958 set_opt("PrintingMode", $pmode, $printer);
959 if ($key =~ /Duplex/) {
960 set_opt("JobMode", "Job", $printer);
961 $pages = $duplex_pages;
962 }
963 my $rawval;
964 my ($mstring) = join "_", @ovals;
965 $mstring =~ s/=/_/g;
966 my ($ostring) = join "+", @ovals;
967 my $case = "${pname}_PrintingMode_${pmode}_${mstring}";
968 $global_case = $case;
969 if (! $rerun || $rerun_cases{$case}) {
970 $global_messages = $case;
971 do_output($case);
972 set_message(" ${pmode}+${ostring}");
973 my $output = print_one_testpattern($printer, $pages, $tp_mode, $rawval);
974 do_print($output, $global_fh);
975 }
976 }
977 }
978 }
979 # Increment the rotor here also, so that if the degree of parallelism is even
980 # and we're running with -o - (an easy way to run minimal cases) we won't wind
981 # up with half the workers running color and half running black and white.
982 $case_no++;
983 }
984
985 sub restart_testpattern {
986 my ($silent) = @_;
987 if (! $silent) {
988 close($global_fh);
989 my ($err) = $? & 255;
990 if ($err > 0) {
991 $error++;
992 }
993 if ($single > 1) {
994 warn("\n***TESTPATTERN CRASHED*** ($global_case) ($err)!\n");
995 } else {
996 warn("\n***TESTPATTERN CRASHED*** (cannot determine case, near $global_case) ($err)!\n");
997 }
998 if ($halt_on_error) {
999 stopit();
1000 }
1001 }
1002 open($global_fh, "|$testpattern_command") or
1003 die "Can't run $testpattern_command: $!\n";
1004 }
1005
1006 sub stopit {
1007 if ($single > 1) {
1008 print "\nStopping, $error case(s) failed.\n";
1009 exit 1;
1010 } elsif ($error) {
1011 print "\nStopping, failures noted.\n";
1012 exit 1;
1013 } else {
1014 print "\nStopping.\n";
1015 exit 0;
1016 }
1017 }
1018
1019 sub get_default($$) {
1020 my ($printer, $opt) = @_;
1021 if (defined $defaults{$printer}{$opt}) {
1022 return $defaults{$printer}{$opt};
1023 } else {
1024 return $stpdata{$printer}{$opt}[0];
1025 }
1026 }
1027
1028 sub list_options() {
1029 if ($#printer_list > 0) {
1030 die "-L must be used with one printer\n";
1031 }
1032 my ($printer) = $printer_list[0];
1033 foreach my $opt (sort keys %{$stpdata{$printer}}) {
1034 print "$opt\n";
1035 if ($verbose) {
1036 if ($param_types{$printer}{$opt} == 3) {
1037 my (@vals) = @{$stp_float_values{$printer}{$opt}};
1038 print " $vals[2]\n";
1039 print " =>$vals[1]\n";
1040 print " $vals[3]\n";
1041 } elsif ($param_types{$printer}{$opt} == 1) {
1042 my (@vals) = @{$stp_float_values{$printer}{$opt}};
1043 print " $vals[2]\n";
1044 print " $vals[3]\n";
1045 } elsif ($param_types{$printer}{$opt} == 2) {
1046 if ($defaults{$printer}{$opt}) {
1047 print " 0\n";
1048 print " =>1\n";
1049 } else {
1050 print " =>0\n";
1051 print " 1\n";
1052 }
1053 } else {
1054 my ($default) = get_default($printer, $opt);
1055 foreach my $val (sort @{$stpdata{$printer}{$opt}}) {
1056 if ($val eq $default) {
1057 print " =>$val\n";
1058 } else {
1059 print " $val\n";
1060 }
1061 }
1062 }
1063 }
1064 }
1065 }
1066
1067 sub runit() {
1068 my $valgrind_command;
1069 my $valopts;
1070 if ($gdb_attach) {
1071 $proc_count = 1;
1072 }
1073
1074 # V A L G R I N D #
1075 if ($callgrind) {
1076 $valopts = '--tool=callgrind --dump-instr=yes --trace-jump=yes';
1077 $valgrind = 4;
1078 } elsif ($valgrind) {
1079 $valopts = '--tool=memcheck';
1080 }
1081 if ($gdb_attach) {
1082 $valopts .= ' --vgdb=yes';
1083 }
1084 if ($valgrind == 1) {
1085 $valgrind_command = "$vg $valopts -q --num-callers=50 --error-limit=no --leak-check=yes --error-exitcode=1";
1086 } elsif ($valgrind == 2) {
1087 $valgrind_command = "$vg $valopts --num-callers=50 --error-limit=no --leak-resolution=high --leak-check=yes --error-exitcode=1";
1088 } elsif ($valgrind == 3) {
1089 $valgrind_command = "$vg $valopts --error-limit=no --num-callers=50 --show-reachable=yes --leak-resolution=high --leak-check=yes --error-exitcode=1";
1090 } elsif ($valgrind == 4) {
1091 $valgrind_command = "$vg $valopts --error-exitcode=1";
1092 }
1093
1094 # O U T P U T #
1095 if (defined $output && $output ne "" && ! -d $output) {
1096 mkdir $output || die "Can't create directory $output: $!\n";
1097 }
1098
1099 if (defined $csum_dir && $csum_dir ne "" && ! -d $csum_dir) {
1100 mkdir $csum_dir || die "Can't create directory $csum_dir: $!\n";
1101 }
1102
1103 if (defined $csum_file && ! $csum_file =~ /^\:([0-9]+)$/) {
1104 unlink $csum_file;
1105 system "touch $csum_file";
1106 }
1107
1108 # # # # # # # #
1109 my ($suppress);
1110 if (! defined $output && ! defined $csum_dir &&
1111 ! defined $csum_file) {
1112 $suppress = '-n';
1113 }
1114 my (@children);
1115 my ($child_no);
1116 my ($kid);
1117 load_printer_data();
1118 # Note that when testing duplex all pages of the duplex run are done by
1119 # one process, but each page counts as a separate test. So the number
1120 # of cases per process may not always be within 1.
1121 if ($proc_count > 1) {
1122 for ($child_no = 0; $child_no < $proc_count; $child_no++) {
1123 $kid = fork();
1124 if ($kid == 0) {
1125 last;
1126 } else {
1127 push @children, $kid;
1128 $proc_rotor++;
1129 }
1130 }
1131 }
1132
1133 my $status = 1;
1134 if ($proc_count > 1 && $kid > 0) {
1135 # Parent in parallel case
1136 while ($proc_count > 0 && $kid > 0) {
1137 $kid = waitpid(-1, 0);
1138 if ($kid > 0 && $? > 0) {
1139 $error++;
1140 }
1141 }
1142 } else {
1143 my ($qopt) = $quiet ? "-q" : "";
1144 my ($Hopt) = $halt_on_error ? "-H" : "";
1145 $testpattern_command = "$valgrind_command ./testpattern -y $suppress $qopt $Hopt";
1146 if ($single > 1) {
1147 $SIG{TERM} = sub() { stopit() };
1148 $SIG{HUP} = sub() { stopit() };
1149 $SIG{INT} = sub() { stopit() };
1150 foreach my $printer (@printer_list) {
1151 do_printer($printer, undef);
1152 }
1153 } elsif ($single) {
1154 $SIG{PIPE} = sub() { restart_testpattern() };
1155 foreach my $printer (@printer_list) {
1156 restart_testpattern(1);
1157 do_printer($printer, $global_fh);
1158 $status |= close $global_fh;
1159 $error += ($? != 0);
1160 }
1161 } else {
1162 $SIG{PIPE} = sub() { restart_testpattern() };
1163 restart_testpattern(1);
1164 map { do_printer($_, $global_fh) } @printer_list;
1165 $status = close $global_fh;
1166 }
1167 }
1168 if ($quiet == 2) {
1169 print STDERR "\n";
1170 }
1171 if ($status && ! $error) {
1172 return 0;
1173 } else {
1174 if ($error) {
1175 if ($single > 1) {
1176 print STDERR "$error cases failed\n";
1177 } else {
1178 my ($plural) = ($error > 1 ? "ES" : "");
1179 print STDERR "*** $error CRASH${plural} NOTED***\n";
1180 }
1181 }
1182 return 1;
1183 }
1184 }
1185
1186 @printer_list = get_printers();
1187 if ($list_printers) {
1188 print join("\n", sort @printer_list), "\n";
1189 } elsif ($list_options) {
1190 load_printer_data();
1191 list_options();
1192 } elsif ($dontrun) {
1193 load_printer_data();
1194 map { do_printer($_, \*STDOUT) } @printer_list;
1195 } else {
1196 exit(runit());
1197 }