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.
12 # input file = AddTest.txt
15 die "Usage: generate_memcheck_tests.pl <CMAKE_HOME_DIRECTORY> AddTests.cmake\n";
18 my ($proj_dir) = $ARGV[0];
19 open MAKETEST, $ARGV[1] or die "Unable to open file: \"$ARGV[1]\". $!\n";
22 my ($text, $name, $value) = @_;
24 $text =~ s/\${$name(?::[=-][^}]*)?}/$value/g;
25 $text =~ s/\$$name(\W|$)/$value$1/g;
28 $text =~ s/\${$name:=([^}]*)}/$1/g;
29 $text =~ s/\${$name}//g;
30 $text =~ s/\$$name(\W|$)/$1/g;
47 while ( defined( $line = <MAKETEST> ) ) {
49 if ( $line =~ /BEGIN TESH TESTS/ ) {
53 if ( $line =~ /END TESH TESTS/ ) {
59 if ( $line =~ /^\s*(?:ADD_TEST\(\S+\s+\S*TESH\_COMMAND\}\s|ADD_TESH\(|ADD_TESH_FACTORIES)/ ) {
68 if ( $line =~ /^(\s*)ADD_(?:TEST|TESH)\((\S+)/ ) {
72 if ( $line =~ /^(\s*)ADD_TESH_FACTORIES\((\S+)\s+\"(\S+)\"/ ) {
77 while ( $line =~ /--cfg\s+(\S+)/g ) {
78 $config_var = "--cfg=$1 $config_var";
80 while ( $line =~ /--cd\s+(\S+)/g ) {
84 while ( $line =~ /--setenv\s+(\S+)\=(\S+)/g ) {
85 my ( $env_var, $value_var ) = ( $1, $2 );
86 $environ{$env_var} = $value_var;
88 if ( $line =~ /(\S+)\s*\)$/ ) {
90 $tesh_file =~ s/^[^\/\$]/$path\/$&/;
91 $tesh_file =~ s/\${CMAKE_HOME_DIRECTORY}/$proj_dir/g;
92 if ( ! -e "$tesh_file" ) {
93 print "# tesh_file: $tesh_file does not exist!\n";
100 print "test_name = $name_test\n";
101 print "config_var = $config_var\n";
102 print "path = $path\n";
103 foreach my $key (keys %environ) {
104 print "$key = $environ{$key}\n";
106 print "tesh_file = $tesh_file\n";
111 open TESH_FILE, $tesh_file or die "Unable to open tesh file: \"$tesh_file\". $!\n";
114 while ( defined( $l = <TESH_FILE> ) ) {
116 if ( $l =~ /^< (.*)$/ ) {
117 $input = $input . $1 . "\n";
119 if ( $l =~ /^\$ (.*)$/ ) {
121 foreach my $key (keys %environ) {
122 $command = var_subst($command, $key, $environ{$key});
124 # substitute remaining known variables, if any
125 $command = var_subst($command, "srcdir", "");
126 $command = var_subst($command, "bindir", "");
127 $command = var_subst($command, "EXEEXT", "");
128 $command = var_subst($command, "SG_TEST_EXENV", "");
129 $command = var_subst($command, "SG_TEST_ENV", "");
130 $command = var_subst($command, "SG_EXENV_TEST", "");
131 $command =~ s/\$@//g;
132 # $command =~ s/..\/..\/bin\/smpirun/\${CMAKE_BINARY_DIR\}\/bin\/smpirun/g;
133 $command =~ s/^\s+//;
134 $command =~ s/^[^\/\$]\S*\//$path\/$&/;
135 $command =~ s/^(\S*\/)(?:\.\/)+/$1/g;
138 $command = "$command $config_var";
140 if ( $command =~ /^mkfile\s+(\S+)/) {
142 # don't ask me to explain why so many backslashes...
143 $input =~ s/\\/\\\\\\\\/g;
144 $input =~ s/\n/\\\\n/g;
145 $input =~ s/"/\\\\042/g;
146 $input =~ s/'/\\\\047/g;
148 $command = "sh -c \"printf '$input' > $file\"";
151 foreach my $factory (split(';', $factories)) {
152 print "${indent}ADD_TEST(NAME memcheck-$name_test-$factory-$count\n";
153 print "${indent} WORKING_DIRECTORY $path\/\n";
154 print "${indent} COMMAND $command --cfg=contexts/factory:$factory)\n";
156 print "${indent}set_tests_properties(memcheck-$name_test-$factory-$count\n";
157 print "${indent} PROPERTIES DEPENDS memcheck-$name_test-$factory-" . ($count - 1) . ")\n";
161 print "${indent}ADD_TEST(NAME memcheck-$name_test-$count\n";
162 print "${indent} WORKING_DIRECTORY $path\/\n";
163 print "${indent} COMMAND $command)\n";
165 print "${indent}set_tests_properties(memcheck-$name_test-$count\n";
166 print "${indent} PROPERTIES DEPENDS memcheck-$name_test-" . ($count - 1) . ")\n";
170 #push @test_list, "memcheck-$name_test-$count";
173 if ( $l =~ /^\& (.*)$/ ) {
179 elsif ( $line =~ /^\s*SET_TESTS_PROPERTIES/ ) {
180 if ( $line =~ /SET_TESTS_PROPERTIES\(([\S]+)/ ) {
181 my ($name_temp) = ($1);
182 $line =~ s/$name_temp/memcheck-$name_temp-0/g;
185 } elsif ( $line =~ /^(\s*)ADD_TEST\((.*)\)/ ) {
186 print "$1ADD_TEST(memcheck-$2)\n";
194 #print "nb_test = $nb_test\n";
195 #print "set(MEMCHECK_LIST\n";
196 #print (join("\n", @test_list));