Skip to content

Commit

Permalink
Show the subresults and their checks in the HTML report
Browse files Browse the repository at this point in the history
Fix the colspan of the main table, add a new column "Actions" into the
table and add possibility to show/hide the checks and subresults row for
each result.

Also, show all the checks in the subresults table. Do not hide them by
default as it's done with general result checks.
  • Loading branch information
seberm authored and happz committed Aug 27, 2024
1 parent 2faebfd commit ef7c14e
Show file tree
Hide file tree
Showing 5 changed files with 236 additions and 12 deletions.
91 changes: 91 additions & 0 deletions tests/report/html/data/faked-subresults-results.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
- name: /test/subresults
result: pass
note:
log:
- data/guest/default-0/test/subresults-1/output.txt
start-time: '2024-08-26T12:12:08.923924+00:00'
end-time: '2024-08-26T12:12:08.942201+00:00'
duration: 00:00:00
serial-number: 1
fmf-id:
name: /test/subresults
context: {}
ids:
id:
extra-nitrate:
extra-task:
guest:
name: default-0
role:
__class__:
module: tmt.result
name: ResultGuestData
subresult:
- name: /test/subresults/good
result: pass
end-time: "2024-07-17T14:16:28.735039+00:00"
__class__:
module: tmt.result
name: SubResult
- name: /test/subresults/fail
result: fail
end-time: "2024-07-17T14:16:28.739501+00:00"
__class__:
module: tmt.result
name: SubResult
- name: /test/subresults/weird
result: warn
end-time: "2024-07-17T14:16:28.743959+00:00"
__class__:
module: tmt.result
name: SubResult
check:
- name: dmesg
result: skip
note:
log: []
start-time: '2024-07-22T10:34:41.135249+00:00'
end-time: '2024-07-22T10:34:41.135279+00:00'
duration: 00:00:00
event: before-test
__class__:
module: tmt.result
name: CheckSubResult
- name: dmesg
result: skip
note:
log: []
start-time: '2024-07-22T10:34:41.393797+00:00'
end-time: '2024-07-22T10:34:41.393819+00:00'
duration: 00:00:00
event: after-test
__class__:
module: tmt.result
name: CheckSubResult
check:
- name: avc
result: skip
note:
log: []
start-time: '2024-07-22T10:34:41.135249+00:00'
end-time: '2024-07-22T10:34:41.135279+00:00'
duration: 00:00:00
event: before-test
__class__:
module: tmt.result
name: CheckSubResult
- name: avc
result: skip
note:
log: []
start-time: '2024-07-22T10:34:41.393797+00:00'
end-time: '2024-07-22T10:34:41.393819+00:00'
duration: 00:00:00
event: after-test
__class__:
module: tmt.result
name: CheckSubResult
data-path: data/guest/default-0/test/subresults-1/data
__class__:
module: tmt.result
name: Result
3 changes: 3 additions & 0 deletions tests/report/html/data/main.fmf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
summary: Run command 'false' but report pass
test: 'false'
result: xfail
/subresults:
summary: Fake the subresults data and print them into final report
test: 'true'

# Special plan to introduce more than one guest, for verification of --display-guest.
# Disabled by default, but enabled in the corresponding test by a magic of context.
Expand Down
24 changes: 23 additions & 1 deletion tests/report/html/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ rlJournalStart
for option in "" "--absolute-paths"; do
rlPhaseStartTest "Check status (${option:-relative paths})"
rlRun -s "tmt run -av --scratch --id $run_dir report -h html $option 2>&1 >/dev/null | tee output" 2
rlAssertGrep "summary: 2 tests passed, 1 test failed and 2 errors" $rlRun_LOG -F
rlAssertGrep "summary: 3 tests passed, 1 test failed and 2 errors" $rlRun_LOG -F

# Path of the generated file should be shown and the page should exist
rlAssertGrep "output: .*/index.html" $rlRun_LOG
Expand Down Expand Up @@ -89,7 +89,29 @@ rlJournalStart
rlAssertNotGrep "<td class=\"guest\">default-0</td>" "$tmp/plan/report/default-0/index.html"
rlPhaseEnd


