[Pkg-libvirt-commits] [libguestfs] 136/233: tests: add a a simple libvirt-is-version test tool

Hilko Bengen bengen at moszumanska.debian.org
Wed Feb 19 21:11:49 UTC 2014


This is an automated email from the git hooks/post-receive script.

bengen pushed a commit to branch experimental
in repository libguestfs.

commit c01fb37839d28678dd8f5e33ec7fa376b03e8d71
Author: Pino Toscano <ptoscano at redhat.com>
Date:   Mon Jan 27 16:31:32 2014 +0100

    tests: add a a simple libvirt-is-version test tool
    
    libvirt-is-version returns successfully in case the available version of
    libvirt is greater or equal than the specified major/minor/release
    values.
---
 .gitignore               |  1 +
 po/POTFILES              |  1 +
 src/Makefile.am          | 17 +++++++++++
 src/libvirt-is-version.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 96 insertions(+)

diff --git a/.gitignore b/.gitignore
index f8e6c71..f84e2cd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -416,6 +416,7 @@ Makefile.in
 /src/libguestfs.pc
 /src/libguestfs.syms
 /src/.libs/libguestfs.so
+/src/libvirt-is-version
 /src/stamp-guestfs.pod
 /src/structs-cleanup.c
 /src/structs-compare.c
diff --git a/po/POTFILES b/po/POTFILES
index 4df7515..c6277e9 100644
--- a/po/POTFILES
+++ b/po/POTFILES
@@ -294,6 +294,7 @@ src/launch-unix.c
 src/launch.c
 src/libvirt-auth.c
 src/libvirt-domain.c
+src/libvirt-is-version.c
 src/listfs.c
 src/lpj.c
 src/match.c
diff --git a/src/Makefile.am b/src/Makefile.am
index b1022e5..f5c8d2d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -17,6 +17,8 @@
 
 include $(top_srcdir)/subdir-rules.mk
 
+noinst_PROGRAMS =
+
 CLEANFILES = stamp-guestfs.pod
 
 generator_built = \
@@ -226,6 +228,21 @@ libutils_la_SOURCES = \
 libutils_la_CPPFLAGS = $(libguestfs_la_CPPFLAGS)
 libutils_la_CFLAGS = $(libguestfs_la_CFLAGS)
 
+if HAVE_LIBVIRT
+# Small utility to check for a needed libvirt version;
+# to be used in shell/script-based tests.
+noinst_PROGRAMS += libvirt-is-version
+
+libvirt_is_version_SOURCES = libvirt-is-version.c
+
+libvirt_is_version_LDADD = \
+	$(LIBVIRT_LIBS)
+
+libvirt_is_version_CFLAGS = \
+	$(WARN_CFLAGS) $(WERROR_CFLAGS) \
+	$(LIBVIRT_CFLAGS)
+endif
+
 # Tests: main tests are in tests/c-api.  Here we just have some
 # internal tests of utility functions.
 
diff --git a/src/libvirt-is-version.c b/src/libvirt-is-version.c
new file mode 100644
index 0000000..3617d5b
--- /dev/null
+++ b/src/libvirt-is-version.c
@@ -0,0 +1,77 @@
+/* libguestfs
+ * Copyright (C) 2014 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.
+ */
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include <libvirt/libvirt.h>
+
+static unsigned int argtoint (const char *prog, const char *arg);
+
+int
+main (int argc, char *argv[])
+{
+  unsigned long ver;
+  unsigned int major = 0, minor = 0, release = 0;
+
+  switch (argc) {
+  case 4:
+    release = argtoint (argv[0], argv[3]);
+    /*FALLTHROUGH*/
+  case 3:
+    minor = argtoint (argv[0], argv[2]);
+    /*FALLTHROUGH*/
+  case 2:
+    major = argtoint (argv[0], argv[1]);
+    break;
+  case 1:
+    fprintf (stderr, "%s: not enough arguments: MAJOR [MINOR [PATCH]]\n",
+             argv[0]);
+    exit (EXIT_FAILURE);
+    break;
+  }
+
+  virInitialize ();
+
+  if (virGetVersion (&ver, NULL, NULL) == -1)
+    exit (EXIT_FAILURE);
+
+  return ver >= (major * 1000000 + minor * 1000 + release)
+         ? EXIT_SUCCESS : EXIT_FAILURE;
+}
+
+static unsigned int
+argtoint (const char *prog, const char *arg)
+{
+  long int res;
+  char *endptr;
+
+  errno = 0;
+  res = strtol (arg, &endptr, 10);
+  if (errno || *endptr) {
+    fprintf (stderr, "%s: cannot parse integer argument '%s'.\n", prog, arg);
+    exit (EXIT_FAILURE);
+  }
+
+  return (unsigned int) res;
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git



More information about the Pkg-libvirt-commits mailing list