-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathguide.html
933 lines (777 loc) · 61.8 KB
/
guide.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Gcovr User Guide — gcovr 4.1 documentation</title>
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="next" title="Gcovr Cookbook" href="cookbook.html" />
<link rel="prev" title="Installation" href="installation.html" />
<script src="_static/js/modernizr.min.js"></script>
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search">
<a href="index.html" class="icon icon-home"> gcovr
</a>
<div class="version">
4.1
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<p class="caption"><span class="caption-text">Contents:</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="installation.html">Installation</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Gcovr User Guide</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#getting-started">Getting Started</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#tabular-output-of-code-coverage">Tabular Output of Code Coverage</a></li>
<li class="toctree-l3"><a class="reference internal" href="#tabular-output-of-branch-coverage">Tabular Output of Branch Coverage</a></li>
<li class="toctree-l3"><a class="reference internal" href="#xml-output">XML Output</a></li>
<li class="toctree-l3"><a class="reference internal" href="#html-output">HTML Output</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#the-gcovr-command">The gcovr Command</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#gcovr">gcovr</a><ul>
<li class="toctree-l4"><a class="reference internal" href="#options">Options</a></li>
<li class="toctree-l4"><a class="reference internal" href="#output-options">Output Options</a></li>
<li class="toctree-l4"><a class="reference internal" href="#filter-options">Filter Options</a></li>
<li class="toctree-l4"><a class="reference internal" href="#gcov-options">GCOV Options</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#using-filters">Using Filters</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#speeding-up-coverage-data-search">Speeding up coverage data search</a></li>
<li class="toctree-l3"><a class="reference internal" href="#filters-for-symlinks">Filters for symlinks</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="#acknowledgements">Acknowledgements</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="cookbook.html">Gcovr Cookbook</a></li>
<li class="toctree-l1"><a class="reference internal" href="faq.html">Frequently Asked Questions</a></li>
<li class="toctree-l1"><a class="reference internal" href="contributing.html">Contributing</a></li>
<li class="toctree-l1"><a class="reference internal" href="changelog.html">Change Log</a></li>
<li class="toctree-l1"><a class="reference internal" href="license.html">License</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="index.html">gcovr</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="index.html">Docs</a> »</li>
<li>Gcovr User Guide</li>
<li class="wy-breadcrumbs-aside">
<a href="_sources/guide.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<div class="section" id="gcovr-user-guide">
<h1>Gcovr User Guide<a class="headerlink" href="#gcovr-user-guide" title="Permalink to this headline">¶</a></h1>
<p>Gcovr provides a utility for managing the use of the GNU <a class="reference external" href="http://gcc.gnu.org/onlinedocs/gcc/Gcov.html">gcov</a> utility
and generating summarized code coverage results. This command is
inspired by the Python <a class="reference external" href="http://nedbatchelder.com/code/coverage/">coverage.py</a> package, which provides a similar
utility for Python.</p>
<p>The <code class="docutils literal notranslate"><span class="pre">gcovr</span></code> command can produce different kinds of coverage reports:</p>
<ul class="simple">
<li>default: compact human-readable summaries</li>
<li><code class="docutils literal notranslate"><span class="pre">--xml</span></code>: machine readable XML reports in <a class="reference external" href="http://cobertura.sourceforge.net/">Cobertura</a> format</li>
<li><code class="docutils literal notranslate"><span class="pre">--html</span></code>: HTML summaries</li>
<li><code class="docutils literal notranslate"><span class="pre">--html-details</span></code>: HTML report with annotated source files</li>
</ul>
<p>Thus, gcovr can be viewed
as a command-line alternative to the <a class="reference external" href="http://ltp.sourceforge.net/coverage/lcov.php">lcov</a> utility, which runs gcov
and generates an HTML-formatted report.
The development of gcovr was motivated by the need for
text summaries and XML reports.</p>
<p>The <a class="reference external" href="http://gcovr.com">Gcovr Home Page</a> is
<a class="reference external" href="http://gcovr.com">http://gcovr.com</a>.
Automated test results are available through
<a class="reference external" href="https://travis-ci.org/gcovr/gcovr">Travis CI</a> and
<a class="reference external" href="https://ci.appveyor.com/project/latk/gcovr-0p8sb/branch/master">Appveyor</a>.
Gcovr is available under the
<a class="reference external" href="http://www.gnu.org/licenses/bsd.html">BSD</a> license.</p>
<p>This documentation describes Gcovr 4.1.</p>
<p>This User Guide provides the following sections:</p>
<div class="contents local topic" id="contents">
<ul class="simple">
<li><a class="reference internal" href="#getting-started" id="id1">Getting Started</a><ul>
<li><a class="reference internal" href="#tabular-output-of-code-coverage" id="id2">Tabular Output of Code Coverage</a></li>
<li><a class="reference internal" href="#tabular-output-of-branch-coverage" id="id3">Tabular Output of Branch Coverage</a></li>
<li><a class="reference internal" href="#xml-output" id="id4">XML Output</a></li>
<li><a class="reference internal" href="#html-output" id="id5">HTML Output</a></li>
</ul>
</li>
<li><a class="reference internal" href="#the-gcovr-command" id="id6">The gcovr Command</a><ul>
<li><a class="reference internal" href="#gcovr" id="id7">gcovr</a></li>
</ul>
</li>
<li><a class="reference internal" href="#using-filters" id="id8">Using Filters</a><ul>
<li><a class="reference internal" href="#speeding-up-coverage-data-search" id="id9">Speeding up coverage data search</a></li>
<li><a class="reference internal" href="#filters-for-symlinks" id="id10">Filters for symlinks</a></li>
</ul>
</li>
<li><a class="reference internal" href="#acknowledgements" id="id11">Acknowledgements</a></li>
</ul>
</div>
<p>Related documents:</p>
<ul class="simple">
<li><a class="reference internal" href="installation.html"><span class="doc">Installation</span></a></li>
<li><a class="reference internal" href="contributing.html"><span class="doc">Contributing</span></a> (includes instructions for bug reports)</li>
<li><a class="reference internal" href="cookbook.html"><span class="doc">Gcovr Cookbook</span></a></li>
<li><a class="reference internal" href="faq.html"><span class="doc">Frequently Asked Questions</span></a></li>
<li><a class="reference internal" href="changelog.html"><span class="doc">Change Log</span></a></li>
<li><a class="reference internal" href="license.html"><span class="doc">License</span></a></li>
</ul>
<div class="section" id="getting-started">
<h2><a class="toc-backref" href="#id1">Getting Started</a><a class="headerlink" href="#getting-started" title="Permalink to this headline">¶</a></h2>
<p>The <code class="docutils literal notranslate"><span class="pre">gcovr</span></code> command provides a summary of the lines that have been
executed in a program. Code coverage statistics help you discover
untested parts of a program, which is particularly important when
assessing code quality. Well-tested code is a characteristic of
high quality code, and software developers often assess code coverage
statistics when deciding if software is ready for a release.</p>
<p>The <code class="docutils literal notranslate"><span class="pre">gcovr</span></code> command can be used to analyze programs compiled with
GCC. The following sections illustrate the application of <code class="docutils literal notranslate"><span class="pre">gcovr</span></code>
to test coverage of the following program:</p>
<pre class="code cpp literal-block">
<span class="ln"> 1 </span><span class="comment single">// example.cpp
</span><span class="ln"> 2 </span><span class="comment single"></span>
<span class="ln"> 3 </span><span class="keyword type">int</span> <span class="name function">foo</span><span class="punctuation">(</span><span class="keyword type">int</span> <span class="name">param</span><span class="punctuation">)</span>
<span class="ln"> 4 </span><span class="punctuation">{</span>
<span class="ln"> 5 </span> <span class="keyword">if</span> <span class="punctuation">(</span><span class="name">param</span><span class="punctuation">)</span>
<span class="ln"> 6 </span> <span class="punctuation">{</span>
<span class="ln"> 7 </span> <span class="keyword">return</span> <span class="literal number integer">1</span><span class="punctuation">;</span>
<span class="ln"> 8 </span> <span class="punctuation">}</span>
<span class="ln"> 9 </span> <span class="keyword">else</span>
<span class="ln">10 </span> <span class="punctuation">{</span>
<span class="ln">11 </span> <span class="keyword">return</span> <span class="literal number integer">0</span><span class="punctuation">;</span>
<span class="ln">12 </span> <span class="punctuation">}</span>
<span class="ln">13 </span><span class="punctuation">}</span>
<span class="ln">14 </span>
<span class="ln">15 </span><span class="keyword type">int</span> <span class="name function">main</span><span class="punctuation">(</span><span class="keyword type">int</span> <span class="name">argc</span><span class="punctuation">,</span> <span class="keyword type">char</span><span class="operator">*</span> <span class="name">argv</span><span class="punctuation">[])</span>
<span class="ln">16 </span><span class="punctuation">{</span>
<span class="ln">17 </span> <span class="name">foo</span><span class="punctuation">(</span><span class="literal number integer">0</span><span class="punctuation">);</span>
<span class="ln">18 </span>
<span class="ln">19 </span> <span class="keyword">return</span> <span class="literal number integer">0</span><span class="punctuation">;</span>
<span class="ln">20 </span><span class="punctuation">}</span>
</pre>
<p>This code executes several subroutines in this program,
but some lines in the program are not executed.</p>
<div class="section" id="tabular-output-of-code-coverage">
<h3><a class="toc-backref" href="#id2">Tabular Output of Code Coverage</a><a class="headerlink" href="#tabular-output-of-code-coverage" title="Permalink to this headline">¶</a></h3>
<p>We compile <code class="docutils literal notranslate"><span class="pre">example1.cpp</span></code> with the GCC compiler as follows:</p>
<pre class="code bash literal-block">
g++ -fprofile-arcs -ftest-coverage -fPIC -O0 example.cpp -o program
</pre>
<p>Note that we compile this program without optimization, because
optimization may combine lines of code and otherwise change the
flow of execution in the program. Additionally, we compile with
the <code class="docutils literal notranslate"><span class="pre">-fprofile-arcs</span> <span class="pre">-ftest-coverage</span> <span class="pre">-fPIC</span></code> compiler options, which
add logic to generate output files that can be processed by the
<code class="docutils literal notranslate"><span class="pre">gcov</span></code> command.</p>
<p>The compiler generates the <code class="docutils literal notranslate"><span class="pre">program</span></code> executable. When we execute this command:</p>
<pre class="code bash literal-block">
./program
</pre>
<p>the files <code class="docutils literal notranslate"><span class="pre">example1.gcno</span></code> and <code class="docutils literal notranslate"><span class="pre">example1.gcda</span></code> are generated. These
files are processed with by <code class="docutils literal notranslate"><span class="pre">gcov</span></code> to generate code coverage
statistics. The <code class="docutils literal notranslate"><span class="pre">gcovr</span></code> command calls <code class="docutils literal notranslate"><span class="pre">gcov</span></code> and summarizes these
code coverage statistics in various formats. For example:</p>
<pre class="code bash literal-block">
gcovr -r .
</pre>
<p>generates a text summary of the lines executed:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">------------------------------------------------------------------------------</span>
<span class="n">GCC</span> <span class="n">Code</span> <span class="n">Coverage</span> <span class="n">Report</span>
<span class="n">Directory</span><span class="p">:</span> <span class="o">.</span>
<span class="o">------------------------------------------------------------------------------</span>
<span class="n">File</span> <span class="n">Lines</span> <span class="n">Exec</span> <span class="n">Cover</span> <span class="n">Missing</span>
<span class="o">------------------------------------------------------------------------------</span>
<span class="n">example</span><span class="o">.</span><span class="n">cpp</span> <span class="mi">7</span> <span class="mi">6</span> <span class="mi">85</span><span class="o">%</span> <span class="mi">7</span>
<span class="o">------------------------------------------------------------------------------</span>
<span class="n">TOTAL</span> <span class="mi">7</span> <span class="mi">6</span> <span class="mi">85</span><span class="o">%</span>
<span class="o">------------------------------------------------------------------------------</span>
</pre></div>
</div>
<p>Each line of this output includes a summary for a given source file,
including the number of lines instrumented, the number of lines
executed, the percentage of lines executed, and a summary of the
line numbers that were not executed. To improve clarity, gcovr
uses an aggressive approach to grouping uncovered lines and will
combine uncovered lines separated by “non-code” lines (blank,
freestanding braces, and single-line comments) into a single region.
As a result, the number of lines listed in the “Missing” list may
be greater than the difference of the “Lines” and “Exec” columns.</p>
<p>The <code class="docutils literal notranslate"><span class="pre">-r</span></code> option specifies the root directory for the files that are
being analyzed. This allows <code class="docutils literal notranslate"><span class="pre">gcovr</span></code> to generate a simpler report
(without absolute path names), and it allows system header files
to be excluded from the analysis.</p>
<p>Note that <code class="docutils literal notranslate"><span class="pre">gcov</span></code> accumulates statistics by line. Consequently, it
works best with a programming style that places only one statement
on each line.</p>
</div>
<div class="section" id="tabular-output-of-branch-coverage">
<h3><a class="toc-backref" href="#id3">Tabular Output of Branch Coverage</a><a class="headerlink" href="#tabular-output-of-branch-coverage" title="Permalink to this headline">¶</a></h3>
<p>The <code class="docutils literal notranslate"><span class="pre">gcovr</span></code> command can also summarize branch coverage using the <code class="docutils literal notranslate"><span class="pre">--branches</span></code> option:</p>
<pre class="code bash literal-block">
gcovr -r . --branches
</pre>
<p>This generates a tabular output that summarizes the number of branches, the number of
branches taken and the branches that were not completely covered:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">------------------------------------------------------------------------------</span>
<span class="n">GCC</span> <span class="n">Code</span> <span class="n">Coverage</span> <span class="n">Report</span>
<span class="n">Directory</span><span class="p">:</span> <span class="o">.</span>
<span class="o">------------------------------------------------------------------------------</span>
<span class="n">File</span> <span class="n">Branches</span> <span class="n">Taken</span> <span class="n">Cover</span> <span class="n">Missing</span>
<span class="o">------------------------------------------------------------------------------</span>
<span class="n">example</span><span class="o">.</span><span class="n">cpp</span> <span class="mi">2</span> <span class="mi">1</span> <span class="mi">50</span><span class="o">%</span> <span class="mi">5</span>
<span class="o">------------------------------------------------------------------------------</span>
<span class="n">TOTAL</span> <span class="mi">2</span> <span class="mi">1</span> <span class="mi">50</span><span class="o">%</span>
<span class="o">------------------------------------------------------------------------------</span>
</pre></div>
</div>
</div>
<div class="section" id="xml-output">
<h3><a class="toc-backref" href="#id4">XML Output</a><a class="headerlink" href="#xml-output" title="Permalink to this headline">¶</a></h3>
<p>The default output format for <code class="docutils literal notranslate"><span class="pre">gcovr</span></code> is to generate a tabular
summary in plain text. The <code class="docutils literal notranslate"><span class="pre">gcovr</span></code> command can also generate an
XML output using the <code class="docutils literal notranslate"><span class="pre">--xml</span></code> and <code class="docutils literal notranslate"><span class="pre">--xml-pretty</span></code> options:</p>
<pre class="code bash literal-block">
gcovr -r . --xml-pretty
</pre>
<p>This generates an XML summary of the lines executed:</p>
<pre class="code xml literal-block">
<span class="comment preproc"><?xml version="1.0" ?></span>
<span class="comment preproc"><!DOCTYPE coverage
SYSTEM 'http://cobertura.sourceforge.net/xml/coverage-04.dtd'></span>
<span class="name tag"><coverage</span> <span class="name attribute">branch-rate=</span><span class="literal string">"0.5"</span> <span class="name attribute">branches-covered=</span><span class="literal string">"1"</span> <span class="name attribute">branches-valid=</span><span class="literal string">"2"</span>
<span class="name attribute">complexity=</span><span class="literal string">"0.0"</span> <span class="name attribute">line-rate=</span><span class="literal string">"0.8571428571428571"</span> <span class="name attribute">lines-covered=</span><span class="literal string">"6"</span>
<span class="name attribute">lines-valid=</span><span class="literal string">"7"</span> <span class="name attribute">timestamp=</span><span class="literal string">"1530565116"</span> <span class="name attribute">version=</span><span class="literal string">"gcovr 4.1"</span><span class="name tag">></span>
<span class="name tag"><sources></span>
<span class="name tag"><source></span>.<span class="name tag"></source></span>
<span class="name tag"></sources></span>
<span class="name tag"><packages></span>
<span class="name tag"><package</span> <span class="name attribute">branch-rate=</span><span class="literal string">"0.5"</span> <span class="name attribute">complexity=</span><span class="literal string">"0.0"</span> <span class="name attribute">line-rate=</span><span class="literal string">"0.8571428571428571"</span>
<span class="name attribute">name=</span><span class="literal string">""</span><span class="name tag">></span>
<span class="name tag"><classes></span>
<span class="name tag"><class</span> <span class="name attribute">branch-rate=</span><span class="literal string">"0.5"</span> <span class="name attribute">complexity=</span><span class="literal string">"0.0"</span> <span class="name attribute">filename=</span><span class="literal string">"example.cpp"</span>
<span class="name attribute">line-rate=</span><span class="literal string">"0.8571428571428571"</span> <span class="name attribute">name=</span><span class="literal string">"example_cpp"</span><span class="name tag">></span>
<span class="name tag"><methods/></span>
<span class="name tag"><lines></span>
<span class="name tag"><line</span> <span class="name attribute">branch=</span><span class="literal string">"false"</span> <span class="name attribute">hits=</span><span class="literal string">"1"</span> <span class="name attribute">number=</span><span class="literal string">"3"</span><span class="name tag">/></span>
<span class="name tag"><line</span> <span class="name attribute">branch=</span><span class="literal string">"true"</span> <span class="name attribute">condition-coverage=</span><span class="literal string">"50% (1/2)"</span> <span class="name attribute">hits=</span><span class="literal string">"1"</span> <span class="name attribute">number=</span><span class="literal string">"5"</span><span class="name tag">></span>
<span class="name tag"><conditions></span>
<span class="name tag"><condition</span> <span class="name attribute">coverage=</span><span class="literal string">"50%"</span> <span class="name attribute">number=</span><span class="literal string">"0"</span> <span class="name attribute">type=</span><span class="literal string">"jump"</span><span class="name tag">/></span>
<span class="name tag"></conditions></span>
<span class="name tag"></line></span>
<span class="name tag"><line</span> <span class="name attribute">branch=</span><span class="literal string">"false"</span> <span class="name attribute">hits=</span><span class="literal string">"0"</span> <span class="name attribute">number=</span><span class="literal string">"7"</span><span class="name tag">/></span>
<span class="name tag"><line</span> <span class="name attribute">branch=</span><span class="literal string">"false"</span> <span class="name attribute">hits=</span><span class="literal string">"1"</span> <span class="name attribute">number=</span><span class="literal string">"11"</span><span class="name tag">/></span>
<span class="name tag"><line</span> <span class="name attribute">branch=</span><span class="literal string">"false"</span> <span class="name attribute">hits=</span><span class="literal string">"1"</span> <span class="name attribute">number=</span><span class="literal string">"15"</span><span class="name tag">/></span>
<span class="name tag"><line</span> <span class="name attribute">branch=</span><span class="literal string">"false"</span> <span class="name attribute">hits=</span><span class="literal string">"1"</span> <span class="name attribute">number=</span><span class="literal string">"17"</span><span class="name tag">/></span>
<span class="name tag"><line</span> <span class="name attribute">branch=</span><span class="literal string">"false"</span> <span class="name attribute">hits=</span><span class="literal string">"1"</span> <span class="name attribute">number=</span><span class="literal string">"19"</span><span class="name tag">/></span>
<span class="name tag"></lines></span>
<span class="name tag"></class></span>
<span class="name tag"></classes></span>
<span class="name tag"></package></span>
<span class="name tag"></packages></span>
<span class="name tag"></coverage></span>
</pre>
<p>This XML format is in the
<a class="reference external" href="http://cobertura.sourceforge.net/xml/coverage-04.dtd">Cobertura XML</a>
format suitable for import and display within the
<a class="reference external" href="http://www.jenkins-ci.org/">Jenkins</a> and <a class="reference external" href="http://www.hudson-ci.org/">Hudson</a>
continuous integration servers using the
<a class="reference external" href="https://wiki.jenkins-ci.org/display/JENKINS/Cobertura+Plugin">Cobertura Plugin</a>.</p>
<p>The <code class="docutils literal notranslate"><span class="pre">--xml</span></code> option generates a denser XML output, and the <code class="docutils literal notranslate"><span class="pre">--xml-pretty</span></code>
option generates an indented XML output that is easier to read.
Note that the XML output contains more information than the tabular
summary. The tabular summary shows the percentage of covered lines,
while the XML output includes branch statistics and the number of
times that each line was covered. Consequently, XML output can be
used to support performance optimization in the same manner that
<code class="docutils literal notranslate"><span class="pre">gcov</span></code> does.</p>
</div>
<div class="section" id="html-output">
<h3><a class="toc-backref" href="#id5">HTML Output</a><a class="headerlink" href="#html-output" title="Permalink to this headline">¶</a></h3>
<p>The <code class="docutils literal notranslate"><span class="pre">gcovr</span></code> command can also generate a simple
HTML output using the <code class="docutils literal notranslate"><span class="pre">--html</span></code> option:</p>
<pre class="code bash literal-block">
gcovr -r . --html -o example-html.html
</pre>
<p>This generates a HTML summary of the lines executed. In this
example, the file <code class="docutils literal notranslate"><span class="pre">example1.html</span></code> is generated, which has the
following output:</p>
<img alt="_images/screenshot-html.png" class="align-center" src="_images/screenshot-html.png" />
<p>The default behavior of the <code class="docutils literal notranslate"><span class="pre">--html</span></code> option is to generate HTML for
a single webpage that summarizes the coverage for all files. The
HTML is printed to standard output, but the <code class="docutils literal notranslate"><span class="pre">-o</span></code> (<code class="docutils literal notranslate"><span class="pre">--output</span></code>) option
is used to specify a file that stores the HTML output.</p>
<p>The <code class="docutils literal notranslate"><span class="pre">--html-details</span></code> option is used to create a separate web page
for each file. Each of these web pages includes the contents of
file with annotations that summarize code coverage. Consider the following
command:</p>
<pre class="code bash literal-block">
gcovr -r . --html --html-details -o example-html-details.html
</pre>
<p>This generates the following HTML page for the file <code class="docutils literal notranslate"><span class="pre">example1.cpp</span></code>:</p>
<img alt="_images/screenshot-html-details.example.cpp.png" class="align-center" src="_images/screenshot-html-details.example.cpp.png" />
<p>Note that the <code class="docutils literal notranslate"><span class="pre">--html-details</span></code> option can only be used with the
<code class="docutils literal notranslate"><span class="pre">-o</span></code> (<code class="docutils literal notranslate"><span class="pre">--output</span></code>) option. For example, if the <code class="docutils literal notranslate"><span class="pre">--output</span></code> option
specifies the output file <code class="docutils literal notranslate"><span class="pre">coverage.html</span></code>, then the web pages
generated for each file will have names of the form
<code class="docutils literal notranslate"><span class="pre">coverage.<filename>.html</span></code>.</p>
</div>
</div>
<div class="section" id="the-gcovr-command">
<h2><a class="toc-backref" href="#id6">The gcovr Command</a><a class="headerlink" href="#the-gcovr-command" title="Permalink to this headline">¶</a></h2>
<p>The <code class="docutils literal notranslate"><span class="pre">gcovr</span></code> command recursively searches a directory tree to find
<code class="docutils literal notranslate"><span class="pre">gcov</span></code> coverage files, and generates a text summary of the code
coverage. The <code class="docutils literal notranslate"><span class="pre">--help</span></code> option generates the following summary of
the <code class="docutils literal notranslate"><span class="pre">gcovr</span></code> command line options:</p>
<div class="section" id="gcovr">
<h3><a class="toc-backref" href="#id7">gcovr</a><a class="headerlink" href="#gcovr" title="Permalink to this headline">¶</a></h3>
<p>A utility to run gcov and summarize the coverage in simple reports.</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="go">usage: gcovr [options] [search_paths...]</span>
</pre></div>
</div>
<p>See <<a class="reference external" href="http://gcovr.com/">http://gcovr.com/</a>> for the full manual.</p>
<div class="section" id="options">
<h4>Options<a class="headerlink" href="#options" title="Permalink to this headline">¶</a></h4>
<dl class="option">
<dt id="cmdoption-gcovr-arg-search-paths">
<code class="descname">search_paths</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-gcovr-arg-search-paths" title="Permalink to this definition">¶</a></dt>
<dd><p>Search these directories for coverage files. Defaults to --root and --object-directory.</p>
</dd></dl>
<dl class="option">
<dt id="cmdoption-gcovr-h">
<code class="descname">-h</code><code class="descclassname"></code><code class="descclassname">, </code><code class="descname">--help</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-gcovr-h" title="Permalink to this definition">¶</a></dt>
<dd><p>Show this help message, then exit.</p>
</dd></dl>
<dl class="option">
<dt id="cmdoption-gcovr-version">
<code class="descname">--version</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-gcovr-version" title="Permalink to this definition">¶</a></dt>
<dd><p>Print the version number, then exit.</p>
</dd></dl>
<dl class="option">
<dt id="cmdoption-gcovr-v">
<code class="descname">-v</code><code class="descclassname"></code><code class="descclassname">, </code><code class="descname">--verbose</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-gcovr-v" title="Permalink to this definition">¶</a></dt>
<dd><p>Print progress messages. Please include this output in bug reports.</p>
</dd></dl>
<dl class="option">
<dt id="cmdoption-gcovr-r">
<code class="descname">-r</code><code class="descclassname"> <root></code><code class="descclassname">, </code><code class="descname">--root</code><code class="descclassname"> <root></code><a class="headerlink" href="#cmdoption-gcovr-r" title="Permalink to this definition">¶</a></dt>
<dd><p>The root directory of your source files. Defaults to ‘.’, the current directory. File names are reported relative to this root. The --root is the default --filter.</p>
</dd></dl>
<dl class="option">
<dt id="cmdoption-gcovr-fail-under-line">
<code class="descname">--fail-under-line</code><code class="descclassname"> <min></code><a class="headerlink" href="#cmdoption-gcovr-fail-under-line" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit with a status of 2 if the total line coverage is less than MIN. Can be ORed with exit status of ‘--fail-under-branch’ option.</p>
</dd></dl>
<dl class="option">
<dt id="cmdoption-gcovr-fail-under-branch">
<code class="descname">--fail-under-branch</code><code class="descclassname"> <min></code><a class="headerlink" href="#cmdoption-gcovr-fail-under-branch" title="Permalink to this definition">¶</a></dt>
<dd><p>Exit with a status of 4 if the total branch coverage is less than MIN. Can be ORed with exit status of ‘--fail-under-line’ option.</p>
</dd></dl>
<dl class="option">
<dt id="cmdoption-gcovr-source-encoding">
<code class="descname">--source-encoding</code><code class="descclassname"> <source_encoding></code><a class="headerlink" href="#cmdoption-gcovr-source-encoding" title="Permalink to this definition">¶</a></dt>
<dd><p>Select the source file encoding. Defaults to the system default encoding (UTF-8).</p>
</dd></dl>
<dl class="option">
<dt id="cmdoption-gcovr-html-medium-threshold">
<code class="descname">--html-medium-threshold</code><code class="descclassname"> <medium></code><a class="headerlink" href="#cmdoption-gcovr-html-medium-threshold" title="Permalink to this definition">¶</a></dt>
<dd><p>If the coverage is below MEDIUM, the value is marked as low coverage in the HTML report. MEDIUM has to be lower than or equal to value of --html-high-threshold. If MEDIUM is equal to value of --html-high-threshold the report has only high and low coverage. Default is 75.0.</p>
</dd></dl>
<dl class="option">
<dt id="cmdoption-gcovr-html-high-threshold">
<code class="descname">--html-high-threshold</code><code class="descclassname"> <high></code><a class="headerlink" href="#cmdoption-gcovr-html-high-threshold" title="Permalink to this definition">¶</a></dt>
<dd><p>If the coverage is below HIGH, the value is marked as medium coverage in the HTML report. HIGH has to be greater than or equal to value of --html-medium-threshold. If HIGH is equal to value of --html-medium-threshold the report has only high and low coverage. Default is 90.0.</p>
</dd></dl>
</div>
<div class="section" id="output-options">
<h4>Output Options<a class="headerlink" href="#output-options" title="Permalink to this headline">¶</a></h4>
<p>Gcovr prints a text report by default, but can switch to XML or HTML.</p>
<dl class="option">
<dt id="cmdoption-gcovr-o">
<code class="descname">-o</code><code class="descclassname"> <output></code><code class="descclassname">, </code><code class="descname">--output</code><code class="descclassname"> <output></code><a class="headerlink" href="#cmdoption-gcovr-o" title="Permalink to this definition">¶</a></dt>
<dd><p>Print output to this filename. Defaults to stdout. Required for --html-details.</p>
</dd></dl>
<dl class="option">
<dt id="cmdoption-gcovr-b">
<code class="descname">-b</code><code class="descclassname"></code><code class="descclassname">, </code><code class="descname">--branches</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-gcovr-b" title="Permalink to this definition">¶</a></dt>
<dd><p>Report the branch coverage instead of the line coverage. For text report only.</p>
</dd></dl>
<dl class="option">
<dt id="cmdoption-gcovr-u">
<code class="descname">-u</code><code class="descclassname"></code><code class="descclassname">, </code><code class="descname">--sort-uncovered</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-gcovr-u" title="Permalink to this definition">¶</a></dt>
<dd><p>Sort entries by increasing number of uncovered lines. For text and HTML report.</p>
</dd></dl>
<dl class="option">
<dt id="cmdoption-gcovr-p">
<code class="descname">-p</code><code class="descclassname"></code><code class="descclassname">, </code><code class="descname">--sort-percentage</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-gcovr-p" title="Permalink to this definition">¶</a></dt>
<dd><p>Sort entries by increasing percentage of uncovered lines. For text and HTML report.</p>
</dd></dl>
<dl class="option">
<dt id="cmdoption-gcovr-x">
<code class="descname">-x</code><code class="descclassname"></code><code class="descclassname">, </code><code class="descname">--xml</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-gcovr-x" title="Permalink to this definition">¶</a></dt>
<dd><p>Generate a Cobertura XML report.</p>
</dd></dl>
<dl class="option">
<dt id="cmdoption-gcovr-xml-pretty">
<code class="descname">--xml-pretty</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-gcovr-xml-pretty" title="Permalink to this definition">¶</a></dt>
<dd><p>Pretty-print the XML report. Implies --xml. Default: False.</p>
</dd></dl>
<dl class="option">
<dt id="cmdoption-gcovr-html">
<code class="descname">--html</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-gcovr-html" title="Permalink to this definition">¶</a></dt>
<dd><p>Generate a HTML report.</p>
</dd></dl>
<dl class="option">
<dt id="cmdoption-gcovr-html-details">
<code class="descname">--html-details</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-gcovr-html-details" title="Permalink to this definition">¶</a></dt>
<dd><p>Add annotated source code reports to the HTML report. Requires --output as a basename for the reports. Implies --html.</p>
</dd></dl>
<dl class="option">
<dt id="cmdoption-gcovr-html-title">
<code class="descname">--html-title</code><code class="descclassname"> <title></code><a class="headerlink" href="#cmdoption-gcovr-html-title" title="Permalink to this definition">¶</a></dt>
<dd><p>Use TITLE as title for the HTML report. Default is Head.</p>
</dd></dl>
<dl class="option">
<dt id="cmdoption-gcovr-html-absolute-paths">
<code class="descname">--html-absolute-paths</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-gcovr-html-absolute-paths" title="Permalink to this definition">¶</a></dt>
<dd><p>Use absolute paths to link the --html-details reports. Defaults to relative links.</p>
</dd></dl>
<dl class="option">
<dt id="cmdoption-gcovr-html-encoding">
<code class="descname">--html-encoding</code><code class="descclassname"> <html_encoding></code><a class="headerlink" href="#cmdoption-gcovr-html-encoding" title="Permalink to this definition">¶</a></dt>
<dd><p>Override the declared HTML report encoding. Defaults to UTF-8. See also --source-encoding.</p>
</dd></dl>
<dl class="option">
<dt id="cmdoption-gcovr-s">
<code class="descname">-s</code><code class="descclassname"></code><code class="descclassname">, </code><code class="descname">--print-summary</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-gcovr-s" title="Permalink to this definition">¶</a></dt>
<dd><p>Print a small report to stdout with line & branch percentage coverage. This is in addition to other reports. Default: False.</p>
</dd></dl>
</div>
<div class="section" id="filter-options">
<h4>Filter Options<a class="headerlink" href="#filter-options" title="Permalink to this headline">¶</a></h4>
<p>Filters decide which files are included in the report. Any filter must match, and no exclude filter must match. A filter is a regular expression that matches a path. Filter paths use forward slashes, even on Windows.</p>
<dl class="option">
<dt id="cmdoption-gcovr-f">
<code class="descname">-f</code><code class="descclassname"> <filter></code><code class="descclassname">, </code><code class="descname">--filter</code><code class="descclassname"> <filter></code><a class="headerlink" href="#cmdoption-gcovr-f" title="Permalink to this definition">¶</a></dt>
<dd><p>Keep only source files that match this filter. Can be specified multiple times. If no filters are provided, defaults to --root.</p>
</dd></dl>
<dl class="option">
<dt id="cmdoption-gcovr-e">
<code class="descname">-e</code><code class="descclassname"> <exclude></code><code class="descclassname">, </code><code class="descname">--exclude</code><code class="descclassname"> <exclude></code><a class="headerlink" href="#cmdoption-gcovr-e" title="Permalink to this definition">¶</a></dt>
<dd><p>Exclude source files that match this filter. Can be specified multiple times.</p>
</dd></dl>
<dl class="option">
<dt id="cmdoption-gcovr-gcov-filter">
<code class="descname">--gcov-filter</code><code class="descclassname"> <gcov_filter></code><a class="headerlink" href="#cmdoption-gcovr-gcov-filter" title="Permalink to this definition">¶</a></dt>
<dd><p>Keep only gcov data files that match this filter. Can be specified multiple times.</p>
</dd></dl>
<dl class="option">
<dt id="cmdoption-gcovr-gcov-exclude">
<code class="descname">--gcov-exclude</code><code class="descclassname"> <gcov_exclude></code><a class="headerlink" href="#cmdoption-gcovr-gcov-exclude" title="Permalink to this definition">¶</a></dt>
<dd><p>Exclude gcov data files that match this filter. Can be specified multiple times.</p>
</dd></dl>
<dl class="option">
<dt id="cmdoption-gcovr-exclude-directories">
<code class="descname">--exclude-directories</code><code class="descclassname"> <exclude_dirs></code><a class="headerlink" href="#cmdoption-gcovr-exclude-directories" title="Permalink to this definition">¶</a></dt>
<dd><p>Exclude directories that match this regex while searching raw coverage files. Can be specified multiple times.</p>
</dd></dl>
</div>
<div class="section" id="gcov-options">
<h4>GCOV Options<a class="headerlink" href="#gcov-options" title="Permalink to this headline">¶</a></h4>
<p>The ‘gcov’ tool turns raw coverage files (.gcda and .gcno) into .gcov files that are then processed by gcovr. The gcno files are generated by the compiler. The gcda files are generated when the instrumented program is executed.</p>
<dl class="option">
<dt id="cmdoption-gcovr-gcov-executable">
<code class="descname">--gcov-executable</code><code class="descclassname"> <gcov_cmd></code><a class="headerlink" href="#cmdoption-gcovr-gcov-executable" title="Permalink to this definition">¶</a></dt>
<dd><p>Use a particular gcov executable. Must match the compiler you are using, e.g. ‘llvm-cov gcov’ for Clang. Can include additional arguments. Defaults to the GCOV environment variable, or ‘gcov’: ‘gcov’.</p>
</dd></dl>
<dl class="option">
<dt id="cmdoption-gcovr-exclude-unreachable-branches">
<code class="descname">--exclude-unreachable-branches</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-gcovr-exclude-unreachable-branches" title="Permalink to this definition">¶</a></dt>
<dd><p>Exclude branch coverage with LCOV/GCOV exclude markers. Additionally, exclude branch coverage from lines without useful source code (often, compiler-generated “dead” code). Default: False.</p>
</dd></dl>
<dl class="option">
<dt id="cmdoption-gcovr-g">
<code class="descname">-g</code><code class="descclassname"></code><code class="descclassname">, </code><code class="descname">--use-gcov-files</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-gcovr-g" title="Permalink to this definition">¶</a></dt>
<dd><p>Use existing gcov files for analysis. Default: False.</p>
</dd></dl>
<dl class="option">
<dt id="cmdoption-gcovr-gcov-ignore-parse-errors">
<code class="descname">--gcov-ignore-parse-errors</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-gcovr-gcov-ignore-parse-errors" title="Permalink to this definition">¶</a></dt>
<dd><p>Skip lines with parse errors in GCOV files instead of exiting with an error. A report will be shown on stderr. Default: False.</p>
</dd></dl>
<dl class="option">
<dt id="cmdoption-gcovr-object-directory">
<code class="descname">--object-directory</code><code class="descclassname"> <objdir></code><a class="headerlink" href="#cmdoption-gcovr-object-directory" title="Permalink to this definition">¶</a></dt>
<dd><p>Override normal working directory detection. Gcovr needs to identify the path between gcda files and the directory where the compiler was originally run. Normally, gcovr can guess correctly. This option specifies either the path from gcc to the gcda file (i.e. gcc’s ‘-o’ option), or the path from the gcda file to gcc’s working directory.</p>
</dd></dl>
<dl class="option">
<dt id="cmdoption-gcovr-k">
<code class="descname">-k</code><code class="descclassname"></code><code class="descclassname">, </code><code class="descname">--keep</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-gcovr-k" title="Permalink to this definition">¶</a></dt>
<dd><p>Keep gcov files after processing. This applies both to files that were generated by gcovr, or were supplied via the --use-gcov-files option. Default: False.</p>
</dd></dl>
<dl class="option">
<dt id="cmdoption-gcovr-d">
<code class="descname">-d</code><code class="descclassname"></code><code class="descclassname">, </code><code class="descname">--delete</code><code class="descclassname"></code><a class="headerlink" href="#cmdoption-gcovr-d" title="Permalink to this definition">¶</a></dt>
<dd><p>Delete gcda files after processing. Default: False.</p>
</dd></dl>
<dl class="option">
<dt id="cmdoption-gcovr-j">
<code class="descname">-j</code><code class="descclassname"> <gcov_parallel></code><a class="headerlink" href="#cmdoption-gcovr-j" title="Permalink to this definition">¶</a></dt>
<dd><p>Set the number of threads to use in parallel.</p>
</dd></dl>
</div>
</div>
<p>The above <a class="reference internal" href="#getting-started">Getting Started</a> guide
illustrates the use of some command line options.
<a class="reference internal" href="#using-filters">Using Filters</a> is discussed below.</p>
</div>
<div class="section" id="using-filters">
<h2><a class="toc-backref" href="#id8">Using Filters</a><a class="headerlink" href="#using-filters" title="Permalink to this headline">¶</a></h2>
<p>Gcovr tries to only report coverage for files within your project,
not for your libraries. This is influenced by the following options:</p>
<ul class="simple">
<li><a class="reference internal" href="#cmdoption-gcovr-r"><code class="xref std std-option docutils literal notranslate"><span class="pre">-r</span></code></a>, <a class="reference internal" href="#cmdoption-gcovr-r"><code class="xref std std-option docutils literal notranslate"><span class="pre">--root</span></code></a></li>
<li><a class="reference internal" href="#cmdoption-gcovr-f"><code class="xref std std-option docutils literal notranslate"><span class="pre">-f</span></code></a>, <a class="reference internal" href="#cmdoption-gcovr-f"><code class="xref std std-option docutils literal notranslate"><span class="pre">--filter</span></code></a></li>
<li><a class="reference internal" href="#cmdoption-gcovr-e"><code class="xref std std-option docutils literal notranslate"><span class="pre">-e</span></code></a>, <a class="reference internal" href="#cmdoption-gcovr-e"><code class="xref std std-option docutils literal notranslate"><span class="pre">--exclude</span></code></a></li>
<li><a class="reference internal" href="#cmdoption-gcovr-gcov-filter"><code class="xref std std-option docutils literal notranslate"><span class="pre">--gcov-filter</span></code></a></li>
<li><a class="reference internal" href="#cmdoption-gcovr-gcov-exclude"><code class="xref std std-option docutils literal notranslate"><span class="pre">--gcov-exclude</span></code></a></li>
<li><a class="reference internal" href="#cmdoption-gcovr-exclude-directories"><code class="xref std std-option docutils literal notranslate"><span class="pre">--exclude-directories</span></code></a></li>
<li>(the current working directory where gcovr is invoked)</li>
</ul>
<p>These options take filters.
A filter is a regular expression that matches a file path.
Because filters are regexes,
you will have to escape “special” characters with a backslash <code class="docutils literal notranslate"><span class="pre">\</span></code>.</p>
<p>Always use forward slashes <code class="docutils literal notranslate"><span class="pre">/</span></code> as path separators, even on Windows:</p>
<ul class="simple">
<li>wrong: <code class="docutils literal notranslate"><span class="pre">--filter</span> <span class="pre">C:\project\src\</span></code></li>
<li>correct: <code class="docutils literal notranslate"><span class="pre">--filter</span> <span class="pre">C:/project/src/</span></code></li>
</ul>
<p>If the filter looks like an absolute path,
it is matched against an absolute path.
Otherwise, the filter is matched against a relative path,
where that path is relative to the current directory.
Examples of relative filters:</p>
<ul class="simple">
<li><code class="docutils literal notranslate"><span class="pre">--filter</span> <span class="pre">subdir/</span></code> matches only that subdirectory</li>
<li><code class="docutils literal notranslate"><span class="pre">--filter</span> <span class="pre">'\.\./src/'</span></code> matches a sibling directory <code class="docutils literal notranslate"><span class="pre">../src</span></code>.
But because a dot <code class="docutils literal notranslate"><span class="pre">.</span></code> matches any character in a regex,
we have to escape it.
You have to use additional shell escaping.
This example uses single quotes for Bash or POSIX shell.</li>
<li><code class="docutils literal notranslate"><span class="pre">--filter</span> <span class="pre">'(.+/)?foo\.c$'</span></code> matches only files called <code class="docutils literal notranslate"><span class="pre">foo.c</span></code>.
The regex must match from the start of the relative path,
so we ignore any leading directory parts with <code class="docutils literal notranslate"><span class="pre">(.+/)?</span></code>.
The <code class="docutils literal notranslate"><span class="pre">$</span></code> at the end ensures that the path ends here.</li>
</ul>
<p>If no <a class="reference internal" href="#cmdoption-gcovr-f"><code class="xref std std-option docutils literal notranslate"><span class="pre">--filter</span></code></a> is provided,
the <a class="reference internal" href="#cmdoption-gcovr-r"><code class="xref std std-option docutils literal notranslate"><span class="pre">--root</span></code></a> is turned into a default filter.
Therefore, files outside of the <a class="reference internal" href="#cmdoption-gcovr-r"><code class="xref std std-option docutils literal notranslate"><span class="pre">--root</span></code></a> directory are excluded.</p>
<p>To be included in a report, the source file must match any <a class="reference internal" href="#cmdoption-gcovr-f"><code class="xref std std-option docutils literal notranslate"><span class="pre">--filter</span></code></a>,
and must not match any <a class="reference internal" href="#cmdoption-gcovr-e"><code class="xref std std-option docutils literal notranslate"><span class="pre">--exclude</span></code></a> filter.</p>
<p>The <a class="reference internal" href="#cmdoption-gcovr-gcov-filter"><code class="xref std std-option docutils literal notranslate"><span class="pre">--gcov-filter</span></code></a> and <a class="reference internal" href="#cmdoption-gcovr-gcov-exclude"><code class="xref std std-option docutils literal notranslate"><span class="pre">--gcov-exclude</span></code></a> filters apply to the <code class="docutils literal notranslate"><span class="pre">.gcov</span></code> files created by <code class="docutils literal notranslate"><span class="pre">gcov</span></code>.
This is useful mostly when running gcov yourself,
and then invoking gcovr with <a class="reference internal" href="#cmdoption-gcovr-g"><code class="xref std std-option docutils literal notranslate"><span class="pre">-g</span></code></a>/<a class="reference internal" href="#cmdoption-gcovr-g"><code class="xref std std-option docutils literal notranslate"><span class="pre">--use-gcov-files</span></code></a>.
But these filters also apply when gcov is launched by gcovr.</p>
<div class="section" id="speeding-up-coverage-data-search">
<h3><a class="toc-backref" href="#id9">Speeding up coverage data search</a><a class="headerlink" href="#speeding-up-coverage-data-search" title="Permalink to this headline">¶</a></h3>
<p>The <a class="reference internal" href="#cmdoption-gcovr-exclude-directories"><code class="xref std std-option docutils literal notranslate"><span class="pre">--exclude-directories</span></code></a> filter is used
while searching for raw coverage data
(or for existing <code class="docutils literal notranslate"><span class="pre">.gcov</span></code> files when <a class="reference internal" href="#cmdoption-gcovr-g"><code class="xref std std-option docutils literal notranslate"><span class="pre">--use-gcov-files</span></code></a> is active).
This filter is matched against directory paths, not file paths.
If a directory matches,
all its contents (files and subdirectories) will be excluded from the search.
For example, consider this build directory:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>build/
├─ main.o
├─ main.gcda
├─ main.gcno
├─ a/
│ ├─ awesome_code.o
│ ├─ awesome_code.gcda
│ └─ awesome_code.gcno
└─ b/
├─ better_code.o
├─ better_code.gcda
└─ better_code.gcno
</pre></div>
</div>
<p>If we run <code class="docutils literal notranslate"><span class="pre">gcovr</span> <span class="pre">--exclude-directories</span> <span class="pre">'build/a$'</span></code>,
this will exclude anything in the <code class="docutils literal notranslate"><span class="pre">build/a</span></code> directory
but will use the coverage data for <code class="docutils literal notranslate"><span class="pre">better_code.o</span></code> and <code class="docutils literal notranslate"><span class="pre">main.o</span></code>.</p>
<p>This can speed up gcovr when you have a complicated build directory structure.
Consider also using the <a class="reference internal" href="#cmdoption-gcovr-arg-search-paths"><code class="xref std std-option docutils literal notranslate"><span class="pre">search_paths</span></code></a>
or <a class="reference internal" href="#cmdoption-gcovr-object-directory"><code class="xref std std-option docutils literal notranslate"><span class="pre">--object-directory</span></code></a> arguments
to specify where gcovr starts searching.
If you are unsure which directories are being searched,
run gcovr in <a class="reference internal" href="#cmdoption-gcovr-v"><code class="xref std std-option docutils literal notranslate"><span class="pre">--verbose</span></code></a> mode.</p>
<p>For each found coverage data file gcovr will invoke the <code class="docutils literal notranslate"><span class="pre">gcov</span></code> tool.
This is typically the slowest part,
and other filters can only be applied <em>after</em> this step.
In some cases, parallel execution with the <a class="reference internal" href="#cmdoption-gcovr-j"><code class="xref std std-option docutils literal notranslate"><span class="pre">-j</span></code></a> option
might be helpful to speed up processing.</p>
</div>
<div class="section" id="filters-for-symlinks">
<h3><a class="toc-backref" href="#id10">Filters for symlinks</a><a class="headerlink" href="#filters-for-symlinks" title="Permalink to this headline">¶</a></h3>
<p>Gcovr matches filters against <em>real paths</em>
that have all their symlinks resolved.
E.g. consider this project layout:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>/home/you/
├─ project/ (pwd)
│ ├─ src/
│ ├─ relevant-library/ -> ../external-library/
│ └─ ignore-this/
└─ external-library/
└─ src/
</pre></div>
</div>
<p>Here, the <code class="docutils literal notranslate"><span class="pre">relevant-library</span></code>
has the real path <code class="docutils literal notranslate"><span class="pre">/home/you/external-library</span></code>.</p>
<p>To write a filter that includes both <code class="docutils literal notranslate"><span class="pre">src/</span></code> and <code class="docutils literal notranslate"><span class="pre">relevant-library/src/</span></code>,
we cannot use <code class="docutils literal notranslate"><span class="pre">--filter</span> <span class="pre">relevant-library/src/</span></code>
because that contains a symlink.
Instead, we have to use an absolute path to the real name:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">gcovr</span> <span class="o">--</span><span class="nb">filter</span> <span class="n">src</span><span class="o">/</span> <span class="o">--</span><span class="nb">filter</span> <span class="o">/</span><span class="n">home</span><span class="o">/</span><span class="n">you</span><span class="o">/</span><span class="n">external</span><span class="o">-</span><span class="n">library</span><span class="o">/</span><span class="n">src</span><span class="o">/</span>
</pre></div>
</div>
<p>or a relative path to the real path:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">gcovr</span> <span class="o">--</span><span class="nb">filter</span> <span class="n">src</span><span class="o">/</span> <span class="o">--</span><span class="nb">filter</span> <span class="s1">'\.\./external-library/src/'</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">This section discusses symlinks on Unix systems.
The behavior under Windows is unclear.
If you have more insight,
please update this section by submitting a pull request
(see our <a class="reference internal" href="contributing.html"><span class="doc">contributing guide</span></a>).</p>
</div>
</div>
</div>
<div class="section" id="acknowledgements">
<h2><a class="toc-backref" href="#id11">Acknowledgements</a><a class="headerlink" href="#acknowledgements" title="Permalink to this headline">¶</a></h2>
<p>Gcovr is maintained by:</p>
<blockquote>
<div>William Hart,
John Siirola,
and Lukas Atkinson.</div></blockquote>
<p>The following developers contributed to gcovr (ordered alphabetically):</p>
<blockquote>
<div>Andrew Stone,
Arvin Schnell,
Attie Grande,
Bernhard Breinbauer,
Carlos Jenkins,
Christian Taedcke,
Dave George,
Dom Postorivo,
goriy,
ja11sop,
James Reynolds,
Jessica Levine,
Joel Klinghed,
John Siirola,
Jörg Kreuzberger,
Kai Blaschke,
Kevin Cai,
libPhipp,
Lukas Atkinson,
Luke Woydziak,
Marek Kurdej,
Martin Mraz,
Matsumoto Taichi,
Matthew Stadelman,
Matthias Schmieder,
Matthieu Darbois,
Michał Pszona,
Michael Förderer,
Mikael Salson,
Mikk Leini,
Nikolaj Schumacher,
Piotr Dziwinski,
Reto Schneider,
Robert Rosengren,
Songmin Li,
Steven Myint,
Sylvestre Ledru,
trapzero,
William Hart,
and possibly others.</div></blockquote>
<p>The development of Gcovr has been partially supported
by Sandia National Laboratories. Sandia National Laboratories is
a multi-program laboratory managed and operated by Sandia Corporation,
a wholly owned subsidiary of Lockheed Martin Corporation, for the
U.S. Department of Energy’s National Nuclear Security Administration
under contract DE-AC04-94AL85000.</p>
</div>
</div>
</div>
</div>
<footer>
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
<a href="cookbook.html" class="btn btn-neutral float-right" title="Gcovr Cookbook" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
<a href="installation.html" class="btn btn-neutral" title="Installation" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
</div>
<hr/>
<div role="contentinfo">
<p>
© Copyright 2018, the gcovr authors.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'./',
VERSION:'4.1',
LANGUAGE:'None',
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<script type="text/javascript" src="_static/js/theme.js"></script>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>
</body>
</html>