# Subresults phase with faked results.yaml data
rlPhaseStartTest "Check the subresults and their checks"
rlRun -s "tmt run -av --scratch --id $tmp plan -n plan test -n subresults report -h html"
rlRun "cp -r faked-subresults-results.yaml $tmp/plan/execute/results.yaml" 0 "Faking the execute/results.yaml with subresult data"
rlRun -s "tmt run --last --id $tmp plan -n plan test -n subresult report -h html -v"

# Subresults and their checks
rlAssertGrep '<td class="name">/test/subresults</td>' "$tmp/plan/report/default-0/index.html"
rlAssertGrep 'subresults&nbsp;\[[+]\]</button>' "$tmp/plan/report/default-0/index.html"
rlAssertGrep '<h3>Subresults</h3>' "$tmp/plan/report/default-0/index.html"
rlAssertGrep '<td class="name">/test/subresults/good</td>' "$tmp/plan/report/default-0/index.html"
rlAssertGrep '<td class="name">/test/subresults/fail</td>' "$tmp/plan/report/default-0/index.html"
rlAssertGrep '<tr class="subresult-check" id="subresult-check-3">' "$tmp/plan/report/default-0/index.html"
rlAssertGrep '<td class="name">dmesg (before-test)</td>' "$tmp/plan/report/default-0/index.html"

# Global result checks
rlAssertGrep 'checks&nbsp;\[[+]\]</button>' "$tmp/plan/report/default-0/index.html"
rlAssertGrep '<td class="name">avc (before-test)</td>' "$tmp/plan/report/default-0/index.html"
rlPhaseEnd

rlPhaseStartCleanup
rlRun "rm output"
rlRun "popd"
rlRun "rm -rf $tmp"
rlPhaseEnd
Expand Down
6 changes: 6 additions & 0 deletions tmt/steps/report/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import webbrowser
from typing import Optional

from jinja2 import select_autoescape

import tmt
import tmt.log
import tmt.options
Expand Down Expand Up @@ -67,6 +69,10 @@ def go(self, *, logger: Optional[tmt.log.Logger] = None) -> None:
# Prepare the template
environment = tmt.utils.templates.default_template_environment()

# Explicitly enable the autoescape because it's disabled by default by TMT
# (see /teemtee/tmt/issues/2873 for more info.
environment.autoescape = select_autoescape(enabled_extensions=('html.j2'))

if self.data.absolute_paths:
def _linkable_path(path: str) -> str:
return str(Path(path).absolute())
Expand Down
124 changes: 113 additions & 11 deletions tmt/steps/report/html/template.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@
margin: 30px 7px 0px 7px;
}
#results table.check,
#results table.subresult-check,
#results table.subresult {
width: 100%;
background: #dadada;
}
#results, #filters {
border-spacing: 7px;
}
Expand Down Expand Up @@ -89,15 +96,22 @@
color: #c00;
}
#results tr.check {
#results tr.check,
/* #results tr.subresult-check, // Do not hide subresult checks by default */
#results tr.subresult {
font-size: 90%;
display: none;
}
#results tr.check td.result {
#results tr.check td.result,
#results tr.subresult-check td.result,
#results tr.subresult td.result {
width: 5ex;
}
#results tr.check td.name {
#results tr.check td.name,
#results tr.subresult-check td.name,
#results tr.subresult td.name {
color: #888;
padding-left: 5ex;
width: 22ex;
Expand Down Expand Up @@ -171,6 +185,18 @@
filter_values["note"] = e.value;
update_rows();
}
// toggle the visibility of a given table row
function toggle_row_visibility(button, e) {
const element = document.getElementById(e);
if (element.style.display === 'none' || element.style.display === '') {
element.style.display = 'table-row';
button.textContent = button.textContent.replace('+', '-');
} else {
element.style.display = 'none';
button.textContent = button.textContent.replace('-', '+');
}
}
</script>
</head>

