您如何阅读 gcno 和 gdna 文件以查看测试覆盖率?
How do you read gcno and gdna files to see test coverage?
我正在使用 gcovr 来尝试查看我的测试覆盖了多少代码库。事实上,我有一个超小的测试,所以我希望 gcovr return 一个非常小的数字,可能不到百分之一。
我编译时启用了每个编译单元中的 --coverage
标志,并且 -lgcov
标志在每个链接命令中都处于活动状态。然后我 运行 可执行文件和测试并生成 gcno 和 gdna 文件。
然后我做:
gcovr --root ../Src/ ../Src/ ./GeometryTests.p
------------------------------------------------------------------------------
GCC Code Coverage Report
Directory: ../Src/
------------------------------------------------------------------------------
File Lines Exec Cover Missing
------------------------------------------------------------------------------
Engine/Geometry/GeometryUtils.hpp 18 18 100%
Engine/Geometry/tests/GeometryTests.cpp 3 3 100%
Engine/Geometry/tests/TestsGeometryUtils.cpp
18 18 100%
------------------------------------------------------------------------------
TOTAL 39 39 100%
-----------------------------------------------------------------------------
这不对,我有几十个文件,我的小测试只测试了 2 个函数,这显然是错误的。
然后我尝试了:
gcovr --root ../Src/ ../Src/ ./GeometryTests.p ./SponzaScene.p
------------------------------------------------------------------------------
GCC Code Coverage Report
Directory: ../Src/
------------------------------------------------------------------------------
File Lines Exec Cover Missing
------------------------------------------------------------------------------
Engine/Animation/GltfLib.hpp 1 1 100%
Engine/Animation/Image/CpuImage.hpp 1 1 100%
Engine/Geometry/GeometryUtils.hpp 18 18 100%
Engine/Geometry/HMesh.hpp 592 0 0% 37,87-89,92-94,96-98,100-101,103,105-107,110,114-118,121,123-125,127,129,132-133,135,137-139,141,143,146,148-150,174-176,180,182-184,186,188-190,192,194-196,198,200-201,203,205-206,208,210,212-213,215,217-218,220,222-223,225,227-228,230,232-233,236,238-239,241,243-244,246,248-249,251,253-254,256,258-259,261,263,265,267-268,271,273,275,277,280,282,285,291,297-298,309,311,313,315,317-318,320,322-324,326-327,329,332,334,336-343,345,348,350-351,354,357,359-360,362,365,367-368,370,373,375-376,378,381,383-384,386,398,410,413-418,420,429-432,434-437,439-441,445,559,561,563-564,566-571,573-574,577-578,580,584,587-588,590-591,593,595-596,598-600,604-605,609,612,614,616-618,620,622-625,631,635-641,643-648,651-653,657-659,661-662,665-670,672-675,677-678,682-684,686-690,692-695,697-699,701-704,706-707,709-711,715,718-719,721-725,727-729,732,737,741-745,747-750,753-755,757-758,760,763-768,770-772,774,778-780,782-788,790-792,794-796,798-800,802,804,808,811-813,815-821,823-828,830-832,834-836,838-840,842-844,846-848,850-852,854-856,858-860,865,867-868,870-871,873,876,882,885-886,888,890-892,895,897,900,913,916-917,919-920,924,926-927,931,933-934,938,941-943,945,947-949,953,955-956,961,969-973,975-976,978,980-983,986,988,990-992,994,996-997,999,1002-1003,1007,1009-1010,1015-1026,1028,1030,1032,1034-1036,1039,1041-1042,1044-1045,1048,1050,1052-1057,1059,1062,1067-1068,1070-1071,1075,1079-1080,1082,1084-1086,1088,1090-1091,1094-1096,1099-1101,1104-1108,1113,1115-1117,1119-1121,1125,1127,1130-1131,1135,1138,1141,1145-1146,1148-1151,1153-1155,1157,1162,1164-1170,1175,1177-1183,1188,1191-1192,1194,1196,1198-1200,1202-1204,1206-1208,1210-1213,1215-1217,1220,1222,1228,1230-1231,1233-1236,1238-1239,1241-1243,1246-1248,1252,1254-1259,1263,1266-1268,1270-1273,1275,1279,1281-1282,1285-1286
Engine/Geometry/tests/GeometryTests.cpp 3 3 100%
Engine/Geometry/tests/TestsGeometryUtils.cpp
18 18 100%
Engine/Helpers/EigenHelpers.hpp 4 0 0% 187,189,192,195
Engine/Renderer/Camera/Camera.hpp 13 12 92% 46
Engine/Renderer/IO/Window.hpp 3 3 100%
Engine/Renderer/Renderer.hpp 7 7 100%
Engine/Renderer/Rendering/Effects.hpp 35 35 100%
Engine/Renderer/Rendering/Gallery.hpp 82 78 95% 294-296,298
Engine/Renderer/Rendering/RenderTargetStorage.hpp
1 1 100%
Engine/Renderer/Rendering/VulkanLayer/Image.hpp
1 1 100%
Engine/Renderer/Rendering/VulkanLayer/Memory.hpp
3 3 100%
Engine/Renderer/Rendering/VulkanLayer/RenderTarget.hpp
1 1 100%
Engine/Renderer/Rendering/VulkanLayer/RenderingPipeline.hpp
3 3 100%
Engine/Renderer/Rendering/VulkanLayer/ShaderProgram.hpp
1 1 100%
Engine/Renderer/Rendering/VulkanLayer/Utils.hpp
5 5 100%
Engine/Shared/Shared.hpp 8 3 37% 71,73,181,184-185
examples/SponzaScene/sponza_scene.cpp 180 172 95% 236,240,242-243,245-246,341,343
------------------------------------------------------------------------------
TOTAL 980 366 37%
------------------------------------------------------------------------------
至少它不是 100%,但我可以保证 运行我的测试没有触及大部分文件,我不太明白我应该如何设置编译、链接和 gcovr 调用来分析测试覆盖率。
看起来之前的结果没有清理干净。尝试使用 -ftest-coverage 进行编译
也许 lcov + htmlgen 适合你。
这是一个例子:
rm -f *.gcno *.gcda coverage.info coverage_dir
gcc -I${INCLUDE_PATH} -fprofile-arcs -ftest-coverage -O0 --coverage main.c -o test-coverage
rm -f *.gcda coverage.info
./test-coverage
lcov --capture --rc lcov_branch_coverage=1 --directory . --config-file ./lcovrc --output coverage.info
genhtml --branch-coverage --output ./coverage_dir coverage.info
我正在使用 gcovr 来尝试查看我的测试覆盖了多少代码库。事实上,我有一个超小的测试,所以我希望 gcovr return 一个非常小的数字,可能不到百分之一。
我编译时启用了每个编译单元中的 --coverage
标志,并且 -lgcov
标志在每个链接命令中都处于活动状态。然后我 运行 可执行文件和测试并生成 gcno 和 gdna 文件。
然后我做:
gcovr --root ../Src/ ../Src/ ./GeometryTests.p
------------------------------------------------------------------------------
GCC Code Coverage Report
Directory: ../Src/
------------------------------------------------------------------------------
File Lines Exec Cover Missing
------------------------------------------------------------------------------
Engine/Geometry/GeometryUtils.hpp 18 18 100%
Engine/Geometry/tests/GeometryTests.cpp 3 3 100%
Engine/Geometry/tests/TestsGeometryUtils.cpp
18 18 100%
------------------------------------------------------------------------------
TOTAL 39 39 100%
-----------------------------------------------------------------------------
这不对,我有几十个文件,我的小测试只测试了 2 个函数,这显然是错误的。
然后我尝试了:
gcovr --root ../Src/ ../Src/ ./GeometryTests.p ./SponzaScene.p
------------------------------------------------------------------------------
GCC Code Coverage Report
Directory: ../Src/
------------------------------------------------------------------------------
File Lines Exec Cover Missing
------------------------------------------------------------------------------
Engine/Animation/GltfLib.hpp 1 1 100%
Engine/Animation/Image/CpuImage.hpp 1 1 100%
Engine/Geometry/GeometryUtils.hpp 18 18 100%
Engine/Geometry/HMesh.hpp 592 0 0% 37,87-89,92-94,96-98,100-101,103,105-107,110,114-118,121,123-125,127,129,132-133,135,137-139,141,143,146,148-150,174-176,180,182-184,186,188-190,192,194-196,198,200-201,203,205-206,208,210,212-213,215,217-218,220,222-223,225,227-228,230,232-233,236,238-239,241,243-244,246,248-249,251,253-254,256,258-259,261,263,265,267-268,271,273,275,277,280,282,285,291,297-298,309,311,313,315,317-318,320,322-324,326-327,329,332,334,336-343,345,348,350-351,354,357,359-360,362,365,367-368,370,373,375-376,378,381,383-384,386,398,410,413-418,420,429-432,434-437,439-441,445,559,561,563-564,566-571,573-574,577-578,580,584,587-588,590-591,593,595-596,598-600,604-605,609,612,614,616-618,620,622-625,631,635-641,643-648,651-653,657-659,661-662,665-670,672-675,677-678,682-684,686-690,692-695,697-699,701-704,706-707,709-711,715,718-719,721-725,727-729,732,737,741-745,747-750,753-755,757-758,760,763-768,770-772,774,778-780,782-788,790-792,794-796,798-800,802,804,808,811-813,815-821,823-828,830-832,834-836,838-840,842-844,846-848,850-852,854-856,858-860,865,867-868,870-871,873,876,882,885-886,888,890-892,895,897,900,913,916-917,919-920,924,926-927,931,933-934,938,941-943,945,947-949,953,955-956,961,969-973,975-976,978,980-983,986,988,990-992,994,996-997,999,1002-1003,1007,1009-1010,1015-1026,1028,1030,1032,1034-1036,1039,1041-1042,1044-1045,1048,1050,1052-1057,1059,1062,1067-1068,1070-1071,1075,1079-1080,1082,1084-1086,1088,1090-1091,1094-1096,1099-1101,1104-1108,1113,1115-1117,1119-1121,1125,1127,1130-1131,1135,1138,1141,1145-1146,1148-1151,1153-1155,1157,1162,1164-1170,1175,1177-1183,1188,1191-1192,1194,1196,1198-1200,1202-1204,1206-1208,1210-1213,1215-1217,1220,1222,1228,1230-1231,1233-1236,1238-1239,1241-1243,1246-1248,1252,1254-1259,1263,1266-1268,1270-1273,1275,1279,1281-1282,1285-1286
Engine/Geometry/tests/GeometryTests.cpp 3 3 100%
Engine/Geometry/tests/TestsGeometryUtils.cpp
18 18 100%
Engine/Helpers/EigenHelpers.hpp 4 0 0% 187,189,192,195
Engine/Renderer/Camera/Camera.hpp 13 12 92% 46
Engine/Renderer/IO/Window.hpp 3 3 100%
Engine/Renderer/Renderer.hpp 7 7 100%
Engine/Renderer/Rendering/Effects.hpp 35 35 100%
Engine/Renderer/Rendering/Gallery.hpp 82 78 95% 294-296,298
Engine/Renderer/Rendering/RenderTargetStorage.hpp
1 1 100%
Engine/Renderer/Rendering/VulkanLayer/Image.hpp
1 1 100%
Engine/Renderer/Rendering/VulkanLayer/Memory.hpp
3 3 100%
Engine/Renderer/Rendering/VulkanLayer/RenderTarget.hpp
1 1 100%
Engine/Renderer/Rendering/VulkanLayer/RenderingPipeline.hpp
3 3 100%
Engine/Renderer/Rendering/VulkanLayer/ShaderProgram.hpp
1 1 100%
Engine/Renderer/Rendering/VulkanLayer/Utils.hpp
5 5 100%
Engine/Shared/Shared.hpp 8 3 37% 71,73,181,184-185
examples/SponzaScene/sponza_scene.cpp 180 172 95% 236,240,242-243,245-246,341,343
------------------------------------------------------------------------------
TOTAL 980 366 37%
------------------------------------------------------------------------------
至少它不是 100%,但我可以保证 运行我的测试没有触及大部分文件,我不太明白我应该如何设置编译、链接和 gcovr 调用来分析测试覆盖率。
看起来之前的结果没有清理干净。尝试使用 -ftest-coverage 进行编译 也许 lcov + htmlgen 适合你。 这是一个例子:
rm -f *.gcno *.gcda coverage.info coverage_dir
gcc -I${INCLUDE_PATH} -fprofile-arcs -ftest-coverage -O0 --coverage main.c -o test-coverage
rm -f *.gcda coverage.info
./test-coverage
lcov --capture --rc lcov_branch_coverage=1 --directory . --config-file ./lcovrc --output coverage.info
genhtml --branch-coverage --output ./coverage_dir coverage.info