File Coverage

blib/lib/Tapper/Reports/Web/Controller/Tapper/Reports/Id.pm
Criterion Covered Total %
statement 40 134 29.8
branch 0 32 0.0
condition 0 5 0.0
subroutine 14 17 82.3
pod n/a
total 54 188 28.7


line stmt bran cond sub pod time code
1             package Tapper::Reports::Web::Controller::Tapper::Reports::Id;
2             our $AUTHORITY = 'cpan:TAPPER';
3             $Tapper::Reports::Web::Controller::Tapper::Reports::Id::VERSION = '5.0.15';
4 11     11   6964 use 5.010;
  11         45  
5 11     11   64 use strict;
  11         26  
  11         264  
6 11     11   66 use warnings;
  11         27  
  11         317  
7              
8 11     11   61 use Tapper::Reports::Web::Util::Report;
  11         26  
  11         340  
9 11     11   69 use File::Basename;
  11         24  
  11         822  
10 11     11   81 use File::stat;
  11         28  
  11         106  
11 11     11   768 use parent 'Tapper::Reports::Web::Controller::Base';
  11         38  
  11         94  
12 11     11   5616 use YAML;
  11         83974  
  11         728  
13              
14 11     11   93 use Data::Dumper;
  11         39  
  11         691  
15 11     11   88 use Data::DPath 'dpath';
  11         27  
  11         123  
