Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Generate tests for memcheck.
[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 <project_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
15 my($line);
16 my($dump)=0;
17 print "if(enable_memcheck)\n";
18 while(defined($line=<MAKETEST>)) {
19     chomp $line;
20     if($line =~ /BEGIN TESH TESTS/) {
21         $dump = 1;
22         next;
23     } 
24     if($line =~ /END TESH TESTS/) {
25         $dump = 0;
26         last;
27     }
28     if($dump) {
29         if($line =~ /ADD_TEST/) 
30         {
31             if($line =~ /ADD_TEST\(([\S]+)\s+.*\$\{CMAKE_BINARY_DIR\}\/bin\/tesh\s*--cd\s*(\S+)\s+(.*)\)$/) 
32             {
33                 my($name_test,$path,$tesh_file)=($1,$2,$3);
34                 $path=~ s/\"//g;
35                 my($complete_tesh_file)=$path."/".$tesh_file;
36                 my($count)=0;
37                 my($count_first)=0;
38                 my($count_second)=0;
39                 $complete_tesh_file =~ s/\$\{CMAKE_BINARY_DIR\}/$proj_dir/g;
40                 $complete_tesh_file =~ s/\$\{PROJECT_DIRECTORY\}/$proj_dir/g;
41                 open TESH_FILE, $complete_tesh_file or die "Unable to open $complete_tesh_file $!\n";
42                 my($l);
43                 while(defined($l=<TESH_FILE>))
44                 {
45                     chomp $l;
46                     if($l =~ /^\$ (.*)$/) 
47                     {
48                         my($command) = $1;
49                         $command =~ s/\${srcdir:=.}/./g;
50                         $command =~ s/\${EXEEXT:=}//g;
51                         $command =~ s/\$SG_TEST_EXENV //g;
52                         $command =~ s/\$SG_TEST_ENV //g;
53                         $command =~ s/\$SG_EXENV_TEST //g; 
54                         $command =~ s/\$EXEEXT//g;
55                         $command =~ s/\${EXEEXT}//g;
56                         $command =~ s/\${srcdir}/\${PROJECT_DIRECTORY}\/src/g;
57                         $command =~ s/ \$ARGS//g;
58                         $command =~ s/ \$@ //g; 
59                         $command =~ s/..\/..\/bin\/smpirun/\${CMAKE_BINARY_DIR\}\/bin\/smpirun/g;
60                         print "ADD_TEST(memcheck-$name_test-$count $command --cd $path\/)\n";
61                         #push @test_list, "memcheck-$name_test-$count";
62                         $count++;
63                     }
64                     if($l =~ /^\& (.*)$/) 
65                     {
66                         last;
67                     }
68                 }
69                 close(TESH_FILE);
70             } 
71             else 
72             {
73                 next;
74             }
75         } 
76         else 
77         {
78             print $line."\n";
79         }
80     }   
81 }
82 close(MAKETEST);
83 print "endif(enable_memcheck)\n";
84 #print "set(MEMCHECK_LIST\n";
85 #print (join("\n", @test_list));
86 #print ")\n";