| 1 | package App::TestOnTap::Harness; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 19 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 19 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 19 | ▶ | use base qw(TAP::Harness); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 19 | ▶ | use App::TestOnTap::Scheduler; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 19 | ▶ | use App::TestOnTap::Dispenser; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 19 | ▶ | use App::TestOnTap::Util qw(slashify runprocess $IS_PACKED); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 19 | ▶ | use TAP::Formatter::Console; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 19 | ▶ | use TAP::Formatter::File; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 19 | ▶ | use List::Util qw(max); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | sub new | ||||||||||||||||||||||||||||
| 18 | { | ||||||||||||||||||||||||||||
| 19 | 27 | ▶ | my $class = shift; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | 27 | my $args = shift; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 27 | my $self = $class->SUPER::new | |||||||||||||||||||||||||||
| 23 | ( | ||||||||||||||||||||||||||||
| 24 | { | ||||||||||||||||||||||||||||
| 25 | formatter => __getFormatter($args), | ||||||||||||||||||||||||||||
| 26 | jobs => $args->getJobs(), | ||||||||||||||||||||||||||||
| 27 | merge => $args->getMerge(), | ||||||||||||||||||||||||||||
| 28 | callbacks => { after_test => $args->getWorkDirManager()->getResultCollector() }, | ||||||||||||||||||||||||||||
| 29 | 'exec' => __getExecMapper($args), | ||||||||||||||||||||||||||||
| 30 | scheduler_class => 'App::TestOnTap::Scheduler' | ||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 27 | $self->{testontap} = { args => $args, pez => App::TestOnTap::Dispenser->new($args) }; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 26 | return $self; | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | sub make_scheduler | ||||||||||||||||||||||||||||
| 40 | { | ||||||||||||||||||||||||||||
| 41 | 26 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
make_scheduler: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 26 | return $self->{scheduler_class}->new($self->{testontap}->{pez}, @_); | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | sub runtests | ||||||||||||||||||||||||||||
| 47 | { | ||||||||||||||||||||||||||||
| 48 | 26 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
runtests: called CC=16 SCAR=28.0
Pod
documented
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 26 | my $args = $self->{testontap}->{args}; | |||||||||||||||||||||||||||
| 51 | 26 | my $sr = $args->getSuiteRoot(); | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 26 | my @pairs; | |||||||||||||||||||||||||||
| 54 | 26 | push(@pairs, [ slashify("$sr/$_"), $_ ]) foreach ($self->{testontap}->{pez}->getAllTests()); | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 26 | my $failed = 0; | |||||||||||||||||||||||||||
| 57 | { | ||||||||||||||||||||||||||||
| 58 | 26 | my $wdmgr = $self->{testontap}->{args}->getWorkDirManager(); | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 26 | local %ENV = %{$self->{testontap}->{args}->getPreprocess()->getEnv()}; | |||||||||||||||||||||||||||
| 61 | 26 | $ENV{TESTONTAP_SUITE_DIR} = $sr; | |||||||||||||||||||||||||||
| 62 | 26 | $ENV{TESTONTAP_TMP_DIR} = $wdmgr->getTmp(); | |||||||||||||||||||||||||||
| 63 | 26 | $ENV{TESTONTAP_SAVE_DIR} = $wdmgr->getSaveSuite(); | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 26 | ▶ | if ($self->{testontap}->{args}->useHarness()) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | { | ||||||||||||||||||||||||||||
| 67 | # the normal case is to run with a 'real' harness that parses | ||||||||||||||||||||||||||||
| 68 | # TAP, handles parallelization, formatters and all that | ||||||||||||||||||||||||||||
| 69 | # | ||||||||||||||||||||||||||||
| 70 | 25 | $wdmgr->beginTestRun(); | |||||||||||||||||||||||||||
| 71 | 25 | my $aggregator = $self->SUPER::runtests(@pairs); | |||||||||||||||||||||||||||
| 72 | 25 | $wdmgr->endTestRun($self->{testontap}->{args}, $aggregator); | |||||||||||||||||||||||||||
| 73 | 25 | ▶ | $failed = $aggregator->failed() || 0; | ||||||||||||||||||||||||||
|
Condition100%2/2
$aggregator->failed || 0
MC/DC100%1/1
$aggregator->failed || 0
$aggregator->failed
Truth table100%2/2
A
A= $aggregator->failed
| |||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | else | ||||||||||||||||||||||||||||
| 76 | { | ||||||||||||||||||||||||||||
| 77 | # if the user has requested 'no harness', just run the jobs serially | ||||||||||||||||||||||||||||
| 78 | # in the right context, but make no effort to parse their output | ||||||||||||||||||||||||||||
| 79 | # in any way - more convenient for debugging (esp. with an execmap | ||||||||||||||||||||||||||||
| 80 | # that can start a test in debug mode) | ||||||||||||||||||||||||||||
| 81 | # | ||||||||||||||||||||||||||||
| 82 | 1 | my $scheduler = $self->make_scheduler(@pairs); | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | # figure out the longest test file name with some extra to produce some | ||||||||||||||||||||||||||||
| 85 | # nice delimiters... | ||||||||||||||||||||||||||||
| 86 | # | ||||||||||||||||||||||||||||
| 87 | 1 | my $longestTestFileName = 0; | |||||||||||||||||||||||||||
| 88 | 1 | $longestTestFileName = max($longestTestFileName, length($_->[0])) foreach (@pairs); | |||||||||||||||||||||||||||
| 89 | 1 | $longestTestFileName += 10; | |||||||||||||||||||||||||||
| 90 | 1 | my $topDelimLine = '#' x $longestTestFileName; | |||||||||||||||||||||||||||
| 91 | 1 | my $bottomDelimLine = '-' x $longestTestFileName; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 1 | ▶ | while (my $job = $scheduler->get_job()) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | { | ||||||||||||||||||||||||||||
| 95 | 1 | my $desc = $job->description(); | |||||||||||||||||||||||||||
| 96 | 1 | my $filename = $job->filename; | |||||||||||||||||||||||||||
| 97 | 1 | my $cmdline = $self->exec()->($self, $filename); | |||||||||||||||||||||||||||
| 98 | 1 | my $dryrun = $self->{testontap}->{args}->doDryRun(); | |||||||||||||||||||||||||||
| 99 | 1 | ▶ | my $parallelizable = ($self->{testontap}->{args}->getConfig()->parallelizable($desc) ? '' : 'not ') . 'parallelizable'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 1 | print "$topDelimLine\n"; | |||||||||||||||||||||||||||
| 101 | 1 | print "Run test '$desc' ($parallelizable) using:\n"; | |||||||||||||||||||||||||||
| 102 | 1 | print " $_\n" foreach (@$cmdline); | |||||||||||||||||||||||||||
| 103 | 1 | print "$bottomDelimLine\n"; | |||||||||||||||||||||||||||
| 104 | 1 | ▶ | if ($dryrun) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 105 | { | ||||||||||||||||||||||||||||
| 106 | 0 | print "(dry run only, actual test not executed)\n"; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | else | ||||||||||||||||||||||||||||
| 109 | { | ||||||||||||||||||||||||||||
| 110 | 1 | ▶ | $failed++ if system(@$cmdline) >> 8; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | 1 | $job->finish(); | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | # run postprocessing | ||||||||||||||||||||||||||||
| 117 | # | ||||||||||||||||||||||||||||
| 118 | 26 | my $postcmd = $self->{testontap}->{args}->getConfig()->getPostprocessCmd(); | |||||||||||||||||||||||||||
| 119 | 26 | ▶ | if ($postcmd && @$postcmd) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$postcmd and @$postcmd
MC/DC50%1/2
$postcmd and @$postcmd
$postcmd
@$postcmd
Truth table66%2/3
A and B
A= $postcmdB= @$postcmd
| |||||||||||||||||||||||||||||
| 120 | { | ||||||||||||||||||||||||||||
| 121 | 1 | my @postproc; | |||||||||||||||||||||||||||
| 122 | my $xit = runprocess | ||||||||||||||||||||||||||||
| 123 | ( | ||||||||||||||||||||||||||||
| 124 | sub | ||||||||||||||||||||||||||||
| 125 | { | ||||||||||||||||||||||||||||
| 126 | 1 | ▶ | push(@postproc, $_[0]); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 127 | 1 | print STDERR $_[0] | |||||||||||||||||||||||||||
| 128 | }, | ||||||||||||||||||||||||||||
| 129 | $sr, | ||||||||||||||||||||||||||||
| 130 | ( | ||||||||||||||||||||||||||||
| 131 | @$postcmd, | ||||||||||||||||||||||||||||
| 132 | 1 | @{$self->{testontap}->{args}->getPreprocess()->getArgv()} | |||||||||||||||||||||||||||
| 133 | ) | ||||||||||||||||||||||||||||
| 134 | ); | ||||||||||||||||||||||||||||
| 135 | 1 | ▶ | if ($xit) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | { | ||||||||||||||||||||||||||||
| 137 | 1 | $failed++; | |||||||||||||||||||||||||||
| 138 | 1 | warn("WARNING: exit code '$xit' when running postprocess command\n"); | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | 1 | ▶ | $failed++ if $xit; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 1 | $args->getWorkDirManager()->recordPostprocess([ @postproc ]); | |||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | # drop the special workaround envvar... | ||||||||||||||||||||||||||||
| 146 | # | ||||||||||||||||||||||||||||
| 147 | 26 | ▶ | delete $ENV{PERL5LIB} if $IS_PACKED; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 26 | ▶ | return ($failed > 127) ? 127 : $failed; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | sub _open_spool | ||||||||||||||||||||||||||||
| 154 | { | ||||||||||||||||||||||||||||
| 155 | 47 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_open_spool: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 156 | 47 | my $testpath = shift; | |||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 47 | return $self->{testontap}->{args}->getWorkDirManager()->openTAPHandle($testpath); | |||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | sub _close_spool | ||||||||||||||||||||||||||||
| 162 | { | ||||||||||||||||||||||||||||
| 163 | 47 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_close_spool: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 164 | 47 | my $parser = shift; | |||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 47 | $self->{testontap}->{args}->getWorkDirManager()->closeTAPHandle($parser); | |||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 47 | return; | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | sub __getExecMapper | ||||||||||||||||||||||||||||
| 172 | { | ||||||||||||||||||||||||||||
| 173 | 27 | ▶ | my $args = shift; | ||||||||||||||||||||||||||
|
Subroutine
__getExecMapper: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | return sub | ||||||||||||||||||||||||||||
| 176 | { | ||||||||||||||||||||||||||||
| 177 | 48 | ▶ | my $harness = shift; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 178 | 48 | my $testfile = shift; | |||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | # trim down the full file name to the test name | ||||||||||||||||||||||||||||
| 181 | # | ||||||||||||||||||||||||||||
| 182 | 48 | my $srfs = slashify($args->getSuiteRoot(), '/'); | |||||||||||||||||||||||||||
| 183 | 48 | my $testname = slashify($testfile, '/'); | |||||||||||||||||||||||||||
| 184 | 48 | $testname =~ s#^\Q$srfs\E/##; | |||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | # get the commandline corresponding to the test name | ||||||||||||||||||||||||||||
| 187 | # | ||||||||||||||||||||||||||||
| 188 | 48 | my $cmdline = $args->getConfig()->getExecMapping($testname); | |||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | # expand it with the full set | ||||||||||||||||||||||||||||
| 191 | # | ||||||||||||||||||||||||||||
| 192 | 48 | $cmdline = [ @$cmdline, $testfile, @{$args->getArgv()} ]; | |||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | # make a note of the result for the work area records | ||||||||||||||||||||||||||||
| 195 | # | ||||||||||||||||||||||||||||
| 196 | 48 | $args->getWorkDirManager()->recordCommandLine($testname, $cmdline); | |||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 48 | return $cmdline; | |||||||||||||||||||||||||||
| 199 | 27 | }; | |||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | sub __getFormatter | ||||||||||||||||||||||||||||
| 203 | { | ||||||||||||||||||||||||||||
| 204 | 27 | ▶ | my $args = shift; | ||||||||||||||||||||||||||
|
Subroutine
__getFormatter: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 27 | my $formatterArgs = | |||||||||||||||||||||||||||
| 207 | { | ||||||||||||||||||||||||||||
| 208 | jobs => $args->getJobs(), | ||||||||||||||||||||||||||||
| 209 | timer => $args->getTimer(), | ||||||||||||||||||||||||||||
| 210 | show_count => 1, | ||||||||||||||||||||||||||||
| 211 | verbosity => $args->getVerbose(), | ||||||||||||||||||||||||||||
| 212 | }; | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | return | ||||||||||||||||||||||||||||
| 215 | 27 | ▶ | -t \*STDOUT | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 216 | ? TAP::Formatter::Console->new($formatterArgs) | ||||||||||||||||||||||||||||
| 217 | : TAP::Formatter::File->new($formatterArgs); | ||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | 19 | 1; | |||||||||||||||||||||||||||