3 # Copyright (c) 2012-2014. The SimGrid Team.
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the license (GNU LGPL) which comes with this package.
11 # input file = AddTest.txt
14 die "Usage: generate_memcheck_tests.pl <CMAKE_HOME_DIRECTORY> AddTests.cmake\n";
17 my ($proj_dir) = $ARGV[0];
18 open MAKETEST, $ARGV[1] or die "Unable to open file: \"$ARGV[1]\". $!\n";
21 my ($text, $name, $value) = @_;
23 $text =~ s/\${$name(?::[=-][^}]*)?}/$value/g;
24 $text =~ s/\$$name(\W|$)/$value$1/g;
27 $text =~ s/\${$name:=([^}]*)}/$1/g;
28 $text =~ s/\${$name}//g;
29 $text =~ s/\$$name(\W|$)/$1/g;
46 while ( defined( $line = <MAKETEST> ) ) {
48 if ( $line =~ /BEGIN TESH TESTS/ ) {
52 if ( $line =~ /END TESH TESTS/ ) {
58 if ( $line =~ /^\s*(?:ADD_TEST\(\S+\s+\S*TESH\_COMMAND\}\s|ADD_TESH\(|ADD_TESH_FACTORIES)/ ) {
67 if ( $line =~ /^(\s*)ADD_(?:TEST|TESH)\((\S+)/ ) {
71 if ( $line =~ /^(\s*)ADD_TESH_FACTORIES\((\S+)\s+\"(\S+)\"/ ) {
76 while ( $line =~ /--cfg\s+(\S+)/g ) {
77 $config_var = "--cfg=$1 $config_var";
79 while ( $line =~ /--cd\s+(\S+)/g ) {
83 while ( $line =~ /--setenv\s+(\S+)\=(\S+)/g ) {
84 my ( $env_var, $value_var ) = ( $1, $2 );
85 $environ{$env_var} = $value_var;
87 if ( $line =~ /(\S+)\s*\)$/ ) {
89 $tesh_file =~ s/^[^\/\$]/$path\/$&/;
90 $tesh_file =~ s/\${CMAKE_HOME_DIRECTORY}/$proj_dir/g;
91 if ( ! -e "$tesh_file" ) {
92 print "# tesh_file: $tesh_file does not exist!\n";
99 print "test_name = $name_test\n";
100 print "config_var = $config_var\n";
101 print "path = $path\n";
102 foreach my $key (keys %environ) {
103 print "$key = $environ{$key}\n";
105 print "tesh_file = $tesh_file\n";
110 my ($count_first) = 0;
111 my ($count_second) = 0;
112 open TESH_FILE, $tesh_file or die "Unable to open tesh file: \"$tesh_file\". $!\n";
115 while ( defined( $l = <TESH_FILE> ) ) {
117 if ( $l =~ /^< (.*)$/ ) {
118 $input = $input . $1 . "\n";
120 if ( $l =~ /^\$ (.*)$/ ) {
122 foreach my $key (keys %environ) {
123 $command = var_subst($command, $key, $environ{$key});
125 # substitute remaining known variables, if any
126 $command = var_subst($command, "srcdir", "");
127 $command = var_subst($command, "bindir", "");
128 $command = var_subst($command, "EXEEXT", "");
129 $command = var_subst($command, "SG_TEST_EXENV", "");
130 $command = var_subst($command, "SG_TEST_ENV", "");
131 $command = var_subst($command, "SG_EXENV_TEST", "");
132 $command =~ s/\$@//g;
133 # $command =~ s/..\/..\/bin\/smpirun/\${CMAKE_BINARY_DIR\}\/bin\/smpirun/g;
134 $command =~ s/^\s+//;
135 $command =~ s/^[^\/\$]\S*\//$path\/$&/;
136 $command =~ s/^(\S*\/)(?:\.\/)+/$1/g;
139 $command = "$command $config_var";
141 if ( $command =~ /^mkfile\s+(\S+)/) {
143 # don't ask me to explain why so many backslashes...
144 $input =~ s/\\/\\\\\\\\\\\\\\\\/g;
145 $input =~ s/\n/\\\\\\\\n/g;
146 $input =~ s/"/\\\\\\\\042/g;
147 $input =~ s/'/\\\\\\\\047/g;
149 $command = "sh -c \"printf '$input' > $file\"";
152 foreach my $factory (split(';', $factories)) {
153 print "${indent}ADD_TEST(NAME memcheck-$name_test-$factory-$count\n";
154 print "${indent} WORKING_DIRECTORY $path\/\n";
155 print "${indent} COMMAND $command --cfg=contexts/factory:$factory)\n";
158 print "${indent}ADD_TEST(NAME memcheck-$name_test-$count\n";
159 print "${indent} WORKING_DIRECTORY $path\/\n";
160 print "${indent} COMMAND $command)\n";
163 #push @test_list, "memcheck-$name_test-$count";
166 if ( $l =~ /^\& (.*)$/ ) {
172 elsif ( $line =~ /^\s*set_tests_properties/ ) {
173 if ( $line =~ /set_tests_properties\(([\S]+)/ ) {
174 my ($name_temp) = ($1);
175 $line =~ s/$name_temp/memcheck-$name_temp-0/g;
186 #print "nb_test = $nb_test\n";
187 #print "set(MEMCHECK_LIST\n";
188 #print (join("\n", @test_list));