summaryrefslogtreecommitdiffstats
path: root/regression-gp.pl
diff options
context:
space:
mode:
authorSolomon Peachy <pizza@shaftnet.org>2018-10-21 17:11:23 -0400
committerSolomon Peachy <pizza@shaftnet.org>2018-10-21 22:35:16 -0400
commit50b66ca15facae662895641d97aabfda8398cfd8 (patch)
tree82891a66158dfe418f328ae16734d67b6969551f /regression-gp.pl
parent7206e4427b8a51725b71ccda2889c6ccbc7da1a3 (diff)
downloadselphy_print-50b66ca15facae662895641d97aabfda8398cfd8.tar.gz
selphy_print-50b66ca15facae662895641d97aabfda8398cfd8.tar.bz2
selphy_print-50b66ca15facae662895641d97aabfda8398cfd8.zip
regression: major improvements to allow parallelism.
should now automatically use all CPUs.
Diffstat (limited to 'regression-gp.pl')
-rwxr-xr-xregression-gp.pl283
1 files changed, 218 insertions, 65 deletions
diff --git a/regression-gp.pl b/regression-gp.pl
index 8b516b7..7fe09dd 100755
--- a/regression-gp.pl
+++ b/regression-gp.pl
@@ -1,4 +1,33 @@
#!/usr/bin/perl
+#######################
+#
+# Test harness code for the dyesub backend (gutenprint rendering)
+#
+# Copyright (c) 2018 Solomon Peachy <pizza@shaftnet.org>
+#
+# The latest version of this program can be found at:
+#
+# http://git.shaftnet.org/cgit/selphy_print.git
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the Free
+# Software Foundation; either version 3 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+# [http://www.gnu.org/licenses/gpl-3.0.html]
+#
+# SPDX-License-Identifier: GPL-3.0+
+#
+#######################
use strict;
use IPC::Run qw( run );
@@ -11,94 +40,218 @@ my $max_copies = 3;
my $input_image = "testjobs/s3s-59.png";
my $max_pages = 3;
my $valgrind = 0;
+my $work_dir_base = "/tmp/";
+
+my $rotor = 0;
+my $rotor_circ = 0;
+my $row = 0;
+
+my $quiet = 1;
+my $proc_count = 0;
+my @children = ();
+my $kid;
+my $error = 0;
$ENV{"STP_SUPPRESS_VERBOSE_MESSAGES"} = 1;
$ENV{"OMP_NUM_THREADS"} = 1;
$ENV{"TEST_MODE"} = "2";
-while (<STDIN>) {
- chomp;
- next if /^#/;
- s/(.+)#.*/$1/;
+if (!defined($ARGV[0])) {
+ die ("need a csv file\n");
+};
+if (defined($ENV{"STP_VERBOSE"})) {
+ $quiet = $ENV{"STP_VERBOSE"};
+};
+if (defined($ENV{"STP_PARALLEL"})) {
+ $proc_count = $ENV{"STP_PARALLEL"};
+};
- if (defined($ARGV[0])) {
- next if (index($_,$ARGV[0]) == -1);
- };
+if ($proc_count > 1) {
+ $quiet = 1;
+ $rotor_circ = $proc_count;
+ for (my $child_no = 0; $child_no < $proc_count; $child_no++) {
+ $kid = fork();
+ if ($kid == 0) {
+ last;
+ } else {
+ push @children, $kid;
+ $rotor++;
+ }
+ }
+}
- my @row = split(/,/);
+if ($proc_count > 1 && $kid > 0) {
+ # Parent in parallel case
+ while ($proc_count > 0 && $kid > 0) {
+ $kid = waitpid(-1, 0);
+ if ($kid > 0 && $? > 0) {
+ $error++;
+ }
+ }
+ $retval = $error;
- my $gp_name = $row[0];
- $ENV{"BACKEND"} = $row[0];
- $ENV{"EXTRA_VID"} = $row[2];
- $ENV{"EXTRA_PID"} = $row[3];
+} else {
+ my $currow = 0;
- if (length($row[4])) {
- $ENV{"MEDIA_CODE"} = $row[4];
- } else {
- undef($ENV{"MEDIA_CODE"});
- }
+ open (INFILE, "<$ARGV[0]") || die ("can't open csv\n");
- my $options = "";
+ while (<INFILE>) {
+ chomp;
+ next if /^#/;
- my @gp_options = split(/;/,$row[5]);
- # generate options list
- foreach my $x (@gp_options) {
- $options .= "$x ";
- }
+ if (defined($ARGV[1])) {
+ next if (index($_,$ARGV[1]) == -1);
+ };
- print "***** $row[0] $row[1] $row[2] $row[3] $row[4] '$row[5]'\n";
+ # for great parallelism!
+ next if ($rotor_circ && ($currow++ % $rotor_circ) != $rotor);
- my @args;
+ s/(.+)#.*/$1/;
+ my @row = split(/,/);
- # Generate PPD
- my $ppd_fname = "/tmp/stp-$gp_name.5.3.ppd";
+ my $gp_name = $row[0];
+ $ENV{"BACKEND"} = $row[0];
+ $ENV{"EXTRA_VID"} = $row[2];
+ $ENV{"EXTRA_PID"} = $row[3];
+ my $work_dir = "${work_dir_base}/$currow/";
+ if (!mkdir($work_dir)) {
+ print("cannot crate work dir ${work_dir}\n");
+ $error++;
+ next;
+ }
- $ENV{"PPD"} = $ppd_fname;
- $ENV{"DEVICE_URI"} = "gutenprint53+usb://$row[0]/12345678";
+ if (length($row[4])) {
+ $ENV{"MEDIA_CODE"} = $row[4];
+ } else {
+ undef($ENV{"MEDIA_CODE"});
+ }
- run ["/usr/sbin/cups-genppd.5.3", "-p", "/tmp", "-Z", $gp_name] or die("FAIL genppd $?: $row[0] $row[1] $row[2] $row[3] $row[4] $row[5]\n");
+ my $options = "";
- for (my $pages = 1 ; $pages <= $max_pages ; $pages++) {
- # generate PDF.
- @args = ("/usr/bin/convert");
- for (my $i = 0 ; $i < $pages ; $i++) {
- push(@args, $input_image);
+ my @gp_options = split(/;/,$row[5]);
+ # generate options list
+ foreach my $x (@gp_options) {
+ $options .= "$x ";
}
- push(@args, "-density");
- push(@args, "300x300");
- push(@args, "/tmp/${gp_name}.pdf");
- print join(":", @args) . "\n";
- run \@args or die ("FAIL: convert: $?");
-
- # Generate raster from PDF
- @args = ("/usr/lib/cups/filter/pdftoraster", $id, $user, $title, 1, $options, "/tmp/${gp_name}.pdf");
- print join(":", @args) . "\n";
- run \@args, ">", "/tmp/${gp_name}.raster" or die ("FAIL: imagetoraster $?: $row[0] $row[1] $row[2] $row[3] $row[4] $row[5] $pages\n");
-
- for (my $copies = 1 ; $copies <= $max_copies ; $copies++) {
- # Call raster2gutenprint
- @args = ("/usr/lib/cups/filter/rastertogutenprint.5.3", $id, $user, $title, $copies, $options);
- if ($valgrind) {
- unshift(@args,"valgrind");
- }
+
+ my $rval;
+ my @args;
+
+ # Generate PPD
+ my $ppd_fname = "${work_dir}stp-${gp_name}.5.3.ppd";
+
+ $ENV{"PPD"} = $ppd_fname;
+ $ENV{"DEVICE_URI"} = "gutenprint53+usb://$row[0]/12345678";
+
+ @args = ("/usr/sbin/cups-genppd.5.3", "-p", $work_dir, "-Z", "-q", $gp_name);
+ if (!$quiet) {
print join(":", @args) . "\n";
- run \@args, "<", "/tmp/${gp_name}.raster", ">", "/tmp/${gp_name}.raw" or die("FAIL: rastertogutenorint $?: $row[0] $row[1] $row[2] $row[3] $row[4] $row[5] $pages $copies\n");
+ }
+ if ($quiet) {
+ $rval = run \@args, "1>", "/dev/null", "2>", "/dev/null";
+ } else {
+ $rval = run \@args;
+ }
+ if (!$rval) {
+ print("***** $row[0] $row[1] $row[2] $row[3] $row[4] '$row[5]' FAIL genppd $?: -- " . join(":", @args) . "\n");
+ $error++;
+ next;
+ }
- # Call backend using CUPS methodologies, using STDIN.
- @args = ("./dyesub_backend", $id, $user, $title, $copies, $options);
- if ($valgrind) {
- unshift(@args,"valgrind");
+ for (my $pages = 1 ; $pages <= $max_pages ; $pages++) {
+ # generate PDF.
+ @args = ("/usr/bin/convert");
+ for (my $i = 0 ; $i < $pages ; $i++) {
+ push(@args, $input_image);
}
- print join(":", @args) . "\n";
- run \@args, "<", "/tmp/${gp_name}.raw" or die("FAIL: backend $?: $row[0] $row[1] $row[2] $row[3] $row[4] $row[5] $pages $copies\n");
+ push(@args, "-density");
+ push(@args, "300x300");
+ push(@args, "${work_dir}$currow-${gp_name}.pdf");
+ if (!$quiet) {
+ print join(":", @args) . "\n";
+ }
+ $rval = run \@args;
+ if (!$rval) {
+ print("***** $row[0] $row[1] $row[2] $row[3] $row[4] '$row[5]' FAIL: convert: $? -- " . join(":", @args) . "\n");
+ $error++;
+ next;
+ }
+
+ # Generate raster from PDF
+ @args = ("/usr/lib/cups/filter/pdftoraster", $id, $user, $title, 1, $options, "${work_dir}$currow-${gp_name}.pdf");
+ if (!$quiet) {
+ print join(":", @args) . "\n";
+ }
+ if ($quiet) {
+ $rval = run \@args, ">", "${work_dir}$currow-${gp_name}.raster", "2>", "/dev/null";
+ } else {
+ $rval = run \@args, ">", "${work_dir}$currow-${gp_name}.raster";
+ }
+ if (!$rval) {
+ print("***** $row[0] $row[1] $row[2] $row[3] $row[4] '$row[5]' FAIL: imagetoraster $?: $pages -- " . join(":", @args) . "\n");
+ $error++;
+ next;
+ }
+
+ for (my $copies = 1 ; $copies <= $max_copies ; $copies++) {
+ # Call raster2gutenprint
+ @args = ("/usr/lib/cups/filter/rastertogutenprint.5.3", $id, $user, $title, $copies, $options);
+ if ($valgrind) {
+ if ($quiet) {
+ unshift(@args,"-q");
+ }
+ unshift(@args,"valgrind");
+ }
+ if (!$quiet) {
+ print join(":", @args) . "\n";
+ }
+ if ($quiet) {
+ $rval = run \@args, "<", "${work_dir}$currow-${gp_name}.raster", ">", "${work_dir}$currow-${gp_name}.raw", "2>", "/dev/null";
+ } else {
+ $rval = run \@args, "<", "${work_dir}$currow-${gp_name}.raster", ">", "${work_dir}$currow-${gp_name}.raw";
+ }
+ if (!$rval) {
+ print("***** $row[0] $row[1] $row[2] $row[3] $row[4] '$row[5]' FAIL: rastertogutenorint $?: $pages $copies -- " . join(":", @args) . "\n");
+ $error++;
+ next;
+ }
+
+ # Call backend using CUPS methodologies, using STDIN.
+ @args = ("./dyesub_backend", $id, $user, $title, $copies, $options);
+ if ($valgrind) {
+ if ($quiet) {
+ unshift(@args,"-q");
+ }
+ unshift(@args,"valgrind");
+ }
+ if (!$quiet) {
+ print join(":", @args) . "\n";
+ }
+ if ($quiet) {
+ run \@args, "<", "${work_dir}$currow-${gp_name}.raw", "2>", "/dev/null";
+ } else {
+ run \@args, "<", "${work_dir}$currow-${gp_name}.raw";
+ }
+ if (!$rval) {
+ print("***** $row[0] $row[1] $row[2] $row[3] $row[4] '$row[5]' FAIL: backend $?: $pages $copies -- " . join(":", @args) . "\n");
+ $error++;
+ next;
+ }
+ }
+
+ print "***** $row[0] $row[1] $row[2] $row[3] $row[4] '$row[5]' PASS\n";
}
- }
- unlink ("/tmp/${gp_name}.pdf");
- unlink ("/tmp/${gp_name}.raster");
- unlink ("/tmp/${gp_name}.raw");
- unlink ($ppd_fname);
+ unlink ("${work_dir}$currow-${gp_name}.pdf");
+ unlink ("${work_dir}$currow-${gp_name}.raster");
+ unlink ("${work_dir}$currow-${gp_name}.raw");
+ unlink ($ppd_fname);
+ rmdir ($work_dir);
+ }
- print "***** PASS\n";
+ $retval = $error;
+ close(INFILE);
+ exit($retval);
}
+
exit($retval);