Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Variable should be initialized.
[simgrid.git] / buildtools / Cmake / Scripts / generate_memcheck_tests.pl
index 23699bb..fbbc74f 100755 (executable)
@@ -34,6 +34,7 @@ my ($bindir);
 my ($tesh_file);
 my ($config_var);
 my ($name_test);
+my ($indent);
 
 while ( defined( $line = <MAKETEST> ) ) {
     chomp $line;
@@ -46,6 +47,7 @@ while ( defined( $line = <MAKETEST> ) ) {
         last;
     }
     if ($dump) {
+        $line =~ s/^  //;
         if ( $line =~ /^\s*ADD_TEST\(\S+\s+\S*\/tesh\s/ ) {
             $srcdir     = "";
             $bindir     = "";
@@ -54,9 +56,11 @@ while ( defined( $line = <MAKETEST> ) ) {
             $nb_test++;
             $tesh_file = "";
             $name_test = "";
+            $indent = "";
 
-            if ( $line =~ /ADD_TEST\((\S+)/ ) {
-                $name_test = ($1);
+            if ( $line =~ /^(\s*)ADD_TEST\((\S+)/ ) {
+                $indent = ($1);
+                $name_test = ($2);
             }
             while ( $line =~ /--cfg\s+(\S+)/g ) {
                 $config_var = "--cfg=$1 $config_var";
@@ -99,9 +103,13 @@ while ( defined( $line = <MAKETEST> ) ) {
             my ($count_first)  = 0;
             my ($count_second) = 0;
             open TESH_FILE, $tesh_file or die "Unable to open $tesh_file $!\n";
+            my ($input) = "";
             my ($l);
             while ( defined( $l = <TESH_FILE> ) ) {
                 chomp $l;
+                if ( $l =~ /^< (.*)$/ ) {
+                    $input = $input . $1 . "\n";
+                }
                 if ( $l =~ /^\$ (.*)$/ ) {
                     my ($command) = $1;
                     $command = var_subst($command, "srcdir", $srcdir);
@@ -119,8 +127,18 @@ while ( defined( $line = <MAKETEST> ) ) {
                     if ($config_var) {
                         $command = "$command $config_var";
                     }
-                    print "ADD_TEST(memcheck-$name_test-$count $command --cd $path\/)\n";
-
+                    if ( $command =~ /^mkfile\s+(\S+)/) {
+                        my $file = $1;
+                        # don't ask me to explain why so many backslashes...
+                        $input =~ s/\\/\\\\\\\\\\\\\\\\/g;
+                        $input =~ s/\n/\\\\\\\\n/g;
+                        $input =~ s/"/\\\\\\\\042/g;
+                        $input =~ s/'/\\\\\\\\047/g;
+                        $input =~ s/%/%%/g;
+                        $command = "sh -c \"printf '$input' > $file\"";
+                    }
+                    print "${indent}ADD_TEST(memcheck-$name_test-$count $command --cd $path\/)\n";
+                    $input = "";
                     #push @test_list, "memcheck-$name_test-$count";
                     $count++;
                 }