chiark / gitweb /
[PATCH] add hints for red hat users from Leann Ogasawara <ogasawara@osdl.org>
[elogind.git] / README-gcov_for_udev
1 ################################################
2
3 Using GCC's code coverage tool, gcov, with udev
4
5 ################################################
6
7 For more information on using gcov please see:
8
9 http://gcc.gnu.org/onlinedocs/gcc/Gcov.html
10
11 With that said, here is how to get code coverage analysis for udev files.
12 Note that this was developed with udev version 024.
13
14 - Make sure you've installed udev and that it is working properly.
15   If you are having problems, refer to the README and HOWTO-udev_for_dev
16   documents in udev tarball.  I've also compiled a udev_for_dev
17   toubleshooting document for Red Hat which can be found at:
18
19   http://developer.osdl.org/ogasawara/gcov_for_udev/rh_udev_for_dev.txt
20
21 - Get the following files:
22     make_gcov.sh
23     run_gcov.sh
24
25   These can be found at http://developer.osdl.org/ogasawara/gcov_for_udev/
26
27 - After grabbing these files, copy both make_gcov.sh and run_gcov.sh
28   into the top level of your udev directory.
29
30 - execute make_gcov.sh
31
32     ./make_gcov.sh
33
34   This will compile udev with gcov support.  Basically make_gcov.sh will
35   run make but override the CFLAGS.  It strips any optimization from
36   CFLAGS in order for gcov to get correct code coverage analysis.  It will
37   also add the -fprofile-arcs and -ftest-coverage options which are the
38   necessary flags needed to use gcov.
39
40   make_gcov.sh will assume the same default parameters as the regular
41   make but also accepts the same parameters.  For example if you want
42   to get code coverage analysis for udev with the DEBUG flag turned
43   on, you would just execute:
44
45     ./make_gcov.sh DEBUG=true
46
47   There is one exception, gcov will not work with klibc as it does not
48   compile cleanly with the -fprofile-arcs and -ftest-coverage flags.
49   With this said it is pretty much useless to set the KERNEL_DIR flag
50   when using make_gcov.sh as well.
51
52   Don't be alarmed if you look into your udev directory and see that it
53   has been polluted with a bunch of *.bb, *.bbg, *.da, and *.gcov files.
54   gcov creates and uses these files to extract the code coverage info.
55
56 - After running make_gcov.sh you need to install udev again.  So basically,
57
58     su to root
59     make install
60
61 - Then execute some udev tasks.  You can run some udev tests, reboot, or
62   do anything your little udev heart desires.  Once you are satisfied, you
63   can now see how much udev code was covered.
64
65 - To get the udev code coverage analysis, execute run_gcov.sh.  You need to
66   be root to do this.
67
68     su to root
69     ./run_gcov.sh
70
71 - This creates udev_gcov.txt which holds all the code coverage information.
72   To see an example of the code coverage info after executing the udev-test.pl
73   test, please see:
74
75   http://developer.osdl.org/ogasawara/gcov_for_udev/udev_gcov.txt
76
77 - Also, after having executed gcov on udev (ie executing run_gcov.sh) a
78   *.gcov file is created for every file which contained code that was
79   used.  Looking at the *.gcov files, one will see what lines of code
80   were hit, and what lines were missed.  For, example if code in udev-add.c
81   were executed, gcov then created a file called udev-add.c.gcov.  And a
82   portion of udev-add.c.gov might look like:
83
84   static int get_major_minor(struct sysfs_class_device *class_dev, struct udevice *udev)
85           95    {
86           95            struct sysfs_attribute *attr = NULL;
87                 
88           95            attr = sysfs_get_classdev_attr(class_dev, "dev");
89           95            if (attr == NULL)
90       ######                    goto error;
91                         dbg("dev='%s'", attr->value);
92                 
93           95            if (sscanf(attr->value, "%u:%u", &udev->major, &udev->minor) != 2)
94       ######                    goto error;
95                         dbg("found major=%d, minor=%d", udev->major, udev->minor);
96                 
97           95            return 0;
98                 error:
99       ######            return -1;
100                 }
101
102   Any line of code that is preceded by a "######" implies that the code
103   was never hit during execution.
104
105 - Once you are done with using gcov for udev and want to return to your
106   normal use of udev.  Simply,
107
108     ./make_gcov.sh clean
109
110   This will clean out all the *.bb, *.bbg, *.da, *.gcov files produced by gcov.
111   It will also run a regular make clean on your udev directory.  Then just run
112   a regular make and make install and you are back to normal:
113
114     make
115     su to root
116     make isntall