Fix a bug in awk code in rsh01
[ltp-debian.git] / tools / create_valgrind_check.pl
blob41ed93eb04e80ef3e5fed59fa69cc90cfa6c7726
1 #!/usr/bin/perl
2 ################################################################################
3 ## ##
4 ## Copyright (c) International Business Machines Corp., 2009 ##
5 ## ##
6 ## This program is free software; you can redistribute it and/or modify ##
7 ## it under the terms of the GNU General Public License as published by ##
8 ## the Free Software Foundation; either version 2 of the License, or ##
9 ## (at your option) any later version. ##
10 ## ##
11 ## This program is distributed in the hope that it will be useful, but ##
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
13 ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ##
14 ## for more details. ##
15 ## ##
16 ## You should have received a copy of the GNU General Public License ##
17 ## along with this program; if not, write to the Free Software ##
18 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ##
19 ## ##
20 ################################################################################
21 # ##
22 # File : create_valgrind_check ##
23 # ##
24 # Usage: create_valgrind_check\ ##
25 # <LTP_COMMAND_FILE> <VALGRIND_CHECK_TYPE> ##
26 # ##
27 # Description: This is a simple perl script which will take ltp command file ##
28 # as input and then create a final command file while will have ##
29 # the following entries for each test tag: ##
30 # 1) <tag_name> <test_binary_name> ##
31 # 2) <tag_name_valgrind_check_type> <valgrind test_binary_name> ##
32 # ##
33 # Author: Subrata Modak <subrata@linux.vnet.ibm.com> ##
34 # ##
35 # History: Aug 23 2009 - Created - Subrata Modak. ##
36 ################################################################################
38 my $command_file = shift (@ARGV) || syntax();
39 my $valgrind_check_type = shift (@ARGV) || syntax();
41 sub syntax() {
42 print "syntax: create_valgrind_check\
43 <LTP_COMMAND_FILE> <VALGRIND_CHECK_TYPE>\n";
44 exit (1);
47 sub print_memory_leak_check {
48 $sub_line = shift;
49 @sub_tag_and_actual_command = split(/\ /, $sub_line);
50 my $sub_token_counter = 0;
51 foreach my $sub_token (@sub_tag_and_actual_command) {
52 if ($sub_token_counter == 0 ) {#print the tagname now
53 print $sub_token . "_valgrind_memory_leak_check " .
54 " valgrind -q --leak-check=full --trace-children=yes ";
55 $sub_token_counter++;
56 next;
58 print " " . $sub_token . " ";
60 print "\n";
63 sub print_thread_concurrency_check {
64 $sub_line = shift;
65 @sub_tag_and_actual_command = split(/\ /, $sub_line);
66 my $sub_token_counter = 0;
67 foreach my $sub_token (@sub_tag_and_actual_command) {
68 if ($sub_token_counter == 0 ) {#print the tagname now
69 print $sub_token . "_valgrind_thread_concurrency_check " .
70 " valgrind -q --tool=helgrind --trace-children=yes ";
71 $sub_token_counter++;
72 next;
74 print " " . $sub_token . " ";
76 print "\n";
79 open (FILE, $command_file) || die "Cannot open file: $command_file\n";
80 while ($line = <FILE>) {
81 if ($line =~ /^#/) {
82 print "$line";
83 next;
85 if ($line =~ /^\n$/) {
86 next;
88 chomp $line;
89 print "$line\n"; #Print one instance for normal execution
91 if ($valgrind_check_type == 3) {
92 #Print for both Memory Leak and Thread Concurrency Checks
93 print_memory_leak_check($line);
94 print_thread_concurrency_check($line);
96 if ($valgrind_check_type == 2) {
97 #Print only for Thread concurrency Check
98 print_thread_concurrency_check($line);
100 if ($valgrind_check_type == 1) {
101 #Print only for Memory leak Check
102 print_memory_leak_check($line);
105 close (FILE);