Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
When execute command line : --cfg=value against --cfg value.
[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_HOME_DIRECTORY}/$proj_dir/g;
79                                 if ( -e "$tesh_file")
80                                 {
81                                         
82                                 }
83                                 elsif( -e "$path/$tesh_file")
84                                 {
85                                         $tesh_file = "$path\/$tesh_file";
86                                         
87                                 }
88                                 else
89                                 {
90                                         print "tesh_file : $tesh_file not exists!\n";
91                                         print "tesh_file : $path\/$tesh_file not exists!\n";
92                                         die;
93                                 }
94                                 
95                         }
96                         
97 #                       print "test_name = $name_test\n";
98 #                       print "$config_var\n";
99 #                       print "path = $path\n";
100 #                       print "srcdir=$srcdir\n";
101 #                       print "bindir=$bindir\n";
102 #                       print "tesh_file = $tesh_file\n";
103 #                       print "\n\n";
104                         
105                         my($count)=0;
106                         my($count_first)=0;
107                         my($count_second)=0;
108                         open TESH_FILE, $tesh_file or die "Unable to open $tesh_file $!\n";
109                         my($l);
110                         while(defined($l=<TESH_FILE>))
111                         {
112                             chomp $l;
113                             if($l =~ /^\$ (.*)$/) 
114                             {
115                                 my($command) = $1;
116                                 $command =~ s/\${srcdir:=.}/$srcdir/g;
117                                 $command =~ s/\${bindir:=.}/$bindir/g;
118                                 $command =~ s/\${EXEEXT:=}//g;
119                                 $command =~ s/\$SG_TEST_EXENV //g;
120                                 $command =~ s/\$SG_TEST_ENV //g;
121                                 $command =~ s/\$SG_EXENV_TEST //g; 
122                                 $command =~ s/\$EXEEXT//g;
123                                 $command =~ s/\${EXEEXT}//g;
124                                 $command =~ s/\${srcdir}/\${CMAKE_HOME_DIRECTORY}\/src/g;
125                                 $command =~ s/ \$ARGS//g;
126                                 $command =~ s/ \$@ //g; 
127                                 $command =~ s/..\/..\/bin\/smpirun/\${CMAKE_BINARY_DIR\}\/bin\/smpirun/g;
128                 if($command =~ /^[^\/\$\s]+\//) {
129                         $command = $path."/".$command;
130                         $command =~ s/\/(.?\/)+/\//g;
131                 }
132                 $command =~ s/$proj_dir/\$\{CMAKE_BINARY_DIR\}/g;
133                 if ($config_var)
134                 {
135                         $command = "$command $config_var";
136                 }
137                                 print "ADD_TEST(memcheck-$name_test-$count $command --cd $path\/)\n";
138                                 #push @test_list, "memcheck-$name_test-$count";
139                                 $count++;
140                             }
141                             if($l =~ /^\& (.*)$/) 
142                             {
143                                 last;
144                             }
145                         }
146                         close(TESH_FILE);
147                 } 
148                 elsif($line =~ /set_tests_properties/)
149                 {
150                         if($line =~ /set_tests_properties\(([\S]+)/)
151                         {
152                                 my($name_temp)=($1);
153                                 $line =~ s/$name_temp/memcheck-$name_temp-0/g;
154                                 print $line."\n";
155                         }
156                 }
157                 else
158                 {
159                     print $line."\n";
160                 }
161         }   
162 }
163 close(MAKETEST);
164 #print "nb_test = $nb_test\n";
165 #print "set(MEMCHECK_LIST\n";
166 #print (join("\n", @test_list));
167 #print ")\n";