-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathautoreduce
executable file
·63 lines (60 loc) · 1.61 KB
/
autoreduce
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
56
57
58
59
60
61
62
63
#!/usr/bin/perl -w
# drop lines from a source file to find a minimal reproducer for indeterminism
# BUILDPROG should return 0 if a dropped line is good to keep dropped
# see the autoreducebuild helper for an example
use strict;
our $file=shift;
if(!@ARGV) {
die "usage: $0 FILE BUILDPROG\ne.g. $0 src/lib.rs autoreducebuild ./build.sh\n";
}
our @lines;
{
open(my $fd, "<", $file) or die "could not read $file";
@lines=<$fd>;
}
sub revert()
{
open(my $fd, ">", $file) or die;
print $fd @lines;
}
sub sighandler()
{
print STDERR "canceled by signal - reverting file\n";
revert;
exit 1;
}
$SIG{'INT'} = $SIG{'TERM'} = \&sighandler;
my $start=$ENV{start}||$#lines;
my $maxdrop=$ENV{maxdrop}||2;
my $workleft=1;
while($workleft) {
$workleft=0;
LINESLOOP:
for(my $i=$start; $i>=0; --$i) {
for(my $drop=$maxdrop; $drop>=1; --$drop) {
next if $i+$drop > @lines;
print "trying to drop $drop lines at line $i:\n";
my @reducedlines=@lines;
splice(@reducedlines, $i+1-$drop, $drop);
next if $#reducedlines == $#lines;
open(my $fd, ">", $file) or die "could not write $file";
print $fd @reducedlines;
close $fd;
system(@ARGV);
my $ret = $?>>8;
revert;
#die "ret $ret";
if ($ret) {
# revert
next;
}
else {
# keep the reduced version
@lines = @reducedlines;
$workleft = 1;
next LINESLOOP;
}
}
}
}
revert;