OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Crocodile HTML output.""" | 5 """Crocodile HTML output.""" |
6 | 6 |
7 import os | 7 import os |
8 import shutil | 8 import shutil |
9 import time | 9 import time |
10 import xml.dom | 10 import xml.dom |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 """Adds a section header to the coverage table. | 187 """Adds a section header to the coverage table. |
188 | 188 |
189 Args: | 189 Args: |
190 table: Table to add rows to. | 190 table: Table to add rows to. |
191 caption: Caption for section, if not None. | 191 caption: Caption for section, if not None. |
192 itemtype: Type of items in this section, if not None. | 192 itemtype: Type of items in this section, if not None. |
193 is_file: Are items in this section files? | 193 is_file: Are items in this section files? |
194 """ | 194 """ |
195 | 195 |
196 if caption is not None: | 196 if caption is not None: |
197 table.E('tr').E('td', e_class='secdesc', colspan=8).Text(caption) | 197 table.E('tr').E('th', e_class='secdesc', colspan=8).Text(caption) |
198 | 198 |
199 sec_hdr = table.E('tr') | 199 sec_hdr = table.E('tr') |
200 | 200 |
201 if itemtype is not None: | 201 if itemtype is not None: |
202 sec_hdr.E('td', e_class='section').Text(itemtype) | 202 sec_hdr.E('th', e_class='section').Text(itemtype) |
203 | 203 |
204 sec_hdr.E('td', e_class='section').Text('Coverage') | 204 sec_hdr.E('th', e_class='section').Text('Coverage') |
205 sec_hdr.E('td', e_class='section', colspan=3).Text( | 205 sec_hdr.E('th', e_class='section', colspan=3).Text( |
206 'Lines executed / instrumented / missing') | 206 'Lines executed / instrumented / missing') |
207 | 207 |
208 graph = sec_hdr.E('td', e_class='section') | 208 graph = sec_hdr.E('th', e_class='section') |
209 graph.E('span', style='color:#00FF00').Text('exe') | 209 graph.E('span', style='color:#00FF00').Text('exe') |
210 graph.Text(' / ') | 210 graph.Text(' / ') |
211 graph.E('span', style='color:#FFFF00').Text('inst') | 211 graph.E('span', style='color:#FFFF00').Text('inst') |
212 graph.Text(' / ') | 212 graph.Text(' / ') |
213 graph.E('span', style='color:#FF0000').Text('miss') | 213 graph.E('span', style='color:#FF0000').Text('miss') |
214 | 214 |
215 if is_file: | 215 if is_file: |
216 sec_hdr.E('td', e_class='section').Text('Language') | 216 sec_hdr.E('th', e_class='section').Text('Language') |
217 sec_hdr.E('td', e_class='section').Text('Group') | 217 sec_hdr.E('th', e_class='section').Text('Group') |
218 else: | 218 else: |
219 sec_hdr.E('td', e_class='section', colspan=2) | 219 sec_hdr.E('th', e_class='section', colspan=2) |
220 | 220 |
221 def AddItem(self, table, itemname, stats, attrs, link=None): | 221 def AddItem(self, table, itemname, stats, attrs, link=None): |
222 """Adds a bar graph to the element. This is a series of <td> elements. | 222 """Adds a bar graph to the element. This is a series of <td> elements. |
223 | 223 |
224 Args: | 224 Args: |
225 table: Table to add item to. | 225 table: Table to add item to. |
226 itemname: Name of item. | 226 itemname: Name of item. |
227 stats: Stats object. | 227 stats: Stats object. |
228 attrs: Attributes dictionary; if None, no attributes will be printed. | 228 attrs: Attributes dictionary; if None, no attributes will be printed. |
229 link: Destination for itemname hyperlink, if not None. | 229 link: Destination for itemname hyperlink, if not None. |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 | 351 |
352 if cov_dir.dirpath: | 352 if cov_dir.dirpath: |
353 title = 'Coverage for ' + cov_dir.dirpath + '/' | 353 title = 'Coverage for ' + cov_dir.dirpath + '/' |
354 f = self.CreateHtmlDoc(cov_dir.dirpath + '/index.html', title) | 354 f = self.CreateHtmlDoc(cov_dir.dirpath + '/index.html', title) |
355 else: | 355 else: |
356 title = 'Coverage summary' | 356 title = 'Coverage summary' |
357 f = self.CreateHtmlDoc('index.html', title) | 357 f = self.CreateHtmlDoc('index.html', title) |
358 | 358 |
359 body = f.body | 359 body = f.body |
360 | 360 |
| 361 dirs = [''] + cov_dir.dirpath.split('/') |
| 362 num_dirs = len(dirs) |
| 363 sort_jsfile = '../' * (num_dirs - 1) + 'sorttable.js' |
| 364 script = body.E('script', src=sort_jsfile) |
| 365 body.E('/script') |
| 366 |
361 # Write header section | 367 # Write header section |
362 if cov_dir.dirpath: | 368 if cov_dir.dirpath: |
363 self.AddCaptionForSubdir(body, cov_dir.dirpath) | 369 self.AddCaptionForSubdir(body, cov_dir.dirpath) |
364 else: | 370 else: |
365 body.E('h2').Text(title) | 371 body.E('h2').Text(title) |
366 | 372 |
367 table = body.E('table') | 373 table = body.E('table', e_class='sortable') |
368 | 374 table.E('h3').Text('Coverage by Group') |
369 # Coverage by group | 375 # Coverage by group |
370 self.AddSectionHeader(table, 'Coverage by Group', 'Group') | 376 self.AddSectionHeader(table, None, 'Group') |
371 | 377 |
372 for group in sorted(cov_dir.stats_by_group): | 378 for group in sorted(cov_dir.stats_by_group): |
373 self.AddItem(table, group, cov_dir.stats_by_group[group], None) | 379 self.AddItem(table, group, cov_dir.stats_by_group[group], None) |
374 | 380 |
| 381 table = body.E('table', e_class='sortable') |
| 382 table.E('h3').Text('Subdirectories') |
375 # List subdirs | 383 # List subdirs |
376 if cov_dir.subdirs: | 384 if cov_dir.subdirs: |
377 self.AddSectionHeader(table, 'Subdirectories', 'Subdirectory') | 385 self.AddSectionHeader(table, None, 'Subdirectory') |
378 | 386 |
379 for d in sorted(cov_dir.subdirs): | 387 for d in sorted(cov_dir.subdirs): |
380 self.AddItem(table, d + '/', cov_dir.subdirs[d].stats_by_group['all'], | 388 self.AddItem(table, d + '/', cov_dir.subdirs[d].stats_by_group['all'], |
381 None, link=d + '/index.html') | 389 None, link=d + '/index.html') |
382 | 390 |
| 391 table = body.E('table', e_class='sortable') |
| 392 table.E('h3').Text('Files in This Directory') |
383 # List files | 393 # List files |
384 if cov_dir.files: | 394 if cov_dir.files: |
385 self.AddSectionHeader(table, 'Files in This Directory', 'Filename', | 395 self.AddSectionHeader(table, None, 'Filename', |
386 is_file=True) | 396 is_file=True) |
387 | 397 |
388 for filename in sorted(cov_dir.files): | 398 for filename in sorted(cov_dir.files): |
389 cov_file = cov_dir.files[filename] | 399 cov_file = cov_dir.files[filename] |
390 self.AddItem(table, filename, cov_file.stats, cov_file.attrs, | 400 self.AddItem(table, filename, cov_file.stats, cov_file.attrs, |
391 link=filename + '.html') | 401 link=filename + '.html') |
392 | 402 |
393 body.E('p', e_class='time').Text(self.time_string) | 403 body.E('p', e_class='time').Text(self.time_string) |
394 f.Write() | 404 f.Write() |
395 | 405 |
396 def WriteRoot(self): | 406 def WriteRoot(self): |
397 """Writes the files in the output root.""" | 407 """Writes the files in the output root.""" |
398 # Find ourselves | 408 # Find ourselves |
399 src_dir = os.path.split(self.WriteRoot.func_code.co_filename)[0] | 409 src_dir = os.path.split(self.WriteRoot.func_code.co_filename)[0] |
400 | 410 |
401 # Files to copy into output root | 411 # Files to copy into output root |
402 copy_files = [ | 412 copy_files = ['croc.css'] |
403 'croc.css', | 413 # Third_party files to copy into output root |
404 ] | 414 third_party_files = ['sorttable.js'] |
405 | 415 |
406 # Copy files from our directory into the output directory | 416 # Copy files from our directory into the output directory |
407 for copy_file in copy_files: | 417 for copy_file in copy_files: |
408 print ' Copying %s' % copy_file | 418 print ' Copying %s' % copy_file |
409 shutil.copyfile(os.path.join(src_dir, copy_file), | 419 shutil.copyfile(os.path.join(src_dir, copy_file), |
410 os.path.join(self.output_root, copy_file)) | 420 os.path.join(self.output_root, copy_file)) |
| 421 # Copy third party files from third_party directory into |
| 422 # the output directory |
| 423 src_dir = os.path.join(src_dir, 'third_party') |
| 424 for third_party_file in third_party_files: |
| 425 print ' Copying %s' % third_party_file |
| 426 shutil.copyfile(os.path.join(src_dir, third_party_file), |
| 427 os.path.join(self.output_root, third_party_file)) |
411 | 428 |
412 def Write(self): | 429 def Write(self): |
413 """Writes HTML output.""" | 430 """Writes HTML output.""" |
414 | 431 |
415 print 'Writing HTML to %s...' % self.output_root | 432 print 'Writing HTML to %s...' % self.output_root |
416 | 433 |
417 # Loop through the tree and write subdirs, breadth-first | 434 # Loop through the tree and write subdirs, breadth-first |
418 # TODO: switch to depth-first and sort values - makes nicer output? | 435 # TODO: switch to depth-first and sort values - makes nicer output? |
419 todo = [self.cov.tree] | 436 todo = [self.cov.tree] |
420 while todo: | 437 while todo: |
421 cov_dir = todo.pop(0) | 438 cov_dir = todo.pop(0) |
422 | 439 |
423 # Append subdirs to todo list | 440 # Append subdirs to todo list |
424 todo += cov_dir.subdirs.values() | 441 todo += cov_dir.subdirs.values() |
425 | 442 |
426 # Write this subdir | 443 # Write this subdir |
427 self.WriteSubdir(cov_dir) | 444 self.WriteSubdir(cov_dir) |
428 | 445 |
429 # Write files in this subdir | 446 # Write files in this subdir |
430 for cov_file in cov_dir.files.itervalues(): | 447 for cov_file in cov_dir.files.itervalues(): |
431 self.WriteFile(cov_file) | 448 self.WriteFile(cov_file) |
432 | 449 |
433 # Write files in root directory | 450 # Write files in root directory |
434 self.WriteRoot() | 451 self.WriteRoot() |
OLD | NEW |