2004-04-17 11:09:17 +04:00
################################################
Using GCC's code coverage tool, gcov, with udev
2005-09-12 17:26:33 +04:00
Leann Ogasawara <ogasawara@osdl.org>, April 2004
2004-04-17 11:09:17 +04:00
################################################
For more information on using gcov please see:
http://gcc.gnu.org/onlinedocs/gcc/Gcov.html
With that said, here is how to get code coverage analysis for udev files.
Note that this was developed with udev version 024.
- Make sure you've installed udev and that it is working properly.
If you are having problems, refer to the README and HOWTO-udev_for_dev
2005-09-12 17:26:33 +04:00
documents in udev tarball.
2004-04-17 11:09:17 +04:00
2004-04-22 04:49:49 +04:00
- execute make_gcov.sh from udev top level directory
2004-04-17 11:09:17 +04:00
2005-09-12 17:26:33 +04:00
make gcov-all
2004-04-17 11:09:17 +04:00
This will compile udev with gcov support. Basically make_gcov.sh will
run make but override the CFLAGS. It strips any optimization from
CFLAGS in order for gcov to get correct code coverage analysis. It will
also add the -fprofile-arcs and -ftest-coverage options which are the
necessary flags needed to use gcov.
2005-09-12 17:26:33 +04:00
If you look into your udev directory and see that it has been polluted with
a bunch of *.gcno, *.gcda and *.gcov files. gcov creates and uses these files
to extract the code coverage info.
2004-04-17 11:09:17 +04:00
- After running make_gcov.sh you need to install udev again. So basically,
su to root
make install
- Then execute some udev tasks. You can run some udev tests, reboot, or
do anything your little udev heart desires. Once you are satisfied, you
2004-04-22 04:49:49 +04:00
can now see how much udev code was covered. I personally recommend just
running test/udev-test.pl for starters.
2004-04-17 11:09:17 +04:00
2004-04-22 04:49:49 +04:00
- To get the udev code coverage analysis, execute run_gcov.sh from udev top
level directory. You need to be root to do this.
2004-04-17 11:09:17 +04:00
su to root
2005-09-12 17:26:33 +04:00
make udev_gcov.txt
2004-04-17 11:09:17 +04:00
2004-04-22 04:49:49 +04:00
- This creates udev_gcov.txt in the udev top level directory which holds all
the code coverage information. To see an example of the code coverage info
after executing the udev-test.pl test, please see:
2004-04-17 11:09:17 +04:00
http://developer.osdl.org/ogasawara/gcov_for_udev/udev_gcov.txt
- Also, after having executed gcov on udev (ie executing run_gcov.sh) a
*.gcov file is created for every file which contained code that was
used. Looking at the *.gcov files, one will see what lines of code
were hit, and what lines were missed. For, example if code in udev-add.c
were executed, gcov then created a file called udev-add.c.gcov. And a
portion of udev-add.c.gov might look like:
static int get_major_minor(struct sysfs_class_device *class_dev, struct udevice *udev)
95 {
95 struct sysfs_attribute *attr = NULL;
95 attr = sysfs_get_classdev_attr(class_dev, "dev");
95 if (attr == NULL)
###### goto error;
dbg("dev='%s'", attr->value);
95 if (sscanf(attr->value, "%u:%u", &udev->major, &udev->minor) != 2)
###### goto error;
dbg("found major=%d, minor=%d", udev->major, udev->minor);
95 return 0;
error:
###### return -1;
}
Any line of code that is preceded by a "######" implies that the code
was never hit during execution.
- Once you are done with using gcov for udev and want to return to your
2005-09-12 17:26:33 +04:00
normal use of udev, run a regular 'make clean' on your udev directory.
Then just run a regular make and make install and you are back to normal:
2004-04-17 11:09:17 +04:00
2005-09-12 17:26:33 +04:00
make clean all
2004-04-17 11:09:17 +04:00
su to root
2005-09-12 17:26:33 +04:00
make install