|
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 # server for coverage testing |
|
17 # |
|
18 # Usage: |
|
19 # - start CodeTest Manager |
|
20 # - start the command shell from CodeTest: File|CmdShell... |
|
21 # - if this script file (testserver.py) is located for ex. in Z:\projects\uiaccelerator\uiaccelerator\uiacceltk\hitchcock\internal\tsrc\Test\Group |
|
22 # start the ctserver by giving a command in CodeTest command shell: |
|
23 # execfile('Z:/projects/uiaccelerator/uiaccelerator/uiacceltk/hitchcock/internal/tsrc/Test/Group/testserver.py') |
|
24 # - the ctserver should now print: |
|
25 # Server Initialised... |
|
26 # Listening... |
|
27 # ctserver is communicating to the CodeTEST host on port 3020 |
|
28 # ready. |
|
29 # |
|
30 # - open a windows command window in in Z:\projects\uiaccelerator\uiaccelerator\uiacceltk\hitchcock\internal\tsrc\Test\Group |
|
31 # - start the client by running client.py in the windows command window |
|
32 # |
|
33 # Client usage: |
|
34 # <script> -b[--binary-buildpath=] binary build path, e.g. x:/s60/mw/project/group\n" |
|
35 # -i[--idb-name=] idb name for profiled source, e.g. project1.idb\n" |
|
36 # -e[--executable=] name of the executeable that should be run for profiled code, e.g. \"x:/epoc32/.../exerunner -arg1 -arg2\"\n" |
|
37 # -u[--unittest-buildpath=] path for unit tests to be build" |
|
38 # -r[--report-location=] report location, e.g. x:/s60/mw/somecomponent/reports" |
|
39 # |
|
40 # An example client command line: |
|
41 # client.py -b Z:\projects\uiaccelerator\uiaccelerator\group -i EunitTests.idb -e Z:\epoc32\release\winscw\udeb\EUnitExeRunner.exe -u Z:\projects\uiaccelerator\uiaccelerator\uiacceltk\hitchcock\internal\tsrc\Test\Group -r . |
|
42 # |
|
43 |
|
44 import time,os,sys,re |
|
45 from ctest import CTCommonDef |
|
46 from ctest.DataObjM import CovObjDef |
|
47 from socket import * |
|
48 |
|
49 ctServerPath = "C:\\APPS\\ct\\bin\\ctserver.exe" |
|
50 host = "" |
|
51 port = 3555 |
|
52 |
|
53 def initialise(): |
|
54 os.spawnv(os.P_NOWAIT, ctServerPath, ['']) |
|
55 print "Server Initialised..." |
|
56 |
|
57 def processCommand(aSocket, aCommand): |
|
58 if aCommand == "EXIT": |
|
59 sys.exit(0) |
|
60 else: |
|
61 commands = re.split(r',',aCommand) |
|
62 print "Retreived commands:",commands |
|
63 data = runCodeTest(commands[0], commands[1]) |
|
64 aSocket.send(data) |
|
65 |
|
66 def runCodeTest(aIdb, aExecutable): |
|
67 ctob.closeWorkspace() |
|
68 ds = ctob.createCtSWIC('localhost', 3020, 30) |
|
69 print ds.getName(), 'Data source created...' |
|
70 ds.setIDB(aIdb) |
|
71 ds.connect() |
|
72 ds.setContinuousMode() |
|
73 ds.start() |
|
74 print 'Starting profiled application...' |
|
75 os.spawnv(os.P_WAIT, aExecutable, [' /e S60AppEnv /r Warning /w 1']) |
|
76 print 'Application exited...' |
|
77 time.sleep(10) |
|
78 print 'Collecting data...' |
|
79 ds.collectData() |
|
80 ds.stop() |
|
81 covObject0 = ds.getCoverageObjs()[0] |
|
82 covObject0.sortData('coverage',1) |
|
83 # html report / per method |
|
84 #covObject0.exportView('c:/cov_data_one.htm', CTCommonDef.HTML_FORMAT,' ',' ' ) |
|
85 covObject0.writeCoverageReport('/cov_report.txt', CovObjDef.OVERALL_SUMMARY) |
|
86 f = open("/cov_report.txt") |
|
87 data = f.read() |
|
88 f.close() |
|
89 ds.disConnect() |
|
90 print 'Report sent to the client...' |
|
91 return data |
|
92 |
|
93 def startServer(): |
|
94 s = socket(AF_INET, SOCK_STREAM) |
|
95 s.bind((host,port)) |
|
96 s.listen(1) |
|
97 print "Listening..." |
|
98 while 1: |
|
99 (clientsocket, address) = s.accept() |
|
100 print "Client connected..." |
|
101 while 1: |
|
102 buff = clientsocket.recv(4096) |
|
103 print "Data received..." |
|
104 if buff: |
|
105 processCommand(clientsocket, buff) |
|
106 else: |
|
107 break |
|
108 clientsocket.close() |
|
109 |
|
110 initialise() |
|
111 startServer() |