mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-22 07:03:38 +00:00
daemon: Add unit tests of the ‘Utils’ module.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -169,6 +169,7 @@ Makefile.in
|
||||
/daemon/actions.h
|
||||
/daemon/callbacks.ml
|
||||
/daemon/caml-stubs.c
|
||||
/daemon/daemon_utils_tests
|
||||
/daemon/dispatch.c
|
||||
/daemon/guestfsd
|
||||
/daemon/guestfsd.8
|
||||
|
||||
@@ -42,6 +42,7 @@ generator_built = \
|
||||
EXTRA_DIST = \
|
||||
$(generator_built) \
|
||||
$(SOURCES_MLI) $(SOURCES_ML) \
|
||||
daemon_utils_tests.ml \
|
||||
guestfsd.pod
|
||||
|
||||
if INSTALL_DAEMON
|
||||
@@ -269,7 +270,8 @@ XOBJECTS = $(BOBJECTS:.cmo=.cmx)
|
||||
OCAMLPACKAGES = \
|
||||
-package str,unix,hivex \
|
||||
-I $(top_srcdir)/common/mlstdutils \
|
||||
-I $(top_srcdir)/common/mlutils
|
||||
-I $(top_srcdir)/common/mlutils \
|
||||
-I $(top_builddir)/common/utils/.libs
|
||||
|
||||
OCAMLFLAGS = $(OCAML_FLAGS) $(OCAML_WARN_FLAGS)
|
||||
|
||||
@@ -310,6 +312,47 @@ depend: .depend
|
||||
|
||||
-include .depend
|
||||
|
||||
# Tests.
|
||||
|
||||
check_PROGRAMS = daemon_utils_tests
|
||||
TESTS_ENVIRONMENT = $(top_builddir)/run --test
|
||||
TESTS = \
|
||||
daemon_utils_tests
|
||||
|
||||
check-valgrind:
|
||||
$(MAKE) VG="@VG@" check
|
||||
|
||||
daemon_utils_tests_SOURCES = dummy.c
|
||||
daemon_utils_tests_CPPFLAGS = \
|
||||
-I. \
|
||||
-I$(top_builddir) \
|
||||
-I$(shell $(OCAMLC) -where) \
|
||||
-I$(top_srcdir)/lib
|
||||
daemon_utils_tests_BOBJECTS = \
|
||||
utils.cmo \
|
||||
daemon_utils_tests.cmo
|
||||
daemon_utils_tests_XOBJECTS = $(daemon_utils_tests_BOBJECTS:.cmo=.cmx)
|
||||
|
||||
if !HAVE_OCAMLOPT
|
||||
daemon_utils_tests_THEOBJECTS = $(daemon_utils_tests_BOBJECTS)
|
||||
else
|
||||
daemon_utils_tests_THEOBJECTS = $(daemon_utils_tests_XOBJECTS)
|
||||
endif
|
||||
|
||||
OCAMLLINKFLAGS = \
|
||||
mlcutils.$(MLARCHIVE) \
|
||||
mlstdutils.$(MLARCHIVE) \
|
||||
$(LINK_CUSTOM_OCAMLC_ONLY)
|
||||
|
||||
daemon_utils_tests_DEPENDENCIES = \
|
||||
$(daemon_utils_tests_THEOBJECTS) \
|
||||
$(top_srcdir)/ocaml-link.sh
|
||||
daemon_utils_tests_LINK = \
|
||||
$(top_srcdir)/ocaml-link.sh -- \
|
||||
$(OCAMLFIND) $(BEST) $(OCAMLFLAGS) $(OCAMLLINKFLAGS) \
|
||||
$(OCAMLPACKAGES) \
|
||||
$(daemon_utils_tests_THEOBJECTS) -o $@
|
||||
|
||||
# Manual pages and HTML files for the website.
|
||||
if INSTALL_DAEMON
|
||||
man_MANS = guestfsd.8
|
||||
|
||||
48
daemon/daemon_utils_tests.ml
Normal file
48
daemon/daemon_utils_tests.ml
Normal file
@@ -0,0 +1,48 @@
|
||||
(* guestfs-inspection
|
||||
* Copyright (C) 2009-2017 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.
|
||||
*)
|
||||
|
||||
open Unix
|
||||
open Printf
|
||||
|
||||
open Utils
|
||||
|
||||
(* Test prog_exists. *)
|
||||
let () =
|
||||
assert (prog_exists "ls");
|
||||
assert (prog_exists "true")
|
||||
|
||||
(* Test command, commandr. *)
|
||||
let () =
|
||||
ignore (command "true" []);
|
||||
|
||||
let r, _, _ = commandr "false" [] in
|
||||
assert (r = 1)
|
||||
|
||||
(* Test split_device_partition. *)
|
||||
let () =
|
||||
assert (split_device_partition "/dev/sda1" = ("sda", 1));
|
||||
assert (split_device_partition "/dev/sdb" = ("sdb", 0));
|
||||
assert (split_device_partition "/dev/ubda9" = ("ubda", 9));
|
||||
assert (split_device_partition "/dev/md0p1" = ("md0", 1))
|
||||
(* XXX The function is buggy:
|
||||
assert (split_device_partition "/dev/md0" = ("md0", 0)) *)
|
||||
|
||||
(* Test proc_unmangle_path. *)
|
||||
let () =
|
||||
assert (proc_unmangle_path "\\040" = " ");
|
||||
assert (proc_unmangle_path "\\040\\040" = " ")
|
||||
2
daemon/dummy.c
Normal file
2
daemon/dummy.c
Normal file
@@ -0,0 +1,2 @@
|
||||
/* Dummy source, to be used for OCaml-based tools with no C sources. */
|
||||
enum { foo = 1 };
|
||||
@@ -97,6 +97,7 @@ daemon/dispatch.c
|
||||
daemon/dmesg.c
|
||||
daemon/dropcaches.c
|
||||
daemon/du.c
|
||||
daemon/dummy.c
|
||||
daemon/echo-daemon.c
|
||||
daemon/ext2.c
|
||||
daemon/fallocate.c
|
||||
|
||||
Reference in New Issue
Block a user