使用Android NDK进行本机代码的代码覆盖率 [英] code coverage for native code using Android NDK

查看:146
本文介绍了使用Android NDK进行本机代码的代码覆盖率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Android NDK r16为我的Android项目构建本机代码。我希望能够获得本机单元测试的代码覆盖率。

I am using Android NDK r16 to build my native code for my Android project. I would like to be able to get the code coverage for my native unit tests. Is this possible?

从我的研究看来,Android默认情况下未提供此功能,因此我们需要使用自定义编译器/链接器标志(-fprofile-

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.

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

I found the following article which seems promising. http://logan.tw/posts/2015/04/28/check-code-coverage-with-clang-and-lcov/

但是,不是与Android无关。我真的希望有一篇专门针对Android并被证明可以与最新的NDK / CMake工具一起使用的文章。

However, it isn't really Android related. I was really hoping for an article that was specific to Android and proven to work with the latest NDK/CMake tools.

有人知道这样的文章吗?

Is anyone aware of such article?

推荐答案

[将此作为评论进行处理,在明确遵守网站准则后将其删除]

[treat this as a comment I'll delete it after clarification to adhere to site guidelines]

我可以跟进此操作的确切实施吗?我正在尝试使用ndk 14b和CMake进行完全相同的过程。我们已经存在用于本机层的单元测试,但是无法从测试运行中获取任何覆盖率指标。

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. We have existing unit tests for the native layer but aren't able to pull any coverage metrics from the tests run.

将cmakeList.txt文件中的描述标记设置为会为先前的建筑项目引入不幸的未定义参考错误。

setting the described flags in the cmakeList.txt file as follows unfortunately introduced undefined reference errors for a previously building project.

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")

错误:

[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?

这篇关于使用Android NDK进行本机代码的代码覆盖率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