linux-test-project / lcov

LCOV
GNU General Public License v2.0
909 stars 240 forks source link

Unable to generate gcda file for cc_library_shared module #302

Closed Jeling-W closed 3 months ago

Jeling-W commented 5 months ago

Hi, I want to generate the coverage of module name1. There are multiple cpp files under name1/, where name1/test/ is the test script for name1. The settings in name1/Android. bp are as follows:

cc_library_shared {
name: "aa.bb",
...
cflags: [
    "-fprofile-arcs",
    "-ftest-coverage",
    "-fprofile-dir=/data/",
    "-coverage",
    "-Xclang",
    "-fPIC",
],
ldflags: [
    "-fprofile-arcs",
    "-ftest-coverage",
    "-coverage",
],
}

The content in name1/test/Android. mk is as follows:

LOCAL LDFLAGS := --coverage -fprofile-arcs -ftest-coverage
LOCAL_CFLAGS := -fprofile-arcs -ftest-coverage -fprofile-dir=/data/ -Xclang
...
include $(BUILD NATIVE TEST)

Set _export GCOV_PREFIX=/data/ export GCOV_PREFIXSTRIP=1 on the testing machine. After successfully running the test, only gcda files were generated under name1/test/, but other files under name1/did not have gcda files generated

henry2cox commented 5 months ago

If I understand your environment: I think that we do exactly this, successfully. (Build coverage-instrumented shared library, use that library in a bunch of executables - generate unified coverage report across all the executables and all the tests.)

Maybe try to walk before you run:

I guess you know that the runtime coverage data (the .gcda files) are generated only after running your executable - and only if it exits normally. Is the code missing from your data actually used/linked in your test executable? Did your tests run?

You did not mention platform or tool versions.

You are more likely to get a useful answer if you provide a small testcase that exhibits the issue you are seeing.

Jeling-W commented 5 months ago

Thank you for your reply.

  1. My data build successfully.
  2. The result is the same when I don't use GCOV-PREFIX and when I use GCOV-PREFIX, gcda will be generated in the /data/ because I have set fpprofile-dir=/data/ in both the bp and mk files, and set export GCOV_PREFIX=/data/ to be more secure.
  3. one source file in each of two directories, when I use GCOV_PREFIX=/data/, the gcda files are generated under /data/, such as /data/name1/test/dir1/test1.gcda, /data/name1/test/dir2/test2.gcda

But there is no corresponding /data/source.cpp for /data/source.gcda, I confirm that both test1.cpp and test2.cpp have called functions in source. cpp.

henry2cox commented 5 months ago

I guess you realize that this is a compiler/toolchain issue - not an lcov issue. You may get better results by asking your question in a clang/llvm group. You will also get better results if you include a small testcase - or even a large testcase - which illustrates the issue you are seeing. Ideally, such a testcase would include a small handful of source files and a makefile or shellscript which builds your example application, runs your tests, and then indicates which data is missing. Without such an example, it is impossible to know what you did - maybe there is a problem in your setup, you used wrong parameters - and impossible to know what happened.

I do not know how -fprofile-dir and GCOV_PREFIX interact. We use one or the other - not both (the former to use the 'llvm profile' coverage data flow, and the latter to use the 'gcov data' coverage flow).

I suggest to start with a small example and build up slowly until you see an error that looks like what you see with your actual application - then you can either debug the issue, or include the example when asking for help. One possible "building up" sequence is:

Gradually make your small testcase look more and more like your actual application as you try to make your testcase fail.

If the above sounds like too much work and too much schedule uncertainty: consider hiring a consultant who is expert in this field.

henry2cox commented 3 months ago

Closing this issue now. There has been no update in a while, and no indication what the issue(s) were in the first place - nor how to reproduce.

If there is still a problem, please reopen this issue or file a new one. Please include a testcase which exhibits the problem and/or include a detailed description of what you tried to do and what happened.