/
tifthread.pl
55 lines (50 loc) · 1.18 KB
/
tifthread.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!perl -w
use strict;
use threads;
use Imager;
++$|;
Imager->preload;
# as a TIFF this file is large, build it from largeish.jpg if it
# doesn't exist
unless (-f "bench/largish.tif") {
my $im = Imager->new(file => "bench/largish.jpg")
or die "Cannot read bench/largish.jpg:", Imager->errstr;
$im->write(file => "bench/largish.tif")
or die "Cannot write bench.largish.tif:", $im->errstr;
}
my @tests =
(
[ "bench/largish.tif", "" ],
[ "TIFF/testimg/grey16.tif", "" ],
[ "TIFF/testimg/comp4bad.tif", "(Iolayer): Read error at scanline 120; got 0 bytes, expected 32" ],
);
my @threads;
my $name = "A";
for my $test (@tests) {
push @threads,
threads->create
(
sub {
my ($file, $result, $name) = @_;
for (1 .. 100000) {
print $name;
my $im = Imager->new(file => $file);
if ($result) {
$im and die "Expected error from $file, got image";
Imager->errstr eq $result
or die "Expected error '$result', got '",Imager->errstr, "'"
}
else {
$im or die "Expected image got error '", Imager->errstr, "'";
}
}
return;
},
@$test,
$name
);
++$name;
}
for my $t (@threads) {
$t->join();
}