2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-11-11 15:40:58 +00:00
qpdf/fuzz/qtest/fuzz.test
Jay Berkenbilt 2320714339 Clean up fuzzer installation and add test files
* Create the seed corpus in the build directory
* Don't assume all fuzzers share an options file
2019-06-21 17:39:53 -04:00

46 lines
1.0 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');
my @files = glob("../build/qpdf_fuzzer_seed_corpus/*");
my $n_test_files = 29;
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;
}