Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add tests for memcheck with perl.
[simgrid.git] / buildtools / Cmake / generate_memcheck_tests.pl
1 #!/usr/bin/perl -w
2 use strict;
3
4 # input file = CMakeTest.txt
5
6 if($#ARGV!=1) {
7     die "Usage: generate_memcheck_tests.pl <project_directory> <CMakeTests.txt>\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 while(defined($line=<MAKETEST>)) {
18     chomp $line;
19     if($line =~ /BEGIN TESH TESTS/) {
20         $dump = 1;
21         next;
22     } 
23     if($line =~ /END TESH TESTS/) {
24         $dump = 0;
25         last;
26     }
27     if($dump) {
28         if($line =~ /ADD_TEST/) {
29             if($line =~ /ADD_TEST\(([\S]+)\s+.*\/tools\/tesh\/tesh\s*--cd\s*(\S+)\s+(.*)\)$/) {
30                 my($name_test,$path,$tesh_file)=($1,$2,$3);
31                 $path=~ s/\"//g;
32                 my($complete_tesh_file)=$path."/".$tesh_file;
33                 my($count)=0;
34                 $complete_tesh_file =~ s/\${PROJECT_DIRECTORY}/$proj_dir/g;
35                 open TESH_FILE, $complete_tesh_file or die "Unable to open $complete_tesh_file. $!\n";
36                 my($l);
37                 while(defined($l=<TESH_FILE>)) {
38                     chomp $l;
39                     if($l =~ /^\$ (.*)$/) {
40                         my($command)=$1;
41                         $command =~ s/\${srcdir:=.}/\${PROJECT_DIRECTORY}\/src/g;
42                         $command =~ s/\${EXEEXT:=}//g;
43                         $command =~ s/\$SG_TEST_EXENV //g;
44                         $command =~ s/\$SG_TEST_ENV //g;
45                         $command =~ s/\$EXEEXT//g;
46                         $command =~ s/\${srcdir}/\${PROJECT_DIRECTORY}\/src/g;
47                         $command =~ s/ \$ARGS//g;
48                         $command =~ s/ \$@ //g;
49                         print "ADD_TEST(memcheck-$name_test-$count $path\/$command)\n";
50                         push @test_list, "memcheck-$name_test-$count";
51                         $count++;
52                     }
53                 }
54                 close(TESH_FILE);
55             } else {
56                 next;
57             }
58         } else {
59             print $line."\n";
60         }
61     }   
62 }
63 close(MAKETEST);
64
65 print "set(MEMCHECK_LIST\n";
66 print (join("\n", @test_list));
67 print ")\n";