Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
983 views
in Technique[技术] by (71.8m points)

code coverage - Only psuedo .gcda files and .gcno symlinks are created when doing kernel insmod of a simple driver? How to get proper *.gcda files?

I'm trying to get gcov coverage for a simple Linux driver. The driver code is very basic with just init() and exit() routines.

/*
** Module Init function
*/
static int __init hello_world_init(void)
{
    printk(KERN_INFO "Welcome to AXeno Driver
");
    printk(KERN_INFO "This is the Simple Module
");
    printk(KERN_INFO "Kernel Module Inserted Successfully...
");
    return 0;
}

/*
** Module Exit function
*/
static void __exit hello_world_exit(void)
{
    printk(KERN_INFO "Kernel Module Removed Successfully...
");
}
 
module_init(hello_world_init);
module_exit(hello_world_exit);
 
MODULE_LICENSE("GPL");
MODULE_AUTHOR("AXeno");
MODULE_DESCRIPTION("A simple hello world driver");
MODULE_VERSION("2:1.0");

I'm cross compiling this to install this on a ARM device. Here's my Makefile.

CROSS_COMPILER = aarch64-tizen-linux-gnu-
ARCH = arm64

TDIR = $(PWD)

KDIR = /home/axeno/Perforce/MAIN/ONEPROD_Prj/SOC/Soc/tester/kernel/linux-4.1.12
VDIR = /home/axeno/Perforce/MAIN/ONEPROD_Prj/SYSPLATFORM/Sysplatform/peri-drivers/vd_kernel-interfaces/include

ccflags-y += -Wall -fprofile-arcs -ftest-coverage -fPIC
GCOV_PROFILE := y
GCOV_PREFIX_testDriver.o := y

include $(KDIR)/.config

export KDIR ARCH CROSS_COMPILER TDIR CFLAGS LDFLAGS

obj-m += testDriver.o

all:
    make -C $(KDIR) M=$(PWD) $(CFLAGS) modules CROSS_COMPILE="$(CROSS_COMPILER)" 

Now when I build this, it properly creates the *.ko and the *.gcno files. Now I moved the *.ko to my target and before insmod, I set

export GCOV_PREFIX="/mnt/gcda"
export GCOV_PREFIX_STRIP=15

to write the *.gcda files to my mounted flash drive. I do insmod, rmmod everything works fine from dmesg logs.

I also compiled the target kernel using the following setup.

CONFIG_DEBUG_FS=y
CONFIG_GCOV_KERNEL=y
CONFIG_GCOV_FORMAT_AUTODETECT=y
CONFIG_ARCH_HAS_GCOV_PROFILE_ALL=n

But when I try to find the *.gcda files it defaults to /sys/kernel/debug/gcov and underneath forming the entire path structure from my host machine. The *.gcda files created do not have any information except for some 10 characters of garbage. It also creates symbolic links for *.gcno files. So it neither redirects to the $GCOV_PREFIX folder, not it produces meaningful *.gcda files. Can anyone help me find out what I'm missing?

P.S. On the same target, when I run a simple app other than driver, it works perfectly fine. It creates proper *.gcda files in the proper directory.

question from:https://stackoverflow.com/questions/65679929/only-psuedo-gcda-files-and-gcno-symlinks-are-created-when-doing-kernel-insmod

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...