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