1# -*- cperl -*-
2# Copyright (c) 2004, 2021, Oracle and/or its affiliates.
3#
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License, version 2.0,
6# as published by the Free Software Foundation.
7#
8# This program is also distributed with certain software (including
9# but not limited to OpenSSL) that is licensed under separate terms,
10# as designated in a particular file or component or in included license
11# documentation.  The authors of MySQL hereby grant you an additional
12# permission to link the program and your derivative works with the
13# separately licensed software that they have included with MySQL.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18# GNU General Public License, version 2.0, for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program; if not, write to the Free Software
22# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23
24# This is a library file used by the Perl version of mysql-test-run,
25# and is part of the translation of the Bourne shell script with the
26# same name.
27
28use strict;
29
30sub gcov_prepare ($) {
31  my ($dir)= @_;
32  print "Purging gcov information from '$dir'...\n";
33
34  system("find $dir -name \*.gcov -o -name \*.da"
35             . " -o -name \*.gcda | grep -v 'README.gcov\$' | xargs rm");
36}
37
38#
39# Collect gcov statistics.
40# Arguments:
41#   $dir       basedir, normally build directory
42#   $gcov      gcov utility program [path] name
43#   $gcov_msg  message file name
44#   $gcov_err  error file name
45#
46sub gcov_collect ($$$) {
47  my ($dir, $gcov, $gcov_msg, $gcov_err)= @_;
48
49  # Get current directory to return to later.
50  my $start_dir= cwd();
51
52  print "Collecting source coverage info using '$gcov'...\n";
53  -f "$dir/$gcov_msg" and unlink("$dir/$gcov_msg");
54  -f "$dir/$gcov_err" and unlink("$dir/$gcov_err");
55
56  my @dirs= `find "$dir" -type d -print | sort`;
57  #print "List of directories:\n@dirs\n";
58
59  foreach my $d ( @dirs ) {
60    chomp($d);
61    chdir($d) or next;
62
63    my @flist= glob("*.*.gcno");
64    print ("Collecting in '$d'...\n") if @flist;
65
66    foreach my $f (@flist) {
67      system("$gcov $f 2>>$dir/$gcov_err >>$dir/$gcov_msg");
68    }
69    chdir($start_dir);
70  }
71  print "gcov info in $dir/$gcov_msg, errors in $dir/$gcov_err\n";
72}
73
74
751;
76