Skip to main content



      Home
Home » Language IDEs » C / C++ IDE (CDT) » Using GCOV with eclipse based ADA code, gives wrong code coverage(GCOV tool is giving WRONG code coverage data, when the test code is written in ADA. However, it is correct when the same code is written in C)
Using GCOV with eclipse based ADA code, gives wrong code coverage [message #1765610] Mon, 12 June 2017 14:54 Go to next message
Eclipse UserFriend
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

Re: Using GCOV with eclipse based ADA code, gives wrong code coverage [message #1765659 is a reply to message #1765610] Tue, 13 June 2017 04:22 Go to previous message
Eclipse UserFriend
Questions 1, 2 and 3 are not about Eclipse, so you will get useful/better answers at gcc/ada forums.

As for 4, while I do not know what effect Ada has on it, you should install the Gcov plug-in for Eclipse (from the http://download.eclipse.org/releases/mars already listed in the Work with drop-down in Install New Software). Then have a look at the user guide: https://wiki.eclipse.org/Linux_Tools_Project/GCov/User_Guide
Previous Topic:Cevelop and Microsoft C/C++ toolchain
Next Topic:Set another gdb by default (programatically)
Goto Forum:
  


Current Time: Sun Mar 23 19:20:36 EDT 2025

Powered by FUDForum. Page generated in 0.04265 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top