#!/usr/bin/env perl # Run the build and/or submit for each test. # If nobuild is off, run the build for each test. # If autosubmit is on, run the submit script for each test. # If nobatch is on, run the test interactively rather than # submitting to the batch queue. use strict; use warnings; use Data::Dumper; use Cwd qw( getcwd chdir); use File::Basename; # Take the testspec.$machine.$testid.xml file, parse it, # and get the names of the case directories # This is a copy of the routine in cs.status - these tools should be # rewritten. sub getCaseDirsFromSpec { my $testspec = shift; my $xml = XML::Lite->new($testspec); my @tests = $xml->elements_by_name("test"); my @casedirs; #print "Casedirs: \n"; #map {print "$_\n"} @casedirs; foreach my $test(@tests) { my %attrs = $test->attributes; foreach my $attr(keys %attrs) { push(@casedirs, $attrs{$attr}); } } #print Dumper(\@casedirs); return @casedirs; } # Given an array of case directories, get the test status for # all the testcase directories found. # This is a modified copy of the routine in cs.status - these tools should be # rewritten. sub getTestStatus { my $testspec = shift; my $testdir = shift; my @casedirs = getCaseDirsFromSpec($testspec); my $tests; foreach my $testcase(@casedirs) { # my %testhash; my $teststatusfile = "$testdir/$testcase/TestStatus"; if (! -e $teststatusfile){ $tests->{$testcase}{status}="FAIL"; }else{ open my $STATUS, "<", $teststatusfile or die $!; my @lines = <$STATUS>; close $STATUS; $tests->{$testcase}{'fullpath'} = "$testdir/$testcase"; $tests->{$testcase}{'rawstatus'} = join('', @lines); $tests->{$testcase}{'status'} = (split('\s+', $lines[0]))[0]; my $memleakline = (grep { /memleak/ } @lines)[0]; $tests->{$testcase}{'memleak'} = (split('\s+', $memleakline))[0] if (defined $memleakline && length $memleakline > 0); my $tputline = (grep { /tput/ } @lines)[0]; $tests->{$testcase}{'throughput'} = (split('\s+', $tputline))[0] if (defined $tputline && length $tputline > 0); my $genline = (grep { /generate/ } @lines)[0]; $tests->{$testcase}{'generate'} = (split('\s+', $genline))[0] if (defined $genline && length $genline > 0); my $compline = (grep { /compare_hist/ } @lines)[0]; $tests->{$testcase}{'compare'} = (split('\s+', $compline))[0] if (defined $compline && length $compline > 0); } } return $tests; } # find the testspec.xml. my $testroot = getcwd; my $csstatus; my $testspec; if ( $0 !~ /cs.submit\.(.*)$/ ) { opendir(D,$testroot); my @testspec = grep /testspec\..*\.xml$/,readdir(D); closedir(D); $testspec = $testspec[0]; if($#testspec > 0){ foreach(@testspec){ $testspec = $_ if(-A $_ < -A $testspec); } } }else{ $csstatus = "cs.status.$1"; $testspec = "$testroot/testspec.$1.xml"; } # Find the scriptsroot open my $SPEC, "<", $testspec or die $!; my @speclines = grep (/scriptsroot/, <$SPEC>); chomp @speclines; close $SPEC; my $scriptsroot = $speclines[0]; $scriptsroot =~ s/\//g; $scriptsroot =~ s/\<\/scriptsroot\>//g; $scriptsroot =~ s/\s+//g; # require/import XML::Lite my @dirs = ( "$scriptsroot/../utils/perl5lib"); unshift @INC, @dirs; require XML::Lite; my $teststatus = getTestStatus($testspec, $testroot); my $xml = XML::Lite->new($testspec); # Get nobatch,nobuild, and autosubmit. # Do the build and/or submit for each test. my @nbatch = $xml->elements_by_name("nobatch"); my @nbuild = $xml->elements_by_name("nobuild"); my @asubmit = $xml->elements_by_name("autosubmit"); my $nobatch = $nbatch[0]->text; my $nobuild = $nbuild[0]->text; my $autosubmit = $asubmit[0]->text; #foreach my $case(@casedirs) #{ foreach my $test (keys %$teststatus){ # print "$test $teststatus->{$test}{status}\n"; my $status = $teststatus->{$test}{status}; my $testdir = "$testroot/$test"; # build the test. my $buildstatus; if( $status ne "DONE" && $status ne "PEND" && $status ne "RUN"){ if($nobuild eq "off" || ! defined $nobuild) { chdir($testdir); if( -e "$testdir/$test.test_build") { print "building $test\n"; system("./$test.test_build"); my $retcode = $?; open my $TESTSTATUS, ">", "./TestStatus" or warn $!; if($retcode != 0) { print $TESTSTATUS "CFAIL $test\n"; $buildstatus = "CFAIL"; print "$test build status: CFAIL\n"; } else { print $TESTSTATUS "BUILD $test\n"; $buildstatus = "BUILD"; print "$test build status: BUILD\n"; } close $TESTSTATUS; if( ( $autosubmit eq "on" || ! defined $autosubmit) && $buildstatus eq "BUILD") { print "submitting $test\n"; system("./$test.submit"); my $submitret = $?; open $TESTSTATUS, ">", "./TestStatus" or warn $!; if($retcode != 0) { print $TESTSTATUS "FAIL $test\n"; } else { print $TESTSTATUS "PEND $test\n"; } close $TESTSTATUS; } } else { print "$test.test_build does not exist, skipping build for $test...\n"; } chdir $testroot; } if( $nobatch eq "on" ) { chdir($testdir); print "running $test\n"; system("./$test.test"); chdir $testroot; } if( $nobatch eq "on" ) { system("./$csstatus"); } }else{ print "Test $test status $status, not resubmitting\n"; } }