Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update perl script for generate memcheck test with new tesh.
[simgrid.git] / buildtools / Cmake / generate_memcheck_tests.pl
1 #!/usr/bin/perl -w
2 use strict;
3
4 # input file = AddTest.txt
5
6 if($#ARGV!=1) {
7     die "Usage: generate_memcheck_tests.pl <CMAKE_HOME_DIRECTORY> AddTests.cmake\n";
8 }
9
10 my($proj_dir)=$ARGV[0];
11 open MAKETEST, $ARGV[1] or die "Unable to open $ARGV[1]. $!\n";
12
13 my(@test_list)=();
14 my($nb_test)=0;
15 my($line);
16 my($path);
17 my($dump)=0;
18 my($srcdir);
19 my($bindir);
20 my($tesh_file);
21 my($config_var);
22 my($name_test);
23
24 while(defined($line=<MAKETEST>))
25 {
26     chomp $line;
27     if($line =~ /BEGIN TESH TESTS/) {
28                 $dump = 1;
29                 next;
30             } 
31     if($line =~ /END TESH TESTS/) {
32                 $dump = 0;
33                 last;
34             }
35     if($dump) 
36     {
37                 if($line =~ /ADD_TEST/) 
38                 {       $srcdir = "";
39                         $bindir = "";
40                         $config_var = "";
41                         $path = "";
42                         $nb_test++;
43                         $tesh_file = "";
44                         $name_test = "";
45                         
46                         if($line =~ /ADD_TEST\(([\S]+)/)
47                         {
48                                 $name_test =($1);
49                         }
50                         if($line =~ /--cfg\s*\t*(\S*)/)
51                         {
52                                 $config_var = "--cfg $1 $config_var";
53                         }
54                         if($line =~ /--cd\s*(\S+)/)
55                         {
56                                 $path=($1);
57                                 $path=~ s/\"//g;
58                                 $path =~ s/\$\{CMAKE_BINARY_DIR\}/$proj_dir/g;
59                                 $path =~ s/\$\{CMAKE_HOME_DIRECTORY\}/$proj_dir/g;
60                         }
61                         if($line =~ /--setenv\s*\t*(\S*)\=(\S*)/)
62                         {
63                                 my($env_var,$value_var)=($1,$2);
64                                 $value_var =~ s/\$\{CMAKE_BINARY_DIR\}/$proj_dir/g;
65                                 $value_var =~ s/\$\{CMAKE_HOME_DIRECTORY\}/$proj_dir/g;
66                                 if($env_var =~ /srcdir/)
67                                 {
68                                         $srcdir = $value_var;
69                                 }
70                                 if($env_var =~ /bindir/)
71                                 {
72                                         $bindir = $value_var;                                   
73                                 }
74                         }
75                         if($line =~ /([\S]+)[)]$/)
76                         {
77                                 $tesh_file =($1);
78                                 $tesh_file =~ s/\$\{CMAKE_BINARY_DIR\}/$proj_dir/g;
79                                 $tesh_file =~ s/\$\{CMAKE_HOME_DIRECTORY\}/$proj_dir/g;
80                                 if ( -e "$tesh_file")
81                                 {
82                                         
83                                 }
84                                 elsif( -e "$path/$tesh_file")
85                                 {
86                                         $tesh_file = "$path\/$tesh_file";
87                                         
88                                 }
89                                 else
90                                 {
91                                         die;
92                                 }
93                                 
94                         }
95                         
96 #                       print "test_name = $name_test\n";
97 #                       print "$config_var\n";
98 #                       print "path = $path\n";
99 #                       print "srcdir=$srcdir\n";
100 #                       print "bindir=$bindir\n";
101 #                       print "tesh_file = $tesh_file\n";
102 #                       print "\n\n";
103                         
104                         my($count)=0;
105                         my($count_first)=0;
106                         my($count_second)=0;
107                         open TESH_FILE, $tesh_file or die "Unable to open $tesh_file $!\n";
108                         my($l);
109                         while(defined($l=<TESH_FILE>))
110                         {
111                             chomp $l;
112                             if($l =~ /^\$ (.*)$/) 
113                             {
114                                 my($command) = $1;
115                                 $command =~ s/\${srcdir:=.}/$srcdir/g;
116                                 $command =~ s/\${bindir:=.}/$bindir/g;
117                                 $command =~ s/\${EXEEXT:=}//g;
118                                 $command =~ s/\$SG_TEST_EXENV //g;
119                                 $command =~ s/\$SG_TEST_ENV //g;
120                                 $command =~ s/\$SG_EXENV_TEST //g; 
121                                 $command =~ s/\$EXEEXT//g;
122                                 $command =~ s/\${EXEEXT}//g;
123                                 $command =~ s/\${srcdir}/\${CMAKE_HOME_DIRECTORY}\/src/g;
124                                 $command =~ s/ \$ARGS//g;
125                                 $command =~ s/ \$@ //g; 
126                                 $command =~ s/..\/..\/bin\/smpirun/\${CMAKE_BINARY_DIR\}\/bin\/smpirun/g;
127                 if($command =~ /^[^\/\$\s]+\//) {
128                         $command = $path."/".$command;
129                         $command =~ s/\/(.?\/)+/\//g;
130                 }
131                 if ($config_var)
132                 {
133                         $command = "$command $config_var";
134                 }
135                                 print "ADD_TEST(memcheck-$name_test-$count $command --cd $path\/)\n";
136                                 #push @test_list, "memcheck-$name_test-$count";
137                                 $count++;
138                             }
139                             if($l =~ /^\& (.*)$/) 
140                             {
141                                 last;
142                             }
143                         }
144                         close(TESH_FILE);
145                 } 
146                 elsif($line =~ /set_tests_properties/)
147                 {
148                         if($line =~ /set_tests_properties\(([\S]+)/)
149                         {
150                                 my($name_temp)=($1);
151                                 $line =~ s/$name_temp/memcheck-$name_temp-0/g;
152                                 print $line."\n";
153                         }
154                 }
155                 else
156                 {
157                     print $line."\n";
158                 }
159         }   
160 }
161 close(MAKETEST);
162 #print "nb_test = $nb_test\n";
163 #print "set(MEMCHECK_LIST\n";
164 #print (join("\n", @test_list));
165 #print ")\n";