tools/e32test-driver/rtestreport.py
changeset 34 92d87f2e53c2
equal deleted inserted replaced
33:1af5c1be89f8 34:92d87f2e53c2
       
     1 #
       
     2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 #
       
     5 # This program is free software: you can redistribute it and/or modify
       
     6 # it under the terms of the GNU Lesser General Public License as published by
       
     7 # the Free Software Foundation, either version 3 of the License, or
       
     8 # (at your option) any later version.
       
     9 #
       
    10 # This program is distributed in the hope that it will be useful,
       
    11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    13 # GNU Lesser General Public License for more details.
       
    14 # 
       
    15 # You should have received a copy of the GNU Lesser General Public License
       
    16 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
       
    17 
       
    18 # A simple report generator for the results of running an RTest testsuite.
       
    19 #
       
    20 
       
    21 import sys
       
    22 import qemuruntest
       
    23 import rtest
       
    24 
       
    25 class RTestReport(object):
       
    26     def __init__(self, testRunner, reportFileRoot = None):
       
    27         self.testRunner = testRunner
       
    28         self.reportFileRoot = reportFileRoot
       
    29 
       
    30     def SummariseErrors(self, file = sys.stdout ):
       
    31         print >> file, "%d errors were detected while running rom %s :" % (len(self.erroredTests), self.parser.GetRomName())
       
    32         for e in self.erroredTests:
       
    33             print >> file, e.GetName()
       
    34         print >> file, "\n"
       
    35 
       
    36     def SummariseFailures(self, file = sys.stdout ):
       
    37         print >> file, "%d failures were detected while running rom %s :" % (len(self.failedTests), self.parser.GetRomName())
       
    38         for e in self.failedTests:
       
    39             print >> file, e.GetName()
       
    40             for l in e.ErrorContext():
       
    41                 print >> file, "\t%s" %(l)
       
    42         print >> file, "\n"
       
    43 
       
    44     def SummarisePassed(self, file = sys.stdout ):
       
    45         print >> file, "The following %d tests passed while running rom %s (times are approximate):" % (len(self.passedTests), self.parser.GetRomName())
       
    46         for e in self.passedTests:
       
    47             print >> file, e.GetName(), " : ", e.GetTimeTaken(), "seconds"
       
    48         print >> file, "\n"
       
    49         
       
    50     def OpenReportFile(self):
       
    51         name = self.reportFileRoot
       
    52         if not name:
       
    53             name = self.testRunner.GetReportFileName()
       
    54         return open(name, 'w')
       
    55 
       
    56     def GetReportFileName(self):
       
    57         return self.reportFileName
       
    58     
       
    59     def PrepareReport(self):
       
    60         self.parser = rtest.RTestParser(self.testRunner)
       
    61         try:
       
    62             self.parser.Parse()
       
    63         except rtest.NoRTestsFound, x:
       
    64             print x
       
    65             sys.exit(1)
       
    66         self.failedTests = filter(rtest.RTest.Failedp, self.parser.GetRTests())
       
    67         self.erroredTests = filter(rtest.RTest.Erroredp, self.parser.GetRTests())
       
    68         self.passedTests = filter(rtest.RTest.Passedp, self.parser.GetRTests())
       
    69 
       
    70     def WriteReport(self, file = sys.stdout):
       
    71         self.PrepareReport()
       
    72         print >> file, self.testRunner.GetSummary()
       
    73         self.SummariseErrors(file)
       
    74         self.SummariseFailures(file)
       
    75         self.SummarisePassed(file)
       
    76         return 0
       
    77         
       
    78