AOSP native code coverage - no coverage data found

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

AOSP native code coverage - no coverage data found

Thomas F
I am trying to get code coverage working for a native AOSP vendor application (aarch64) using LLVM's source-based code coverage, but I keep getting Failed to load coverage: No coverage data found when attempting to generate the report.

I enable coverage by passing the relevant flags like so (Android.mk):
----
# Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := coverage_test
LOCAL_PROPRIETARY_MODULE := true
LOCAL_CPPFLAGS += -std=c++17
LOCAL_CFLAGS += -fprofile-instr-generate -fcoverage-mapping
LOCAL_LDFLAGS += -fprofile-instr-generate
LOCAL_SRC_FILES += main.cpp
LOCAL_SHARED_LIBRARIES += liblog
# LOCAL_NATIVE_COVERAGE := true # I also tried this as a Hail Mary.
include $(BUILD_EXECUTABLE)
----

After building (and verifying the correct flags are actually passed), I push and run the application:
----
adb push coverage_test /vendor/bin/ && adb shell "LLVM_PROFILE_FILE=/data/tmp/coverage.raw /vendor/bin/coverage_test"
----


After running the program, a raw coverage file is clearly produced (so far so good), and after pulling it, here is how I process it using the coverage tools:
----
llvm-profdata merge coverage.raw -o coverage.data
llvm-cov report -instr-profile=coverage.data <build output dir>/coverate_test
----

which then produces said error: Failed to load coverage: No coverage data found.

If I take a look at the generated data (e.g. by exporting text instead of binary: llvm-profdata merge coverage.raw -o coverage.data --text, then I can clearly see that all the data is there.

Now for the strange part. If I build the exact same code outside of AOSP (for the same Android version), it works as expected, and a report is successfully generated. I should mention that the AOSP build is using Clang/LLVM 10, while my standalone toolchain is version 8, but I find it hard to believe that would be a factor.

My test application is simply a class Foobar with two methods add(int, int) and sub(int, int), and add() is called by main(). I print the result to ensure that the call is not optimized away. I have compared the data files from the two cases, and they are identical except that the order of entries is reversed (main is listed before Foobar::add) in one of them.

Any ideas why llvm-cov fails to find any coverage data for an application built in the AOSP tree by the Android build system?, even though the data is clearly there? What am I missing?

Best regards,
Thomas

--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/android-platform/1d647afc-2090-423d-a89d-4a4f3230e6bdn%40googlegroups.com.