OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2016 the V8 project authors. All rights reserved. | 2 # Copyright 2016 the V8 project authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Script to transform and merge sancov files into human readable json-format. | 6 """Script to transform and merge sancov files into human readable json-format. |
7 | 7 |
8 The script supports three actions: | 8 The script supports three actions: |
9 all: Writes a json file with all instrumented lines of all executables. | 9 all: Writes a json file with all instrumented lines of all executables. |
10 merge: Merges sancov files with coverage output into an existing json file. | 10 merge: Merges sancov files with coverage output into an existing json file. |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 # Flat-copy the old dict. | 394 # Flat-copy the old dict. |
395 new_data = dict(data) | 395 new_data = dict(data) |
396 | 396 |
397 # Update current file. | 397 # Update current file. |
398 new_data['files'] = {file_name: coverage} | 398 new_data['files'] = {file_name: coverage} |
399 | 399 |
400 # Write json data. | 400 # Write json data. |
401 json.dump(new_data, f, sort_keys=True) | 401 json.dump(new_data, f, sort_keys=True) |
402 | 402 |
403 | 403 |
404 def main(): | 404 def main(args=None): |
405 parser = argparse.ArgumentParser() | 405 parser = argparse.ArgumentParser() |
406 parser.add_argument('--coverage-dir', | 406 parser.add_argument('--coverage-dir', |
407 help='Path to the sancov output files.') | 407 help='Path to the sancov output files.') |
408 parser.add_argument('--json-input', | 408 parser.add_argument('--json-input', |
409 help='Path to an existing json file with coverage data.') | 409 help='Path to an existing json file with coverage data.') |
410 parser.add_argument('--json-output', | 410 parser.add_argument('--json-output', |
411 help='Path to a file to write json output to.') | 411 help='Path to a file to write json output to.') |
412 parser.add_argument('--output-dir', | 412 parser.add_argument('--output-dir', |
413 help='Directory where to put split output files to.') | 413 help='Directory where to put split output files to.') |
414 parser.add_argument('action', choices=['all', 'merge', 'split'], | 414 parser.add_argument('action', choices=['all', 'merge', 'split'], |
415 help='Action to perform.') | 415 help='Action to perform.') |
416 | 416 |
417 options = parser.parse_args() | 417 options = parser.parse_args(args) |
418 if options.action.lower() == 'all': | 418 if options.action.lower() == 'all': |
419 if not options.json_output: | 419 if not options.json_output: |
420 print '--json-output is required' | 420 print '--json-output is required' |
421 return 1 | 421 return 1 |
422 write_instrumented(options) | 422 write_instrumented(options) |
423 elif options.action.lower() == 'merge': | 423 elif options.action.lower() == 'merge': |
424 if not options.coverage_dir: | 424 if not options.coverage_dir: |
425 print '--coverage-dir is required' | 425 print '--coverage-dir is required' |
426 return 1 | 426 return 1 |
427 if not options.json_input: | 427 if not options.json_input: |
428 print '--json-input is required' | 428 print '--json-input is required' |
429 return 1 | 429 return 1 |
430 if not options.json_output: | 430 if not options.json_output: |
431 print '--json-output is required' | 431 print '--json-output is required' |
432 return 1 | 432 return 1 |
433 merge(options) | 433 merge(options) |
434 elif options.action.lower() == 'split': | 434 elif options.action.lower() == 'split': |
435 if not options.json_input: | 435 if not options.json_input: |
436 print '--json-input is required' | 436 print '--json-input is required' |
437 return 1 | 437 return 1 |
438 if not options.output_dir: | 438 if not options.output_dir: |
439 print '--output-dir is required' | 439 print '--output-dir is required' |
440 return 1 | 440 return 1 |
441 split(options) | 441 split(options) |
442 return 0 | 442 return 0 |
443 | 443 |
444 | 444 |
445 if __name__ == '__main__': | 445 if __name__ == '__main__': |
446 sys.exit(main()) | 446 sys.exit(main()) |
OLD | NEW |