From 4da5a940728271cf1d7e49348ee6f5fd56046f5c Mon Sep 17 00:00:00 2001 From: "Lukasz A.J. Wrona" Date: Mon, 30 Oct 2017 10:12:51 +0000 Subject: [PATCH] Add templating functionality to the perl script --- regression/test.pl | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/regression/test.pl b/regression/test.pl index 608653d9b1a..41d659ee96d 100755 --- a/regression/test.pl +++ b/regression/test.pl @@ -64,9 +64,21 @@ ($) return @data; } -sub test($$$$$$) { - my ($name, $test, $t_level, $cmd, $ign, $dry_run) = @_; +sub test($$$$$$$) { + my ($name, $test, $t_level, $cmd, $ign, $dry_run, $defines) = @_; my ($level, $input, $options, $grep_options, @results) = load("$test"); + my @keys = keys %{$defines}; + foreach my $key (@keys) { + my $value = $defines->{$key}; + $options =~ s/(\$$key$|\$$key )/$value /g; + } + if (scalar @keys) { + foreach my $word (split(/\s/, $options)) { + if ((substr($word, 0, 1) cmp '$') == 0) { + print "$name: variable \"$word\" not replaced; consider passing \"-D$word\"=..."; + } + } + } # If the 4th line is activate-multi-line-match we enable multi-line checks if($grep_options ne "activate-multi-line-match") { @@ -227,6 +239,8 @@ ($$$$) -T thorough: run expensive tests -F future: run checks for future features -K known: run tests associated with known bugs + -D Define - replace \$key string with "value" string in + test descriptors test.pl expects a test.desc file in each subdirectory. The file test.desc @@ -258,10 +272,12 @@ ($$$$) } use Getopt::Std; +use Getopt::Long qw(:config pass_through bundling); $main::VERSION = 0.1; $Getopt::Std::STANDARD_HELP_VERSION = 1; -our ($opt_c, $opt_i, $opt_j, $opt_n, $opt_h, $opt_C, $opt_T, $opt_F, $opt_K); # the variables for getopt +our ($opt_c, $opt_i, $opt_j, $opt_n, $opt_h, $opt_C, $opt_T, $opt_F, $opt_K, %defines); # the variables for getopt $opt_j = 0; +GetOptions("D=s", \%defines); getopts('c:i:j:nhCTFK') or &main::HELP_MESSAGE(\*STDOUT, "", $main::VERSION, ""); $opt_c or &main::HELP_MESSAGE(\*STDOUT, "", $main::VERSION, ""); (!$opt_j || $has_thread_pool) or &main::HELP_MESSAGE(\*STDOUT, "", $main::VERSION, ""); @@ -298,7 +314,10 @@ ($) my @files = glob "$test/*.desc"; for (0..$#files){ defined($pool) or print " Running $files[$_]"; - $failed_skipped = test($test, $files[$_], $t_level, $opt_c, $opt_i, $dry_run); + my $start_time = time(); + $failed_skipped = test( + $test, $files[$_], $t_level, $opt_c, $opt_i, $dry_run, \%defines); + my $runtime = time() - $start_time; lock($skips); defined($pool) and print " Running $test $files[$_]"; @@ -306,7 +325,7 @@ ($) $skips++; print " [SKIPPED]\n"; } elsif(0 == $failed_skipped) { - print " [OK]\n"; + print " [OK] in $runtime seconds\n"; } else { $failures++; print " [FAILED]\n";