This will generate HTML output of the testsuite coverage in
_build-gcc/coverage/*.

After running "ovs-dev.py coverage", the source will be configured to
collect coverage information. This may cause testsuite failures,
particularly if running with high parallelism. Re-run "ovs-dev.py conf"
to remove the coverage configuration.

Signed-off-by: Joe Stringer <joestrin...@nicira.com>
---
I've uploaded an initial run of the test coverage here for a sample:
http://joestringer.github.io/openvswitch/index.html

If people are interested in having a coverage site like this accessible
all the time, I could probably set up a cron job to keep it up to date.

The main thing I've noticed so far is that IPFIX is almost completely
untested. There are some limitations, this is not running the linux
datapath and attached netlink code. Furthermore the testsuite primarily
tests for true positives/false negatives, and doesn't check for false
positives/true negatives. This decreases the % coverage considerably.
---
 utilities/ovs-dev.py |   54 ++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 43 insertions(+), 11 deletions(-)

diff --git a/utilities/ovs-dev.py b/utilities/ovs-dev.py
index 91732e1..244fa40 100755
--- a/utilities/ovs-dev.py
+++ b/utilities/ovs-dev.py
@@ -89,6 +89,10 @@ def conf():
     if options.optimize is None:
         options.optimize = 0
 
+    coverage = "" # Only apply to GCC builds.
+    if options.coverage:
+        coverage = "--enable-coverage"
+
     cflags += " -O%d" % options.optimize
 
     ENV["CFLAGS"] = cflags
@@ -101,7 +105,8 @@ def conf():
         pass # Directory exists.
 
     os.chdir(BUILD_GCC)
-    _sh(*(configure + ["--with-linux=/lib/modules/%s/build" % uname()]))
+    _sh(*(configure + ["--with-linux=/lib/modules/%s/build" % uname(),
+                       coverage]))
 
     clang = program_exists("clang")
     sparse = program_exists("sparse")
@@ -159,6 +164,30 @@ def check():
 commands.append(check)
 
 
+def coverage():
+    _sh('lcov', '-q', '--zerocounters', '--directory', BUILD_GCC)
+
+    if not options.jobs:
+        # Decrease the chance of tests failing due to coverage collection.
+        options.jobs = 2
+    options.coverage = True
+    conf()
+
+    e = None
+    try:
+        check()
+    except Exception as e:
+        print e
+        pass
+
+    _sh('lcov', '-q', '--capture', '-b', BUILD_GCC, '--directory', BUILD_GCC,
+        '--output-file', '%s/coverage.info' % BUILD_GCC)
+    _sh('genhtml', '-q', '%s/coverage.info' % BUILD_GCC,
+        '--output-directory', '%s/coverage' % BUILD_GCC)
+    print("\nCoverage was successfully written to %s/coverage/." % BUILD_GCC)
+commands.append(coverage)
+
+
 def tag():
     ctags = ['ctags', '-R', '-f', '.tags']
 
@@ -315,16 +344,17 @@ Basic Configuration:
     %(v)s run
 
 Commands:
-    conf    - Configure the ovs source.
-    make    - Build the source (must have been configured).
-    check   - Run the unit tests.
-    tag     - Run ctags and cscope over the source.
-    kill    - Kill all running instances of ovs.
-    reset   - Reset any runtime configuration in %(run)s.
-    run     - Run ovs.
-    modinst - Build ovs and install the kernel module.
-    env     - Print the required path environment variable.
-    doc     - Print this message.
+    conf     - Configure the ovs source.
+    make     - Build the source (must have been configured).
+    check    - Run the unit tests.
+    coverage - Run the unit tests and generate lcov output.
+    tag      - Run ctags and cscope over the source.
+    kill     - Kill all running instances of ovs.
+    reset    - Reset any runtime configuration in %(run)s.
+    run      - Run ovs.
+    modinst  - Build ovs and install the kernel module.
+    env      - Print the required path environment variable.
+    doc      - Print this message.
 """ % {"ovs": OVS_SRC, "v": sys.argv[0], "run": ROOT}
     sys.exit(0)
 commands.append(doc)
@@ -360,6 +390,8 @@ def main():
                      help="configure the man documentation install directory")
     group.add_option("--with-dpdk", dest="with_dpdk", metavar="DPDK_BUILD",
                      help="built with dpdk libraries located at DPDK_BUILD");
+    group.add_option("--enable-coverage", dest="coverage", action="store_true",
+                     default=False, help="enable gcov coverage collection.")
 
     for i in range(4):
         group.add_option("--O%d" % i, dest="optimize", action="store_const",
-- 
1.7.10.4

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to