graphicsdeviceinterface/directgdi/test/scripts/htmlreport.py
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 # Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 # All rights reserved.
       
     3 # This component and the accompanying materials are made available
       
     4 # under the terms of "Eclipse Public License v1.0"
       
     5 # which accompanies this distribution, and is available
       
     6 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 #
       
     8 # Initial Contributors:
       
     9 # Nokia Corporation - initial contribution.
       
    10 #
       
    11 # Contributors:
       
    12 #
       
    13 # Description:
       
    14 #
       
    15 
       
    16 """
       
    17 Html Report Tools
       
    18 
       
    19 Tools for generating the HTML reports.
       
    20 
       
    21 """
       
    22 
       
    23 import os
       
    24 import os.path
       
    25 from string import *
       
    26 
       
    27 # HTML file name for failed images
       
    28 KPageForFailedImages = "failed.html"
       
    29 # HTML file name for passed images
       
    30 KPageForPassedImages = "passed.html"
       
    31 KPageForFailedAtImages = "failedAt.html"
       
    32 # HTML file name for a summary page where passed and failed image information is summarised
       
    33 KPageForSummary = "summary.html"
       
    34 
       
    35 # HTML file name for an error message page of the test results
       
    36 KErrorMessagePageName = "error.html"
       
    37 
       
    38 # Prefix of the diff image name when the test image passes 
       
    39 KNoDiffPrefix = "NoDiff_"
       
    40 
       
    41 # Prefix of the diff image name when the test image fails 
       
    42 DiffPrefix = "RGBDiff_diffImg_"
       
    43 
       
    44 # Write html header
       
    45 # @param file The file object to be accessed
       
    46 def writeTitle(file):
       
    47     file.write("<head>\n")
       
    48     file.write("<title> Graphics DirectGdi / BitGdi Test Report</title>\n")
       
    49     file.write("</head>\n")
       
    50 
       
    51 # Write html footer
       
    52 # @param file The file object to be accessed
       
    53 def writeHtmlFooter(file):
       
    54     file.write('<br/>Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).\n')
       
    55     file.write("</body></html>\n")
       
    56 
       
    57 # Write overall test results
       
    58 # @param file The file object to be accessed
       
    59 # @param aNumFailed The number of failed images
       
    60 # @param aNumPassed The number of passed images
       
    61 def writeHtmlHeader(file, aNumFailed, aNumPassed, aNumFailedAt, aFailedAtThreshold):
       
    62     writeTitle(file)
       
    63     file.write("<body>\n")
       
    64     file.write("<h1>Graphics DirectGdi / BitGdi Test Report</h1><br/>\n")
       
    65     writeLink(file, "All Cases", KPageForSummary, aNumFailed + aNumPassed)
       
    66     file.write('Note: Some Asynchronous Interleaving images may be missing due to nature of that test.<br><br>')
       
    67     writeLink(file, "Failed Cases", KPageForFailedImages, aNumFailed)
       
    68     writeLink(file, "Passed Cases", KPageForPassedImages, aNumPassed)
       
    69     failureNotice = 'Failed At Threshold %d Cases'%aFailedAtThreshold
       
    70     writeLink(file, failureNotice, KPageForFailedAtImages, aNumFailedAt)
       
    71     file.write("<br><h2>")
       
    72     file.write('<a href="'+ KErrorMessagePageName +'">' + "Error Messages" + '</a>')
       
    73     file.write(" from the tests</h2><br>")
       
    74     
       
    75 
       
    76 # Write simple overall test results for the Overnight Build
       
    77 # @param file The file object to be accessed
       
    78 # @param aNumFailed The number of failed images
       
    79 # @param aNumPassed The number of passed images
       
    80 def writeHtmlONB(file, aNumFailed, aNumPassed, aNumFailedAt, aFailedAtThreshold, linkFile):
       
    81     file.write("<font color=00AFFF>SUMMARY:</font><br>\n")
       
    82     total = aNumPassed + aNumFailed
       
    83     file.write('<font color=00AF00>ALL = %d</font><br>\n' % total)
       
    84     file.write('<font color=00AF00>PASS = %d</font><br>\n' % aNumPassed)
       
    85     file.write('<font color=FF0000>FAIL = %d</font><br>\n' % aNumFailed)
       
    86     file.write('<font color=FF0000>FAIL AT THRESHOLD %d' % aFailedAtThreshold)
       
    87     file.write(' = %d</font><br>\n' % aNumFailedAt)
       
    88     file.write("<font color=0000FF>ABORT = 0</font><br>\n")
       
    89     file.write("<font color=0000FF>PANIC = 0</font><br>\n")
       
    90     file.write("<font color=0000FF>INCONCLUSIVE = 0</font><br>\n")
       
    91     file.write("<font color=0000FF>UNKNOWN = 0</font><br>\n")
       
    92     file.write("<font color=0000FF>UNEXECUTED = 0</font><br>\n")
       
    93     file.write("<font color=0000FF>COMMENTED OUT COMMAND'S = 0</font><br>\n")
       
    94     file.write('<a href="directgdi_results\\logs\\' + linkFile + '">Test Results</a><br>\n')
       
    95 
       
    96 # Write overall test results
       
    97 # @param file The file object to be accessed
       
    98 def writeSimpleHtmlHeader(file):
       
    99     writeTitle(file)
       
   100     file.write("<body>\n")
       
   101 
       
   102 # Write link pages for test results
       
   103 # @param file The file object to be accessed
       
   104 # @param aTitle The text to appear on the page
       
   105 # @param aPage A URL that the page links to
       
   106 # @param aNum A number in brackets on the page
       
   107 def writeLink(file, aTitle, aPage, aNum):
       
   108     file.write("<h2>")
       
   109     file.write('<span class="listlink">')
       
   110     file.write('<a href="'+ aPage +'">' + aTitle + '</a>')
       
   111     file.write(' (%d)</span>&nbsp;' % aNum)
       
   112     file.write("</h2>")
       
   113 
       
   114 # Create a html page for all failed images index
       
   115 # @param file The file object to be accessed
       
   116 # @param aFailedTestImgs The test images that failed the tests
       
   117 # @param aFailedRefImgs The reference images referred by the test images
       
   118 # @param aTestDir The directory of the test images
       
   119 # @param aRefDir The directory of the reference images
       
   120 # @param aDiffDir The directory of the diff images
       
   121 # @param aLogDir The directory of the log files
       
   122 def writeFailedDetails(file, aFailedTestImgs, aFailedRefImgs, aTestDir, aRefDir, aDiffDir, aLogDir):
       
   123     writeTitle(file)
       
   124     file.write("<body>\n")
       
   125     file.write("<h2>")
       
   126     file.write("Failed test images:")
       
   127     file.write("</h2>\n")  
       
   128     writeSingleFileDetail(file, aFailedTestImgs, aFailedRefImgs, False, aTestDir, aRefDir, aDiffDir, aLogDir)  
       
   129     file.write("</body></html>\n") 
       
   130 
       
   131 # Create a html page for all failed images index
       
   132 # @param file The file object to be accessed
       
   133 # @param aFailedTestImgs The test images that failed the tests
       
   134 # @param aFailedRefImgs The reference images referred by the test images
       
   135 # @param aTestDir The directory of the test images
       
   136 # @param aRefDir The directory of the reference images
       
   137 # @param aDiffDir The directory of the diff images
       
   138 # @param aLogDir The directory of the log files
       
   139 def writeFailedAtDetails(file, aFailedAtTestImgs, aFailedAtRefImgs, aTestDir, aRefDir, aDiffDir, aLogDir, aThreshold):
       
   140     writeTitle(file)
       
   141     file.write("<body>\n")
       
   142     file.write("<h2>")
       
   143     file.write("Failed At Threshold %d test images:" % aThreshold)
       
   144     file.write("</h2>\n")  
       
   145     writeSingleFileDetail(file, aFailedAtTestImgs, aFailedAtRefImgs, False, aTestDir, aRefDir, aDiffDir, aLogDir)  
       
   146     file.write("</body></html>\n")
       
   147 
       
   148 # Create a html page for all passed images index
       
   149 # @param file The file object to be accessed
       
   150 # @param aPassdTestImgs The images that passed the tests
       
   151 # @param aPassedRefImgs The reference images referred by the test images
       
   152 # @param aTestDir The directory of the test images
       
   153 # @param aRefDir The directory of the reference images
       
   154 # @param aDiffDir The directory of the diff images
       
   155 # @param aLogDir The directory of the log files
       
   156 def writePassedDetails(file, aPassdTestImgs, aPassedRefImgs, aTestDir, aRefDir, aDiffDir, aLogDir):
       
   157     writeTitle(file)
       
   158     file.write("<body>\n")
       
   159     file.write("<h2>")
       
   160     file.write("Passed test images:")
       
   161     file.write("</h2>\n")
       
   162     writeSingleFileDetail(file, aPassdTestImgs, aPassedRefImgs, True, aTestDir, aRefDir, aDiffDir, aLogDir)
       
   163     file.write("</body></html>\n")
       
   164 
       
   165 # Create a html page for each test image (with its reference image and diff image)
       
   166 # @param file The file object to be accessed
       
   167 # @param aTestImgs The test images to be processed
       
   168 # @param aRefImgs The reference images referred by the test images
       
   169 # @param aIsPass The boolean value of image test result 
       
   170 # @param aTestDir The directory of the test images
       
   171 # @param aRefDir The directory of the reference images
       
   172 # @param aDiffDir The directory of the diff images
       
   173 # @param aLogDir The directory of the log files
       
   174 def writeSingleFileDetail(file, aTestImgs, aRefImgs, aIsPass, aTestDir, aRefDir, aDiffDir, aLogDir):
       
   175     i = 0
       
   176     for testImg in aTestImgs:
       
   177         file.write('<a href=%s.html> %s</a> Pyramid diff: %d\n'%(testImg[0], testImg[0], testImg[1]))
       
   178         writeDetailedDiffImg(aLogDir, testImg, aRefImgs[i], aIsPass, aTestDir, aRefDir, aDiffDir)
       
   179         file.write('<br/>\n')
       
   180         i = i + 1
       
   181 
       
   182 # Show a test, reference and diff images on a html page
       
   183 # @param aLogDir The directory of the log files
       
   184 # @param aTestImgs The test images to be processed
       
   185 # @param aRefImgs The reference images referred by the test images
       
   186 # @param aIsPass The boolean value of image test result 
       
   187 # @param aTestDir The directory of the test images
       
   188 # @param aRefDir The directory of the reference images
       
   189 # @param aDiffDir The directory of the diff images
       
   190 def writeDetailedDiffImg(aLogDir, aTestImg, aRefImg, aIsPass, aTestDir, aRefDir, aDiffDir):
       
   191 
       
   192 
       
   193     (alphatestimgname,alphatestimgext) = os.path.splitext(aTestImg[0])
       
   194     alphatestimg = alphatestimgname + "-alpha" + alphatestimgext
       
   195     if os.path.exists(os.path.join(aTestDir,alphatestimg)):
       
   196         diff = file((aLogDir + aTestImg[0] + ".html"), "wt")
       
   197         writeTitle(diff)
       
   198         writeSimpleHtmlHeader(diff)
       
   199         
       
   200         diff.write('<h2>')
       
   201         diff.write("Test " + aTestImg[0])
       
   202         diff.write('</h2>\n')
       
   203         diff.write('<h2>Pyramid diff: %d </h2>\n' % aTestImg[1])
       
   204         # show a test image on the diff page
       
   205         diff.write('<h2>Test Image and alpha channel:</h2>\n')
       
   206         diff.write(aTestImg[0] + '<br>')
       
   207         diff.write('<table border=1><tr>')
       
   208         diff.write('<td><img src="../img/test/' + aTestImg[0] + '"> </td>')
       
   209         diff.write('<td><img src="../img/test/' + alphatestimg + '"> </td>')
       
   210         diff.write('</tr></table>')
       
   211         diff.write('<br/>\n')
       
   212         
       
   213         # show a reference image on the diff page
       
   214         diff.write('<h2>Reference Image and alpha channel: </h2>\n')
       
   215         diff.write(aRefImg[0] + '<br>')
       
   216         diff.write('<table border=1><tr>')
       
   217         diff.write('<td><img src="../img/ref/' + aRefImg[0] + '"> </td>')
       
   218         
       
   219         (alpharefimgname,alpharefimgext) = os.path.splitext(aRefImg[0])
       
   220         alpharefimg = alpharefimgname + "-alpha" + alpharefimgext
       
   221         
       
   222         diff.write('<td><img src="../img/ref/' + alpharefimg + '"> </td>')
       
   223         diff.write('</tr></table>')
       
   224         diff.write('<br/>\n')
       
   225         
       
   226         # show a diff image on the diff page
       
   227         diff.write('<h2>Diff Image and alpha channel: </h2>\n')
       
   228         diff.write('<table border=1><tr>')
       
   229         diff.write('<td><img src="../img/' + DiffPrefix + aRefImg[0] + '"> </td>')
       
   230         diff.write('<td><img src="../img/' + DiffPrefix + alpharefimg + '"> </td>')
       
   231         
       
   232         diff.write('</tr></table>')
       
   233         diff.write('<br/>\n')
       
   234         writeHtmlFooter(diff)
       
   235     else:
       
   236         diff = file((aLogDir + aTestImg[0] + ".html"), "wt")
       
   237         writeTitle(diff)
       
   238         writeSimpleHtmlHeader(diff)
       
   239         
       
   240         diff.write('<h2>')
       
   241         diff.write("Test " + aTestImg[0])
       
   242         diff.write('</h2>\n')
       
   243         diff.write('<h2>Pyramid diff: %d </h2>\n' % aTestImg[1])
       
   244         # show a test image on the diff page
       
   245         diff.write('<h2>Test Image: </h2>\n')
       
   246         diff.write(aTestImg[0] + '<br>')
       
   247         diff.write('<table border=1><tr>')
       
   248         diff.write('<td><img src="../img/test/' + aTestImg[0] + '"> </td>')
       
   249         diff.write('</tr></table>')
       
   250         diff.write('<br/>\n')
       
   251         
       
   252         # show a reference image on the diff page
       
   253         diff.write('<h2>Reference Image: </h2>\n')
       
   254         diff.write(aRefImg[0] + '<br>')
       
   255         diff.write('<table border=1><tr>')
       
   256         diff.write('<td><img src="../img/ref/' + aRefImg[0] + '"> </td>')
       
   257         diff.write('</tr></table>')
       
   258         diff.write('<br/>\n')
       
   259         
       
   260         # show a diff image on the diff page
       
   261         diff.write('<h2>Diff Image: </h2>\n')
       
   262         diff.write('<table border=1><tr>')
       
   263         diff.write('<td><img src="../img/' + DiffPrefix + aRefImg[0] + '"> </td>')
       
   264         diff.write('</tr></table>')
       
   265         diff.write('<br/>\n')
       
   266         writeHtmlFooter(diff)
       
   267 
       
   268 def writeErroInfo(file, aErroInfo):
       
   269     file.write(aErroInfo)
       
   270