UnityChipForXiangShan/documents/layouts/shortcodes/list-dut-test-status.html

306 lines
9.8 KiB
HTML

<style>
.div-dut-test-report {
all:none;
display: flex;
align-items: center;
text-align: center;
justify-content: center;
width: 100%;
margin: 0 auto;
}
.div-dut-test-report tbody {
--bs-table-striped-bg: white;
}
.div-dut-test-report .td-name {
text-align: left;
}
.div-dut-test-report .td-index {
text-align: center;
}
.div-dut-test-report table {
width: 90%;
margin: 0 auto;
}
.div-dut-test-report td {
text-align: right;
}
.div-dut-test-report .td-desc{
text-align: left;
}
.div-dut-test-report th {
text-align: right;
}
.div-dut-test-report tr {
border-bottom: 1px solid #ddd;
}
.em-red {
color: yellow;
font-weight: bold;
background-color: rgb(247, 36, 152);
border-radius: 2px;
}
.em-orange {
color: white;
font-weight: bold;
background-color: orange;
border-radius: 2px;
}
.em-green {
font-weight: bold;
color: yellow;
background-color: green;
border-radius: 2px;
}
.modal-linecov {
display: none; /* 默认隐藏 */
position: absolute; /* 使用绝对定位 */
z-index: 1;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0,0.4);
}
.modal-content {
background-color: #fefefe;
padding: 20px;
border: 1px solid #888;
width: 300px;
position: absolute;
}
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}
table .td-desc .tooltiptext {
visibility: hidden;
width: 250px;
background-color: rgb(87, 87, 87);
color: #fff1f1;
text-align: center;
border-radius: 6px;
padding: 5px 0;
/* Position the tooltip */
position: absolute;
z-index: 1;
}
.td-desc:hover .tooltiptext{
visibility: visible;
}
</style>
<div id="line-file-modal" class="modal-linecov">
<div class="modal-content" id="linecov-text">
</div>
</div>
<div class="div-dut-test-report">
<table id="dut-test-items" align="center" class="td-initial">
</table>
</div>
<script>
function closeLineCovModal() {
$("#line-file-modal").hide();
}
$(window).click(function(event) {
var modal = $("#line-file-modal");
if (! modal.is(":hidden")) {
if (! $(event.target).closest(".modal-content").length){
closeLineCovModal();
}
}
});
function updateDUTestStatus(data_url){
$.getJSON(data_url, function (data) {
$("#dut-test-items").html(
" <tbody align=\"center\">\
<tr>\
<th class=\"td-index\">Index</th>\
<th class=\"td-name\">Name</th>\
<th class=\"td-desc\">Description </th> \
<th>Document</th>\
<th>&nbsp;&nbsp;Cases</th>\
<th>&nbsp;&nbsp;&nbsp;Fail</th>\
<th>&nbsp;&nbsp;&nbsp;SKip</th>\
<th>CsRate (%)</th>\
<th>Checks\
<th>Fail\
<th>CkRate (%)</th>\
<th>Lines</th>\
<th>CvRate (%)</th>\
</tr>\
</tbody>");
var prefix = data.tree.meta.paths;
var index = 1;
function calcRateColor(rate){
var color = "";
if(rate < data.config.rate_low){
color = "red";
} else if(rate < data.config.rate_middle){
color = "orange";
} else if(rate > data.config.rate_high){
color = "green";
}
return "<em class=\"em-"+color+"\">" + rate + "</em>";
}
function calcRate(a, b){
if(b === 0){
return 0;
}
return calcRateColor((a / b * 100).toFixed(2));
}
function redItem(item){
if (item > 0) {
return "<em class=\"em-red\">" + item + "</em>";
}
return item;
}
function getDocUrl(url){
if(url){
return "<a href=\"" + url + "\" target=\"_blank\">Detail</a>";
}
return "-";
}
function getLinFileUrl(paths){
var txt = ""
var meta = data.extend[paths]
if (!meta) return txt;
meta.target_line_coverage_files.forEach(f=> {
var url = null;
if(!f.includes("not found")){
meta.matched_line_coverage_files.forEach(u=> {
if(u[0].includes(f)){
var base_url = data_url.split("/").slice(0, -1).join("/");
txt += "<li><a href=\"" + base_url + u[0] + "\" target=\"_blank\">" + f + "</a> <em style=\"float: right;\"> ("
+u[1]+"/"+u[2]+")<em> </li>";
}else{
console.log("not found: " + f + " in " + u);
}
});
}else{
txt += "<li>" + f + "</li>";
}
});
return $("#linecov-text").html(txt);
}
function openLineCovModal(event, paths) {
event.preventDefault();
event.stopPropagation();
closeLineCovModal();
getLinFileUrl(paths);
var modal = $("#line-file-modal")
var text = $("#linecov-text")
modal.css({
left: event.pageX - text.width()/2 + "px",
top: event.pageY - text.height()/2 + "px"
});
modal.show();
}
window.openLineCovModal = openLineCovModal;
function getLineCovUrl(paths, hints, total){
var text = hints + "/" + total;
if(total > 0){
return "<a href=\"\" onclick=\"openLineCovModal(event, '" + paths + "')\">" + text + "</a>";
}
return text;
}
function getCaseUrl(paths, pass, total){
if (total < 1){
return "0/0";
}
var url = data_url.split("/").slice(0, -1).join("/") + "?";
var K = "K=details,file,,,span," + paths.split("/").slice(2, -1).join("/");
return "<a href=\""+ url + K +"\" target=\"_blank\">" + pass + "/" + total + "</a>";
}
function getCaseFailSkipUrl(paths, fail, skip){
if (fail < 1){
if(skip){
return "0"
}
return redItem(fail);
}
var url = data_url.split("/").slice(0, -1).join("/") + "?";
var key = skip ? "skipped" : "failed";
var K = "K=details,file,span,"+key+",span," + paths.split("/").slice(2, -1).join("/");
var text = skip? fail: redItem(fail);
return "<a href=\""+ url + K +"\" target=\"_blank\">" + text + "</a>";
}
function getFuncovUrl(paths, cover, total){
if (total < 1){
return "0/0";
}
var group_name = paths.split("/").slice(2, -1).join(".")
var url = data_url.split("/").slice(0, -1).join("/") + "?";
var K_case = "ShowFunCov=1&K=li,group_name,,,span," + group_name + "&K=ul,group_name,,,span,"+ group_name;
return "<a href=\""+ url + K_case +"\" target=\"_blank\">" + cover + "/" + total + "</a>";
}
function getFuncovFailUrl(paths, cover, total){
if (total == cover || total < 1){
return "0";
}
var group_name = paths.split("/").slice(2, -1).join(".")
var url = data_url.split("/").slice(0, -1).join("/") + "?";
var K_case = "ShowFunCov=1&K=li,group_name,,,span," + group_name + "&K=ul,group_name,,,span,"+ group_name;
var K_fail = K_case + "&K=li,point_name,,,span,Failed&K=ul,grou_name,,,ul,failed";
return "<a href=\""+ url + K_fail +"\" target=\"_blank\">" + redItem(total - cover) + "</a>";
}
function getDescComp(desc) {
initial = "<td class=\"td-desc\">";
end = "</td>"
scale = 15
if (desc.length <= scale){
return initial + desc + end
}
emit_desc = desc.substr(0, scale) + "..."
tooltip_res = "<div class=\"tooltiptext\">" + desc + "</div>"
return initial + emit_desc + tooltip_res + end
}
function traverse(node) {
if (!node.children || node.children.length === 0) {
var meta = node.meta
var desc = node.desc
console.log("meta infos!")
console.log(node)
$("#dut-test-items").html($("#dut-test-items").html() +
"<tr><td class=\"td-index\">" + index + "</td>" +
"<td class=\"td-name\">" + meta.paths.replace(prefix + "/",
"").replaceAll("/", ".") + "</td>" +
getDescComp(desc) +
"<td>" + getDocUrl(meta.doc_url) + "</td>" +
"<td>" + getCaseUrl(meta.paths, meta.cases.pass, meta.cases.total) + "</td>" +
"<td>" + getCaseFailSkipUrl(meta.paths, meta.cases.fail, false) + "</td>" +
"<td>" + getCaseFailSkipUrl(meta.paths, meta.cases.skip, true) + "</td>" +
"<td>" + calcRate(meta.cases.pass, meta.cases.total) + "</td>" +
"<td>" + getFuncovUrl(meta.paths, meta.functions.cover, meta.functions.total) + "</td>" +
"<td>" + getFuncovFailUrl(meta.paths, meta.functions.cover, meta.functions.total) + "</td>" +
"<td>" + calcRate(meta.functions.cover, meta.functions.total) + "</td>" +
"<td>" + getLineCovUrl(meta.paths, meta.lines.cover, meta.lines.total) + "</td>" +
"<td>" + calcRate(meta.lines.cover, meta.lines.total) + "</td>" +
"</tr>"
);
index++;
} else {
$.each(node.children, function(index, child) {
traverse(child);
});
}
}
traverse(data.tree);
});
}
</script>