2

I am trying to generate code coverage report using lcov from home directory. Sorce code is compiled with -coverage option to generate coverage information at compilation time(gcno files are created). Then I have copied the executables and gcno files to home directory.I am trying to check if by ./exe in home directory ,is it possible to generate coverage report.I run the executables in /home and its showing test cases passed but it was discovered that the .gcda files are not created.

I add the following CPP flag:
 -fprofile-dir= “/home” 
and hence run the executable but still .gcda is not created .

Where I need to specify the path so that it will take .gcno files from home directory and generates the .gcdo files in the current directory??

himsikha
  • 101
  • 2
  • 11
  • Can we have have an option to specify the different dirctory or to use the current dirctory at the run-time?I have set the env variables ,but not getting the desired output. – himsikha Jul 19 '18 at 11:52
  • Hi himshikha, I'm new to gcov and lcov. Trying to generate coverage report for modules with gtest which are built with Android.mk and Android.bp. Either of the way is not working for me. Could you please help me on this blocker. – Pankaj Jan 29 '19 at 07:25

2 Answers2

3

This can be done using GCOV_PREFIX and GCOV_PREFIX_STRIP

Please, refer to the documentation: https://gcc.gnu.org/onlinedocs/gcc/Cross-profiling.html

Regards Thomas

Totoc1001
  • 338
  • 2
  • 11
  • @Thomas I have set those env variables but its regenerating .gcda files for all other modules.I have .gcno files for a particular module ,while executing the test case for that specific modules,its creating .gcda +.gcda files from other modules too. – himsikha Jul 20 '18 at 03:31
  • have you removed the previous gcda files? before relaunching the test? If the gcda files already exist even if your test will no go through all the gcno files, your gcda files will not be removed... – Totoc1001 Jul 20 '18 at 13:11
  • yeah,all the previous gcda files were removed – himsikha Jul 23 '18 at 03:29
  • 1
    This mean that your tests goes through all modules, if you want to cover a single module, the easiest way is to remove all gcno file from other modules. Then, you'll have the coverage for one module.. – Totoc1001 Jul 23 '18 at 08:55
  • ok. But what's the purpose of an image displaying text in lcov? – himsikha Jul 24 '18 at 05:34
  • Sorry, I'm not sure to understand the question about the image. BTW, I think this is another subject, you should open another topic. – Totoc1001 Jul 24 '18 at 05:39
  • I have deleted all the previous .gcno + .gcda files.Recompiled the specific module -->But still generating gcno for some other modules – himsikha Jul 24 '18 at 05:59
  • I am not getting why its nt generating the report for all the source files for which .gcno +gcda are created???Plsss help me in understanding – himsikha Jul 24 '18 at 06:06
  • sorry, I did not see your question... maybe you tests does not cover the whole code... – Totoc1001 Mar 01 '19 at 15:33
2

Maybe, you're compiling more than one module, have you checked the dependencies between modules? Please do this:

  1. compile all your code,
  2. then remove the useless .gcno files. (Gcno are generated at compilation time)
  3. Execute your tests (gcda should be created matching gcno files)
  4. Generate your report

Second possibility:

  1. Compile your code
  2. Execute the tests
  3. Remove useless gcno + gcda files
  4. Generate your report

Others: I guess you can use some options to generate report for a dedicated module, but I'm not very familiar with those options.

Regards

Totoc1001
  • 338
  • 2
  • 11
  • Hi Thomas, Could you please share me some sample project or module or reference link to generate coverage step by step in AOSP ? – Pankaj Jan 29 '19 at 07:31