2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-11-02 11:46:35 +00:00
qpdf/fuzz/qtest/fuzz.test
Jay Berkenbilt bcfa407912 As a test suite, run stand-alone fuzzer on seed corpus
Temporarily skip fuzz tests on Windows. There are Windows-specific
failures to address later.
2019-06-15 17:24:24 -04:00

53 lines
1.2 KiB
Perl

#!/usr/bin/env perl
require 5.008;
use warnings;
use strict;
use Digest::SHA;
use File::Basename;
require TestDriver;
my $td = new TestDriver('fuzz');
if (($^O eq 'MSWin32') || ($^O eq 'msys'))
{
$td->emphasize("temporarily skipping fuzz tests in Windows");
$td->report(0);
exit(0);
}
my @files = glob("../qpdf_fuzzer_seed_corpus/*");
my $n_test_files = 27;
my $n_orig_files = 2559;
my $n_files = $n_test_files + $n_orig_files;
if (scalar(@files) != $n_files)
{
die "wrong number of files seen in fuzz.test";
}
foreach my $f (@files)
{
my $sum = basename($f);
$td->runtest("checksum $sum",
{$td->STRING => get_sha1_checksum($f)},
{$td->STRING => $sum});
$td->runtest("fuzz check $sum",
{$td->COMMAND => "qpdf_fuzzer $f"},
{$td->REGEXP => ".*$f successful\n",
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
}
$td->report(2 * $n_files);
sub get_sha1_checksum
{
my $file = shift;
open(F, "<$file") or fatal("can't open $file: $!");
binmode F;
my $digest = Digest::SHA->new('sha1')->addfile(*F)->hexdigest;
close(F);
$digest;
}