chiark / gitweb /
doc: update "writing udev rules"
[elogind.git] / docs / README-gcov_for_udev
1 ################################################
2
3 Using GCC's code coverage tool, gcov, with udev
4
5 Leann Ogasawara <ogasawara@osdl.org>, April 2004
6
7 ################################################
8
9 For more information on using gcov please see:
10
11 http://gcc.gnu.org/onlinedocs/gcc/Gcov.html
12
13 With that said, here is how to get code coverage analysis for udev files.
14 Note that this was developed with udev version 024.
15
16 - Make sure you've installed udev and that it is working properly.
17   If you are having problems, refer to the README and HOWTO-udev_for_dev
18   documents in udev tarball.
19
20 - execute make_gcov.sh from udev top level directory
21
22     make gcov-all
23
24   This will compile udev with gcov support.  Basically make_gcov.sh will
25   run make but override the CFLAGS.  It strips any optimization from
26   CFLAGS in order for gcov to get correct code coverage analysis.  It will
27   also add the -fprofile-arcs and -ftest-coverage options which are the
28   necessary flags needed to use gcov.
29
30   If you look into your udev directory and see that it has been polluted with
31   a bunch of *.gcno, *.gcda and *.gcov files. gcov creates and uses these files
32   to extract the code coverage info.
33
34 - After running make_gcov.sh you need to install udev again.  So basically,
35
36     su to root
37     make install
38
39 - Then execute some udev tasks.  You can run some udev tests, reboot, or
40   do anything your little udev heart desires.  Once you are satisfied, you
41   can now see how much udev code was covered.  I personally recommend just
42   running test/udev-test.pl for starters.
43
44 - To get the udev code coverage analysis, execute run_gcov.sh from udev top
45   level directory.  You need to be root to do this.
46
47     su to root
48     make udev_gcov.txt
49
50 - This creates udev_gcov.txt in the udev top level directory which holds all
51   the code coverage information. To see an example of the code coverage info
52   after executing the udev-test.pl test, please see:
53
54   http://developer.osdl.org/ogasawara/gcov_for_udev/udev_gcov.txt
55
56 - Also, after having executed gcov on udev (ie executing run_gcov.sh) a
57   *.gcov file is created for every file which contained code that was
58   used.  Looking at the *.gcov files, one will see what lines of code
59   were hit, and what lines were missed.  For, example if code in udev-add.c
60   were executed, gcov then created a file called udev-add.c.gcov.  And a
61   portion of udev-add.c.gov might look like:
62
63   static int get_major_minor(struct sysfs_class_device *class_dev, struct udevice *udev)
64           95    {
65           95            struct sysfs_attribute *attr = NULL;
66                 
67           95            attr = sysfs_get_classdev_attr(class_dev, "dev");
68           95            if (attr == NULL)
69       ######                    goto error;
70                         dbg("dev='%s'", attr->value);
71                 
72           95            if (sscanf(attr->value, "%u:%u", &udev->major, &udev->minor) != 2)
73       ######                    goto error;
74                         dbg("found major=%d, minor=%d", udev->major, udev->minor);
75                 
76           95            return 0;
77                 error:
78       ######            return -1;
79                 }
80
81   Any line of code that is preceded by a "######" implies that the code
82   was never hit during execution.
83
84 - Once you are done with using gcov for udev and want to return to your
85   normal use of udev, run a regular 'make clean' on your udev directory.
86   Then just run a regular make and make install and you are back to normal:
87
88     make clean all
89     su to root
90     make install