|
1 # Copyright (c) 2006-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 import ConfigParser |
|
17 |
|
18 from datainput import getEntries, getFolded, getTypes |
|
19 from teststep import TestStep |
|
20 from time import strftime |
|
21 from utils import doTimeStampCompareAndWrite |
|
22 |
|
23 # |
|
24 # Creates test step from .ini file as used when creating commands and events. |
|
25 # |
|
26 |
|
27 def makeTestSteps(aCfg, aSections): |
|
28 if aSections == []: |
|
29 return [] |
|
30 else: |
|
31 return makeTestStep(aCfg.get(aSections[0], 'Type'), |
|
32 getFolded(getEntries(aCfg.get(aSections[0], 'Datafile')), getTypes(aCfg.get(aSections[0], 'Typefile')), 0)) + makeTestSteps(aCfg, aSections[1:]) |
|
33 |
|
34 # |
|
35 # Creates a test step from an entry as provided by the getFolded method. |
|
36 # |
|
37 |
|
38 def makeTestStep(aType, aEntries): |
|
39 if len(aEntries) == 0: |
|
40 return [] |
|
41 else: |
|
42 key, value = aEntries.popitem() |
|
43 return [TestStep(key, aType)] + makeTestStep(aType, aEntries) |
|
44 |
|
45 # |
|
46 # Makes a string of the form |
|
47 # |
|
48 # if(aStepName == KTestStepName1) |
|
49 # { |
|
50 # return new CTestStepName; |
|
51 # } |
|
52 # else if(aStepName == KTestStepName2) |
|
53 # { |
|
54 # .... |
|
55 # |
|
56 # for every test name in the list provided. |
|
57 # |
|
58 |
|
59 def makeCreateTestStepImpl(aTestSteps): |
|
60 impl_str = '' |
|
61 |
|
62 for t in aTestSteps: |
|
63 impl_str += 'if(aStepName == K' + t.teststepName() + ')\n\t\t{\n\t\treturn new C' + t.teststepName() + ';\n\t\t}\n\telse ' |
|
64 |
|
65 impl_str += '\n\t\t{\n\t\treturn NULL;\n\t\t}' |
|
66 return impl_str |
|
67 |
|
68 # |
|
69 # Makes a string of the form '#include "teststepheaderfile.h"\n' for every test step in the list provided. |
|
70 # |
|
71 |
|
72 def makeTestStepHeaders(aTestSteps): |
|
73 hdr_str = '' |
|
74 |
|
75 for t in aTestSteps: |
|
76 hdr_str += '#include "' + t.headerFile() + '"\n' |
|
77 |
|
78 return hdr_str |
|
79 |
|
80 # |
|
81 # Returns a string for test step run instructions. |
|
82 # |
|
83 |
|
84 def makeTests(aName, aTestSteps): |
|
85 scr_str = '' |
|
86 |
|
87 for t in aTestSteps: |
|
88 if t.isPanic(): # Test step will panic |
|
89 scr_str += 'RUN_TEST_STEP !PanicCode=' + t.panicCode() + ' 100 ' + aName + ' ' + t.teststepName() + '\n' |
|
90 else: |
|
91 scr_str += 'RUN_TEST_STEP 100 ' + aName + ' ' + t.teststepName() + '\n' |
|
92 |
|
93 return scr_str |
|
94 |
|
95 # |
|
96 # Writes a test server with test script. Template substitutions are: |
|
97 # |
|
98 # For the source template: |
|
99 # $CREATE_TEST_STEP_IMPL: implementation of CreateTestStep method |
|
100 # $TEST_STEP_HEADERS: #include "teststep.h", include directive for all test step implementations |
|
101 # $SERVERNAME: test step server name, used for SetServerName |
|
102 # $CLASSNAME: test step server class name, of the form CTestStepServerName |
|
103 # $FILENAME: filename for test step server |
|
104 # $HEADERGUARD: the name of the server in capital letters, suitable for include guards |
|
105 # $GENERATE_TIME_STAMP: timestamp showing when the generator produced the file |
|
106 # |
|
107 # For the header template: |
|
108 # $CLASSNAME: test step server class name, of the form CTestStepServerName |
|
109 # $FILENAME: filename for test step server |
|
110 # $HEADERGUARD: the name of the server in capital letters, suitable for include guards |
|
111 # $GENERATE_TIME_STAMP: timestamp showing when the generator produced the file |
|
112 |
|
113 def writeTestServer(aName, aHeaderTemplate, aSourceTemplate, aScriptTemplate, aTestSteps, aPath): |
|
114 cfg = ConfigParser.ConfigParser() |
|
115 cfg.readfp(file(aTestSteps)) |
|
116 |
|
117 steps = makeTestSteps(cfg, cfg.sections()) |
|
118 |
|
119 src = {'CREATE_TEST_STEP_IMPL': makeCreateTestStepImpl(steps), |
|
120 'TEST_STEP_HEADERS': makeTestStepHeaders(steps), |
|
121 'SERVERNAME': aName, |
|
122 'CLASSNAME': 'C' + aName, |
|
123 'FILENAME': aName.lower(), |
|
124 'HEADERGUARD': aName.upper(), |
|
125 'GENERATE_TIME_STAMP': strftime("%a, %d %b %Y %H:%M:%S") + ' (time stamp)'} |
|
126 |
|
127 hdr = {'CLASSNAME': 'C' + aName, |
|
128 'FILENAME': aName.lower(), |
|
129 'HEADERGUARD': aName.upper(), |
|
130 'GENERATE_TIME_STAMP': strftime("%a, %d %b %Y %H:%M:%S") + ' (time stamp)'} |
|
131 |
|
132 #file(aPath + '\\' + hdr['FILENAME'] + '.h', 'w+').write(aHeaderTemplate.substitute(hdr)) |
|
133 #file(aPath + '\\' + src['FILENAME'] + '.cpp', 'w+').write(aSourceTemplate.substitute(src)) |
|
134 doTimeStampCompareAndWrite(aPath + '\\' + hdr['FILENAME'] + '.h', aHeaderTemplate.substitute(hdr)) |
|
135 doTimeStampCompareAndWrite(aPath + '\\' + src['FILENAME'] + '.cpp', aSourceTemplate.substitute(src)) |
|
136 |
|
137 writeTestScripts(aName, aScriptTemplate, steps, aPath) |
|
138 |
|
139 # |
|
140 # Writes test scripts. Template substitutions: |
|
141 # $FILENAME: name of script file to write |
|
142 # $TESTSERVERNAME: name of test server to load |
|
143 # $TESTS: calls to test steps, of the form RUN... |
|
144 # $GENERATE_TIME_STAMP: timestamp showing when the generator produced the file |
|
145 # |
|
146 |
|
147 def writeTestScripts(aName, aScriptTemplate, aTestSteps, aPath): |
|
148 script = {'FILENAME': aName.lower(), |
|
149 'TESTSERVERNAME': aName, |
|
150 'TESTS': makeTests(aName, aTestSteps), |
|
151 'GENERATE_TIME_STAMP': strftime("%a, %d %b %Y %H:%M:%S") + ' (time stamp)'} |
|
152 |
|
153 #file(aPath + '\\' + script['FILENAME'] + '.script', 'w+').write(aScriptTemplate.substitute(script)) |
|
154 doTimeStampCompareAndWrite(aPath + '\\' + script['FILENAME'] + '.script', aScriptTemplate.substitute(script)) |