summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgreg@kroah.com <greg@kroah.com>2004-04-17 00:09:17 -0700
committerGreg KH <gregkh@suse.de>2005-04-26 21:35:15 -0700
commitd9154d11760bc650ca396d19bd31240616d4f80a (patch)
tree47704644b2e137acfbdc2cafa26074111b2913a9
parentb2983b9d4a05b44c9230e17a3d6737d185d1c749 (diff)
[PATCH] add scripts to run gcov for udev from Leann Ogasawara <ogasawara@osdl.org>
-rw-r--r--README-gcov_for_udev116
-rw-r--r--make_gcov.sh53
-rw-r--r--run_gcov.sh40
3 files changed, 209 insertions, 0 deletions
diff --git a/README-gcov_for_udev b/README-gcov_for_udev
new file mode 100644
index 0000000000..fa377bc4af
--- /dev/null
+++ b/README-gcov_for_udev
@@ -0,0 +1,116 @@
+################################################
+
+Using GCC's code coverage tool, gcov, with udev
+
+################################################
+
+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
+ documents in udev tarball. I've also compiled a udev_for_dev
+ toubleshooting document for Red Hat which can be found at:
+
+ http://developer.osdl.org/ogasawara/gcov_for_udev/rh_udev_for_dev.txt
+
+- Get the following files:
+ make_gcov.sh
+ run_gcov.sh
+
+ These can be found at http://developer.osdl.org/ogasawara/gcov_for_udev/
+
+- After grabbing these files, copy both make_gcov.sh and run_gcov.sh
+ into the top level of your udev directory.
+
+- execute make_gcov.sh
+
+ ./make_gcov.sh
+
+ 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.
+
+ make_gcov.sh will assume the same default parameters as the regular
+ make but also accepts the same parameters. For example if you want
+ to get code coverage analysis for udev with the DEBUG flag turned
+ on, you would just execute:
+
+ ./make_gcov.sh DEBUG=true
+
+ There is one exception, gcov will not work with klibc as it does not
+ compile cleanly with the -fprofile-arcs and -ftest-coverage flags.
+ With this said it is pretty much useless to set the KERNEL_DIR flag
+ when using make_gcov.sh as well.
+
+ Don't be alarmed if you look into your udev directory and see that it
+ has been polluted with a bunch of *.bb, *.bbg, *.da, and *.gcov files.
+ gcov creates and uses these files to extract the code coverage info.
+
+- 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
+ can now see how much udev code was covered.
+
+- To get the udev code coverage analysis, execute run_gcov.sh. You need to
+ be root to do this.
+
+ su to root
+ ./run_gcov.sh
+
+- This creates udev_gcov.txt 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:
+
+ 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
+ normal use of udev. Simply,
+
+ ./make_gcov.sh clean
+
+ This will clean out all the *.bb, *.bbg, *.da, *.gcov files produced by gcov.
+ It will also run a regular make clean on your udev directory. Then just run
+ a regular make and make install and you are back to normal:
+
+ make
+ su to root
+ make isntall
diff --git a/make_gcov.sh b/make_gcov.sh
new file mode 100644
index 0000000000..907c1ebd48
--- /dev/null
+++ b/make_gcov.sh
@@ -0,0 +1,53 @@
+#!/bin/sh
+#
+# gcov capability for udev
+#
+# Provides code coverage analysis for udev.
+#
+# make_gcov.sh assumes the same same default parameters as make, but also
+# accepts the same parameters as make (see README file in udev/ for
+# parameter info). There is one exception, klibc can not be used with
+# gcov as it will not compile cleanly.
+#
+# make_gcov.sh then overrides CFLAGS to strip out optimization in order
+# for gcov to get correct code coverage analysis.
+#
+# Leann Ogasawara <ogasawara@osdl.org>, April 2004
+
+# clean up udev dir
+clean_udev () {
+ find -name "*.da" -exec rm -f "{}" \;
+ find -name "*.bb" -exec rm -f "{}" \;
+ find -name "*.bbg" -exec rm -f "{}" \;
+ find -name "*.gcov" -exec rm -f "{}" \;
+ make clean
+}
+
+PWD=`pwd`
+GCCINCDIR=`gcc -print-search-dirs | sed -ne "s/install: \(.*\)/\1include/gp"`
+LIBSYSFS="-I$PWD/libsysfs"
+WARNINGS="-Wall -Wshadow -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations"
+GCC="-I$GCCINCDIR"
+USE_LOG="-DLOG"
+DEBUG="-D_GNU_SOURCE"
+GCOV_FLAGS="-pipe -fprofile-arcs -ftest-coverage"
+
+for i in $*; do
+ pre=`echo $i | sed 's/=.*//g'`
+ post=`echo $i | sed 's/.*=//g'`
+ if [ $pre = "USE_KLIBC" ] && [ $post = "true" ]; then
+ echo "cannot use gcov with klibc, will not compile"
+ exit
+ elif [ $pre = "USE_LOG" ] && [ $post = "false" ]; then
+ USE_LOG=""
+ elif [ $pre = "DEBUG" ] && [ $post = "true" ]; then
+ DEBUG="-g -DDEBUG -D_GNU_SOURCE"
+ elif [ $pre = "clean" ]; then
+ clean_udev
+ exit
+ fi
+done
+
+clean_udev
+
+make $* CFLAGS="$WARNINGS $GCOV_FLAGS $USE_LOG $DEBUG $GCC $LIBSYSFS"
diff --git a/run_gcov.sh b/run_gcov.sh
new file mode 100644
index 0000000000..4fe936199f
--- /dev/null
+++ b/run_gcov.sh
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+#
+# run gcov on udev
+#
+# Generate code coverage analysis for udev files
+#
+# This requires that you compiled udev with gcov flags i.e.
+# you should have compiled udev with the make_gcov.sh script.
+#
+# Leann Ogasawara <ogasawara@osdl.org>, April 2004
+
+PWD=`pwd`
+
+# check if root else may not have access to *.da files
+# and gcov analysis will fail.
+if [ $(id -u) -ne 0 ]; then
+ echo "please become root before executing run_gcov.sh"
+ exit 1
+fi
+
+echo > udev_gcov.txt
+echo "CODE COVERAGE ANALYSIS FOR UDEV" >> udev_gcov.txt
+echo >> udev_gcov.txt
+
+for file in `find -maxdepth 1 -name "*.bb"`; do
+ name=`basename $file .bb`
+ echo "################" >> udev_gcov.txt
+ echo "$name.c" >> udev_gcov.txt
+ echo "################" >> udev_gcov.txt
+ if [ -e "$name.da" ]; then
+ gcov -l "$name.c" >> udev_gcov.txt 2>&1
+ else
+ echo "code for $name.c was never executed" >> udev_gcov.txt 2>&1
+ echo "no code coverage analysis to be done" >> udev_gcov.txt 2>&1
+ fi
+ echo >> udev_gcov.txt
+done
+
+echo "udev gcov analysis done. View udev_gcov.txt for results."