4 # input file = AddTest.txt
7 die "Usage: generate_memcheck_tests.pl <CMAKE_HOME_DIRECTORY> AddTests.cmake\n";
10 my ($proj_dir) = $ARGV[0];
11 open MAKETEST, $ARGV[1] or die "Unable to open $ARGV[1]. $!\n";
14 my ($text, $name, $value) = @_;
16 $text =~ s/\${$name(?::=[^}]*)?}/$value/g;
17 $text =~ s/\$$name(\W|$)/$value$1/g;
20 $text =~ s/\${$name:=([^}]*)}/$1/g;
21 $text =~ s/\${$name}//g;
22 $text =~ s/\$$name(\W|$)/$1/g;
39 while ( defined( $line = <MAKETEST> ) ) {
41 if ( $line =~ /BEGIN TESH TESTS/ ) {
45 if ( $line =~ /END TESH TESTS/ ) {
51 if ( $line =~ /^\s*ADD_TEST\(\S+\s+\S*\/tesh\s/ ) {
61 if ( $line =~ /^(\s*)ADD_TEST\((\S+)/ ) {
65 while ( $line =~ /--cfg\s+(\S+)/g ) {
66 $config_var = "--cfg=$1 $config_var";
68 while ( $line =~ /--cd\s+(\S+)/g ) {
72 while ( $line =~ /--setenv\s+(\S+)\=(\S+)/g ) {
73 my ( $env_var, $value_var ) = ( $1, $2 );
74 if ( $env_var =~ /srcdir/ ) {
77 elsif ( $env_var =~ /bindir/ ) {
81 if ( $line =~ /(\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\n";
95 print "path = $path\n";
96 print "srcdir=$srcdir\n";
97 print "bindir=$bindir\n";
98 print "tesh_file = $tesh_file\n";
103 my ($count_first) = 0;
104 my ($count_second) = 0;
105 open TESH_FILE, $tesh_file or die "Unable to open $tesh_file $!\n";
108 while ( defined( $l = <TESH_FILE> ) ) {
110 if ( $l =~ /^< (.*)$/ ) {
111 $input = $input . $1 . "\n";
113 if ( $l =~ /^\$ (.*)$/ ) {
115 $command = var_subst($command, "srcdir", $srcdir);
116 $command = var_subst($command, "bindir", $bindir);
117 $command = var_subst($command, "EXEEXT", "");
118 $command = var_subst($command, "SG_TEST_EXENV", "");
119 $command = var_subst($command, "SG_TEST_ENV", "");
120 $command = var_subst($command, "SG_EXENV_TEST", "");
121 $command =~ s/\$@//g;
122 # $command =~ s/..\/..\/bin\/smpirun/\${CMAKE_BINARY_DIR\}\/bin\/smpirun/g;
123 $command =~ s/^\s+//;
124 $command =~ s/^[^\/\$]\S*\//$path\/$&/;
125 $command =~ s/^(\S*\/)(?:\.\/)+/$1/g;
128 $command = "$command $config_var";
130 if ( $command =~ /^mkfile\s+(\S+)/) {
132 # don't ask me to explain why so many backslashes...
133 $input =~ s/\\/\\\\\\\\\\\\\\\\/g;
134 $input =~ s/\n/\\\\\\\\n/g;
135 $input =~ s/"/\\\\\\\\042/g;
136 $input =~ s/'/\\\\\\\\047/g;
138 $command = "sh -c \"printf '$input' > $file\"";
140 print "${indent}ADD_TEST(memcheck-$name_test-$count $command --cd $path\/)\n";
142 #push @test_list, "memcheck-$name_test-$count";
145 if ( $l =~ /^\& (.*)$/ ) {
151 elsif ( $line =~ /^\s*set_tests_properties/ ) {
152 if ( $line =~ /set_tests_properties\(([\S]+)/ ) {
153 my ($name_temp) = ($1);
154 $line =~ s/$name_temp/memcheck-$name_temp-0/g;
165 #print "nb_test = $nb_test\n";
166 #print "set(MEMCHECK_LIST\n";
167 #print (join("\n", @test_list));