Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add tests for memcheck.
[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                         print "ADD_TEST(memcheck-$name_test-$count /bin/sh -c 'cd $path && $command')\n";
44                         push @test_list, "memcheck-$name_test-$count";
45                         $count++;
46                     }
47                 }
48                 close(TESH_FILE);
49             } else {
50                 next;
51             }
52         } else {
53             print $line."\n";
54         }
55     }   
56 }
57 close(MAKETEST);
58
59 print "set(MEMCHECK_LIST\n";
60 print (join("\n", @test_list));
61 print ")\n";