Debian Codegraph @

bin/xml2lcov

raw
1 #!/usr/bin/env python3
2
3 # Copyright (c) MediaTek USA Inc., 2020-2024
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or (at
8 # your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, see
17 # <http://www.gnu.org/licenses/>.
18 #
19 #
20 # This script traverses Python coverage data in one or more coverage
21 # data file (generated by the Coverage.py module) and translates it into
22 # LCOV .info format.
23 #
24 # xml2lcov [--output mydata.info] [--test-name name] [options] coverage.xml+
25 #
26 # See 'xml2lcov --help' for more usage information
27 #
28 # See the Cobertura documentation to see how to generate the XML coverage data
29
30 import os
31 import os.path
32 import sys
33 import re
34 import argparse
35 import xml.etree.ElementTree as ET
36 import fnmatch
37 import subprocess
38 import copy
39 import base64
40 import hashlib
41 import pdb
42 from xml2lcovutil import ProcessFile
43
44 def main():
45 usageString="""xml2lcov: Translate XML coverage data (e.g., generated by Cobertura)
46 to LCOV .info format.
47 See the Cobertura documentation for information on how to generate the
48 XML coverage data file.
49
50 Note that xml2lcov does not implement the full suite of LCOV features
51 (e.g., demangling, filtering, substitutions, etc.).
52 Please generate the translated LCOV format file and then read the data
53 back in to lcov to use any of those features.
54 %(usage)s
55 Example:
56
57 # generate the LCOV-format .info file
58 $ xml2lcov -o mydata.info coverage1.xml coverage2.xml
59
60 # apply some filtering
61 $ lcov -a mydata.info --filter branch,blank -o filtered.info
62
63 # and use genhtml to produce an HTML coverage report:
64 $ genhtml -o html_report mydata.info ....
65 $ genhtml -o html_filtered filtered.info ....
66 # use differential coverage to see exactly what filtering did
67 $ genhtml -o html_differential --baseline-file mydata.info filtered.info ...
68
69 """ % {
70 'usage' : ProcessFile.usageNote,
71 }
72
73 parser = argparse.ArgumentParser(
74 formatter_class=argparse.RawDescriptionHelpFormatter,
75 epilog=usageString)
76
77 parser.add_argument('-o', '--output', dest='output', default='xml2lcov.info',
78 help="specify the out LCOV .info file, default: xml2lcov.info")
79 parser.add_argument('-t', '--test-name', '--testname', dest='testName', default='',
80 help="specify the test name for the TN: entry in LCOV .info file")
81 parser.add_argument('-e', '--exclude', dest='excludePatterns', default='',
82 help="specify the exclude file patterns separated by ','")
83 parser.add_argument('-v', '--verbose', dest='verbose', default=0, action='count',
84 help="print debug messages")
85 parser.add_argument('--version-script', dest='version',
86 help="version extract callback")
87 parser.add_argument('--checksum', dest='checksum', action='store_true',
88 default=False,
89 help="compute line checksum - see 'man lcov'")
90 parser.add_argument('-k', "--keep-going", dest='keepGoing', default=False, action='store_true',
91 help="ignore errors")
92 parser.add_argument('inputs', nargs='*',
93 help="list of python coverage data input files - expected to be XML or Python .dat format")
94
95 args = parser.parse_args()
96
97 if not args.inputs:
98 print("Error: no input files")
99 sys.exit(1)
100
101 p = ProcessFile(args)
102
103 for f in args.inputs:
104 p.process_xml_file(f)
105
106 p.close()
107
108
109 if __name__ == '__main__':
110 main()