16              
17             sub younger
18             {
19 0     0   0 my $astat = stat($a);
20 0         0 my $bstat = stat($b);
21 0         0 return $bstat->mtime() <=> $astat->mtime();
22             }
23              
24              
25              
26             sub generate_metareport_link
27             {
28 0     0   0 my ( $self, $report ) = @_;
29 0         0 my %metareport;
30 0         0 my $path = Tapper::Config->subconfig->{paths}{config_path};
31 0         0 $path .= "/web/metareport_associate.yml";
32              
33 0 0       0 return if not -e $path;
34              
35 0         0 my $config;
36 0         0 eval {
37 0         0 $config = YAML::LoadFile($path);
38             };
39 0 0       0 if ($@) {
40             # TODO: Enable Log4perl
41             # $self->log->error("Can not open association config for metareports: $@");
42 0         0 say STDERR "Can not open association config for metareports: $@";
43 0         0 return ();
44             }
45 11     11   5302 use Data::Dumper;
  11         25  
  11         597  
46 0         0 my $suite;
47 11   0 11   72 { no warnings 'uninitialized'; $suite = $config->{suite}->{$report->{suite}} || $config->{suite}->{$report->{group_suite}};}
  11         27  
  11         13249  
  0         0  
  0         0  
48 0 0       0 if ($suite) {
49 0         0 my $category = $suite->{category};
50 0         0 my $subcategory = $suite->{subcategory};
51 0         0 my $time_frame = $suite->{time_frame};
52              
53 0         0 $path = Tapper::Config->subconfig->{paths}{metareport_path};
54 0         0 my ($filename) = sort younger <$path/$category/$subcategory/teaser/*.png>;
55 0 0       0 if (not $filename) {
56 0         0 ($filename) = sort younger <$path/$category/$subcategory/$time_frame/*.png>;
57 0         0 $filename = "/tapper/static/metareports/$category/$subcategory/$time_frame/".basename($filename);
58             } else {
59 0         0 $filename = "/tapper/static/metareports/$category/$subcategory/teaser/".basename($filename);
60             }
61 0 0       0 return () if not $filename;
62              
63             %metareport = (url => "/tapper/metareports/$category/$subcategory/$time_frame/",
64             img => $filename,
65             alt => $suite->{alt},
66             headline => $suite->{headline},
67 0         0 );
68             }
69 0         0 return %metareport;
70             }
71              
72             # get array of not_ok sub tests
73              
74             sub get_report_failures
75             {
76 1     1   932623 my ($self, $report) = @_;
77              
78 1         8 return [ dpath('//tap//lines//is_ok[value eq 0]/..')->match($report->get_cached_tapdom) ];
79             }
80              
81             sub index :Path :Args(1)
82             {
83 0     0   0 my ( $self, $c, $report_id ) = @_;
84              
85 0         0 $c->stash->{failures} = {};
86 0         0 $c->stash->{reportlist_rga} = {};
87 0         0 $c->stash->{reportlist_rgt} = {};
88 0         0 $c->stash->{overview} = undef;
89 0         0 $c->stash->{report} = $c->model('TestrunDB')->resultset('Report')->find($report_id);
90              
91 0 0       0 if (not $c->stash->{report}) {
92 0         0 $c->response->body("No such report");
93 0         0 $c->stash->{title} = "No such report";
94 0         0 return;
95             }
96              
97 0 0       0 if (not $c->stash->{report}->suite) {
98 0   0     0 $c->response->body("No such testsuite with id: ". ($c->stash->{report}->suite_id // ""));
99 0         0 $c->stash->{title} = "No such testsuite";
100 0         0 return;
101             }
102              
103 0         0 my $suite_name = $c->stash->{report}->suite->name;
104 0         0 my $machine_name = $c->stash->{report}->machine_name;
105 0         0 $c->stash->{title} = "Report $report_id: $suite_name @ $machine_name";
106              
107 0         0 my $util_report = Tapper::Reports::Web::Util::Report->new();
108              
109 0 0       0 if (my $rga = $c->stash->{report}->reportgrouparbitrary) {
110             #my $rga_reports = $c->model('TestrunDB')->resultset('ReportgroupArbitrary')->search ({ arbitrary_id => $rga->arbitrary_id });
111 0         0 my $rga_reports = $c->model('TestrunDB')->resultset('Report')->search
112             (
113             {
114             "reportgrouparbitrary.arbitrary_id" => $rga->arbitrary_id
115             },
116             { order_by => 'me.id desc',
117             join => [ 'reportgrouparbitrary', 'reportgrouptestrun', 'suite'],
118             '+select' => [ 'reportgrouparbitrary.arbitrary_id', 'reportgrouparbitrary.primaryreport', 'reportgrouptestrun.testrun_id', 'reportgrouptestrun.primaryreport', 'suite.id', 'suite.name', 'suite.type', 'suite.description' ],
119             '+as' => [ 'rga_id', 'rga_primary', 'rgt_id', 'rgt_primary', 'suite_id', 'suite_name', 'suite_type', 'suite_description' ],
120             }
121             );
122 0         0 $c->stash->{reportlist_rga} = $util_report->prepare_simple_reportlist($c, $rga_reports);
123              
124 0         0 $rga_reports->reset;
125 0         0 while (my $r = $rga_reports->next) {
126 0 0       0 if (my @report_failures = @{ $self->get_report_failures($r) }) {
  0         0  
127 0         0 $c->stash->{failures}->{$r->id}{name} = $r->suite->name;
128 0         0 $c->stash->{failures}->{$r->id}{machine_name} = $r->machine_name;
129 0         0 my @descriptions = ();
130 0         0 my $sections = $r->reportsections;
131 0 0       0 while (my $section = $sections->next) { my %col = $section->get_columns; push @descriptions, $col{description} if $col{description} };
  0         0  
  0         0  
132 0         0 $c->stash->{failures}->{$r->id}{report_description} = join(",", @descriptions);
133 0         0 push @{$c->stash->{failures}->{$r->id}{failures}}, @report_failures;
  0         0  
134             }
135             }
136             }
137              
138 0 0       0 if (my $rgt = $c->stash->{report}->reportgrouptestrun) {
139             #my $rgt_reports = $c->model('TestrunDB')->resultset('ReportgroupTestrun')->search ({ testrun_id => $rgt->testrun_id });
140 0         0 my $rgt_reports = $c->model('TestrunDB')->resultset('Report')->search
141             (
142             {
143             "reportgrouptestrun.testrun_id" => $rgt->testrun_id
144             },
145             { order_by => 'me.id desc',
146             join => [ 'reportgrouparbitrary', 'reportgrouptestrun', 'suite'],
147             '+select' => [ 'reportgrouparbitrary.arbitrary_id', 'reportgrouparbitrary.primaryreport', 'reportgrouptestrun.testrun_id', 'reportgrouptestrun.primaryreport', 'suite.name', 'suite.type', 'suite.description' ],
148             '+as' => [ 'rga_id', 'rga_primary', 'rgt_id', 'rgt_primary', 'suite_name', 'suite_type', 'suite_description' ],
149             }
150             );
151 0         0 $c->stash->{reportlist_rgt} = $util_report->prepare_simple_reportlist($c, $rgt_reports);
152              
153 0         0 $rgt_reports->reset;
154 0         0 while (my $r = $rgt_reports->next) {
155 0 0       0 if (my @report_failures = @{ $self->get_report_failures($r) }) {
  0         0  
156 0         0 $c->stash->{failures}->{$r->id}{name} = $r->suite->name;
157 0         0 $c->stash->{failures}->{$r->id}{machine_name} = $r->machine_name;
158 0         0 push @{$c->stash->{failures}->{$r->id}{failures}}, @report_failures;
  0         0  
159             }
160             }
161              
162 0         0 my %cols = $rgt_reports->search({}, {rows => 1})->first->get_columns;
163 0         0 my $testrun_id = $cols{rgt_id};
164 0         0 my $testrun;
165 0         0 eval {
166 0         0 $testrun = $c->model('TestrunDB')->resultset('Testrun')->find($testrun_id);
167             };
168 0         0 $c->stash->{overview} = $c->forward('/tapper/testruns/get_testrun_overview', [ $testrun ]);
169             }
170              
171 0 0       0 my $tmp = [ grep {defined($_->{rgt_primary}) and $_->{rgt_primary} == 1} @{$c->stash->{reportlist_rgt}->{all_reports}} ]->[0]->{suite_name};
  0         0  
  0         0  
172 0 0       0 my $report_data = {suite => $c->stash->{report}->suite ? $c->stash->{report}->suite->name : 'unknownsuite' ,
173             group_suite => $tmp};
174              
175 0 0       0 unless (my @report_failures = @{$c->stash->{failures}->{$c->stash->{report}->id}{failures} || []}) {
  0 0       0  
176 0         0 $c->stash->{failures}->{$c->stash->{report}->id}{name} = $c->stash->{report}->suite->name;
177 0         0 $c->stash->{failures}->{$c->stash->{report}->id}{machine_name} = $c->stash->{report}->machine_name;
178 0         0 push @{$c->stash->{failures}->{$c->stash->{report}->id}{failures}}, @report_failures;
  0         0  
179             }
180 0         0 %{$c->stash->{metareport}} = $self->generate_metareport_link($report_data);
  0         0  
181              
182 11     11   104 }
  11         33  
  11         91  
183              
184             1;
185              
186             __END__
187              
188             =pod
189              
190             =encoding UTF-8
191              
192             =head1 NAME
193              
194             Tapper::Reports::Web::Controller::Tapper::Reports::Id
195              
196             =head2 generate_metareport_link
197              
198             Generate config for showing metareport image associated to given report.
199              
200             @param hash - config describing the relevant report
201              
202             @return success - hash containing (url, img, alt, headline)
203             @return error - empty list
204              
205             =head1 AUTHORS
206              
207             =over 4
208              
209             =item *
210              
211             AMD OSRC Tapper Team <tapper@amd64.org>
212              
213             =item *
214              
215             Tapper Team <tapper-ops@amazon.com>
216              
217             =back
218              
219             =head1 COPYRIGHT AND LICENSE
220              
221             This software is Copyright (c) 2020 by Advanced Micro Devices, Inc..
222              
223             This is free software, licensed under:
224              
225             The (two-clause) FreeBSD License
226              
227             =cut