#!/usr/local/bin/perl -w
use strict;
my $DOC = <<"EOF";
Usage: $0
Run first:
- fault_cov_instances
- Run an empty test case and link/copy the resulting coverage file (*.txt) to /init_cov.txt
Args:
-
Affects:
- /fault_cov_instances_with_init.txt
Header:
- SuiteNum, >= 1
- TstNum, >= 0
- StepNum, >= 1
- FaultNum, >= 1
- TimesExec, # times faulty line executed at SuiteNum:TstNum:StepNum for clean version (1 if faults.InMethod=0 for FaultNum)
- TimesInInit, if StepNum=1, # times line is executed in initialization code (executed before any events); 0 otherwise
Adds TimesInInit to fault_cov_instances.
EOF
;
if (@ARGV != 1) {
print $DOC;
exit 1;
}
my ($table_dir) = @ARGV;
$table_dir =~ s|/$||;
my $out_file = "$table_dir/fault_cov_instances_with_init.txt";
if (-e $out_file) {
die "$out_file already exists\n";
}
my %fault_lines; # key = FaultNum, value = Line
my $faults_file = "$table_dir/faults.txt";
open(FAULTS, $faults_file) or die "Couldn't read $faults_file\n";
my $head = ;
while () {
chomp;
my ($fault_num, $line) = split;
$fault_lines{$fault_num} = $line;
}
close(FAULTS);
my %init_times; # key = file:line, value = times
my $init_cov_file = "$table_dir/init_cov.txt";
open(INIT, $init_cov_file) or die "Couldn't read $init_cov_file\n";
while () {
chomp;
my ($file, $line, $times) = split;
if (! defined $init_times{"$file:$line"}) {
$init_times{"$file:$line"} = 0;
}
$init_times{"$file:$line"} += $times;
}
close(INIT);
open(OUT, ">$out_file") or die "Couldn't write to $out_file\n";
print OUT "SuiteNum TstNum StepNum FaultNum TimesExec InInit InEvent\n";
my $fault_cov_instances_file = "$table_dir/fault_cov_instances.txt";
open(FCI, $fault_cov_instances_file) or die "Couldn't read $fault_cov_instances_file\n";
$head = ;
while () {
chomp;
my ($suite_num, $tst_num, $step_num, $fault_num, $times_exec) = split;
my $line = $fault_lines{$fault_num};
my $times_in_init;
if ($step_num == 1 && defined $init_times{$line}) {
$times_in_init = $init_times{$line};
} else {
$times_in_init = 0;
}
print OUT "$suite_num $tst_num $step_num $fault_num $times_exec $times_in_init\n";
}
close(FCI);
close(OUT);