ndk
ndk copied to clipboard
[BUG] Ndk r23 with Gcov tool
Description
Gcov tool doesn't create .gcda files in the device, when using Ndk r23. It's working with Ndk r21d when running the same. .Gcno files are generated on the computer, but there are no .gcda files in the device after running gtest. Does anyone have ideas of the cause?
In both ndk versions I build with these makefile flags: LOCAL_LDFLAGS += -coverage LOCAL_CFLAGS += -coverage LOCAL_NATIVE_COVERAGE :=true
Thanks!
@pirama-arumuga-nainar might know.
The above flags should work. (Not sure what LOCAL_NATIVE_COVERAGE does but LOCAL_LDFLAGS and LOCAL_CFLAGS look correct).
Do you see any message starting with LLVM Profile in logcat or stderr? If not, please share a repro. @DanAlbert /@rprichard Can you also try one of the NDK samples with the above flags?
Wait, iirc LOCAL_NATIVE coverage isn't even an NDK thing. That's the platform build system.
Thanks for the answers! I don't see any LLVM Profile messages in the logcat output. Btw I also use - export GCOV_PREFIX=/data/local/tmp/test-vpl/coverageGcdaFiles, export GCOV_PREFIX_STRIP=100
My running test app is inside /data/local/tmp/test-vpl (This is the folder inside the Android phone)
I thought it might be related to this issue - https://github.com/android/ndk/issues/1120 But changing the path didn't work either.
And I think you're right about LOCAL_NATIVE_COVERAGE, it's not related to the issue
Any other ideas? Btw have you got the chance to try a NDK sample with the same flags?
export GCOV_PREFIX_STRIP=100
iirc if you set this arbitrary high it won't work? Might be trying to write the profile data to the root, which you don't have permission to write to.
Btw have you got the chance to try a NDK sample with the same flags?
Haven't had time yet.
Tried to change GCOV_PREFIX_STRIP to a large number, tried to also remove it, and some more numbers, but it didn't work
I meant that 100 was an arbitrary large number, and that could be your problem. Iirc it needs to be set precisely. It's been a very long time since I've touched baby coverage tooling though.
Oh now I get it, I did try to run with several different numbers for the strip variable and nothing worked. As far as I understand the GCOV_PREFIX_STRIP doesn't have to be set at all, it can be equal to 0 by default and everything should work (worked for me with Ndk-r21d). So the question is what's the accurate number you wrote about? We're dealing with this bug for quite some time and we are out of ideas... So every idea or check can help :) Thanks!
Btw Ndk-r22b also didn't work
Hi @DanAlbert , I can see you added the issue the r24 version, is it because it's indeed some ndk bug? I just want to be sure there's nothing I can do from my side:) Thanks!
Don't know yet. We haven't had a chance to investigate yet but want to do so before we ship r24 so we can include a fix if needed.
Ok great, thanks!
Hi @DanAlbert , I want to update that the bug is solved! Gcov implementation was changed: " As the llvm version is upgraded in android 12, __gcov_flush() is deleted and separated into __gcov_reset() and __gcov_dump(). __gcov_reset() is called in the constructor (or daemon entry point) and __gcov_dump() is called in the destructor (or any point you want)"
So you have to add calls to __gcov_dump() and __gcov_reset() in the code running your tests.
Anyway thanks a lot for the support!
Ah, cool. I've been busy but was planning to play with this soon, and I guess now I don't have to :) Glad you found your answer!
But we should really document how to.do coverage with the NDK, so I'm going to leave this open as a doc bug.