# -*- coding: utf-8 -*- # $Id: wuitestresult.py $ """ Test Manager WUI - Test Results. """ __copyright__ = \ """ Copyright (C) 2012-2023 Oracle and/or its affiliates. This file is part of VirtualBox base platform packages, as available from https://www.virtualbox.org. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, in version 3 of the License. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, see . The contents of this file may alternatively be used under the terms of the Common Development and Distribution License Version 1.0 (CDDL), a copy of it is provided in the "COPYING.CDDL" file included in the VirtualBox distribution, in which case the provisions of the CDDL are applicable instead of those of the GPL. You may elect to license modified versions of this file under the terms and conditions of either the GPL or the CDDL or both. SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0 """ __version__ = "$Revision: 155244 $" # Python imports. import datetime; # Validation Kit imports. from testmanager.webui.wuicontentbase import WuiContentBase, WuiListContentBase, WuiHtmlBase, WuiTmLink, WuiLinkBase, \ WuiSvnLink, WuiSvnLinkWithTooltip, WuiBuildLogLink, WuiRawHtml, \ WuiHtmlKeeper; from testmanager.webui.wuimain import WuiMain; from testmanager.webui.wuihlpform import WuiHlpForm; from testmanager.webui.wuiadminfailurereason import WuiFailureReasonAddLink, WuiFailureReasonDetailsLink; from testmanager.webui.wuitestresultfailure import WuiTestResultFailureDetailsLink; from testmanager.core.failurereason import FailureReasonData, FailureReasonLogic; from testmanager.core.report import ReportGraphModel, ReportModelBase; from testmanager.core.testbox import TestBoxData; from testmanager.core.testcase import TestCaseData; from testmanager.core.testset import TestSetData; from testmanager.core.testgroup import TestGroupData; from testmanager.core.testresultfailures import TestResultFailureData; from testmanager.core.build import BuildData; from testmanager.core import db; from testmanager import config; from common import webutils, utils; class WuiTestSetLink(WuiTmLink): """ Test set link. """ def __init__(self, idTestSet, sName = WuiContentBase.ksShortDetailsLink, fBracketed = False): WuiTmLink.__init__(self, sName, WuiMain.ksScriptName, { WuiMain.ksParamAction: WuiMain.ksActionTestResultDetails, TestSetData.ksParam_idTestSet: idTestSet, }, fBracketed = fBracketed); self.idTestSet = idTestSet; class WuiTestResultsForSomethingLink(WuiTmLink): """ Test results link for a grouping. """ def __init__(self, sGroupedBy, idGroupMember, sName = WuiContentBase.ksShortTestResultsLink, dExtraParams = None, fBracketed = False): dParams = dict(dExtraParams) if dExtraParams else {}; dParams[WuiMain.ksParamAction] = sGroupedBy; dParams[WuiMain.ksParamGroupMemberId] = idGroupMember; WuiTmLink.__init__(self, sName, WuiMain.ksScriptName, dParams, fBracketed = fBracketed); class WuiTestResultsForTestBoxLink(WuiTestResultsForSomethingLink): """ Test results link for a given testbox. """ def __init__(self, idTestBox, sName = WuiContentBase.ksShortTestResultsLink, dExtraParams = None, fBracketed = False): WuiTestResultsForSomethingLink.__init__(self, WuiMain.ksActionResultsGroupedByTestBox, idTestBox, sName = sName, dExtraParams = dExtraParams, fBracketed = fBracketed); class WuiTestResultsForTestCaseLink(WuiTestResultsForSomethingLink): """ Test results link for a given testcase. """ def __init__(self, idTestCase, sName = WuiContentBase.ksShortTestResultsLink, dExtraParams = None, fBracketed = False): WuiTestResultsForSomethingLink.__init__(self, WuiMain.ksActionResultsGroupedByTestCase, idTestCase, sName = sName, dExtraParams = dExtraParams, fBracketed = fBracketed); class WuiTestResultsForBuildRevLink(WuiTestResultsForSomethingLink): """ Test results link for a given build revision. """ def __init__(self, iRevision, sName = WuiContentBase.ksShortTestResultsLink, dExtraParams = None, fBracketed = False): WuiTestResultsForSomethingLink.__init__(self, WuiMain.ksActionResultsGroupedByBuildRev, iRevision, sName = sName, dExtraParams = dExtraParams, fBracketed = fBracketed); class WuiTestResult(WuiContentBase): """Display test case result""" def __init__(self, fnDPrint = None, oDisp = None): WuiContentBase.__init__(self, fnDPrint = fnDPrint, oDisp = oDisp); # Cyclic import hacks. from testmanager.webui.wuiadmin import WuiAdmin; self.oWuiAdmin = WuiAdmin; def _toHtml(self, oObject): """Translate some object to HTML.""" if isinstance(oObject, WuiHtmlBase): return oObject.toHtml(); if db.isDbTimestamp(oObject): return webutils.escapeElem(self.formatTsShort(oObject)); if db.isDbInterval(oObject): return webutils.escapeElem(self.formatIntervalShort(oObject)); if utils.isString(oObject): return webutils.escapeElem(oObject); return webutils.escapeElem(str(oObject)); def _htmlTable(self, aoTableContent): """Generate HTML code for table""" sHtml = u' \n'; for aoSubRows in aoTableContent: if not aoSubRows: continue; # Can happen if there is no testsuit. oCaption = aoSubRows[0]; sHtml += u' \n' \ u' \n' \ u' \n' \ u' \n' \ % (self._toHtml(oCaption),); iRow = 0; for aoRow in aoSubRows[1:]: iRow += 1; sHtml += u' \n' % ('tmodd' if iRow & 1 else 'tmeven',); if len(aoRow) == 1: sHtml += u' \n' \ % (self._toHtml(aoRow[0]),); else: sHtml += u' \n' % (webutils.escapeElem(aoRow[0]),); if len(aoRow) > 2: sHtml += u' \n' % (aoRow[2](aoRow[1]),); else: sHtml += u' \n' % (self._toHtml(aoRow[1]),); sHtml += u' \n'; sHtml += u'
%s
%s%s%s%s
\n'; return sHtml def _highlightStatus(self, sStatus): """Return sStatus string surrounded by HTML highlight code """ sTmp = '%s' \ % ('red' if sStatus == 'failure' else 'green', webutils.escapeElem(sStatus.upper())) return sTmp def _anchorAndAppendBinaries(self, sBinaries, aoRows): """ Formats each binary (if any) into a row with a download link. """ if sBinaries is not None: for sBinary in sBinaries.split(','): if not webutils.hasSchema(sBinary): sBinary = config.g_ksBuildBinUrlPrefix + sBinary; aoRows.append([WuiLinkBase(webutils.getFilename(sBinary), sBinary, fBracketed = False),]); return aoRows; def _formatEventTimestampHtml(self, tsEvent, tsLog, idEvent, oTestSet): """ Formats an event timestamp with a main log link. """ tsEvent = db.dbTimestampToZuluDatetime(tsEvent); #sFormattedTimestamp = u'%04u\u2011%02u\u2011%02u\u00a0%02u:%02u:%02uZ' \ # % ( tsEvent.year, tsEvent.month, tsEvent.day, # tsEvent.hour, tsEvent.minute, tsEvent.second,); sFormattedTimestamp = u'%02u:%02u:%02uZ' \ % ( tsEvent.hour, tsEvent.minute, tsEvent.second,); sTitle = u'#%u - %04u\u2011%02u\u2011%02u\u00a0%02u:%02u:%02u.%06uZ' \ % ( idEvent, tsEvent.year, tsEvent.month, tsEvent.day, tsEvent.hour, tsEvent.minute, tsEvent.second, tsEvent.microsecond, ); tsLog = db.dbTimestampToZuluDatetime(tsLog); sFragment = u'%02u_%02u_%02u_%06u' % ( tsLog.hour, tsLog.minute, tsLog.second, tsLog.microsecond); return WuiTmLink(sFormattedTimestamp, '', { WuiMain.ksParamAction: WuiMain.ksActionViewLog, WuiMain.ksParamLogSetId: oTestSet.idTestSet, }, sFragmentId = sFragment, sTitle = sTitle, fBracketed = False, ).toHtml(); def _recursivelyGenerateEvents(self, oTestResult, sParentName, sLineage, iRow, iFailure, oTestSet, iDepth): # pylint: disable=too-many-locals """ Recursively generate event table rows for the result set. oTestResult is an object of the type TestResultDataEx. """ # Hack: Replace empty outer test result name with (pretty) command line. if iRow == 1: sName = ''; sDisplayName = sParentName; else: sName = oTestResult.sName if sParentName == '' else '%s, %s' % (sParentName, oTestResult.sName,); sDisplayName = webutils.escapeElem(sName); # Format error count. sErrCnt = ''; if oTestResult.cErrors > 0: sErrCnt = ' (1 error)' if oTestResult.cErrors == 1 else ' (%d errors)' % oTestResult.cErrors; # Format bits for adding or editing the failure reason. Level 0 is handled at the top of the page. sChangeReason = ''; if oTestResult.cErrors > 0 and iDepth > 0 and self._oDisp is not None and not self._oDisp.isReadOnlyUser(): dTmp = { self._oDisp.ksParamAction: self._oDisp.ksActionTestResultFailureAdd if oTestResult.oReason is None else self._oDisp.ksActionTestResultFailureEdit, TestResultFailureData.ksParam_idTestResult: oTestResult.idTestResult, }; sChangeReason = ' %s ' \ % ( webutils.encodeUrlParams(dTmp), WuiContentBase.ksShortEditLinkHtml ); # Format the include in graph checkboxes. sLineage += ':%u' % (oTestResult.idStrName,); sResultGraph = '' \ % (WuiMain.ksParamReportSubjectIds, ReportGraphModel.ksTypeResult, sLineage,); sElapsedGraph = ''; if oTestResult.tsElapsed is not None: sElapsedGraph = '' \ % ( WuiMain.ksParamReportSubjectIds, ReportGraphModel.ksTypeElapsed, sLineage); if not oTestResult.aoChildren \ and len(oTestResult.aoValues) + len(oTestResult.aoMsgs) + len(oTestResult.aoFiles) == 0: # Leaf - single row. tsEvent = oTestResult.tsCreated; if oTestResult.tsElapsed is not None: tsEvent += oTestResult.tsElapsed; sHtml = ' \n' \ ' %s\n' \ ' %s\n' \ ' %s\n' \ ' %s\n' \ ' %s%s%s\n' \ ' %s\n' \ ' \n' \ % ( 'tmodd' if iRow & 1 else 'tmeven', iDepth, oTestResult.enmStatus, oTestResult.idTestResult, oTestResult.idTestResult, self._formatEventTimestampHtml(tsEvent, oTestResult.tsCreated, oTestResult.idTestResult, oTestSet), sElapsedGraph, webutils.escapeElem(self.formatIntervalShort(oTestResult.tsElapsed)) if oTestResult.tsElapsed is not None else '', sDisplayName, ' id="failure-%u"' % (iFailure,) if oTestResult.isFailure() else '', webutils.escapeElem(oTestResult.enmStatus), webutils.escapeElem(sErrCnt), sChangeReason if oTestResult.oReason is None else '', sResultGraph ); iRow += 1; else: # Multiple rows. sHtml = ' \n' \ ' %s\n' \ ' \n' \ ' \n' \ ' %s\n' \ ' %s\n' \ ' \n' \ ' \n' \ % ( 'tmodd' if iRow & 1 else 'tmeven', iDepth, self._formatEventTimestampHtml(oTestResult.tsCreated, oTestResult.tsCreated, oTestResult.idTestResult, oTestSet), sDisplayName, 'running' if oTestResult.tsElapsed is None else '', ); iRow += 1; # Depth. Check if our error count is just reflecting the one of our children. cErrorsBelow = 0; for oChild in oTestResult.aoChildren: (sChildHtml, iRow, iFailure) = self._recursivelyGenerateEvents(oChild, sName, sLineage, iRow, iFailure, oTestSet, iDepth + 1); sHtml += sChildHtml; cErrorsBelow += oChild.cErrors; # Messages. for oMsg in oTestResult.aoMsgs: sHtml += ' \n' \ ' %s\n' \ ' \n' \ ' \n' \ ' %s: %s\n' \ ' \n' \ ' \n' \ % ( 'tmodd' if iRow & 1 else 'tmeven', iDepth, self._formatEventTimestampHtml(oMsg.tsCreated, oMsg.tsCreated, oMsg.idTestResultMsg, oTestSet), webutils.escapeElem(oMsg.enmLevel), webutils.escapeElem(oMsg.sMsg), ); iRow += 1; # Values. for oValue in oTestResult.aoValues: sHtml += ' \n' \ ' %s\n' \ ' \n' \ ' \n' \ ' %s\n' \ ' %s\n' \ ' %s\n' \ ' \n' \ ' \n' \ % ( 'tmodd' if iRow & 1 else 'tmeven', iDepth, self._formatEventTimestampHtml(oValue.tsCreated, oValue.tsCreated, oValue.idTestResultValue, oTestSet), webutils.escapeElem(oValue.sName), utils.formatNumber(oValue.lValue).replace(' ', ' '), webutils.escapeElem(oValue.sUnit), WuiMain.ksParamReportSubjectIds, ReportGraphModel.ksTypeValue, sLineage, oValue.idStrName, ); iRow += 1; # Files. for oFile in oTestResult.aoFiles: if oFile.sMime in [ 'text/plain', ]: aoLinks = [ WuiTmLink('%s (%s)' % (oFile.sFile, oFile.sKind), '', { self._oDisp.ksParamAction: self._oDisp.ksActionViewLog, self._oDisp.ksParamLogSetId: oTestSet.idTestSet, self._oDisp.ksParamLogFileId: oFile.idTestResultFile, }, sTitle = oFile.sDescription), WuiTmLink('View Raw', '', { self._oDisp.ksParamAction: self._oDisp.ksActionGetFile, self._oDisp.ksParamGetFileSetId: oTestSet.idTestSet, self._oDisp.ksParamGetFileId: oFile.idTestResultFile, self._oDisp.ksParamGetFileDownloadIt: False, }, sTitle = oFile.sDescription), ] else: aoLinks = [ WuiTmLink('%s (%s)' % (oFile.sFile, oFile.sKind), '', { self._oDisp.ksParamAction: self._oDisp.ksActionGetFile, self._oDisp.ksParamGetFileSetId: oTestSet.idTestSet, self._oDisp.ksParamGetFileId: oFile.idTestResultFile, self._oDisp.ksParamGetFileDownloadIt: False, }, sTitle = oFile.sDescription), ] aoLinks.append(WuiTmLink('Download', '', { self._oDisp.ksParamAction: self._oDisp.ksActionGetFile, self._oDisp.ksParamGetFileSetId: oTestSet.idTestSet, self._oDisp.ksParamGetFileId: oFile.idTestResultFile, self._oDisp.ksParamGetFileDownloadIt: True, }, sTitle = oFile.sDescription)); sHtml += ' \n' \ ' %s\n' \ ' \n' \ ' \n' \ ' %s\n' \ ' \n' \ ' \n' \ ' \n' \ ' \n' \ % ( 'tmodd' if iRow & 1 else 'tmeven', iDepth, self._formatEventTimestampHtml(oFile.tsCreated, oFile.tsCreated, oFile.idTestResultFile, oTestSet), '\n'.join(oLink.toHtml() for oLink in aoLinks),); iRow += 1; # Done? if oTestResult.tsElapsed is not None: tsEvent = oTestResult.tsCreated + oTestResult.tsElapsed; sHtml += ' \n' \ ' %s\n' \ ' %s\n' \ ' %s\n' \ ' %s\n' \ ' %s%s%s\n' \ ' %s\n' \ ' \n' \ % ( 'tmodd' if iRow & 1 else 'tmeven', iDepth, oTestResult.enmStatus, oTestResult.idTestResult, self._formatEventTimestampHtml(tsEvent, tsEvent, oTestResult.idTestResult, oTestSet), sElapsedGraph, webutils.escapeElem(self.formatIntervalShort(oTestResult.tsElapsed)), sDisplayName, ' id="failure-%u"' % (iFailure,) if oTestResult.isFailure() else '', webutils.escapeElem(oTestResult.enmStatus), webutils.escapeElem(sErrCnt), sChangeReason if cErrorsBelow < oTestResult.cErrors and oTestResult.oReason is None else '', sResultGraph); iRow += 1; # Failure reason. if oTestResult.oReason is not None: sReasonText = '%s / %s' % ( oTestResult.oReason.oFailureReason.oCategory.sShort, oTestResult.oReason.oFailureReason.sShort, ); sCommentHtml = ''; if oTestResult.oReason.sComment and oTestResult.oReason.sComment.strip(): sCommentHtml = '
' + webutils.escapeElem(oTestResult.oReason.sComment.strip()); sCommentHtml = sCommentHtml.replace('\n', '
'); sDetailedReason = ' %s' \ % ( webutils.encodeUrlParams({ self._oDisp.ksParamAction: self._oDisp.ksActionTestResultFailureDetails, TestResultFailureData.ksParam_idTestResult: oTestResult.idTestResult,}), WuiContentBase.ksShortDetailsLinkHtml,); sHtml += ' \n' \ ' %s\n' \ ' %s\n' \ ' %s%s%s%s\n' \ ' %s\n' \ ' \n' \ % ( 'tmodd' if iRow & 1 else 'tmeven', iDepth, webutils.escapeElem(self.formatTsShort(oTestResult.oReason.tsEffective)), oTestResult.oReason.oAuthor.sUsername, webutils.escapeElem(sReasonText), sDetailedReason, sChangeReason, sCommentHtml, 'todo'); iRow += 1; if oTestResult.isFailure(): iFailure += 1; return (sHtml, iRow, iFailure); def _generateMainReason(self, oTestResultTree, oTestSet): """ Generates the form for displaying and updating the main failure reason. oTestResultTree is an instance TestResultDataEx. oTestSet is an instance of TestSetData. """ _ = oTestSet; sHtml = ' '; if oTestResultTree.isFailure() or oTestResultTree.cErrors > 0: sHtml += '

