X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/145029726ec6891f5818e2888e9e55e7ae1e3f50..0dcd4a1d2441249d190b5300249b587a5762bb7f:/buildtools/Cmake/Scripts/generate_memcheck_tests.pl diff --git a/buildtools/Cmake/Scripts/generate_memcheck_tests.pl b/buildtools/Cmake/Scripts/generate_memcheck_tests.pl index b8528d9649..421bbe5978 100755 --- a/buildtools/Cmake/Scripts/generate_memcheck_tests.pl +++ b/buildtools/Cmake/Scripts/generate_memcheck_tests.pl @@ -1,4 +1,11 @@ #!/usr/bin/perl -w + +# Copyright (c) 2012-2014. The SimGrid Team. +# All rights reserved. + +# This program is free software; you can redistribute it and/or modify it +# under the terms of the license (GNU LGPL) which comes with this package. + use strict; # input file = AddTest.txt @@ -8,12 +15,12 @@ if ( $#ARGV != 1 ) { } my ($proj_dir) = $ARGV[0]; -open MAKETEST, $ARGV[1] or die "Unable to open $ARGV[1]. $!\n"; +open MAKETEST, $ARGV[1] or die "Unable to open file: \"$ARGV[1]\". $!\n"; sub var_subst { my ($text, $name, $value) = @_; if ($value) { - $text =~ s/\${$name(?::=[^}]*)?}/$value/g; + $text =~ s/\${$name(?::[=-][^}]*)?}/$value/g; $text =~ s/\$$name(\W|$)/$value$1/g; } else { @@ -29,9 +36,9 @@ my ($nb_test) = 0; my ($line); my ($path); my ($dump) = 0; -my ($srcdir); -my ($bindir); +my (%environ); my ($tesh_file); +my ($factories); my ($config_var); my ($name_test); my ($indent); @@ -48,20 +55,24 @@ while ( defined( $line = ) ) { } if ($dump) { $line =~ s/^ //; - if ( $line =~ /^\s*ADD_TEST\(\S+\s+\S*\/tesh\s/ ) { - $srcdir = ""; - $bindir = ""; + if ( $line =~ /^\s*(?:ADD_TEST\(\S+\s+\S*TESH\_COMMAND\}\s|ADD_TESH\(|ADD_TESH_FACTORIES)/ ) { + undef %environ; $config_var = ""; + $factories = ""; $path = ""; $nb_test++; $tesh_file = ""; $name_test = ""; $indent = ""; - - if ( $line =~ /^(\s*)ADD_TEST\((\S+)/ ) { + if ( $line =~ /^(\s*)ADD_(?:TEST|TESH)\((\S+)/ ) { $indent = ($1); $name_test = ($2); } + if ( $line =~ /^(\s*)ADD_TESH_FACTORIES\((\S+)\s+\"(\S+)\"/ ) { + $indent = ($1); + $name_test = ($2); + $factories = ($3); + } while ( $line =~ /--cfg\s+(\S+)/g ) { $config_var = "--cfg=$1 $config_var"; } @@ -71,14 +82,9 @@ while ( defined( $line = ) ) { } while ( $line =~ /--setenv\s+(\S+)\=(\S+)/g ) { my ( $env_var, $value_var ) = ( $1, $2 ); - if ( $env_var =~ /srcdir/ ) { - $srcdir = $value_var; - } - elsif ( $env_var =~ /bindir/ ) { - $bindir = $value_var; - } + $environ{$env_var} = $value_var; } - if ( $line =~ /(\S+)\)$/ ) { + if ( $line =~ /(\S+)\s*\)$/ ) { $tesh_file = $1; $tesh_file =~ s/^[^\/\$]/$path\/$&/; $tesh_file =~ s/\${CMAKE_HOME_DIRECTORY}/$proj_dir/g; @@ -91,25 +97,32 @@ while ( defined( $line = ) ) { if (0) { print "test_name = $name_test\n"; - print "$config_var\n"; + print "config_var = $config_var\n"; print "path = $path\n"; - print "srcdir=$srcdir\n"; - print "bindir=$bindir\n"; + foreach my $key (keys %environ) { + print "$key = $environ{$key}\n"; + } print "tesh_file = $tesh_file\n"; print "\n\n"; } my ($count) = 0; - my ($count_first) = 0; - my ($count_second) = 0; - open TESH_FILE, $tesh_file or die "Unable to open $tesh_file $!\n"; + open TESH_FILE, $tesh_file or die "Unable to open tesh file: \"$tesh_file\". $!\n"; + my ($input) = ""; my ($l); while ( defined( $l = ) ) { chomp $l; + if ( $l =~ /^< (.*)$/ ) { + $input = $input . $1 . "\n"; + } if ( $l =~ /^\$ (.*)$/ ) { my ($command) = $1; - $command = var_subst($command, "srcdir", $srcdir); - $command = var_subst($command, "bindir", $bindir); + foreach my $key (keys %environ) { + $command = var_subst($command, $key, $environ{$key}); + } + # substitute remaining known variables, if any + $command = var_subst($command, "srcdir", ""); + $command = var_subst($command, "bindir", ""); $command = var_subst($command, "EXEEXT", ""); $command = var_subst($command, "SG_TEST_EXENV", ""); $command = var_subst($command, "SG_TEST_ENV", ""); @@ -123,8 +136,36 @@ while ( defined( $line = ) ) { if ($config_var) { $command = "$command $config_var"; } - print "${indent}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\""; + } + if ($factories) { + foreach my $factory (split(';', $factories)) { + print "${indent}ADD_TEST(NAME memcheck-$name_test-$factory-$count\n"; + print "${indent} WORKING_DIRECTORY $path\/\n"; + print "${indent} COMMAND $command --cfg=contexts/factory:$factory)\n"; + if ($count > 0) { + print "${indent}set_tests_properties(memcheck-$name_test-$factory-$count\n"; + print "${indent} PROPERTIES DEPENDS memcheck-$name_test-$factory-" . ($count - 1) . ")\n"; + } + } + } else { + print "${indent}ADD_TEST(NAME memcheck-$name_test-$count\n"; + print "${indent} WORKING_DIRECTORY $path\/\n"; + print "${indent} COMMAND $command)\n"; + if ($count > 0) { + print "${indent}set_tests_properties(memcheck-$name_test-$count\n"; + print "${indent} PROPERTIES DEPENDS memcheck-$name_test-" . ($count - 1) . ")\n"; + } + } + $input = ""; #push @test_list, "memcheck-$name_test-$count"; $count++; }