Skip to content

Commit

Permalink
Add percent and aggregate sorting on coverage report columns.
Browse files Browse the repository at this point in the history
R=mmoroz@chromium.org,liaoyuke@chromium.org

Change-Id: Icf8cc7df8b21e5a992d64f13c0cce1ec3acaecd0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1584991
Reviewed-by: Max Moroz <mmoroz@chromium.org>
Commit-Queue: Abhishek Arya <inferno@chromium.org>
Cr-Commit-Position: refs/heads/master@{#654229}
  • Loading branch information
inferno-chromium authored and Commit Bot committed Apr 25, 2019
1 parent c8262ed commit a88e7cd
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 9 deletions.
65 changes: 57 additions & 8 deletions tools/code_coverage/html_templates/table.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,18 @@
<thead>
<tr>
<th class="column-entry-bold">{{ table_entry_type }}</th>
<th class="column-entry-bold" title=
<th class="column-entry-bold" onclick="sortTable(SORT_COLUMN.LINE)" title=
"Line coverage is the percentage of code lines which have been executed at least once. Only executable lines within function bodies are considered to be code lines.">
Line Coverage</th>
<th class="column-entry-bold" title=
Line Coverage
</th>
<th class="column-entry-bold" onclick="sortTable(SORT_COLUMN.FUNCTION)" title=
"Function coverage is the percentage of functions which have been executed at least once. A function is considered to be executed if any of its instantiations are executed.">
Function Coverage</th>
<th class="column-entry-bold" title=
Function Coverage
</th>
<th class="column-entry-bold" onclick="sortTable(SORT_COLUMN.REGION)" title=
"Region coverage is the percentage of code regions which have been executed at least once. A code region may span multiple lines (e.g in a large function body with no control flow). However, it's also possible for a single line to contain multiple code regions (e.g in 'return x || y &amp;&amp; z').">
Region Coverage</th>
Region Coverage
</th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -51,8 +54,54 @@
</tfoot>
{% endif %}
</table>
{% if table_entry_type == "Component" %}

<script>
const SORT_COLUMN = {
LINE: 2,
FUNCTION: 3,
REGION: 4,
}

const SORT_TYPES = {
UNSET: -1,
PERCENT: 0,
AGGREGATE: 1,
}

var SORT_ORDER = {
[SORT_COLUMN.LINE]: [SORT_TYPES.UNSET],
[SORT_COLUMN.FUNCTION]: [SORT_TYPES.UNSET],
[SORT_COLUMN.REGION]: [SORT_TYPES.UNSET],
}

function sortTable(columnNumber) {
SORT_ORDER[columnNumber] = ++SORT_ORDER[columnNumber] % 2;

let columnSortOrder = SORT_ORDER[columnNumber];
let tbody = document.getElementsByTagName("tbody")[0];

[].slice.call(tbody.rows).sort(function(a, b) {
let aColumn = a.cells[columnNumber-1].textContent;
let bColumn = b.cells[columnNumber-1].textContent;

let aColumnCompare, bColumnCompare;
if (columnSortOrder == SORT_TYPES.PERCENT) {
aColumnCompare = parseFloat(/([0-9.]+)%/.exec(aColumn)[1]);
bColumnCompare = parseFloat(/([0-9.]+)%/.exec(bColumn)[1]);
} else {
aColumnCompare = parseInt(/\/(\d+)/.exec(aColumn)[1]);
bColumnCompare = parseInt(/\/(\d+)/.exec(bColumn)[1]);
}

return (
aColumnCompare < bColumnCompare ? -1:
aColumnCompare > bColumnCompare ? 1 : 0);
}).forEach(function(value, index) {
tbody.appendChild(value);
});
}

{% if table_entry_type == "Component" %}
function filterInputChanged() {
let filter = document.getElementById("filter");
let filterString = filter.value;
Expand Down Expand Up @@ -104,5 +153,5 @@

var filter = document.getElementById("filter");
filter.onchange = filter.onkeyup = filterInputChanged;
</script>
{% endif %}
</script>
2 changes: 1 addition & 1 deletion tools/code_coverage/run_fuzz_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def _RunWithTimeout(cmd, timeout):
# SIGINT, suppress it here to prevent interrupting the script itself.
pass

output, error = runner.communicate()
runner.communicate()

logging.info('Finished running the fuzz target.')

Expand Down

0 comments on commit a88e7cd

Please sign in to comment.