Use Perl to check Purify result automatically
1. BackgroundI often need run purify to confirm whether memory errors exist.
And because our project has above 4000 test cases, each case will produce one *.pfy(or *.txt") file as the test result.
So we need check about 4000 *.pfy files one by one to see whether memory error exist. This is time consumed and unreliable.
2. Solution
Use perl script to examine the test result automatically.
In order to use perl script to check the test result, we should prepare plain text format(*.txt) test result. (supported by purify)
Then perl script will do all check work and show clear result for us.
3. Conclusion
1) There is a tip in <The Pragmatic Programmer>
-> "Keep Knowledge in Plain Text."
Plain text is powerful. Especially plain it is easy to test.
2) There is also a tip in <The Pragmatic Programmer>
-> "Learn a Text Manipulation Language"
Be a programmer, it's better to learn a text manipulation language.
ex. perl, python, awk, tcl, sed etc..
They can rescue us from repeated and tiresome work.
This is the perl script for checking purify test result->
# Script for checking purify test result
#
# All *.txt under 'dirnames_/testdir' directory will be searched by this script.
#
# Check items:
# 1) error
# 2) UMR
# 3) Memory leak above 1000 bytes
# Following settings will check all *.txt under ../../scripts/c.Sg-purify
# You can modify following two arraies by yourself.
# Higher diretory name
@dirnames_ = qw(../../scripts);
# Lower directory name
@testdir_ = qw(c.Sg-purify);
# Arraies to hold error, memory leak and warning.
@error;
@memory;
@warning;
####################################### func #######################################
# Print array content
sub print_array
{
my ($type, @array) = @_;
print "$type...\n";
print "name\tdescription\n";
print "---------------------------------------------------------------------------------\n";
#foreach $item (@_)
while (@array) {
$item = shift(@array);
print "$item\n";
}
print "\n";
#return @array;
} # end sub
# Print result
sub print_res
{
# Delete dupulicated content in arraies
@error = delete_dupulicate(@error);
@memory= delete_dupulicate(@memory);
@warning = delete_dupulicate(@warning);
print "#########################\t$dirnames/$testdir\t#########################\n\n";
if ( (!@error) && (!@memory) && (!@warning) ){ print ("No Error, Memory Leak Error, and Waring found\n\n"); }
else {
if (!@error) { print ("No Error found \n\n"); }
if (!@memory){ print ("No Memory Leak Error found \n\n"); }
if (!@warning) { print ("No Waring found \n\n"); }
}
if (@error) { @error = print_array("Error...", @error); }
if (@memory){ @memory= print_array("Memory Leak Error...", @memory); }
if (@warning) { @warning = print_array("Warning...", @warning); }
print "\n";
} # end print_res
# Delete dupulicated content in arraies
sub delete_dupulicate
{
%ct;
return @_ = grep(!$ct{$_}++, @_);
} # end sub
# Main loop
sub normalize
{
my $num;
while ( @_ ) {
$text = shift(@_);
$text =~ /^.+$testdir\//;
$num = $';
open( SRC, "< $text" ) or die;
while( )
{
# :
if ($_ =~ /^\/) {
chomp($line = "$num\t$_");
push (@error, $line);
}
# UMR
if ($_ =~ /^\ UMR/) {
chomp($line = "$num\t$_");
push (@warning, $line);
}
# memory leak above 1000 bytes
if ( $_ =~ /all memory\D+\{(\d+)/ ) {
if ($1 >= 1000) {
chomp($line = "$num\t$_");
push (@memory, $line);
}
}
}
close(SRC);
} # while
print_res();
} # end normalize
####################################### main #######################################
# All .txt files are looked for from specified dir.
foreach $dirnames (@dirnames_) {
foreach $testdir (@testdir_) {
@files_ = <./$dirnames/$testdir/*.txt>;
normalize(@files_) if (@files_);
}
}
页:
[1]