[Libguestfs] The issue about code coverage for libguestfs

Richard W.M. Jones rjones at redhat.com
Thu Aug 31 11:58:36 UTC 2017


On Thu, Aug 31, 2017 at 05:45:38AM -0400, Yongkui Guo wrote:
> Hi,
> 
> I tried to do code coverage testing for libguestfs with gcov.
> 
> The steps are shown as follows:
> 1. Download and install the source package(libguestfs-1.36.5-1.el7.src.rpm)

Probably best to try building this from git instead of using RPMs, so
we can get the changes working upstream first.  Make sure to read this
page first:

  http://libguestfs.org/guestfs-building.1.html

> +CFLAGS="-fprofile-arcs -ftest-coverage -g -O0"; export CFLAGS
> +LDFLAGS="-fprofile-arcs -ftest-coverage -lgcov"; export LDFLAGS

> +sed -i 's/^CFLAGS = -fprofile-arcs -ftest-coverage -g -O0/CFLAGS = /g' /home/mockbuild/rpmbuild/BUILD/libguestfs-1.36.5/ocaml/Makefile

> ../libmlguestfs.a(libguestfsocaml_a-utils.o): In function `guestfs_int_string_is_valid':
> utils.c:(.text+0xb99): undefined reference to `c_isalpha'
> utils.c:(.text+0xbbf): undefined reference to `c_isdigit'

I suppose that we need to link the OCaml bindings to -lgnu, which
your patch attempts:

> +libguestfsocaml_a_LIBADD = \
> +	$(top_builddir)/gnulib/lib/libgnu.la
> +

... but the problem is that libguestfsocaml.a isn't really used for
anything.  See the comment in the same Makefile.am:

  # Build the C part into a library, so that automake handles the C
  # compilation step for us.  Note that we don't directly use this
  # library; we link with the object files that it generates.
  noinst_LIBRARIES = libguestfsocaml.a

You'll need to change all the places where
$(libguestfsocaml_a_OBJECTS) is used instead, eg something like this
untested change:

 stamp-mlguestfs: libguestfsocaml.a $(guestfs_cmm)
         $(OCAMLMKLIB) -o mlguestfs \
           $(libguestfsocaml_a_OBJECTS) guestfs.cmo \
           $(LDFLAGS) \
           $(LTLIBINTL) \
-         -L../lib/.libs -lguestfs
+         -L../lib/.libs -lguestfs \
+         -L../gnulib/lib/.libs -lgnu
 if HAVE_OCAMLOPT
         $(OCAMLMKLIB) -o mlguestfs \
           $(libguestfsocaml_a_OBJECTS) guestfs.cmx \
           $(LDFLAGS) \
           $(LTLIBINTL) \
-         -L../lib/.libs -lguestfs
+         -L../lib/.libs -lguestfs \
+         -L../gnulib/lib/.libs -lgnu
 endif
         touch $@

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://libguestfs.org




More information about the Libguestfs mailing list