2018-09-23 19:56:22 -04:00
|
|
|
#!/usr/bin/perl
|
2018-10-21 17:11:23 -04:00
|
|
|
#######################
|
|
|
|
#
|
|
|
|
# Test harness code for the dyesub backend (gutenprint rendering)
|
|
|
|
#
|
2024-07-11 07:20:38 -04:00
|
|
|
# Copyright (c) 2019-2024 Solomon Peachy <pizza@shaftnet.org>
|
2018-10-21 17:11:23 -04:00
|
|
|
#
|
|
|
|
# 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+
|
|
|
|
#
|
|
|
|
#######################
|
2018-09-23 19:56:22 -04:00
|
|
|
use strict;
|
|
|
|
use IPC::Run qw( run );
|
|
|
|
|
|
|
|
my $retval = 0;
|
|
|
|
|
|
|
|
my $id = 123;
|
|
|
|
my $user = "tester";
|
|
|
|
my $title = "image_test";
|
|
|
|
my $input_image = "testjobs/s3s-59.png";
|
2019-05-23 08:37:36 -04:00
|
|
|
|
|
|
|
my @pages_set = (1, 3);
|
|
|
|
my @copies_set = (1, 3);
|
|
|
|
|
2018-09-29 20:51:30 -04:00
|
|
|
my $valgrind = 0;
|
2021-01-24 14:37:33 -05:00
|
|
|
my $work_dir_base = "/tmp";
|
2018-10-21 17:11:23 -04:00
|
|
|
|
|
|
|
my $rotor = 0;
|
|
|
|
my $rotor_circ = 0;
|
|
|
|
my $row = 0;
|
|
|
|
|
2021-01-22 22:49:50 -05:00
|
|
|
my $pano_mode = 0;
|
|
|
|
|
2018-10-21 17:11:23 -04:00
|
|
|
my $quiet = 1;
|
|
|
|
my $proc_count = 0;
|
|
|
|
my @children = ();
|
|
|
|
my $kid;
|
|
|
|
my $error = 0;
|
2018-09-23 19:56:22 -04:00
|
|
|
|
2019-05-19 09:23:12 -04:00
|
|
|
my $genppd_exec = "/usr/sbin/cups-genppd.5.3";
|
2024-07-11 07:20:38 -04:00
|
|
|
my $im_exec = "/usr/bin/gm";
|
2019-05-19 09:23:12 -04:00
|
|
|
my $pdftoraster_exec = "/usr/lib/cups/filter/pdftoraster";
|
|
|
|
my $rastertogutenprint_exec = "/usr/lib/cups/filter/rastertogutenprint.5.3";
|
|
|
|
my $backend_exec = "./dyesub_backend";
|
2021-01-22 22:49:50 -05:00
|
|
|
my $pano_exec = "./pano-split.sh";
|
2019-05-19 09:23:12 -04:00
|
|
|
|
2018-09-23 19:56:22 -04:00
|
|
|
$ENV{"STP_SUPPRESS_VERBOSE_MESSAGES"} = 1;
|
|
|
|
$ENV{"OMP_NUM_THREADS"} = 1;
|
|
|
|
$ENV{"TEST_MODE"} = "2";
|
|
|
|
|
2018-10-21 17:11:23 -04:00
|
|
|
if (!defined($ARGV[0])) {
|
|
|
|
die ("need a csv file\n");
|
|
|
|
};
|
|
|
|
if (defined($ENV{"STP_VERBOSE"})) {
|
2018-10-22 22:27:55 -04:00
|
|
|
$quiet = !$ENV{"STP_VERBOSE"};
|
2018-10-21 17:11:23 -04:00
|
|
|
};
|
|
|
|
if (defined($ENV{"STP_PARALLEL"})) {
|
|
|
|
$proc_count = $ENV{"STP_PARALLEL"};
|
|
|
|
};
|
2019-05-19 09:23:12 -04:00
|
|
|
if (defined($ENV{"STP_GENPPD"})) {
|
|
|
|
$genppd_exec = $ENV{"STP_GENPPD"};
|
|
|
|
}
|
|
|
|
if (defined($ENV{"STP_RASTERTOGUTENPRINT"})) {
|
|
|
|
$rastertogutenprint_exec = $ENV{"STP_RASTERTOGUTENPRINT"};
|
|
|
|
}
|
|
|
|
|
2018-09-23 19:56:22 -04:00
|
|
|
|
2018-10-21 17:11:23 -04:00
|
|
|
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++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-23 19:56:22 -04:00
|
|
|
|
2018-10-21 17:11:23 -04:00
|
|
|
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;
|
2018-09-23 19:56:22 -04:00
|
|
|
|
2018-10-21 17:11:23 -04:00
|
|
|
} else {
|
|
|
|
my $currow = 0;
|
2018-09-23 19:56:22 -04:00
|
|
|
|
2018-10-21 17:11:23 -04:00
|
|
|
open (INFILE, "<$ARGV[0]") || die ("can't open csv\n");
|
2018-09-23 19:56:22 -04:00
|
|
|
|
2018-10-21 17:11:23 -04:00
|
|
|
while (<INFILE>) {
|
|
|
|
chomp;
|
|
|
|
next if /^#/;
|
2018-09-23 19:56:22 -04:00
|
|
|
|
2018-10-21 17:11:23 -04:00
|
|
|
if (defined($ARGV[1])) {
|
|
|
|
next if (index($_,$ARGV[1]) == -1);
|
|
|
|
};
|
2018-09-23 19:56:22 -04:00
|
|
|
|
2018-10-21 17:11:23 -04:00
|
|
|
# for great parallelism!
|
|
|
|
next if ($rotor_circ && ($currow++ % $rotor_circ) != $rotor);
|
2018-09-23 19:56:22 -04:00
|
|
|
|
2018-10-21 17:11:23 -04:00
|
|
|
s/(.+)#.*/$1/;
|
|
|
|
my @row = split(/,/);
|
2018-09-23 19:56:22 -04:00
|
|
|
|
2018-10-21 17:11:23 -04:00
|
|
|
my $gp_name = $row[0];
|
|
|
|
$ENV{"BACKEND"} = $row[0];
|
2019-05-18 08:01:23 -04:00
|
|
|
$ENV{"EXTRA_VID"} = $row[1];
|
|
|
|
$ENV{"EXTRA_PID"} = $row[2];
|
2021-01-24 14:37:33 -05:00
|
|
|
my $work_dir = "${work_dir_base}/$currow";
|
2018-10-21 17:11:23 -04:00
|
|
|
if (!mkdir($work_dir)) {
|
|
|
|
print("cannot crate work dir ${work_dir}\n");
|
|
|
|
$error++;
|
|
|
|
next;
|
|
|
|
}
|
2018-09-23 19:56:22 -04:00
|
|
|
|
2019-05-18 08:01:23 -04:00
|
|
|
if (length($row[3])) {
|
|
|
|
$ENV{"MEDIA_CODE"} = $row[3];
|
2018-10-21 17:11:23 -04:00
|
|
|
} else {
|
|
|
|
undef($ENV{"MEDIA_CODE"});
|
|
|
|
}
|
2018-09-23 19:56:22 -04:00
|
|
|
|
2018-10-21 17:11:23 -04:00
|
|
|
my $options = "";
|
2018-09-23 19:56:22 -04:00
|
|
|
|
2019-05-18 08:01:23 -04:00
|
|
|
my @gp_options = split(/;/,$row[4]);
|
2018-10-21 17:11:23 -04:00
|
|
|
# generate options list
|
|
|
|
foreach my $x (@gp_options) {
|
|
|
|
$options .= "$x ";
|
2018-09-28 20:26:50 -04:00
|
|
|
}
|
2018-10-21 17:11:23 -04:00
|
|
|
|
2021-01-22 22:49:50 -05:00
|
|
|
# See if we're in panorama mode
|
|
|
|
if (defined($row[5])) {
|
|
|
|
$pano_mode = 1;
|
|
|
|
pop(@pages_set); # 1 "page"
|
|
|
|
pop(@copies_set); # 1 copy
|
|
|
|
}
|
|
|
|
|
2018-10-21 17:11:23 -04:00
|
|
|
my $rval;
|
|
|
|
my @args;
|
|
|
|
|
|
|
|
# Generate PPD
|
2021-01-24 14:37:33 -05:00
|
|
|
my $ppd_fname = "${work_dir}/stp-${gp_name}.5.3.ppd";
|
2018-10-21 17:11:23 -04:00
|
|
|
|
|
|
|
$ENV{"PPD"} = $ppd_fname;
|
|
|
|
$ENV{"DEVICE_URI"} = "gutenprint53+usb://$row[0]/12345678";
|
|
|
|
|
2019-03-19 19:23:50 -04:00
|
|
|
if (!$quiet) {
|
|
|
|
print "PPD=$ENV{PPD}\n";
|
|
|
|
print "DEVICE_URI=$ENV{DEVICE_URI}\n";
|
|
|
|
}
|
|
|
|
|
2019-05-19 09:23:12 -04:00
|
|
|
@args = ($genppd_exec, "-p", $work_dir, "-Z", "-q", $gp_name);
|
2018-10-21 17:11:23 -04:00
|
|
|
if (!$quiet) {
|
2018-09-28 20:26:50 -04:00
|
|
|
print join(":", @args) . "\n";
|
2018-10-21 17:11:23 -04:00
|
|
|
}
|
|
|
|
if ($quiet) {
|
|
|
|
$rval = run \@args, "1>", "/dev/null", "2>", "/dev/null";
|
|
|
|
} else {
|
|
|
|
$rval = run \@args;
|
|
|
|
}
|
|
|
|
if (!$rval) {
|
2019-05-18 08:01:23 -04:00
|
|
|
print("***** $row[0] $row[1] $row[2] $row[3] '$row[4]' FAIL genppd $?: -- " . join(":", @args) . "\n");
|
2018-10-21 17:11:23 -04:00
|
|
|
$error++;
|
|
|
|
next;
|
|
|
|
}
|
2018-09-28 20:26:50 -04:00
|
|
|
|
2019-05-23 08:37:36 -04:00
|
|
|
foreach my $pages (@pages_set) {
|
2021-01-22 22:49:50 -05:00
|
|
|
if ($pano_mode) {
|
2021-01-24 14:37:33 -05:00
|
|
|
print("... $row[0] $row[1] $row[2] $row[3]\n");
|
2021-01-22 22:49:50 -05:00
|
|
|
# XXX generate panorama bitmap
|
|
|
|
my $pano_tmp = $input_image; # XXX
|
|
|
|
|
|
|
|
# Generate PDF by running through script.
|
2021-01-24 14:37:33 -05:00
|
|
|
@args = ($pano_exec, $pano_tmp, "${work_dir}/$currow-${gp_name}.pdf", $gp_name, $row[5]);
|
2021-01-22 22:49:50 -05:00
|
|
|
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: pano-split.sh: $? -- " . join(":", @args) . "\n");
|
|
|
|
$error++;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
# generate PDF.
|
2024-07-11 07:20:38 -04:00
|
|
|
@args = ($im_exec, "convert");
|
2021-01-22 22:49:50 -05:00
|
|
|
for (my $i = 0 ; $i < $pages ; $i++) {
|
|
|
|
push(@args, $input_image);
|
|
|
|
}
|
|
|
|
push(@args, "-density");
|
|
|
|
push(@args, "300x300");
|
2021-01-24 14:37:33 -05:00
|
|
|
push(@args, "${work_dir}/$currow-${gp_name}.pdf");
|
2021-01-22 22:49:50 -05:00
|
|
|
if (!$quiet) {
|
|
|
|
print join(":", @args) . "\n";
|
|
|
|
}
|
|
|
|
$rval = run \@args;
|
|
|
|
if (!$rval) {
|
2024-07-11 07:20:38 -04:00
|
|
|
print("***** $row[0] $row[1] $row[2] $row[3] '$row[4]' FAIL: magick convert: $? -- " . join(":", @args) . "\n");
|
2021-01-22 22:49:50 -05:00
|
|
|
$error++;
|
|
|
|
next;
|
|
|
|
}
|
2018-10-21 17:11:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
# Generate raster from PDF
|
2021-01-24 14:37:33 -05:00
|
|
|
@args = ($pdftoraster_exec, $id, $user, $title, 1, $options, "${work_dir}/$currow-${gp_name}.pdf");
|
2018-10-21 17:11:23 -04:00
|
|
|
if (!$quiet) {
|
|
|
|
print join(":", @args) . "\n";
|
|
|
|
}
|
|
|
|
if ($quiet) {
|
2021-01-24 14:37:33 -05:00
|
|
|
$rval = run \@args, ">", "${work_dir}/$currow-${gp_name}.raster", "2>", "/dev/null";
|
2018-10-21 17:11:23 -04:00
|
|
|
} else {
|
2021-01-24 14:37:33 -05:00
|
|
|
$rval = run \@args, ">", "${work_dir}/$currow-${gp_name}.raster";
|
2018-10-21 17:11:23 -04:00
|
|
|
}
|
|
|
|
if (!$rval) {
|
2019-05-18 08:01:23 -04:00
|
|
|
print("***** $row[0] $row[1] $row[2] $row[3] '$row[4]' FAIL: imagetoraster $?: $pages -- " . join(":", @args) . "\n");
|
2018-10-21 17:11:23 -04:00
|
|
|
$error++;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
2019-05-23 08:37:36 -04:00
|
|
|
foreach my $copies (@copies_set) {
|
2018-10-21 17:11:23 -04:00
|
|
|
# Call raster2gutenprint
|
2019-05-19 09:23:12 -04:00
|
|
|
@args = ($rastertogutenprint_exec, $id, $user, $title, $copies, $options);
|
2018-10-21 17:11:23 -04:00
|
|
|
if ($valgrind) {
|
|
|
|
if ($quiet) {
|
|
|
|
unshift(@args,"-q");
|
|
|
|
}
|
|
|
|
unshift(@args,"valgrind");
|
|
|
|
}
|
|
|
|
if (!$quiet) {
|
|
|
|
print join(":", @args) . "\n";
|
|
|
|
}
|
|
|
|
if ($quiet) {
|
2021-01-24 14:37:33 -05:00
|
|
|
$rval = run \@args, "<", "${work_dir}/$currow-${gp_name}.raster", ">", "${work_dir}/$currow-${gp_name}.raw", "2>", "/dev/null";
|
2018-10-21 17:11:23 -04:00
|
|
|
} else {
|
2021-01-24 14:37:33 -05:00
|
|
|
$rval = run \@args, "<", "${work_dir}/$currow-${gp_name}.raster", ">", "${work_dir}/$currow-${gp_name}.raw";
|
2018-10-21 17:11:23 -04:00
|
|
|
}
|
|
|
|
if (!$rval) {
|
2019-05-18 08:01:23 -04:00
|
|
|
print("***** $row[0] $row[1] $row[2] $row[3] '$row[4]' FAIL: rastertogutenorint $?: $pages $copies -- " . join(":", @args) . "\n");
|
2018-10-21 17:11:23 -04:00
|
|
|
$error++;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Call backend using CUPS methodologies, using STDIN.
|
2019-05-19 09:23:12 -04:00
|
|
|
@args = ($backend_exec, $id, $user, $title, $copies, $options);
|
2018-10-21 17:11:23 -04:00
|
|
|
if ($valgrind) {
|
|
|
|
if ($quiet) {
|
|
|
|
unshift(@args,"-q");
|
|
|
|
}
|
|
|
|
unshift(@args,"valgrind");
|
|
|
|
}
|
|
|
|
if (!$quiet) {
|
|
|
|
print join(":", @args) . "\n";
|
|
|
|
}
|
|
|
|
if ($quiet) {
|
2021-01-24 14:37:33 -05:00
|
|
|
$rval = run \@args, "<", "${work_dir}/$currow-${gp_name}.raw", "2>", "/dev/null";
|
2018-10-21 17:11:23 -04:00
|
|
|
} else {
|
2021-01-24 14:37:33 -05:00
|
|
|
$rval = run \@args, "<", "${work_dir}/$currow-${gp_name}.raw";
|
2018-10-21 17:11:23 -04:00
|
|
|
}
|
|
|
|
if (!$rval) {
|
2019-05-18 08:01:23 -04:00
|
|
|
print("***** $row[0] $row[1] $row[2] $row[3] '$row[4]' FAIL: backend $?: $pages $copies -- " . join(":", @args) . "\n");
|
2018-10-21 17:11:23 -04:00
|
|
|
$error++;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
}
|
2018-09-28 20:26:50 -04:00
|
|
|
}
|
2019-05-18 08:01:23 -04:00
|
|
|
print "***** $row[0] $row[1] $row[2] $row[3] '$row[4]' PASS\n";
|
2018-09-23 19:56:22 -04:00
|
|
|
|
2021-01-24 14:37:33 -05:00
|
|
|
unlink ("${work_dir}/$currow-${gp_name}.pdf");
|
|
|
|
unlink ("${work_dir}/$currow-${gp_name}.raster");
|
|
|
|
unlink ("${work_dir}/$currow-${gp_name}.raw");
|
2018-10-21 17:11:23 -04:00
|
|
|
unlink ($ppd_fname);
|
|
|
|
rmdir ($work_dir);
|
|
|
|
}
|
2018-09-28 20:26:50 -04:00
|
|
|
|
2018-10-21 17:11:23 -04:00
|
|
|
$retval = $error;
|
|
|
|
close(INFILE);
|
|
|
|
exit($retval);
|
2018-09-23 19:56:22 -04:00
|
|
|
}
|
2018-10-21 17:11:23 -04:00
|
|
|
|
2018-09-23 19:56:22 -04:00
|
|
|
exit($retval);
|