1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

gcov 詳細メモ (コマンドのみ列挙。詳細な説明なし)

Last updated at Posted at 2022-06-25

概要

下図のような gcov 計測結果を得るための手順メモ.
数年ごとに gcov を使用することになるのだが、そのたびにコマンドを調べ直すのが手間なので書き出しておく.

今回は「*.c ファイルを対象」にして、「C1 カバレッジまで取得」する場合とする.

image.png

なお、余談になるが、
c++ の場合は string型などを定義しただけで分岐が発生し、正確な計測ができない問題があった.
(この場合は gcov -b のログから C1 計測するしかなかった)
 

環境

- Ubuntu 18.04
- gcc 7.5.0
- gcov 7.5.0
- lcov 1.13

 

手順

全ファイルを計測する場合

#! gcov ありオプションでビルド (コンパイル&リンク) する
$ gcc () -fprofile-arcs -ftest-coverage ()

#! 作成したプログラムを実行する
$ ./mini_expect ls -1

#! カバレッジ率を算出する (*.gcda)
$ find . -type f -name "*.gcda" | xargs -I@ gcov -b @

#! lcov を使って *.info を生成する
$ lcov --rc lcov_branch_coverage=1 -c -d . -o tmp.info

#! genhtml を使って *.info から HTML を生成する
$ genhtml --branch-coverage -o OUTPUT -p . -f tmp.info 

 

特定ファイルのみ除外したい場合

lcov に「-r tmp.info '/usr/include/*'」といったように除外したいファイルを指定すること

#! gcov ありオプションでビルド (コンパイル&リンク) する
$ gcc () -fprofile-arcs -ftest-coverage ()

#! 作成したプログラムを実行する
$ ./mini_expect ls -1

#! カバレッジ率を算出する (*.gcda)
$ find . -type f -name "*.gcda" | xargs -I@ gcov -b @ | tee -a log

#! lcov を使って *.info を生成する
$ lcov --rc lcov_branch_coverage=1 -c -d . -o tmp.info

#! /usr/include/ を計測対象外にする (tmp.info から output.info を作る)
$ lcov --rc lcov_branch_coverage=1 -b -c -d . -r tmp.info  '/usr/include/*' -o output.info

#! genhtml を使って *.info から HTML を生成する
$ genhtml --branch-coverage -o OUTPUT -p . -f output.info 

 

以上.

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?