0

I have following AOSP project setup

1) I have test.cpp in (AOSP root directory)/vendor/myProject/test.cpp

2) In Android.mk i have used LOCAL_CFLAGS += -g -fprofile-arcs -ftest-coverage LOCAL_LDFLAGS += -lgcov

3) When I compile the code i get test.gcno in: (AOSP root directory)/out/target/product/generic/obj/EXECUTABLES/myProject_intermediates

4) Then i put the test on device (adb sync)

5) Then on device i have used following: export GCOV_PREFIX=/vendor
export GCOV_PREFIX_STRIP=13 (to strip down the un-necessary path)

6) I run the test ./system/bin/test and i get test.gcda file on device (shell) /vendor/test.gcda

7) I copy the test.gcda (from device) to my build directory (/out/target/product/generic/obj/EXECUTABLES/myProject_intermediates) where i already have test.gcno

8) Now i am in /out/target/product/generic/obj/EXECUTABLES/myProject_intermediates Then run gcov as follows:

(AOSP root directory)/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-gcov test

For this i get output as follows:

File 'vendor/myProject/test.cpp' Lines executed:23.00% of 223

vendor/myProject/test.cpp:creating 'test.cpp.gcov'

vendor/myProject/test.cpp:cannot open source file

Can anybody help me on how to solve this. It says test.cpp:cannot open source file gcov is not generating complete report. I have also checked -b option by specifying the path to source as follows:

(AOSP root directory)/prebuilt/linux-x86/toolchain/arm-eabi-4.4.3/bin/arm-eabi-gcov -b (AOSP root directory)/vendor/myProject test

It didn't worked.

I guess the problem is because of distributed files (gcno,gcda,test.cpp) in different directories.

Thanks

Akshay
  • 1,137
  • 1
  • 10
  • 12

2 Answers2

2

Solution is while building the test in which directory you were, you should be in the same directory while running gcov later, then all the .gcov files will be created successfully.

For example:

Project directory : android/frameworks/Myproj
In this you have test.cpp and Android.mk

Then say suppose from android directory you'll build the app or test.cpp, i.e. android$

Then the *.gcno files will be present in android/out/Myproj_Intermediates/

You will get the *.gcda files by running app in device, you will bring that *.gcda files from device to folder android/out/Myproj_intermediates/

Now to run gcov on these:

You should be in the android directory (since you built app from there)

android$ ./prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin/arm-eabi-gcov \ -o out/Myproj_intermediates/ -a frameworks/Myproj/test.cpp -b -c

Yossarian
  • 5,226
  • 1
  • 37
  • 59
  • Note : i was running gcov after bringing *.gcda files from different directory not from android...so i was getting "can not open source file" Also running from "Intermediates" folder will not do..**Only from directory where you built the app (in eg: android)** running gcov works – user2438949 Jul 13 '13 at 09:11
  • @ user2438949 : Are you able to use lcov after successful gcov. I got geninfo: ERROR: GCOV failed for /home/user/AOSP/JB_emulatorBuild/out/target/product/generic/obj/EXECUTABLES/my_project_intermediates/test_project.gcda! – Akshay Sep 16 '13 at 05:47
  • Running gcov from the same directory where gcc is run works on CentOS linux as well (none mobile OS) – shfnet Jul 15 '21 at 11:28
0

There has been a better approach in AOSP for several months now.

  1. Add LOCAL_NATIVE_COVERAGE := true to your makefile.
  2. $ export NATIVE_COVERAGE := true
  3. Build, sync, run.
  4. $ acov

acov will pull all the coverage files off the device, put them in the right place, and lcov (iirc this will prompt you to install if you don't already have it), and generate and HTML report for you.

Dan Albert
  • 10,079
  • 2
  • 36
  • 79
  • Hey Dan.. I'm trying to generate code coverage for native components in aosp. Could you please point me to some git projects with sample or references ??? – Pankaj Jan 23 '19 at 10:09
  • Try something like https://android.googlesource.com/platform/bionic/+/master/README.md#gathering-test-coverage, but I think this all bitrot years ago. It didn't work last time I tried. – Dan Albert Jan 23 '19 at 23:10