tools/e32test-driver/runtests.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 # Provides 'ui' for running RTests on target and generating a report of the results.
       
    19 # Uses qemuruntest to run the tests and rtestreport to generate the results.
       
    20 
       
    21 import glob
       
    22 import sys
       
    23 import os.path
       
    24 
       
    25 from optparse import OptionParser
       
    26 
       
    27 import qemuruntest
       
    28 import rtestreport
       
    29 
       
    30 def ParseOptions():
       
    31     optParser = OptionParser()
       
    32     optParser.add_option("-b", "--board", action="store", type="string", default="syborg")
       
    33     optParser.add_option("-c", "--cpu", action="store", type="string", default="cortex-a8")
       
    34     optParser.add_option("-d", "--display", action="store_true", dest="displayp")
       
    35     optParser.add_option("-i", "--input", action="store", type="string")
       
    36     optParser.add_option("-o", "--output", action="store", type="string")
       
    37     optParser.add_option("-q", "--qemu", action="store", type="string", dest="qemupath", default="qemu-system-arm.exe")
       
    38     optParser.add_option("-r", "--rom", action="store", type="string", default="syborg.e32test.a8.urel.elf")
       
    39     optParser.add_option("-s", "--summary", action="store", type="string")
       
    40 
       
    41     return optParser.parse_args()
       
    42 
       
    43 def main():
       
    44     errors = False
       
    45     (options, args) = ParseOptions()
       
    46 
       
    47     if  not options.input:
       
    48         gl = glob.glob(options.qemupath)
       
    49         if len(gl) == 0:
       
    50             gl = glob.glob(options.qemupath + ".exe")
       
    51 
       
    52         if len(gl) == 0:
       
    53             print >> sys.stderr, "ERROR: can't find qemu executable %s" % (options.qemupath)
       
    54             errors = True
       
    55         else:
       
    56             qemupath = gl[0]
       
    57 
       
    58         gl = glob.glob(options.rom)
       
    59         if len(gl) == 0:
       
    60             print >> sys.stderr, "ERROR: can't find ROM image %s" % (options.rom)
       
    61             errors = True
       
    62         else:
       
    63             rompath = gl[0]
       
    64 
       
    65         if errors:
       
    66             sys.exit(1)
       
    67 
       
    68         output = options.output
       
    69         if output == None:
       
    70             output = rompath
       
    71 
       
    72         runner = qemuruntest.QemuTestRunner(qemupath, options.cpu, rompath, board = options.board, displayp = options.displayp, dataFile = output)
       
    73         runner.Run()
       
    74     else:
       
    75         gl = glob.glob(options.input)
       
    76         if len(gl) == 0:
       
    77             print >> sys.stderr, "ERROR: can't find input file %s" % (options.input)
       
    78             sys.exit(1)
       
    79 
       
    80         input = gl[0]
       
    81         runner = qemuruntest.PseudoRunner(input)
       
    82         
       
    83     testReporter = rtestreport.RTestReport(runner, reportFileRoot = options.summary)
       
    84     reportFile = False
       
    85     status = 1
       
    86     try:
       
    87         reportFile = testReporter.OpenReportFile()
       
    88         status = testReporter.WriteReport(reportFile)
       
    89     except Exception, x:
       
    90         print >> sys.stderr, x
       
    91         status = 1
       
    92         if reportFile:
       
    93             reportFile.close()
       
    94 
       
    95     return status
       
    96         
       
    97     
       
    98 if __name__ == "__main__":
       
    99     main()