uiaccelerator_plat/alf_extended_visual_api/tsrc/group/sis/client.py
branchRCL_3
changeset 20 31fccae4f8a7
parent 10 7c5dd702d6d3
equal deleted inserted replaced
19:e5af45d51884 20:31fccae4f8a7
       
     1 #
       
     2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description: 
       
    15 #
       
    16 #client for coverage testing
       
    17 
       
    18 import getopt
       
    19 import time,os,sys,re
       
    20 from socket import *
       
    21 from StringIO import *
       
    22 host = "localhost"
       
    23 port = 3555
       
    24 build_command = "bldmake bldfiles & abld build winscw udeb"
       
    25 unittest_build_command = "bldmake bldfiles & abld build winscw udeb & ..\\..\\Group\\bldmake bldfiles & ..\\..\\Group\\abld test build winscw udeb"
       
    26 clean_command = "abld reallyclean"
       
    27 copy_command = "copy Z:\\epoc32\\release\\winscw\\udeb\\UT_*.dll Z:\\epoc32\\release\\winscw\\udeb\\Z\\sys\\bin\\ & copy Z:\\epoc32\\release\\winscw\\udeb\\MT_*.dll Z:\\epoc32\\release\\winscw\\udeb\\Z\\sys\\bin\\"
       
    28 
       
    29 def buildProfiledBinaries(aPath,aBuildCommand,aIdbName):
       
    30     os.chdir(aPath)
       
    31     os.putenv("CODETEST_LIB","NTmvc_TargetLibMD.lib ctsymbiannativemem.lib")
       
    32     os.putenv("CTDRIVER_ARGS","-CTsize_t=unsigned -CTtag-allocator -CTv -CTno-tag-includes -CTtag-level=SC -CTidb=" + aIdbName)
       
    33     os.system(clean_command)
       
    34     os.system(aBuildCommand)
       
    35     os.putenv("CODETEST_LIB","") # put env vars back
       
    36     os.putenv("CTDRIVER_ARGS","")
       
    37 
       
    38 def buildModuleTests(aPath,aBuildCommand):
       
    39     os.chdir(aPath)
       
    40     os.system(aBuildCommand)
       
    41     os.system(copy_command)
       
    42     
       
    43 def startProfiling(aFullIdbName, aExecutable):
       
    44     s = socket(AF_INET, SOCK_STREAM)
       
    45     s.connect((host,port))
       
    46     s.send(aFullIdbName + "," + aExecutable)
       
    47     data = s.recv(8192)
       
    48     s.close()
       
    49     return data
       
    50 
       
    51 def parseAndWriteReport(aData, aReportLocation):
       
    52     filename = None
       
    53     date = None
       
    54     covered = None
       
    55     not_covered = None
       
    56     s = StringIO(aData)
       
    57     
       
    58     for line in s:
       
    59         idb_match = re.match(r"^\s+(?P<filename>.*\.idb$)", line)
       
    60         time_match = re.match(r"^\s+\w+-\w+\s+(?P<day_name>\w+)\s+(?P<month_name>\w+)\s+(?P<day_number>\d+)\s+(?P<time>\d+:\d+:\d+)\s+(?P<year>\d+$)", line)
       
    61         covered_match = re.match(r"^\s+\d+\s+(?P<coverage>\d+\.\d+)%\s+covered$", line)
       
    62         if idb_match is not None:
       
    63             filename = idb_match.group('filename')
       
    64         if time_match is not None:            
       
    65             date = time_match.group('day_number') + "-" + time_match.group('month_name') + "-" + time_match.group('year') + "-" + time_match.group('time').replace(":","")
       
    66         if covered_match is not None:
       
    67             covered = covered_match.group('coverage')
       
    68             not_covered = 100 - float(covered)
       
    69         if filename is not None and date is not None and covered is not None:
       
    70             break            
       
    71     s.close()    
       
    72     # write report to location
       
    73     print filename
       
    74     print date
       
    75     print covered
       
    76     
       
    77     
       
    78 def cleanSystem(aComponentPath,aCleanCommand):
       
    79     os.chdir(aComponentPath)
       
    80     os.system(aCleanCommand)
       
    81     
       
    82 def main():
       
    83     try:    
       
    84         opts, args = getopt.getopt(sys.argv[1:], 'b:i:e:u:r:', ['binary-buildpath=','idb-name=','executable=','unittest-buildpath=', 'report-location='])
       
    85         binary_buildpath = None
       
    86         idb_name = None
       
    87         executable = None
       
    88         unittest_buildpath = None
       
    89         report_location = None
       
    90         p = re.compile(r'/$')
       
    91         
       
    92         for o, a in opts:
       
    93             if o in ("-b", "--binary-buildpath"):
       
    94                 binary_buildpath = a.replace("\\", "/")
       
    95                 binary_buildpath = p.sub('', binary_buildpath)
       
    96             if o in ("-i", "--idb-name"):
       
    97                 idb_name = a
       
    98             if o in ("-e", "--executable"):
       
    99                 executable = a.replace("\\", "/")
       
   100             if o in ("-u", "--unittest-buildpath"):
       
   101                 unittest_buildpath = a.replace("\\", "/")
       
   102                 unittest_buildpath = p.sub('', unittest_buildpath)
       
   103             if o in ("-r", "--report-location"):
       
   104                 report_location = a.replace("\\", "/")
       
   105                 report_location = p.sub('', report_location)
       
   106                 
       
   107         if (binary_buildpath is None) or (idb_name is None) or (executable is None) or (unittest_buildpath is None) or (report_location is None):
       
   108             usage()
       
   109             sys.exit(1)
       
   110         else:
       
   111             buildProfiledBinaries(binary_buildpath, build_command, idb_name)
       
   112             buildModuleTests(unittest_buildpath, unittest_build_command)
       
   113             report = startProfiling(binary_buildpath + "/" + idb_name, executable)
       
   114             parseAndWriteReport(report,report_location)
       
   115             cleanSystem(binary_buildpath, clean_command)
       
   116             cleanSystem(unittest_buildpath, clean_command)
       
   117             
       
   118     except getopt.GetoptError:
       
   119         usage()
       
   120         sys.exit(2)
       
   121       
       
   122 def usage():
       
   123     print "Usage: <script> -b[--binary-buildpath=] binary build path, e.g. x:/s60/mw/project/group\n"
       
   124     print "                -i[--idb-name=] idb name for profiled source, e.g. project1.idb\n"
       
   125     print "                -e[--executable=] name of the executeable that should be run for profiled code, e.g. \"x:/epoc32/.../exerunner -arg1 -arg2\"\n"
       
   126     print "                -u[--unittest-buildpath=] path for unit tests to be build"
       
   127     print "                -r[--report-location=] report location, e.g. x:/s60/mw/somecomponent/reports"
       
   128     print " -b x:/.../group -i project.idb -e \"x:/..../exerunner.exe -arg1 -arg2\" -u x:/.../test/group -r x:/reports/component.txt"
       
   129     
       
   130 main()