Expand Down Expand Up @@ -218,11 +244,13 @@ Context:
<tr>
<th>Result</th>
<th>Test</th>
{% if display_guest %}
{% if display_guest %}
<th>Guest</th>
{% endif %}
{% endif %}
<th>Logs</th>
<th>Data</th>
<th>Note</th>
<th>Actions</th>
</tr>
</thead>
{% for result in results %}
Expand All @@ -238,21 +266,37 @@ Context:
{% endfor %}
</td>
<td class="data"><a href="{{ base_dir | linkable_path | urlencode }}/{{ result.data_path | urlencode }}">data</a></td>
{% if result.note %}
<td class="note">{{ result.note | e }}</td>
{% endif %}
<td class="note">{% if result.note %}{{ result.note | e }}{% else %}-{% endif %}</td>
<td class="action">
{% if result.check %}
<button onclick="toggle_row_visibility(this, 'check-{{ loop.index }}')" title="Show / hide checks">checks&nbsp;[+]</button>
{% endif %}
{% if result.subresult %}
<button onclick="toggle_row_visibility(this, 'subresult-{{ loop.index }}')" title="Show / hide subresults">subresults&nbsp;[+]</button>
{% endif %}
</td>
</tr>
{% if result.check %}
<tr class="check">
<td colspan="4">
<table>
<tr class="check" id="check-{{ loop.index }}">
<td colspan="{% if display_guest %}7{% else %}6{% endif %}">
<h3>Checks</h3>
<table class="check">
<thead>
<tr>
<th>Result</th>
<th>Name</th>
<th>Logs</th>
</tr>
</thead>
{% for check in result.check %}
<tr>
<td class="result {{ check.result.value | e }}">{{ check.result.value | e }}</td>
<td class="name">{{ check.name | e }} ({{ check.event.value }})</td>
<td class="log">
{% for log in check.log %}
<a href="{{ base_dir | linkable_path | urlencode }}/{{ log | urlencode }}">{{ log | basename }}</a>
{% else %}
-
{% endfor %}
</td>
</tr>
Expand All @@ -261,6 +305,64 @@ Context:
</td>
</tr>
{% endif %}
{% if result.subresult %}
<tr class="subresult" id="subresult-{{ loop.index }}">
<td colspan="{% if display_guest %}7{% else %}6{% endif %}">
<h3>Subresults</h3>
<table class="subresult">
<thead>
<tr>
<th>Result</th>
<th>Name</th>
<th>Logs</th>
</tr>
</thead>
{% for subresult in result.subresult %}
<tr>
<td class="result {{ subresult.result.value | e }}">{{ subresult.result.value | e }}</td>
<td class="name">{{ subresult.name | e }}</td>
<td class="log">
{% for log in subresult.log %}
<a href="{{ base_dir | linkable_path | urlencode }}/{{ log | urlencode }}">{{ log | basename }}</a>
{% else %}
-
{% endfor %}
</td>
</tr>
{% if subresult.check %}
<tr class="subresult-check" id="subresult-check-{{ loop.index }}">
<td colspan="3">
<h3>Subresult checks</h3>
<table class="check">
<thead>
<tr>
<th>Result</th>
<th>Name</th>
<th>Logs</th>
</tr>
</thead>
{% for check in subresult.check %}
<tr>
<td class="result {{ check.result.value | e }}">{{ check.result.value | e }}</td>
<td class="name">{{ check.name | e }} ({{ check.event.value }})</td>
<td class="log">
{% for log in check.log %}
<a href="{{ base_dir | linkable_path | urlencode }}/{{ log | urlencode }}">{{ log | basename }}</a>
{% else %}
-
{% endfor %}
</td>
</tr>
{% endfor %}
</table>
</td>
</tr>
{% endif %}
{% endfor %}
</table>
</td>
</tr>
{% endif %}
{% endfor %}
</table>
{% else %}
Expand Down

0 comments on commit ef7c14e

Please sign in to comment.