--- ocaml/Makefile.am | 2 ++ ocaml/t/guestfs_065_implicit_close.ml | 32 ++++++++++++++++++++++++++++++++ src/guestfs.pod | 1 + 3 files changed, 35 insertions(+) create mode 100644 ocaml/t/guestfs_065_implicit_close.ml diff --git a/ocaml/Makefile.am b/ocaml/Makefile.am index d838561..ea41377 100644 --- a/ocaml/Makefile.am +++ b/ocaml/Makefile.am @@ -111,6 +111,7 @@ test_progs_bc = \ t/guestfs_040_create_multiple.bc \ t/guestfs_050_handle_properties.bc \ t/guestfs_060_explicit_close.bc \ + t/guestfs_065_implicit_close.bc \ t/guestfs_070_optargs.bc \ t/guestfs_410_close_event.bc \ t/guestfs_420_log_messages.bc @@ -122,6 +123,7 @@ test_progs_opt = \ t/guestfs_040_create_multiple.opt \ t/guestfs_050_handle_properties.opt \ t/guestfs_060_explicit_close.opt \ + t/guestfs_065_implicit_close.opt \ t/guestfs_070_optargs.opt \ t/guestfs_410_close_event.opt \ t/guestfs_420_log_messages.opt diff --git a/ocaml/t/guestfs_065_implicit_close.ml b/ocaml/t/guestfs_065_implicit_close.ml new file mode 100644 index 0000000..764ec63 --- /dev/null +++ b/ocaml/t/guestfs_065_implicit_close.ml @@ -0,0 +1,32 @@ +(* libguestfs OCaml tests + * Copyright (C) 2009-2015 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + *) + +let close_invoked = ref 0 + +let close _ _ _ _ = + incr close_invoked + +let () = + let g = new Guestfs.guestfs () in + ignore (g#set_event_callback close [Guestfs.EVENT_CLOSE]); + assert (!close_invoked = 0); + (* This should cause the GC to close the handle. *) + Gc.compact (); + assert (!close_invoked = 1) + +let () = Gc.compact () diff --git a/src/guestfs.pod b/src/guestfs.pod index 9ec7bbc..248a4d0 100644 --- a/src/guestfs.pod +++ b/src/guestfs.pod @@ -4169,6 +4169,7 @@ This is the numbering scheme used by the tests: 040 create multiple handles 050 test setting and getting config properties 060 explicit close + 065 implicit close (in GC'd languages) 070 optargs - 100 launch, create partitions and LVs and filesystems -- 2.5.0