From 70c2ffc39677a9f5eb6b2230cb9ca2606b2fd966 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Mon, 13 Apr 2009 19:10:10 +0100 Subject: [PATCH] Additional test programs for Perl, Python, OCaml bindings. --- .gitignore | 20 +++++++++---------- libguestfs.spec.in | 3 +++ ocaml/Makefile.am | 22 ++++++++++++++++++++- ocaml/t/guestfs_005_load.ml | 19 ++++++++++++++++++ ocaml/t/guestfs_010_launch.ml | 32 ++++++++++++++++++++++++++++++ ocaml/t/guestfs_050_lvcreate.ml | 43 +++++++++++++++++++++++++++++++++++++++++ perl/t/050-lvcreate.t | 2 +- python/t/010-launch.py | 3 +++ python/t/050-lvcreate.py | 2 +- 9 files changed, 133 insertions(+), 13 deletions(-) create mode 100644 ocaml/t/guestfs_005_load.ml create mode 100644 ocaml/t/guestfs_010_launch.ml create mode 100644 ocaml/t/guestfs_050_lvcreate.ml diff --git a/.gitignore b/.gitignore index f3fc531..9fb9f04 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,13 @@ *.lo *.o *~ +*.cmi +*.cmo +*.cmx +*.cma +*.cmxa +*.a +*.so Makefile.in Makefile aclocal.m4 @@ -45,17 +52,10 @@ m4/ltsugar.m4 m4/ltversion.m4 m4/lt~obsolete.m4 ocaml/META -ocaml/*.cmi -ocaml/*.cmo -ocaml/*.cmx -ocaml/*.cma -ocaml/*.cmxa -ocaml/*.a -ocaml/*.so -ocaml/examples/*.cmi -ocaml/examples/*.cmo -ocaml/examples/*.cmx ocaml/examples/lvs +ocaml/t/guestfs_005_load +ocaml/t/guestfs_010_launch +ocaml/t/guestfs_050_lvcreate perl/Guestfs.c perl/Guestfs.bs perl/Makefile-pl diff --git a/libguestfs.spec.in b/libguestfs.spec.in index 0da3ce6..f6931b7 100644 --- a/libguestfs.spec.in +++ b/libguestfs.spec.in @@ -123,6 +123,8 @@ Summary: Python bindings for %{name} Group: Development/Libraries Requires: %{name} = %{version}-%{release} +%{!?python_sitelib: %global python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")} +%{!?python_sitearch: %global python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)")} %description python %{name}-python contains Python bindings for %{name}. @@ -193,6 +195,7 @@ rm -rf $RPM_BUILD_ROOT %files devel %defattr(-,root,root,-) %doc HACKING TODO README ex html/guestfs.3.html html/pod.css +%doc src/generator.ml %{_libdir}/libguestfs.so %{_mandir}/man3/guestfs.3* %{_includedir}/guestfs.h diff --git a/ocaml/Makefile.am b/ocaml/Makefile.am index 67f4a15..0f1c349 100644 --- a/ocaml/Makefile.am +++ b/ocaml/Makefile.am @@ -18,11 +18,13 @@ EXTRA_DIST = \ guestfs.mli guestfs.ml \ guestfs_c.c guestfs_c.h guestfs_c_actions.c \ - .depend META.in + .depend META.in \ + t/*.ml SUBDIRS = examples CLEANFILES = *~ *.cmi *.cmo *.cmx *.cma *.cmxa *.o *.a *.so +CLEANFILES += t/*~ t/*.cmi t/*.cmo t/*.o t/*.a t/*.so if HAVE_OCAML @@ -40,6 +42,22 @@ guestfs_c.o: guestfs_c.c guestfs_c_actions.o: guestfs_c_actions.c $(CC) $(CFLAGS) -I$(OCAMLLIB) -I$(top_builddir)/src -fPIC -Wall -c $< +TESTS_ENVIRONMENT = \ + LD_LIBRARY_PATH=$(abs_top_builddir)/src/.libs \ + LIBGUESTFS_PATH=$(abs_top_builddir) + +TESTS = t/guestfs_005_load t/guestfs_010_launch t/guestfs_050_lvcreate +noinst_DATA += $(TESTS) + +t/guestfs_005_load: t/guestfs_005_load.ml + $(OCAMLFIND) ocamlopt -cclib -L$(top_builddir)/src/.libs -I . unix.cmxa mlguestfs.cmxa $< -o $@ + +t/guestfs_010_launch: t/guestfs_010_launch.ml + $(OCAMLFIND) ocamlopt -cclib -L$(top_builddir)/src/.libs -I . unix.cmxa mlguestfs.cmxa $< -o $@ + +t/guestfs_050_lvcreate: t/guestfs_050_lvcreate.ml + $(OCAMLFIND) ocamlopt -cclib -L$(top_builddir)/src/.libs -I . unix.cmxa mlguestfs.cmxa $< -o $@ + .mli.cmi: $(OCAMLFIND) ocamlc -c $< .ml.cmo: @@ -66,4 +84,6 @@ install-data-hook: guestfs \ META *.so *.a *.cma *.cmx *.cmxa *.cmi *.mli +CLEANFILES += $(noinst_DATA) + endif \ No newline at end of file diff --git a/ocaml/t/guestfs_005_load.ml b/ocaml/t/guestfs_005_load.ml new file mode 100644 index 0000000..779e1c0 --- /dev/null +++ b/ocaml/t/guestfs_005_load.ml @@ -0,0 +1,19 @@ +(* libguestfs OCaml bindings + * Copyright (C) 2009 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + *) + +let _ = Guestfs.create diff --git a/ocaml/t/guestfs_010_launch.ml b/ocaml/t/guestfs_010_launch.ml new file mode 100644 index 0000000..b253e0c --- /dev/null +++ b/ocaml/t/guestfs_010_launch.ml @@ -0,0 +1,32 @@ +(* libguestfs OCaml bindings + * Copyright (C) 2009 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + *) + +open Unix + +let () = + let g = Guestfs.create () in + + let fd = openfile "test.img" [O_WRONLY;O_CREAT;O_NOCTTY;O_TRUNC] 0o666 in + ftruncate fd (500 * 1024 * 1024); + close fd; + + Guestfs.add_drive g "test.img"; + Guestfs.launch g; + Guestfs.wait_ready g; + + unlink "test.img" diff --git a/ocaml/t/guestfs_050_lvcreate.ml b/ocaml/t/guestfs_050_lvcreate.ml new file mode 100644 index 0000000..2d5bb1f --- /dev/null +++ b/ocaml/t/guestfs_050_lvcreate.ml @@ -0,0 +1,43 @@ +(* libguestfs OCaml bindings + * Copyright (C) 2009 Red Hat Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + *) + +open Unix + +let () = + let g = Guestfs.create () in + + let fd = openfile "test.img" [O_WRONLY;O_CREAT;O_NOCTTY;O_TRUNC] 0o666 in + ftruncate fd (500 * 1024 * 1024); + close fd; + + Guestfs.add_drive g "test.img"; + Guestfs.launch g; + Guestfs.wait_ready g; + + Guestfs.pvcreate g "/dev/sda"; + Guestfs.vgcreate g "VG" [|"/dev/sda"|]; + Guestfs.lvcreate g "LV1" "VG" 200; + Guestfs.lvcreate g "LV2" "VG" 200; + + let lvs = Guestfs.lvs g in + if lvs <> [|"/dev/VG/LV1"; "/dev/VG/LV2"|] then + failwith "Guestfs.lvs returned incorrect result"; + + Guestfs.sync g; + Guestfs.close g; + unlink "test.img" diff --git a/perl/t/050-lvcreate.t b/perl/t/050-lvcreate.t index 418428c..1b3e313 100644 --- a/perl/t/050-lvcreate.t +++ b/perl/t/050-lvcreate.t @@ -57,4 +57,4 @@ ok (1); undef $h; ok (1); -#unlink ("test.img"); +unlink ("test.img"); diff --git a/python/t/010-launch.py b/python/t/010-launch.py index c2bdd1d..1cba322 100644 --- a/python/t/010-launch.py +++ b/python/t/010-launch.py @@ -15,6 +15,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +import os import guestfs g = guestfs.guestfs() @@ -24,3 +25,5 @@ f.close () g.add_drive ("test.img") g.launch () g.wait_ready () + +os.unlink ("test.img") diff --git a/python/t/050-lvcreate.py b/python/t/050-lvcreate.py index 98227e2..444cee9 100644 --- a/python/t/050-lvcreate.py +++ b/python/t/050-lvcreate.py @@ -15,6 +15,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +import os import guestfs g = guestfs.guestfs() @@ -33,5 +34,4 @@ if (g.lvs () != ["/dev/VG/LV1", "/dev/VG/LV2"]): g.sync () del g -import os os.unlink ("test.img") -- 1.8.3.1