-
Notifications
You must be signed in to change notification settings - Fork 6
/
err_recovery.pl
executable file
·389 lines (296 loc) · 9.18 KB
/
err_recovery.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
#!/usr/bin/perl -w
=head1 NAME
err_recovery.pl ( Produce random Mizar articles and test Mizar error recovery )
=head1 SYNOPSIS
err_recovery.pl [options] filename
Options:
--number=<arg> -n<arg>
--pepperamount=<arg>, -p<arg>
--mixamount=<arg>, -x<arg>
--cpulimit=<arg>, -c<arg>
--startpos=<arg>, -s<arg>
--maxoutbytes=<arg>, -b<arg>
--verifier=<arg>, -v<arg>
--accom=<arg>, -a<arg>
--keeperrors, -k
--rerun, -r
--help, -h
--man
=head1 OPTIONS
=over 8
=item B<<< --number=<arg>, -n<arg> >>>
Number of random articles created, default is 100.
=item B<<< --pepperamount=<arg>, -p<arg> >>>
Amount of randomly added keywords, default is 30.
=item B<<< --mixamount=<arg>, -x<arg> >>>
Amount of random permutations. default is 10.
Not implemented yet!
=item B<<< --cpulimit=<arg>, -c<arg> >>>
CPU limit for each try, default is 7.
=item B<<< --maxoutbytes=<arg>, -b<arg> >>>
Maximal length of output printed from one test,
default is 2000. Used to keep the log file reasonably
small when performing large number of tests giving
long error output like access violations.
=item B<<< --verifier=<arg>, -v<arg> >>>
The verifier to run. Default is "verifier".
=item B<<< --accom=<arg>, -a<arg> >>>
The accommodator to run. Default is "accom".
=item B<<< --keeperrors, -k >>>
Keep the error files (*.err) after each run.
Useful for comparison of two verifier versions, when
followed by rerun (--rerun).
=item B<<< --rerun, -r >>>
Do not create problems, assuming that they are already
generated, and just rerun them.
=item B<<< --help, -h >>>
Print a brief help message and exit.
=item B<<< --man >>>
Print the manual page and exit.
=back
=head1 CONTACT
Josef Urban [email protected]
=cut
=head1 APPENDIX
Description of functions defined here.
=cut
use strict;
use Pod::Usage;
use Getopt::Long;
my $ARTICLE_NUMBER = 100;
my $PEPPER_AMOUNT = 30;
my $MIX_AMOUNT = 10;
my $CPU_LIMIT = 7;
my $START_POS = 1200;
my $MAX_OUTPUT_BYTES = 2000;
my $VERIFIER = "verifier";
my $ACCOM = "accom";
my $KEEPERRORS;
my $RERUN;
## Name of the original Mizar article to be peppered - $ARGV[0]
my $MIZ_NAME;
## Keywords starting main mizar text items.
## Now also the environmental declarations.
my @mizar_main_keywords =
( 'theorem', 'scheme', 'definition', 'registration',
'notation', 'schemes', 'constructors', 'definitions',
'theorems', 'vocabulary', 'clusters', 'signature',
'requirements'
);
## Keywords for Mizar block starts and ends.
my @mizar_block_keywords =
( 'proof', 'now', 'end', 'hereby', 'case', 'suppose');
## Keywords for logical symbols in Mizar formulas.
my @mizar_formula_keywords =
( 'for', 'ex', 'not', '&', 'or', 'implies', 'iff', 'st', 'holds', 'being');
## Keywords denoting skeleton proof steps.
my @mizar_skeleton_keywords =
( 'assume', 'cases', 'given', 'hence', 'let', 'per', 'take', 'thus');
## Mizar keywords not mentioned in other place.
my @mizar_normal_keywords =
('and', 'antonym', 'attr', 'as', 'be', 'begin', 'canceled', 'cluster',
'coherence', 'compatibility', 'consider', 'consistency',
'contradiction', 'correctness', 'def', 'deffunc',
'defpred', 'environ', 'equals', 'existence',
'func', 'if', 'irreflexivity',
'it', 'means', 'mode', 'of', 'otherwise', 'over',
'pred', 'provided', 'qua', 'reconsider', 'redefine', 'reflexivity',
'reserve', 'struct', 'such', 'synonym',
'that', 'then', 'thesis', 'where',
'associativity', 'commutativity', 'connectedness', 'irreflexivity',
'reflexivity', 'symmetry', 'uniqueness', 'transitivity', 'idempotence',
'asymmetry', 'projectivity', 'involutiveness'
);
## All keywords used for pepper.
my @mizar_keywords =
(@mizar_main_keywords,
@mizar_block_keywords,
@mizar_formula_keywords,
@mizar_skeleton_keywords,
@mizar_normal_keywords);
sub min { my ($x,$y) = @_; ($x <= $y)? $x : $y }
sub max { my ($x,$y) = @_; ($x <= $y)? $y : $x }
sub DEBUGGING { 0 };
sub Debug_Print
{
my($str) = @_;
if(DEBUGGING) { print $str};
}
# Assumes that the two arguments are integers themselves!
sub Random_Int_In ($$)
{
my($min, $max) = @_;
return $min if $min == $max;
($min, $max) = ($max, $min) if $min > $max;
return $min + int rand(1 + $max - $min);
}
# Pointer to random list of length LEN with integer values
# from 0 to MAXVAL
sub Rand_List
{
my ($maxval, $len) = @_;
my (@res);
while( $#res < $len - 1) { push(@res, Random_Int_In(1, $maxval)) };
return @res;
}
# Now randomly deletes a random substring
sub Mix
{
my ($str) = @_;
if(1/$MIX_AMOUNT < rand)
{
my $offset1 = Random_Int_In(0, length($str) - 1);
my $offset2 = Random_Int_In($offset1, length($str) - 1);
return substr($str,0,$offset1).substr($str,$offset2);
}
else
{
return $str;
}
}
sub Pepper_With_Syntax
{
my ($fname, $pepper_nr, $mix_nr, $start, $white_nr, $contents) = @_;
open(OUT, ">$fname");
my @posvec = sort { $a <=> $b } Rand_List($white_nr, $pepper_nr);
my @wordvec = Rand_List($#mizar_keywords, $pepper_nr);
my $i = -1;
my $lastpos = 0;
my $cur_white = 0;
Debug_Print "\nposvec: @posvec\n";
while($i++ < $#posvec)
{
while(($contents =~ m/[ \t\n]+/sg) && ($cur_white < $posvec[$i]))
{
$cur_white++;
};
my $newpos = pos $contents;
Debug_Print "$lastpos,$newpos;";
if( $cur_white == $posvec[$i])
{
print OUT Mix(substr($contents, $lastpos,
($newpos - $lastpos)));
print OUT ($mizar_keywords[$wordvec[$i]], " ");
$lastpos = $newpos;
}
else
{
Debug_Print "FAILED\n";
print OUT Mix(substr($contents,$lastpos));
};
}
close(OUT);
}
=head2 Create_Peppered()
Title : Create_Peppered()
Usage : Create_Peppered($orig, $art_nr, $pepper_nr,
$mix_nr, $start);
Function : Create the peppered articles from $orig
Returns : List of the created filenames
Global Vars : @mizar_keywords
Args : ($orig, $art_nr, $pepper_nr, $mix_nr, $start)
=cut
sub Create_Peppered
{
my ($orig, $art_nr, $pepper_nr, $mix_nr, $start) = @_;
my ($base, $contents, $white_nr, $i, @res);
die "$orig does not exist" unless(-e $orig);
$orig =~ m/(.*)[.]miz$/
or die "Not a Mizar file name: $orig";
$base = $1;
$contents = `cat $orig`;
while($contents =~ m/[ \t\n]+/sg) { $white_nr++ };
$pepper_nr = min($pepper_nr, $white_nr);
while($i++ < $art_nr)
{
my $new_name = $base."$i.miz";
if(-e $new_name) { system("rm -f $new_name"); };
Pepper_With_Syntax($new_name, $pepper_nr, $mix_nr,
$start, $white_nr, $contents);
push @res, $new_name;
}
return @res;
}
=head2 Check_Existence()
Title : Check_Existence()
Usage : Create_Peppered($orig, $art_nr);
Function : Check that $art_nr files created from $orig
by previous run exist.
Returns : List of the created filenames
Global Vars : -
Args : ($orig, $art_nr)
=cut
sub Check_Existence
{
my ($orig, $art_nr) = @_;
my ($base, $i, @res);
die "$orig does not exist" unless(-e $orig);
$orig =~ m/(.*)[.]miz$/
or die "Not a Mizar file name: $orig";
$base = $1;
while($i++ < $art_nr)
{
my $new_name = $base."$i.miz";
die "$new_name does not exist" unless(-e $new_name);
push @res, $new_name;
}
return @res;
}
=head2 Test_Run()
Title : Test_Run()
Usage : Test_Run($orig, $newfiles, $cpu, $keep);
Function : Run verifier efficiently on @$newfiles,
printing output to STDOUT.
Returns : -
Global Vars : $MAX_OUTPUT_BYTES
Args : $orig, $newfiles, $cpu, $keep;
=cut
## The moving prevents accommodation
sub Test_Run
{
my ($orig, $newfiles, $cpu, $keep) = @_;
my ($res, $file, $orig_base);
my $hidden_orig = $orig."000";
$orig =~ m/(.*)[.]miz$/;
$orig_base = $1;
`$ACCOM $orig; $VERIFIER -q -l $orig`;
system("mv $orig $hidden_orig");
foreach $file (@$newfiles)
{
print "Processing: $file\n";
system("mv $file $orig");
$res = `ulimit -t$cpu; $VERIFIER -q $orig 2>&1`;
system("mv $orig $file");
if($keep)
{
$file =~ m/(.*)[.]miz$/;
my $new_base = $1;
system("mv $orig_base.err $new_base.err");
}
print (substr($res,0,$MAX_OUTPUT_BYTES), "\n");
}
system("mv $hidden_orig $orig");
}
my ($help, $man);
Getopt::Long::Configure ("bundling");
GetOptions('number|n=i' => \$ARTICLE_NUMBER,
'pepperamount|p=i' => \$PEPPER_AMOUNT,
'mixamount|x=i' => \$MIX_AMOUNT,
'cpulimit|c=i' => \$CPU_LIMIT,
'startpos|s=i' => \$START_POS,
'maxoutbytes|b=i' => \$MAX_OUTPUT_BYTES,
'verifier|v=s' => \$VERIFIER,
'accom|a=s' => \$ACCOM,
'keeperrors|k' => \$KEEPERRORS,
'rerun|r' => \$RERUN,
'help|h' => \$help,
'man' => \$man)
or pod2usage(2);
pod2usage(1) if($help);
pod2usage(-exitstatus => 0, -verbose => 2) if($man);
pod2usage(2) if ($#ARGV != 0);
$MIZ_NAME = shift @ARGV;
my @created = $RERUN ? Check_Existence($MIZ_NAME, $ARTICLE_NUMBER)
: Create_Peppered($MIZ_NAME, $ARTICLE_NUMBER, $PEPPER_AMOUNT,
$MIX_AMOUNT, $START_POS);
Test_Run($MIZ_NAME, \@created, $CPU_LIMIT, $KEEPERRORS);