Merge pull request #2240 from DOCGroup/revert-2239-jwi-pi23
[ACE_TAO.git] / ACE / bin / auto_run_tests.pl
blob36c0748f2c697fa7bc978a7d8766f1c666ee6f0a
1 eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
2 & eval 'exec perl -S $0 $argv:q'
3 if 0;
5 # -*- perl -*-
6 # Executes test list files (*.lst), which contain commands with conditions
7 # called configurations under which the commands are run.
9 use strict;
11 use lib "$ENV{ACE_ROOT}/bin";
12 if (defined $ENV{srcdir}) {
13 use lib "$ENV{srcdir}/bin";
15 use PerlACE::Run_Test;
17 use Getopt::Long;
18 use Cwd;
20 use Env qw(ACE_ROOT PATH TAO_ROOT);
22 if (!defined $TAO_ROOT && -d "$ACE_ROOT/TAO") {
23 $TAO_ROOT = "$ACE_ROOT/TAO";
26 sub run_command {
27 my $test = shift;
28 my $command = shift;
29 my $print_error = shift;
31 my $result = 0;
32 if (system($command)) {
33 $result = $? >> 8;
34 if ($print_error) {
35 my $signal = $? & 127;
36 my $coredump = $? & 128;
37 my $error_message;
38 if ($? == -1) {
39 $error_message = "failed to run: $!";
41 elsif ($signal) {
42 $error_message = sprintf("exited on signal %d", ($signal));
43 $error_message .= " and created coredump" if ($coredump);
45 else {
46 $error_message = sprintf("returned with status %d", $result);
48 print "Error: $test $error_message\n";
51 return $result;
54 sub print_help {
55 my $fd = shift;
56 print $fd
57 "auto_run_tests.pl [<options> ...] [<list_file> ...]\n" .
58 "\n" .
59 "Executes test list files (*.lst), which contain commands with conditions called\n" .
60 "configurations under which the commands are run.\n" .
61 "\n" .
62 "Test lists files can be specified using the -l option or as non-option\n" .
63 "arguments. The standard test list files for ACE/TAO and related software are\n" .
64 "built-in and can be included via the listed options before. If not test list\n" .
65 "files are specified, the script tries to use all the standard test list files\n" .
66 "that can be found.\n" .
67 "\n" .
68 "Options:\n" .
69 " --help | -h Display this help\n" .
71 " --ace | -a Include the ACE tests\n" .
72 " --orb | -o Include the TAO ORB tests\n" .
73 " --tao | -t Include the TAO non-ORB tests\n" .
75 " -l <list_file> Include the tests from <list_file>\n" .
77 " --sandbox | -s <sandbox> Runs each program using a sandbox program\n" .
78 " --root | -r <dir> Root directory for running the tests\n" .
79 " --dry-run | -z Just print the commands that would be ran\n" .
80 " --show-configs Just print possible values for -Config\n" .
82 # These two are processed by PerlACE/ConfigList.pm
83 " -Config <cfg> Include tests with <cfg> configuration\n" .
84 " -Exclude <cfg> Exclude tests with <cfg> configuration\n" .
86 # This one is processed by PerlACE/Process.pm
87 " -ExeSubDir <dir> Subdirectory for finding the executables\n";
90 ################################################################################
92 # Parse Options
93 my $help = 0;
94 my $ace_tests = 0;
95 my $tao_orb_tests = 0;
96 my $tao_tests = 0;
97 my @l_options = ();
98 my $sandbox = '';
99 my $dry_run = 0;
100 my $startdir = '';
101 my $show_configs = 0;
102 Getopt::Long::Configure('bundling', 'no_auto_abbrev');
103 my $invalid_arguments = !GetOptions(
104 'help|h' => \$help,
105 'ace|a' => \$ace_tests,
106 'orb|o' => \$tao_orb_tests,
107 'tao|t' => \$tao_tests,
108 'l=s' => \@l_options,
109 'sandbox|s=s' => \$sandbox,
110 'dry-run|z' => \$dry_run,
111 'root|r=s' => \$startdir,
112 'show-configs' => \$show_configs,
114 if ($invalid_arguments || $help) {
115 print_help($invalid_arguments ? *STDERR : *STDOUT);
116 exit($invalid_arguments ? 1 : 0);
119 # Determine what test list files to use
120 my @main_test_lists = (
121 [\$ace_tests, $ACE_ROOT, "bin/ace_tests.lst", "ACE"],
122 [\$tao_orb_tests, $TAO_ROOT, "bin/tao_orb_tests.lst", "TAO ORB"],
123 [\$tao_tests, $TAO_ROOT, "bin/tao_other_tests.lst", "TAO non-ORB"],
125 my @file_list = ();
126 my $list_error = 0;
127 foreach my $i (@main_test_lists) {
128 my $enabled_ref = $i->[0];
129 my $root = $i->[1];
130 my $list_file = $i->[2];
131 my $name = $i->[3];
132 my $list_file_path = "$root/$list_file";
133 if (defined $root && $$enabled_ref) {
134 push(@file_list, $list_file_path);
136 elsif ($$enabled_ref) {
137 $list_error = "option for $name tests passed, but the root enviroment variable isn't set";
140 push(@file_list, @l_options);
141 push(@file_list, @ARGV);
142 if (!scalar(@file_list)) {
143 foreach my $i (@main_test_lists) {
144 my $root = $i->[1];
145 my $list_file = $i->[2];
146 my $list_file_path = "$root/$list_file";
147 if (defined $root && -f $list_file_path) {
148 push (@file_list, $list_file_path);
151 if (!scalar(@file_list)) {
152 $list_error = "no default test lists could be found";
155 if ($list_error) {
156 print STDERR "ERROR: $list_error\n";
157 exit(1);
160 if ($show_configs) {
161 foreach my $test_list (@file_list) {
162 my $config_list = new PerlACE::ConfigList;
163 $config_list->load($test_list);
164 print "$test_list: " . $config_list->list_configs() . "\n";
166 exit (0);
169 my $explicit_startdir = 0;
170 if ($startdir) {
171 $explicit_startdir = 1;
173 else {
174 $startdir = "$ACE_ROOT";
177 foreach my $test_lst (@file_list) {
179 my $config_list = new PerlACE::ConfigList;
180 if (-r $ACE_ROOT.$test_lst) {
181 $config_list->load($ACE_ROOT.$test_lst);
183 elsif (-r "$startdir/$test_lst") {
184 $config_list->load("$startdir/$test_lst");
186 else {
187 $config_list->load($test_lst);
190 # Insures that we search for stuff in the current directory.
191 $PATH .= $Config::Config{path_sep} . '.';
193 foreach my $test ($config_list->valid_entries()) {
194 my $directory = ".";
195 my $program = ".";
197 ## Remove intermediate '.' directories to allow the
198 ## scoreboard matrix to read things correctly
199 $test =~ s!/./!/!g;
201 if ($test =~ /(.*)\/([^\/]*)$/) {
202 $directory = $1;
203 $program = $2;
205 else {
206 $program = $test;
209 # this is to ensure that we dont print out the time for tests/run_test.pl
210 # that test prints out the times for each of the ace tests individually
211 my $is_ace_test = ($directory eq "tests");
213 if (! $is_ace_test) {
214 print "auto_run_tests: $test\n";
215 if ($config_list->check_config('Coverity')) {
216 $ENV{COVERITY_TEST_NAME} = $test;
217 $ENV{COVERITY_SUITE_NAME} = $test_lst;
218 $ENV{COVERITY_TEST_SOURCE} = "$directory/$program";
222 my($orig_dir) = $directory;
223 if ($directory =~ m:^TAO/(.*):) {
224 $directory = $1;
226 my $status;
227 my @dirlist = ($ACE_ROOT."/$directory",
228 $TAO_ROOT."/$directory");
229 # make sure to *first* check the explicitly specified directory and
230 # only when nothing found there check the default dirs
231 if ($explicit_startdir) {
232 unshift (@dirlist, $startdir."/$directory");
233 unshift (@dirlist, $startdir."/$orig_dir");
235 foreach my $path (@dirlist) {
236 if (-d $path && ($status = chdir($path))) {
237 last;
241 if (!$status) {
242 if ($explicit_startdir) {
243 print STDERR "ERROR: Cannot chdir to $startdir/$directory\n";
244 } else {
245 print STDERR "ERROR: Cannot chdir to $directory\n";
247 next;
250 if ($program =~ /(.*?) (.*)/) {
251 if (! -e $1) {
252 print STDERR "ERROR: $directory.$1 does not exist\n";
253 next;
256 else {
257 if (! -e $program) {
258 print STDERR "ERROR: $directory.$program does not exist\n";
259 next;
263 ### Generate the -ExeSubDir and -Config options
264 my $inherited_options = " -ExeSubDir $PerlACE::Process::ExeSubDir ";
266 foreach my $config ($config_list->my_config_list()) {
267 $inherited_options .= " -Config $config ";
270 my $cmd = '';
271 if ($sandbox) {
272 #The Win32 sandbox takes the program and options in quotes, but the
273 #posix sandbox takes the program and options as separate args.
274 my($q) = ($^O eq 'MSWin32') ? '"' : '';
275 $cmd = "$sandbox ${q}perl $program $inherited_options${q}";
277 else {
278 $cmd = "perl $program$inherited_options";
281 if ($dry_run) {
282 my $cwd = getcwd();
283 print "In \"$cwd\" would run:\n $cmd\n";
285 else {
286 my $start_time = time();
287 my $result = run_command($test, $cmd, !$is_ace_test);
288 my $time = time() - $start_time;
290 # see note about tests/run_test.pl printing reports for ace tests individually
291 if (!$is_ace_test) {
292 print "\nauto_run_tests_finished: $test Time:$time"."s Result:$result\n";
293 print "==============================================================================\n";