Using GCOV with eclipse based ADA code, gives wrong code coverage [message #1765610] |
Mon, 12 June 2017 14:54  |
Eclipse User |
|
|
|
Hi,
I have created a basic test function in ADA, and I want to find out it's code coverage using GCOV.
Below is the function under test in ADA:
with GNAT.IO; use GNAT.IO;
procedure ada_test is
month : in
teger := 0;
begin
case month is
when 1 =>
Put_Line ("January");
when 2 =>
Put_Line ("February");
when 3 =>
Put_Line ("March");
when 4 =>
Put_Line ("April");
when others =>
Put_Line ("Outside the list");
end case;
end ada_test;
I have just one file 'ada_test.adb' to be compiled.
Compiling the project generates:
- 2 .gcno files (ada_test.gcno & b~ada_test.gcno), instead of 1.
Executing the code generates :
- 2 .gcda files (ada_test.gcda & b~ada_test.gcda), instead of 1.
Then, running the command:
'gcov ada_test.exe'
generates ada_test.adb.gcov file.= which shows 100% code coverage.
Now the *.gcov file looks like below:
-: 1:with GNAT.IO; use GNAT.IO;
-: 2:
1: 3:procedure ada_helloworld is
1: 4: month : integer := 0;
-: 5:
-: 6:begin
-: 7: case month is
-: 8: when 1 =>
-: 9: Put_Line ("January");
-: 10: when 2 =>
-: 11: Put_Line ("February");
-: 12: when 3 =>
-: 13: Put_Line ("March");
-: 14: when 4 =>
-: 15: Put_Line ("April");
-: 16: when others =>
1: 17: Put_Line ("Outside the list");
-: 18: end case;
1: 19:end ada_helloworld;
This shows that only line numbers 3, 4, 17 and 19 got instrumented, while the 'case' statements that turned out to be false, are not instrumented by the compiler at all.
The result is same if I use if-then-else statements instead of case.
My questions are:
1. Why did all the executable statements not get instrumented by the compiler?
2. When only one branch out of the 5 'case' statements is executed (the value of 'month' being 0), the GCOV tool should have flagged '#' sign against the false statements, suggesting these as uncovered statements, instead of giving 100% coverage result. This is misleading.
3. What is the purpose of extra .gcno and .gcda files that are prefixed with b~<file_name>?
4. I do not see the highlighted result showing the covered, uncovered, and non-instrumented code. How can I get that view?
The same code when I write in C and execute, I see that the coverage is much less than 100% which is correct since I did not hit all the cases, and the color highlighting is also available.
I am using GCOV version 4.6.2, eclipse MARS 32-bit version , and ADA plugin for eclipse from libre.com.
Can someone please help me understand and correct this behavior?
Thanks a lot,
Best Regards,
Khushboo
[Updated on: Mon, 12 June 2017 16:00] by Moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.04265 seconds