Failure Reason:

\n'; oData = oTestResultTree.oReason; # We need the failure reasons for the combobox. aoFailureReasons = FailureReasonLogic(self._oDisp.getDb()).fetchForCombo('Test Sheriff, you figure out why!'); assert aoFailureReasons; # For now we'll use the standard form helper. sFormActionUrl = '%s?%s=%s' % ( self._oDisp.ksScriptName, self._oDisp.ksParamAction, WuiMain.ksActionTestResultFailureAddPost if oData is None else WuiMain.ksActionTestResultFailureEditPost ) fReadOnly = not self._oDisp or self._oDisp.isReadOnlyUser(); oForm = WuiHlpForm('failure-reason', sFormActionUrl, sOnSubmit = WuiHlpForm.ksOnSubmit_AddReturnToFieldWithCurrentUrl, fReadOnly = fReadOnly); oForm.addTextHidden(TestResultFailureData.ksParam_idTestResult, oTestResultTree.idTestResult); oForm.addTextHidden(TestResultFailureData.ksParam_idTestSet, oTestSet.idTestSet); if oData is not None: oForm.addComboBox(TestResultFailureData.ksParam_idFailureReason, oData.idFailureReason, 'Reason', aoFailureReasons, sPostHtml = u' ' + WuiFailureReasonDetailsLink(oData.idFailureReason).toHtml() + (u' ' + WuiFailureReasonAddLink('New', fBracketed = False).toHtml() if not fReadOnly else u'')); oForm.addMultilineText(TestResultFailureData.ksParam_sComment, oData.sComment, 'Comment') oForm.addNonText(u'%s (%s), %s' % ( oData.oAuthor.sUsername, oData.oAuthor.sUsername, self.formatTsShort(oData.tsEffective),), 'Sheriff', sPostHtml = ' ' + WuiTestResultFailureDetailsLink(oData.idTestResult, "Show Details").toHtml() ) oForm.addTextHidden(TestResultFailureData.ksParam_tsEffective, oData.tsEffective); oForm.addTextHidden(TestResultFailureData.ksParam_tsExpire, oData.tsExpire); oForm.addTextHidden(TestResultFailureData.ksParam_uidAuthor, oData.uidAuthor); oForm.addSubmit('Change Reason'); else: oForm.addComboBox(TestResultFailureData.ksParam_idFailureReason, -1, 'Reason', aoFailureReasons, sPostHtml = ' ' + WuiFailureReasonAddLink('New').toHtml() if not fReadOnly else ''); oForm.addMultilineText(TestResultFailureData.ksParam_sComment, '', 'Comment'); oForm.addTextHidden(TestResultFailureData.ksParam_tsEffective, ''); oForm.addTextHidden(TestResultFailureData.ksParam_tsExpire, ''); oForm.addTextHidden(TestResultFailureData.ksParam_uidAuthor, ''); oForm.addSubmit('Add Reason'); sHtml += oForm.finalize(); return sHtml; def showTestCaseResultDetails(self, # pylint: disable=too-many-locals,too-many-statements oTestResultTree, oTestSet, oBuildEx, oValidationKitEx, oTestBox, oTestGroup, oTestCaseEx, oTestVarEx): """Show detailed result""" def getTcDepsHtmlList(aoTestCaseData): """Get HTML