简体   繁体   English

使用Android NDK进行本机代码的代码覆盖率

[英]code coverage for native code using Android NDK

I am using Android NDK r16 to build my native code for my Android project. 我正在使用Android NDK r16为我的Android项目构建本机代码。 I would like to be able to get the code coverage for my native unit tests. 我希望能够获得本机单元测试的代码覆盖率。 Is this possible? 这可能吗?

From my research, it seems that this isn't provided by default in Android and that we need to use custom compiler/linker flags (-fprofile-arcs -ftest-coverage) with Clang. 从我的研究看来,Android默认情况下未提供此功能,我们需要在Clang中使用自定义编译器/链接器标志(-fprofile-arcs -ftest-coverage)。

I found the following article which seems promising. 我发现以下文章似乎很有希望。 http://logan.tw/posts/2015/04/28/check-code-coverage-with-clang-and-lcov/ http://logan.tw/posts/2015/04/28/check-code-coverage-with-clang-and-lcov/

However, it isn't really Android related. 但是,它与Android无关。 I was really hoping for an article that was specific to Android and proven to work with the latest NDK/CMake tools. 我真的希望有一篇专门针对Android并被证明可以与最新的NDK / CMake工具一起使用的文章。

Is anyone aware of such article? 有人知道这样的文章吗?

[treat this as a comment I'll delete it after clarification to adhere to site guidelines] [将此作为评论进行处理,我将在澄清以遵守网站准则后将其删除]

Could I get a follow up to the exact implementation of this? 我可以跟进此操作的确切实施吗? I'm trying to do the exact same process but with ndk 14b and CMake. 我正在尝试使用ndk 14b和CMake进行完全相同的过程。 We have existing unit tests for the native layer but aren't able to pull any coverage metrics from the tests run. 我们已经存在用于本机层的单元测试,但是无法从测试运行中获取任何覆盖率指标。

setting the described flags in the cmakeList.txt file as follows unfortunately introduced undefined reference errors for a previously building project. 如下所示在cmakeList.txt文件中设置描述的标志,不幸的是,为先前构建的项目引入了未定义的参考错误。

CMAKE cmake的

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage -fprofile-arcs -ftest-coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage -fprofile-arcs -ftest-coverage")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage -fprofile-arcs -ftest-coverage")

ERROR: 错误:

[3/3] Linking CXX shared library ../../../../build/intermediates/cmake/project/debug/obj/armeabi/libscanhwl_camif.so
  FAILED: : && /home/user/tools/android-ndk-r14b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++  --target=armv5te-none-linux-androideabi --gcc-toolchain=/home/user/tools/android-ndk-r14b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 --sysroot=/home/user/tools/android-ndk-r14b/sysroot -fPIC -isystem /home/user/tools/android-ndk-r14b/sysroot/usr/include/arm-linux-androideabi -D__ANDROID_API__=19 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv5te -mtune=xscale -msoft-float -fno-integrated-as -mthumb -Wa,--noexecstack -Wformat -Werror=format-security  -D__STDC_FORMAT_MACROS  -fexceptions -frtti --coverage -fprofile-arcs -ftest-coverage -O0 -fno-limit-debug-info  -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a --sysroot /home/user/tools/android-ndk-r14b/platforms/android-19/arch-arm -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libscanhwl_camif.so -o <This was a list of files> -latomic -lm "/home/user/tools/android-ndk-r14b/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi/libgnustl_static.a" && :
  out/stage2/soong/ndk/sysroot/usr/include/string.h:348: error: undefined reference to '__strncpy_chk2'
  clang++: error: linker command failed with exit code 1 (use -v to see invocation)
  ninja: build stopped: subcommand failed.

Do these flags need to be defined elsewhere? 这些标志是否需要在其他地方定义? OR am I completely off base somewhere? 还是我完全不在某个地方基地?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM