Yongkui Guo
2017-Sep-01 08:28 UTC
Re: [Libguestfs] The issue about code coverage for libguestfs
----- Original Message -----> 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.htmlI will read it later. And I need to think about how to do code coverage in this way. Thanks.> > > +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 $@I added the above changes as a patch. But it failed with the following error: --------------------------------------------------------- ... ocamlmklib -o mlguestfs \ libguestfsocaml_a-guestfs-c.o libguestfsocaml_a-guestfs-c-actions.o libguestfsocaml_a-guestfs-c-errnos.o ../common/utils/libguestfsocaml_a-utils.o guestfs.cmo \ -Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld \ \ -L../lib/.libs -lguestfs \ -L../gnulib/lib/.libs -lgnu Unknown option -Wl,-z,relro Unknown option -specs=/usr/lib/rpm/redhat/redhat-hardened-ld ocamlmklib -o mlguestfs \ libguestfsocaml_a-guestfs-c.o libguestfsocaml_a-guestfs-c-actions.o libguestfsocaml_a-guestfs-c-errnos.o ../common/utils/libguestfsocaml_a-utils.o guestfs.cmx \ -Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld \ \ -L../lib/.libs -lguestfs \ -L../gnulib/lib/.libs -lgnu Unknown option -Wl,-z,relro Unknown option -specs=/usr/lib/rpm/redhat/redhat-hardened-ld touch stamp-mlguestfs make[2]: Leaving directory `/home/mockbuild/rpmbuild/BUILD/libguestfs-1.36.5/ocaml' Making all in ocaml/examples make[2]: Entering directory `/home/mockbuild/rpmbuild/BUILD/libguestfs-1.36.5/ocaml/examples' ocamlfind ocamlopt -cclib -L../../lib/.libs -package unix -linkpkg \ -warn-error A -I .. mlguestfs.cmxa create_disk.ml -o create_disk ocamlfind ocamlopt -cclib -L../../lib/.libs -package unix -linkpkg \ -warn-error A -I .. mlguestfs.cmxa debug_logging.ml -o debug_logging /usr/bin/ld: cannot find -lgnu collect2: error: ld returned 1 exit status --------------------------------------------------------- Then I removed the '-lgnu' option. The error was still the same as before: --------------------------------------------------------- ... ocamlmklib -o mlguestfs \ libguestfsocaml_a-guestfs-c.o libguestfsocaml_a-guestfs-c-actions.o libguestfsocaml_a-guestfs-c-errnos.o ../common/utils/libguestfsocaml_a-utils.o guestfs.cmo \ -fprofile-arcs -ftest-coverage -lgcov \ \ -L../lib/.libs -lguestfs \ -L../gnulib/lib/.libs Unknown option -fprofile-arcs Unknown option -ftest-coverage ocamlmklib -o mlguestfs \ libguestfsocaml_a-guestfs-c.o libguestfsocaml_a-guestfs-c-actions.o libguestfsocaml_a-guestfs-c-errnos.o ../common/utils/libguestfsocaml_a-utils.o guestfs.cmx \ -fprofile-arcs -ftest-coverage -lgcov \ \ -L../lib/.libs -lguestfs \ -L../gnulib/lib/.libs Unknown option -fprofile-arcs Unknown option -ftest-coverage touch stamp-mlguestfs Warning: Element Unix.error not found make[2]: Leaving directory `/home/mockbuild/rpmbuild/BUILD/libguestfs-1.36.5/ocaml' Making all in ocaml/examples make[2]: Entering directory `/home/mockbuild/rpmbuild/BUILD/libguestfs-1.36.5/ocaml/examples' ocamlfind ocamlopt -cclib -L../../lib/.libs -package unix -linkpkg \ -warn-error A -I .. mlguestfs.cmxa create_disk.ml -o create_disk ocamlfind ocamlopt -cclib -L../../lib/.libs -package unix -linkpkg \ -warn-error A -I .. mlguestfs.cmxa debug_logging.ml -o debug_logging ../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' collect2: error: ld returned 1 exit status File "caml_startup", line 1: Error: Error during linking make[2]: *** [debug_logging] Error 2 make[2]: *** Waiting for unfinished jobs.... ../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' collect2: error: ld returned 1 exit status File "caml_startup", line 1: Error: Error during linking make[2]: *** [create_disk] Error 2 make[2]: Leaving directory `/home/mockbuild/rpmbuild/BUILD/libguestfs-1.36.5/ocaml/examples' make[1]: *** [all-recursive] Error 1 make[1]: Leaving directory `/home/mockbuild/rpmbuild/BUILD/libguestfs-1.36.5' make: *** [all] Error 2 error: Bad exit status from /var/tmp/rpm-tmp.FM2viv (%build) --------------------------------------------------------- Best wishes Yongkui Guo IRC: yoguo Tel: 15010777318
Richard W.M. Jones
2017-Sep-01 08:38 UTC
Re: [Libguestfs] The issue about code coverage for libguestfs
On Fri, Sep 01, 2017 at 04:28:52AM -0400, Yongkui Guo wrote:> > 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[...]> ocamlmklib -o mlguestfs \ > libguestfsocaml_a-guestfs-c.o libguestfsocaml_a-guestfs-c-actions.o libguestfsocaml_a-guestfs-c-errnos.o ../common/utils/libguestfsocaml_a-utils.o guestfs.cmo \ > -Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld \The problem is unrelated to the patch. $(LDFLAGS) are added to the ocamlmklib command, but ocamlmklib only understands a limited subset of linker flags, including -L but not including -Wl. Possibly something like this might work: stamp-mlguestfs: libguestfsocaml.a $(guestfs_cmm) $(OCAMLMKLIB) -o mlguestfs \ $(libguestfsocaml_a_OBJECTS) guestfs.cmo \ - $(LDFLAGS) \ + -ldopt '$(LDFLAGS)' \ $(LTLIBINTL) \ -L../lib/.libs -lguestfs (in all the places where $(LDFLAGS) is passed to ocamlmklib). Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/
Yongkui Guo
2017-Sep-08 12:50 UTC
Re: [Libguestfs] The issue about code coverage for libguestfs
> On Fri, Sep 01, 2017 at 04:28:52AM -0400, Yongkui Guo wrote: > > > 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 > [...] > > ocamlmklib -o mlguestfs \ > > libguestfsocaml_a-guestfs-c.o libguestfsocaml_a-guestfs-c-actions.o > > libguestfsocaml_a-guestfs-c-errnos.o > > ../common/utils/libguestfsocaml_a-utils.o guestfs.cmo \ > > -Wl,-z,relro -specs=/usr/lib/rpm/redhat/redhat-hardened-ld \ > > The problem is unrelated to the patch. > > $(LDFLAGS) are added to the ocamlmklib command, but ocamlmklib only > understands a limited subset of linker flags, including -L but not > including -Wl. > > Possibly something like this might work: > > stamp-mlguestfs: libguestfsocaml.a $(guestfs_cmm) > $(OCAMLMKLIB) -o mlguestfs \ > $(libguestfsocaml_a_OBJECTS) guestfs.cmo \ > - $(LDFLAGS) \ > + -ldopt '$(LDFLAGS)' \ > $(LTLIBINTL) \ > -L../lib/.libs -lguestfs > > (in all the places where $(LDFLAGS) is passed to ocamlmklib). >Unfortunately, it still didn't work well. Should I need to modify Makefile.am in /home/mockbuild/rpmbuild/BUILD/libguestfs-1.36.5/ocaml/examples? ------------------------------------------------- ocamlfind ocamlc -g -annot -warn-error CDEFLMPSUVYZX-3 -package unix -c guestfs.ml -o guestfs.cmo ocamlfind ocamlopt -g -annot -warn-error CDEFLMPSUVYZX-3 -package unix -c guestfs.ml -o guestfs.cmx rm -f libguestfsocaml.a ar cr libguestfsocaml.a libguestfsocaml_a-guestfs-c.o libguestfsocaml_a-guestfs-c-actions.o libguestfsocaml_a-guestfs-c-errnos.o ../common/utils/libguestfsocaml_a-utils.o ranlib libguestfsocaml.a ocamlmklib -o mlguestfs \ libguestfsocaml_a-guestfs-c.o libguestfsocaml_a-guestfs-c-actions.o libguestfsocaml_a-guestfs-c-errnos.o ../common/utils/libguestfsocaml_a-utils.o guestfs.cmo \ -ldopt '-fprofile-arcs -ftest-coverage -lgcov' \ \ -L../lib/.libs -lguestfs \ -L../gnulib/lib/.libs -lgnu ocamlmklib -o mlguestfs \ libguestfsocaml_a-guestfs-c.o libguestfsocaml_a-guestfs-c-actions.o libguestfsocaml_a-guestfs-c-errnos.o ../common/utils/libguestfsocaml_a-utils.o guestfs.cmx \ -ldopt '-fprofile-arcs -ftest-coverage -lgcov' \ \ -L../lib/.libs -lguestfs \ -L../gnulib/lib/.libs -lgnu touch stamp-mlguestfs Warning: Element Unix.error not found make[2]: Leaving directory `/home/mockbuild/rpmbuild/BUILD/libguestfs-1.36.5/ocaml' Making all in ocaml/examples make[2]: Entering directory `/home/mockbuild/rpmbuild/BUILD/libguestfs-1.36.5/ocaml/examples' ocamlfind ocamlopt -cclib -L../../lib/.libs -package unix -linkpkg \ -warn-error A -I .. mlguestfs.cmxa create_disk.ml -o create_disk ocamlfind ocamlopt -cclib -L../../lib/.libs -package unix -linkpkg \ -warn-error A -I .. mlguestfs.cmxa debug_logging.ml -o debug_logging /usr/bin/ld: cannot find -lgnu collect2: error: ld returned 1 exit status File "caml_startup", line 1: Error: Error during linking make[2]: *** [debug_logging] Error 2 make[2]: *** Waiting for unfinished jobs.... -------------------------------------------------
Seemingly Similar Threads
- Re: The issue about code coverage for libguestfs
- Re: The issue about code coverage for libguestfs
- [PATCH] ocaml: make sure to pass LDFLAGS to ocamlmklibs linker (RHBZ#1624130)
- The issue about code coverage for libguestfs
- [PATCH libguestfs] build: don't use automake-internal variable