@@ -68,79 +68,185 @@ def abort_build(args):
68
68
r = requests .put (urlparse .urljoin (args .url , "api/builds/" + args .build_id ), headers = create_headers (args ), json = data )
69
69
finish_command ('abort-build' , r )
70
70
71
- def add_test_runs (args ):
71
+ def add_project_runs (args ):
72
+ '''
73
+ -------------------------------------
74
+ Notes on 'project_run_data' structure:
75
+ --------------------------------------
76
+ 'projectRuns' - Tree structure used to keep track of what projects have
77
+ been logged in different report files. The tree is organized as follows:
78
+
79
+ 'projectRuns': { - Root element of tree
80
+
81
+ 'hostOs': { - Host OS on which project was built/tested
82
+ - ex. windows, linux, or mac
83
+
84
+ 'platform': { - Platform for which project was built/tested
85
+ (Corresponds to platform names in targets.py)
86
+ - ex. K64F, LPC1768, NRF51822, etc.
87
+
88
+ 'toolchain': { - Toolchain with which project was built/tested
89
+ (Corresponds to TOOLCHAIN_CLASSES names in toolchains/__init__.py)
90
+ - ex. ARM, uARM, GCC_ARM, etc.
91
+
92
+ 'project': { - Project that was build/tested
93
+ (Corresponds to test id in tests.py or library id in libraries.py)
94
+ - For tests, ex. MBED_A1, MBED_11, DTCT_1 etc.
95
+ - For libraries, ex. MBED, RTX, RTOS, etc.
96
+
97
+ },
98
+ ...
99
+ },
100
+ ...
101
+ },
102
+ ...
103
+ }
104
+ }
105
+
106
+ 'platforms_set' - Set of all the platform names mentioned in the given report files
107
+
108
+ 'toolchains_set' - Set of all the toolchain names mentioned in the given report files
109
+
110
+ 'names_set' - Set of all the project names mentioned in the given report files
111
+
112
+ 'hostOses_set' - Set of all the host names given (only given by the command line arguments)
113
+ '''
114
+
115
+ project_run_data = {}
116
+ project_run_data ['projectRuns' ] = {}
117
+ project_run_data ['platforms_set' ] = set ()
118
+ project_run_data ['toolchains_set' ] = set ()
119
+ project_run_data ['names_set' ] = set ()
120
+ project_run_data ['hostOses_set' ] = set ()
121
+ project_run_data ['hostOses_set' ].add (args .host_os )
122
+
123
+ add_report (project_run_data , args .build_report , True , args .build_id , args .host_os )
124
+
125
+ if (args .test_report ):
126
+ add_report (project_run_data , args .test_report , False , args .build_id , args .host_os )
127
+
128
+ ts_data = format_project_run_data (project_run_data )
129
+ r = requests .post (urlparse .urljoin (args .url , "api/projectRuns" ), headers = create_headers (args ), json = ts_data )
130
+ finish_command ('add-project-runs' , r )
131
+
132
+ def format_project_run_data (project_run_data ):
133
+ ts_data = {}
134
+ ts_data ['projectRuns' ] = []
135
+
136
+ for hostOs in project_run_data ['projectRuns' ].values ():
137
+ for platform in hostOs .values ():
138
+ for toolchain in platform .values ():
139
+ for project in toolchain .values ():
140
+ ts_data ['projectRuns' ].append (project )
141
+
142
+ ts_data ['platforms' ] = list (project_run_data ['platforms_set' ])
143
+ ts_data ['toolchains' ] = list (project_run_data ['toolchains_set' ])
144
+ ts_data ['names' ] = list (project_run_data ['names_set' ])
145
+ ts_data ['hostOses' ] = list (project_run_data ['hostOses_set' ])
146
+
147
+ return ts_data
148
+
149
+ def find_project_run (projectRuns , project ):
150
+ keys = ['hostOs' , 'platform' , 'toolchain' , 'project' ]
151
+
152
+ elem = projectRuns
153
+
154
+ for key in keys :
155
+ if not project [key ] in elem :
156
+ return None
157
+
158
+ elem = elem [project [key ]]
159
+
160
+ return elem
161
+
162
+ def add_project_run (projectRuns , project ):
163
+ keys = ['hostOs' , 'platform' , 'toolchain' ]
164
+
165
+ elem = projectRuns
166
+
167
+ for key in keys :
168
+ if not project [key ] in elem :
169
+ elem [project [key ]] = {}
170
+
171
+ elem = elem [project [key ]]
172
+
173
+ elem [project ['project' ]] = project
174
+
175
+ def update_project_run_results (project_to_update , project ):
176
+ project_to_update ['pass' ] = project ['pass' ]
177
+ project_to_update ['result' ] = project ['result' ]
178
+
179
+ if 'buildOutput' in project :
180
+ project_to_update ['buildOutput' ] = project ['buildOutput' ]
181
+ else :
182
+ project_to_update ['testOutput' ] = project ['testOutput' ]
183
+
184
+ def update_project_run (projectRuns , project ):
185
+ found_project = find_project_run (projectRuns , project )
186
+ if found_project :
187
+ update_project_run_results (found_project , project )
188
+ else :
189
+ add_project_run (projectRuns , project )
190
+
191
+ def add_report (project_run_data , report_file , is_build , build_id , host_os ):
72
192
tree = None
73
193
74
194
try :
75
- tree = ET .parse (args . test_report )
195
+ tree = ET .parse (report_file )
76
196
except :
77
197
print (sys .exc_info ()[0 ])
78
- print ('Invalid path to test report.' )
198
+ print ('Invalid path to report: %s' , report_file )
79
199
sys .exit (1 )
80
200
81
201
test_suites = tree .getroot ()
82
202
83
- ts_data = {}
84
- ts_data ['testRuns' ] = []
85
-
86
- platforms_set = set ()
87
- toolchains_set = set ()
88
- testIds_set = set ()
89
- hostOses_set = set ()
90
-
91
- hostOses_set .add (args .host_os )
92
-
93
203
for test_suite in test_suites :
94
204
platform = ""
95
205
toolchain = ""
96
206
for properties in test_suite .findall ('properties' ):
97
207
for property in properties .findall ('property' ):
98
208
if property .attrib ['name' ] == 'target' :
99
209
platform = property .attrib ['value' ]
100
- platforms_set .add (platform )
210
+ project_run_data [ ' platforms_set' ] .add (platform )
101
211
elif property .attrib ['name' ] == 'toolchain' :
102
212
toolchain = property .attrib ['value' ]
103
- toolchains_set .add (toolchain )
213
+ project_run_data [ ' toolchains_set' ] .add (toolchain )
104
214
105
215
for test_case in test_suite .findall ('testcase' ):
106
- testRun = {}
107
- testRun ['build' ] = args . build_id
108
- testRun ['hostOs' ] = args . host_os
109
- testRun ['platform' ] = platform
110
- testRun ['toolchain' ] = toolchain
111
- testRun [ 'test ' ] = test_case .attrib ['classname' ].split ('.' )[- 1 ]
216
+ projectRun = {}
217
+ projectRun ['build' ] = build_id
218
+ projectRun ['hostOs' ] = host_os
219
+ projectRun ['platform' ] = platform
220
+ projectRun ['toolchain' ] = toolchain
221
+ projectRun [ 'project ' ] = test_case .attrib ['classname' ].split ('.' )[- 1 ]
112
222
113
- testIds_set .add (testRun [ 'test ' ])
223
+ project_run_data [ 'names_set' ] .add (projectRun [ 'project ' ])
114
224
115
225
system_outs = test_case .findall ('system-out' )
116
226
227
+ output = ""
117
228
if system_outs :
118
- testRun ['output' ] = system_outs [0 ].text
229
+ output = system_outs [0 ].text
230
+
231
+ if is_build :
232
+ projectRun ['buildOutput' ] = output
119
233
else :
120
- testRun [ 'output ' ] = ""
234
+ projectRun [ 'testOutput ' ] = output
121
235
122
236
errors = test_case .findall ('error' )
123
237
failures = test_case .findall ('failure' )
124
238
125
239
if errors :
126
- testRun ['pass' ] = False
127
- testRun ['result' ] = errors [0 ].attrib ['message' ]
240
+ projectRun ['pass' ] = False
241
+ projectRun ['result' ] = errors [0 ].attrib ['message' ]
128
242
elif failures :
129
- testRun ['pass' ] = False
130
- testRun ['result' ] = failures [0 ].attrib ['message' ]
243
+ projectRun ['pass' ] = False
244
+ projectRun ['result' ] = failures [0 ].attrib ['message' ]
131
245
else :
132
- testRun ['pass' ] = True
133
- testRun ['result' ] = 'OK'
134
-
135
- ts_data ['testRuns' ].append (testRun )
136
-
137
- ts_data ['platforms' ] = list (platforms_set )
138
- ts_data ['toolchains' ] = list (toolchains_set )
139
- ts_data ['testIds' ] = list (testIds_set )
140
- ts_data ['hostOses' ] = list (hostOses_set )
246
+ projectRun ['pass' ] = True
247
+ projectRun ['result' ] = 'OK'
141
248
142
- r = requests .post (urlparse .urljoin (args .url , "api/testRuns" ), headers = create_headers (args ), json = ts_data )
143
- finish_command ('add-test-runs' , r )
249
+ update_project_run (project_run_data ['projectRuns' ], projectRun )
144
250
145
251
def main (arguments ):
146
252
# Register and parse command line arguments
@@ -165,11 +271,12 @@ def main(arguments):
165
271
abort_build_parser .add_argument ('-b' , '--build-id' , required = True , help = 'build id' )
166
272
abort_build_parser .set_defaults (func = abort_build )
167
273
168
- add_test_runs_parser = subparsers .add_parser ('add-test-runs' , help = 'add test runs to a build' )
169
- add_test_runs_parser .add_argument ('-b' , '--build-id' , required = True , help = 'build id' )
170
- add_test_runs_parser .add_argument ('-t' , '--test-report' , required = True , help = 'path to junit xml test report' )
171
- add_test_runs_parser .add_argument ('-o' , '--host-os' , required = True , help = 'host os on which test was run' )
172
- add_test_runs_parser .set_defaults (func = add_test_runs )
274
+ add_project_runs_parser = subparsers .add_parser ('add-project-runs' , help = 'add project runs to a build' )
275
+ add_project_runs_parser .add_argument ('-b' , '--build-id' , required = True , help = 'build id' )
276
+ add_project_runs_parser .add_argument ('-r' , '--build-report' , required = True , help = 'path to junit xml build report' )
277
+ add_project_runs_parser .add_argument ('-t' , '--test-report' , required = False , help = 'path to junit xml test report' )
278
+ add_project_runs_parser .add_argument ('-o' , '--host-os' , required = True , help = 'host os on which test was run' )
279
+ add_project_runs_parser .set_defaults (func = add_project_runs )
173
280
174
281
args = parser .parse_args (arguments )
175
282
args .func (args )
0 commit comments