Skip to content

Commit

Permalink
Add primitive manual fuzz testing
Browse files Browse the repository at this point in the history
  • Loading branch information
pkubowicz committed Dec 17, 2023
1 parent 2490a3d commit 75a1fa2
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test.pl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

use strict;

use File::stat;

assert_produces_correct_output('in.tex', 'correct.txt');
assert_produces_correct_output('in.tex', 'correct.txt', '-l');
assert_produces_correct_output('noinclude.tex', 'noinclude-correct.txt', '-n');
Expand All @@ -20,6 +22,8 @@
run_for_input_with_error("test/unterminated-verb.tex");
run_for_input_with_error("test/unterminated-verb-eol.tex");

fuzz();

print "Tests ok\n";

sub assert_produces_correct_output {
Expand Down Expand Up @@ -60,6 +64,22 @@ sub run_for_input_with_error {
die "exit code $res" if ($res != 1);
}

sub fuzz {
chdir 'test';
my $input = 'in.tex';
my $sb = stat($input);
for (my $i=0; $i<25; ++$i) {
my $bytes = int(rand($sb->size));
printf("Fuzz: bytes %5d/%5d of %s. ", $bytes, $sb->size, $input);
system("head -c $bytes $input > /tmp/trunc.tex");
my $res = system(get_cmd("../delatex /tmp/trunc.tex > /tmp/trunc.log")) >> 8;
print "Exit code $res\n";
if ($res != 0 && $res != 1) {
die;
}
}
}

sub execute_cmd {
my ($cmd) = @_;
my $res = system(get_cmd($cmd));
Expand Down

0 comments on commit 75a1fa2

Please sign in to comment.