diff options
author | Vladimir Glazounov <vg@openoffice.org> | 2003-05-19 12:16:54 +0000 |
---|---|---|
committer | Vladimir Glazounov <vg@openoffice.org> | 2003-05-19 12:16:54 +0000 |
commit | 72e2d20cb0463107bc036a6041aa56343e806b06 (patch) | |
tree | 6645f0d907a007c422f0a6f4acce4ef972c5878e /sal/qa/helper | |
parent | 6bee74a93d6ab5f3308252ae0cdaea2f2f20365b (diff) |
INTEGRATION: CWS qadev5 (1.1.2); FILE ADDED
2003/04/25 06:45:42 lla 1.1.2.1: #108721# gcov statistic helper functions.
Diffstat (limited to 'sal/qa/helper')
-rwxr-xr-x | sal/qa/helper/gcov/gcov_all | 15 | ||||
-rwxr-xr-x | sal/qa/helper/gcov/gcov_filter.pl | 351 |
2 files changed, 366 insertions, 0 deletions
diff --git a/sal/qa/helper/gcov/gcov_all b/sal/qa/helper/gcov/gcov_all new file mode 100755 index 000000000000..5e894e1fb702 --- /dev/null +++ b/sal/qa/helper/gcov/gcov_all @@ -0,0 +1,15 @@ +#!/bin/bash +# $Id: gcov_all,v 1.2 2003-05-19 13:16:46 vg Exp $ +# This helper run lists all c and cxx files from selected directories. + +# PRJ points to the flat project directory +PRJ='../../..' + +# selected directories +FILES=`/bin/ls $PRJ/osl/unx/*.c $PRJ/osl/unx/*.cxx $PRJ/rtl/source/*.c $PRJ/rtl/source/*.cxx $PRJ/osl/all/*.c $PRJ/osl/all/*.cxx $PRJ/textenc/*.c` + +# Use gcov_filter on every c/cxx file. +for file in $FILES; do + # echo $file + ./gcov_filter.pl -i $PRJ/util/sal.map $file $* +done diff --git a/sal/qa/helper/gcov/gcov_filter.pl b/sal/qa/helper/gcov/gcov_filter.pl new file mode 100755 index 000000000000..4b17ce54ff3b --- /dev/null +++ b/sal/qa/helper/gcov/gcov_filter.pl @@ -0,0 +1,351 @@ +#!/usr/bin/perl -w +# +# $Id: gcov_filter.pl,v 1.2 2003-05-19 13:16:54 vg Exp $ +# + +# GCOV_FILTER +# +# Helper to filter the gcov output. +# Handle a compare between the hole gcov output and a given select list of exported functions. +# +# Q: Why perl? +# A: regexp ;-) +# + + +use strict; +use File::Basename; +use Getopt::Long; + +# Global constants +our $version_info = 'gcov helper $Revision: 1.2 $'; +our $help; # Help option flag +our $version; # Version option flag +our $cwd = `pwd`; # current working directory +chomp($cwd); +# our $tool_dir = dirname($0); +# our $tool_file = basename($0); + +# our $output_filename; +our $input_allfunc; +# our $input_filename; + +our $allfuncinfo; # allfuncinfo option flag +our $showallfunc; # showallfunc option flag +our $no_percentage; # no_percentage option flag +our $donotfilter; # donotfilter option flag + +# Prototypes +sub print_usage(*); +sub read_gcov_function_file($); +sub get_PRJ_from_makefile_mk(); +sub read_ExportedFunctionList(); + +# if (! ($tool_dir =~ /^\/(.*)$/)) +# { +# $tool_dir = "$cwd/$tool_dir"; +# } + +# Parse command line options +if (!GetOptions( "input-allfunc=s" => \$input_allfunc, + "allfuncinfo" => \$allfuncinfo, + "showallfunc" => \$showallfunc, + "no-percentage" => \$no_percentage, + "do-not-filter" => \$donotfilter, + "help" => \$help, + "version" => \$version + )) +{ + print_usage(*STDERR); + exit(1); +} + +# Check for help option +if ($help) +{ + print_usage(*STDOUT); + exit(0); +} + +# Check for version option +if ($version) +{ + print("$version_info\n"); + exit(0); +} + +# check if enough parameters +if ($#ARGV < 0) +{ + print("No input filename specified\n"); + print_usage(*STDERR); + exit(1); +} + +# special case: +# the filename contains a . or '/' at the beginning +my $startdir = $ARGV[0]; +if ( ($startdir =~ /^\.\./) || + ($startdir =~ /^\//) ) +{ + $startdir = dirname($startdir); + # print("start directory is $startdir\n"); + # chdir $startdir; +} +else +{ + $startdir = ""; +} + +# check for sal.map +if ( ! $input_allfunc ) +{ + # this is a try, to get the project directory form a found makefile.mk + # may work, but fails due to some disunderstandings may be problems in perl :-( + my $sDir = get_PRJ_from_makefile_mk(); + # chomp($sDir); + # HDW: print("PRJ is $dir\n"); + + # $sDir2 = "../.."; + my $sMapFile = "$sDir" . "/util/sal.map"; + # $sMapFile = "$sDir2" . "/util/sal.map"; + + if ( -e $sMapFile) + { + $input_allfunc = $sMapFile; + } + else + { + print("No input-allfunc filename specified\n"); + print_usage(*STDERR); + exit(1); + } +} +our @aExportedFunctionList; +read_ExportedFunctionList(); + +if ($allfuncinfo) +{ + print("Count of all functions: $#aExportedFunctionList\n"); + exit(0); +} + +if ($showallfunc) +{ + my $func; + foreach $func (@aExportedFunctionList) + { + print("$func\n"); + } + exit(0); +} + +# back to current directory +# this chdir was for a before chdir (in $startdir creation) but due to the fact, +# that the get_PRJ_from_makefile_mk works but the after concat of strings not, this +# chdir is also remarked. +# chdir $cwd; + +# HWD: print "count of param: \n"; +# $input_filename = $ARGV[0]; + +my $nCount = $#ARGV + 1; +my $nIdx; + +for ($nIdx = 0; $nIdx < $nCount ; ++$nIdx) +{ + my $file = $ARGV[$nIdx]; + # print("processing: $file\n"); + + # change directory, to the current file, due to the fact, that we may be need to call gcov + # and gcov will create some extra files, like *.gcov near the current file. + if ( $startdir ne "" ) + { + chdir $startdir; + $file = basename($file); + } + + if (! ($file =~ /\.f$/ )) + { + my $filef = "$file.f"; + if (! -e $filef ) + { + my $blah = `gcov -f $file >$filef`; + } + $file = $filef; + } + read_gcov_function_file($file); + + # go back to old directory, because it's possible to change relative to an other directory. + if ( $startdir ne "" ) + { + chdir $cwd; + } +} + +# print "$tool_dir\n"; +# print "all is right\n"; +exit(0); + + +# -------------------------------------------------------------------------------- +# Read the map file, which should contain all exported functions. +sub read_ExportedFunctionList() +{ + local *INPUT_HANDLE; + my $line = ""; + open(INPUT_HANDLE, $input_allfunc) + or die("ERROR: cannot open $input_allfunc!\n"); + + while ($line = <INPUT_HANDLE>) + { + chomp($line); + # reg exp: [spaces]functionname[semicolon][line end] + if ($line =~ /^\s+(\w*);$/) + { + # print("$1\n"); + push(@aExportedFunctionList, $1); + } + } + close(INPUT_HANDLE); +} + +# -------------------------------------------------------------------------------- +# Helper function, test is a given value is found in the global exported function list. +# the given value format could be a simple function name +# or a prototype +# e.g. +# osl_getSystemPathFromFileURL +# or +# void getSystemPathFromFileURL( const char* rtl_...) +# +sub contain_in_ExportedFunctionList($) +{ + my $func; + my $value = $_[0]; + + if ($donotfilter) + { + return 1; + } + + foreach $func (@aExportedFunctionList) + { + # first try, direct check + if ($value eq $func) + { + # HWD: print("$value eq $func\n"); + return $value; + } + + # value not found, second try, may be we found it if we search word wise. + # helper, to insert a space after the word, before '(' + $value =~ s/\(/ \(/g; + # may be here we should replace all white spaces by ' ' + + # split by 'space' + my @list = split(' ', $value); + for(@list) + { + # HWD: print "$list[$n]\n"; + if ($_ eq $func) + { + # HWD: print ("found $func in $value\n"); + return $_; + } + } + } + # not found + return ""; +} +# -------------------------------------------------------------------------------- +# Read the gcov function (gcov -f) file +# and compare line by line with the export function list +# so we get a list of functions, which are only exported, and not all stuff. + +sub read_gcov_function_file($) +{ + local *INPUT_HANDLE; + my $file = $_[0]; + my $line = ""; + open(INPUT_HANDLE, $file) + or die("ERROR: cannot open $file!\n"); + + while ($line = <INPUT_HANDLE>) + { + chomp($line); + # sample line (for reg exp:) + # 100.00% of 3 source lines executed in function osl_thread_init_Impl + if ($line =~ /^(.*)% of \d+ source lines executed in function (.*)$/ ) + { + my $value = contain_in_ExportedFunctionList( $2 ); + if ($value) + { + if ($no_percentage) + { + print("$value\n"); + } + else + { + print("$1 $value\n"); + } + } + # push(@aExportedFunctionList, $1); + } + } + close(INPUT_HANDLE); +} + +# ------------------------------------------------------------------------------ +# helper, to read the PRJ value out of a makefile.mk file +sub get_PRJ_from_makefile_mk() +{ + local *INPUT_HANDLE; + # my $startdir = @_[0]; + my $line = ""; + my $value = ""; + open(INPUT_HANDLE, "makefile.mk") + or die("ERROR: cannot open makefile.mk\n"); + + while ($line = <INPUT_HANDLE>) + { + chomp($line); + # sample line + # PRJ= + # HWD: print("$line\n"); + if ($line =~ /^PRJ\s*=(.*)/) + { + # HWD: print("FOUND #####\n"); + $value = $1; + chomp($value); + $value =~ s/\$\//\//g; + } + } + close(INPUT_HANDLE); + return $value; +} + +# ---------------------------------------------------------------------------- +sub print_usage(*) +{ + local *HANDLE = $_[0]; + my $tool_name = basename($0); + + print(HANDLE <<END_OF_USAGE); + +Usage: $tool_name [OPTIONS] INPUTFILE + + foo bla + + -h, --help Print this help, then exit + -v, --version Print version number, then exit + -i, --input-allfunc FILENAME Map file, which contain all exported functions + -s, --showallfunc Shows all exported functions then exit + -a, --allfuncinfo Shows the count of all exported functions then quit + -n, --no-percentage Suppress the output of the percent value for tested functions + -d, --do-not-filter Show all functions, which gcov -f produce + +END_OF_USAGE + ; +} + |