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;
45 while ( defined( $line = <MAKETEST> ) ) {
47 if ( $line =~ /BEGIN TESH TESTS/ ) {
51 if ( $line =~ /END TESH TESTS/ ) {
57 if ( $line =~ /^\s*ADD_TEST\(\S+\s+\S*TESH\_COMMAND\}\s/ ) {
66 if ( $line =~ /^(\s*)ADD_TEST\((\S+)/ ) {
70 while ( $line =~ /--cfg\s+(\S+)/g ) {
71 $config_var = "--cfg=$1 $config_var";
73 while ( $line =~ /--cd\s+(\S+)/g ) {
77 while ( $line =~ /--setenv\s+(\S+)\=(\S+)/g ) {
78 my ( $env_var, $value_var ) = ( $1, $2 );
79 $environ{$env_var} = $value_var;
81 if ( $line =~ /(\S+)\s*\)$/ ) {
83 $tesh_file =~ s/^[^\/\$]/$path\/$&/;
84 $tesh_file =~ s/\${CMAKE_HOME_DIRECTORY}/$proj_dir/g;
85 if ( ! -e "$tesh_file" ) {
86 print "# tesh_file: $tesh_file does not exist!\n";
93 print "test_name = $name_test\n";
94 print "config_var = $config_var\n";
95 print "path = $path\n";
96 foreach my $key (keys %environ) {
97 print "$key = $environ{$key}\n";
99 print "tesh_file = $tesh_file\n";
104 my ($count_first) = 0;
105 my ($count_second) = 0;
106 open TESH_FILE, $tesh_file or die "Unable to open tesh file: \"$tesh_file\". $!\n";
109 while ( defined( $l = <TESH_FILE> ) ) {
111 if ( $l =~ /^< (.*)$/ ) {
112 $input = $input . $1 . "\n";
114 if ( $l =~ /^\$ (.*)$/ ) {
116 foreach my $key (keys %environ) {
117 $command = var_subst($command, $key, $environ{$key});
119 # substitute remaining known variables, if any
120 $command = var_subst($command, "srcdir", "");
121 $command = var_subst($command, "bindir", "");
122 $command = var_subst($command, "EXEEXT", "");
123 $command = var_subst($command, "SG_TEST_EXENV", "");
124 $command = var_subst($command, "SG_TEST_ENV", "");
125 $command = var_subst($command, "SG_EXENV_TEST", "");
126 $command =~ s/\$@//g;
127 # $command =~ s/..\/..\/bin\/smpirun/\${CMAKE_BINARY_DIR\}\/bin\/smpirun/g;
128 $command =~ s/^\s+//;
129 $command =~ s/^[^\/\$]\S*\//$path\/$&/;
130 $command =~ s/^(\S*\/)(?:\.\/)+/$1/g;
133 $command = "$command $config_var";
135 if ( $command =~ /^mkfile\s+(\S+)/) {
137 # don't ask me to explain why so many backslashes...
138 $input =~ s/\\/\\\\\\\\\\\\\\\\/g;
139 $input =~ s/\n/\\\\\\\\n/g;
140 $input =~ s/"/\\\\\\\\042/g;
141 $input =~ s/'/\\\\\\\\047/g;
143 $command = "sh -c \"printf '$input' > $file\"";
145 print "${indent}ADD_TEST(memcheck-$name_test-$count $command --cd $path\/)\n";
147 #push @test_list, "memcheck-$name_test-$count";
150 if ( $l =~ /^\& (.*)$/ ) {
156 elsif ( $line =~ /^\s*set_tests_properties/ ) {
157 if ( $line =~ /set_tests_properties\(([\S]+)/ ) {
158 my ($name_temp) = ($1);
159 $line =~ s/$name_temp/memcheck-$name_temp-0/g;
170 #print "nb_test = $nb_test\n";
171 #print "set(MEMCHECK_LIST\n";
172 #print (join("\n", @test_list));