[PATCH] fish: reset the console on ^Z RHBZ#1213844
by Maros Zatko
Patch registers SIGTSTP hook where it sends reset terminal color control
sequence.
Maros Zatko (1):
fish: reset the console on ^Z RHBZ#1213844
fish/fish.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 72 insertions(+)
--
2.5.0
8 years, 9 months
New API: node_nr_values
by Kevin Haroldsen
As a follow-up to node_nr_children discussed in
"hivex lib: Add function hivex_node_num_children",
I've also created the function node_nr_values, which just returns the
number of values of a node (primarily for optimization purposes).
I hope I've done it correctly so that a follow-up commit is unneeded.
The git tree is here: https://github.com/kupiakos/hivex/tree/node_nr_values
This is the patch:
diff --git a/generator/generator.ml b/generator/generator.ml
index 4f878ff..83fd276 100755
--- a/generator/generator.ml
+++ b/generator/generator.ml
@@ -242,6 +242,12 @@ string C<\"\"> here. The default key is often
written C<\"@\">, but
inside hives that has no meaning and won't give you the
default key.";
+ "node_nr_values", (RSize, [AHive; ANode "node"]),
+ "return the number of values attached to a node",
+ "\
+Return the number of (key, value) pairs attached to this node
+as produced by C<hivex_node_values>.";
+
"value_key_len", (RSize, [AHive; AValue "val"]),
"return the length of a value's key",
"\
diff --git a/lib/value.c b/lib/value.c
index 43e89f9..2dfe006 100644
--- a/lib/value.c
+++ b/lib/value.c
@@ -159,6 +159,22 @@ hivex_node_get_value (hive_h *h, hive_node_h
node, const char *key)
}
size_t
+hivex_node_nr_values (hive_h *h, hive_node_h node)
+{
+ if (!IS_VALID_BLOCK (h, node) || !block_id_eq (h, node, "nk")) {
+ SET_ERRNO (EINVAL, "invalid block or not an 'nk' block");
+ return 0;
+ }
+
+ struct ntreg_nk_record *nk =
+ (struct ntreg_nk_record *) ((char *) h->addr + node);
+
+ size_t nr_values = le32toh (nk->nr_values);
+
+ return nr_values;
+}
+
+size_t
hivex_value_struct_length (hive_h *h, hive_value_h value)
{
size_t key_len;
Regards,
- Kevin Haroldsen (kupiakos)
8 years, 9 months
Re: [Libguestfs] Help with Win10
by Richard W.M. Jones
On Mon, Feb 08, 2016 at 04:50:09PM -0800, Joshua Pincus wrote:
> Mr Jones,
>
> I recently came across your excellent 2010 blog entry,
> https://rwmj.wordpress.com/2010/04/30/tip-install-a-device-driver-in-a-wi....
> The blog entry was incredibly useful for Win7. I was wondering if you have
> any similar insights for Win10? The CDDB is gone, and it's replacement, or
> partial replacement, the DeviceDriver database, doesn't seem to serve a
> similar purpose.
>
> My problem is this: I have a Win10 installation that was installed natively
> onto physical media using the standard Intel storage drivers. In short, I
> want to do precisely that you detailed in your 2010 entry under Win10; I
> want to boot that native installation using the current RedHat viostor
> driver. Win10 keeps hitting me with an 0x7B error, and it's rather
> difficult to get into debugger mode. If I install Win7 and then try
> booting Win7 using viostor as you detailed, it works perfectly. Win10 does
> not. Any insights?
See:
https://github.com/libguestfs/libguestfs/blob/master/v2v/windows_virtio.ml
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/
8 years, 9 months
[PATCH] Start adding return values tests for bindings
by Pino Toscano
Introduce a new kind of bindings tests, 090-retvalues, to check all the
possible return values in bindings; start implementing them for
scripting languages such as GObject introspection, Perl, PHP, Python,
and Ruby, reusing existing implementations where existing.
---
docs/guestfs-hacking.pod | 1 +
gobject/Makefile.am | 4 +-
gobject/bindtests-manual.js | 110 ---------
gobject/bindtests-retvalues.js | 110 +++++++++
gobject/run-tests | 2 -
gobject/run-tests-retvalues | 26 +++
perl/t/090-retvalues.t | 125 +++++++++++
php/extension/tests/guestfs_090_retvalues.phpt | 294 +++++++++++++++++++++++++
python/t/090-retvalues.py | 138 ++++++++++++
python/t/900-python-dict.py | 40 ----
ruby/t/tc_090_retvalues.rb | 141 ++++++++++++
11 files changed, 838 insertions(+), 153 deletions(-)
delete mode 100644 gobject/bindtests-manual.js
create mode 100644 gobject/bindtests-retvalues.js
create mode 100755 gobject/run-tests-retvalues
create mode 100644 perl/t/090-retvalues.t
create mode 100644 php/extension/tests/guestfs_090_retvalues.phpt
create mode 100644 python/t/090-retvalues.py
delete mode 100644 python/t/900-python-dict.py
create mode 100644 ruby/t/tc_090_retvalues.rb
diff --git a/docs/guestfs-hacking.pod b/docs/guestfs-hacking.pod
index ecd10bf..c357717 100644
--- a/docs/guestfs-hacking.pod
+++ b/docs/guestfs-hacking.pod
@@ -202,6 +202,7 @@ This is the numbering scheme used by the tests:
065 implicit close (in GC'd languages)
070 optargs
080 version
+ 090 retvalues
- 100 launch, create partitions and LVs and filesystems
diff --git a/gobject/Makefile.am b/gobject/Makefile.am
index b7e7f10..1f523b7 100644
--- a/gobject/Makefile.am
+++ b/gobject/Makefile.am
@@ -90,7 +90,9 @@ gir_DATA = $(INTROSPECTION_GIRS)
typelibdir = $(libdir)/girepository-1.0
typelib_DATA = $(INTROSPECTION_GIRS:.gir=.typelib)
-TESTS = run-tests
+TESTS = \
+ run-tests \
+ run-tests-retvalues
if ENABLE_APPLIANCE
TESTS += run-live-tests
diff --git a/gobject/bindtests-manual.js b/gobject/bindtests-manual.js
deleted file mode 100644
index d7bbe5f..0000000
--- a/gobject/bindtests-manual.js
+++ /dev/null
@@ -1,110 +0,0 @@
-// libguestfs manually written gobject binding tests
-// Copyright (C) 2012 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.
-
-const Guestfs = imports.gi.Guestfs;
-
-var fail = false;
-
-function check_error(f) {
- var threw = false;
-
- try {
- g[f]();
- } catch (error) {
- threw = true;
- if (!error.message.match(/error$/)) {
- print(f + " threw unexpected error: " + error.message);
- fail = true;
- }
- }
- if (!threw) {
- print(f + " failed to throw an error");
- fail = true;
- }
-}
-
-function eq_fail(f, v) {
- print(f + " returned unexpected value: " + v);
- fail = true;
-}
-
-var g = new Guestfs.Session();
-
-var v;
-var eq;
-
-v = g.internal_test_rint('1');
-v == 1 || eq_fail('internal_test_rint', v);
-check_error('internal_test_rinterr');
-
-v = g.internal_test_rint64('1');
-v == 1 || eq_fail('internal_test_rint64', v);
-check_error('internal_test_rint64err');
-
-v = g.internal_test_rbool('true');
-v == 1 || eq_fail('internal_test_rbool', v);
-check_error('internal_test_rboolerr');
-
-v = g.internal_test_rconststring('1');
-v == 'static string' || eq_fail('internal_test_rconststring', v);
-check_error('internal_test_rconststringerr');
-
-v = g.internal_test_rconstoptstring('1');
-v == 'static string' || eq_fail('internal_test_rconstoptstring', v);
-//check_error('internal_test_rconstoptstringerr');
-
-v = g.internal_test_rstring('string');
-v == 'string' || eq_fail('internal_test_rstring', v);
-check_error('internal_test_rstringerr');
-
-v = g.internal_test_rstringlist('5');
-eq = v.length == 5;
-for (var i = 0; eq && i < 5; i++) {
- if (v[i] != i) eq = false;
-}
-eq || eq_fail('internal_test_rstringlist', v.join(' '));
-check_error('internal_test_rstringlisterr');
-
-v = g.internal_test_rstruct('1');
-v.pv_size == 0 || eq_fail('internal_test_rstruct', v);
-check_error('internal_test_rstructerr');
-
-v = g.internal_test_rstructlist('5');
-eq = v.length == 5;
-for (var i = 0; eq && i < 5; i++) {
- if (v[i].pv_size != i) eq = false;
-}
-eq || eq_fail('internal_test_rstructlist', v);
-check_error('internal_test_rstructlisterr');
-
-v = g.internal_test_rhashtable('5');
-eq = true;
-for (var i = 0; eq && i < 5; i++) {
- if (v[i] != i) eq = false;
-}
-eq || eq_fail('internal_test_rhashtable', v);
-check_error('internal_test_rhashtableerr');
-
-v = g.internal_test_rbufferout("01234");
-eq = v.length == 5;
-for (var i = 0; i < v.length; i++) {
- if (v[i] != 48 + i) eq = false; // 48 = ascii '0'
-}
-eq || eq_fail('internal_test_rbufferout', v);
-check_error('internal_test_rbufferouterr');
-
-fail ? 1 : 0;
diff --git a/gobject/bindtests-retvalues.js b/gobject/bindtests-retvalues.js
new file mode 100644
index 0000000..d7bbe5f
--- /dev/null
+++ b/gobject/bindtests-retvalues.js
@@ -0,0 +1,110 @@
+// libguestfs manually written gobject binding tests
+// Copyright (C) 2012 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.
+
+const Guestfs = imports.gi.Guestfs;
+
+var fail = false;
+
+function check_error(f) {
+ var threw = false;
+
+ try {
+ g[f]();
+ } catch (error) {
+ threw = true;
+ if (!error.message.match(/error$/)) {
+ print(f + " threw unexpected error: " + error.message);
+ fail = true;
+ }
+ }
+ if (!threw) {
+ print(f + " failed to throw an error");
+ fail = true;
+ }
+}
+
+function eq_fail(f, v) {
+ print(f + " returned unexpected value: " + v);
+ fail = true;
+}
+
+var g = new Guestfs.Session();
+
+var v;
+var eq;
+
+v = g.internal_test_rint('1');
+v == 1 || eq_fail('internal_test_rint', v);
+check_error('internal_test_rinterr');
+
+v = g.internal_test_rint64('1');
+v == 1 || eq_fail('internal_test_rint64', v);
+check_error('internal_test_rint64err');
+
+v = g.internal_test_rbool('true');
+v == 1 || eq_fail('internal_test_rbool', v);
+check_error('internal_test_rboolerr');
+
+v = g.internal_test_rconststring('1');
+v == 'static string' || eq_fail('internal_test_rconststring', v);
+check_error('internal_test_rconststringerr');
+
+v = g.internal_test_rconstoptstring('1');
+v == 'static string' || eq_fail('internal_test_rconstoptstring', v);
+//check_error('internal_test_rconstoptstringerr');
+
+v = g.internal_test_rstring('string');
+v == 'string' || eq_fail('internal_test_rstring', v);
+check_error('internal_test_rstringerr');
+
+v = g.internal_test_rstringlist('5');
+eq = v.length == 5;
+for (var i = 0; eq && i < 5; i++) {
+ if (v[i] != i) eq = false;
+}
+eq || eq_fail('internal_test_rstringlist', v.join(' '));
+check_error('internal_test_rstringlisterr');
+
+v = g.internal_test_rstruct('1');
+v.pv_size == 0 || eq_fail('internal_test_rstruct', v);
+check_error('internal_test_rstructerr');
+
+v = g.internal_test_rstructlist('5');
+eq = v.length == 5;
+for (var i = 0; eq && i < 5; i++) {
+ if (v[i].pv_size != i) eq = false;
+}
+eq || eq_fail('internal_test_rstructlist', v);
+check_error('internal_test_rstructlisterr');
+
+v = g.internal_test_rhashtable('5');
+eq = true;
+for (var i = 0; eq && i < 5; i++) {
+ if (v[i] != i) eq = false;
+}
+eq || eq_fail('internal_test_rhashtable', v);
+check_error('internal_test_rhashtableerr');
+
+v = g.internal_test_rbufferout("01234");
+eq = v.length == 5;
+for (var i = 0; i < v.length; i++) {
+ if (v[i] != 48 + i) eq = false; // 48 = ascii '0'
+}
+eq || eq_fail('internal_test_rbufferout', v);
+check_error('internal_test_rbufferouterr');
+
+fail ? 1 : 0;
diff --git a/gobject/run-tests b/gobject/run-tests
index aa1aaa6..7393e73 100755
--- a/gobject/run-tests
+++ b/gobject/run-tests
@@ -31,6 +31,4 @@ rm -f bindtests.tmp
$GJS $srcdir/bindtests.js > bindtests.tmp
diff -u ${srcdir}/../bindtests bindtests.tmp
-$GJS $srcdir/bindtests-manual.js 2>/dev/null
-
rm bindtests.tmp
diff --git a/gobject/run-tests-retvalues b/gobject/run-tests-retvalues
new file mode 100755
index 0000000..b4f4d4b
--- /dev/null
+++ b/gobject/run-tests-retvalues
@@ -0,0 +1,26 @@
+#!/bin/sh -
+# libguestfs GObject bindings
+# Copyright (C) 2012-2016 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.
+
+set -e
+
+if [ -z "$GJS" ]; then
+ echo "GObject bind tests skipped: gjs is missing"
+ exit 77
+fi
+
+$GJS $srcdir/bindtests-retvalues.js 2>/dev/null
diff --git a/perl/t/090-retvalues.t b/perl/t/090-retvalues.t
new file mode 100644
index 0000000..c339316
--- /dev/null
+++ b/perl/t/090-retvalues.t
@@ -0,0 +1,125 @@
+# libguestfs Perl bindings -*- perl -*-
+# Copyright (C) 2016 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.
+
+use strict;
+use warnings;
+use Test::More tests => 42;
+
+use Sys::Guestfs;
+
+my $g = Sys::Guestfs->new ();
+ok ($g);
+
+# rint
+is ($g->internal_test_rint ("10"), 10, "rint");
+eval {
+ my $foo = $g->internal_test_rinterr ();
+};
+like ($@, qr/error/, "rinterr");
+
+# rint64
+is ($g->internal_test_rint64 ("10"), 10, "rint64");
+eval {
+ my $foo = $g->internal_test_rint64err ();
+};
+like ($@, qr/error/, "rint64err");
+
+# rbool
+is ($g->internal_test_rbool ("true"), 1, "rbool/true");
+is ($g->internal_test_rbool ("false"), 0, "rbool/false");
+eval {
+ my $foo = $g->internal_test_rboolerr ();
+};
+like ($@, qr/error/, "rboolerr");
+
+# rconststring
+is ($g->internal_test_rconststring ("test"), "static string", "rconststring");
+eval {
+ my $foo = $g->internal_test_rconststringerr ();
+};
+like ($@, qr/error/, "rconststringerr");
+
+# rconstoptstring
+is ($g->internal_test_rconstoptstring ("test"), "static string", "rconstoptstring");
+# this never fails
+eval {
+ my $foo = $g->internal_test_rconstoptstringerr ();
+};
+unlike ($@, qr/error/, "rconstoptstringerr");
+
+# rstring
+is ($g->internal_test_rstring ("test"), "test", "rstring");
+eval {
+ my $foo = $g->internal_test_rstringerr ();
+};
+like ($@, qr/error/, "rstringerr");
+
+# rstringlist
+my @l = $g->internal_test_rstringlist ("0");
+is (@l, 0, "rstringlist/empty");
+@l = $g->internal_test_rstringlist ("5");
+is (@l, 5, "rstringlist/5/size");
+for (my $i = 0; $i < @l; $i++) {
+ is ($l[$i], $i, "rstringlist/5/$i");
+}
+eval {
+ my $foo = $g->internal_test_rstringlisterr ();
+};
+like ($@, qr/error/, "rstringlisterr");
+
+# rstruct
+my %s = $g->internal_test_rstruct ("unused");
+is ($s{'pv_name'}, "pv0", "rstruct/0");
+eval {
+ my $foo = $g->internal_test_rstructerr ();
+};
+like ($@, qr/error/, "rstructerr");
+
+# rstructlist
+my @sl = $g->internal_test_rstructlist ("0");
+is (@sl, 0, "rstructlist/empty");
+@sl = $g->internal_test_rstructlist ("5");
+is (@sl, 5, "rstructlist/5/size");
+for (my $i = 0; $i < @sl; $i++) {
+ is ($sl[$i]{'pv_name'}, "pv$i", "rstructlist/5/$i");
+}
+eval {
+ my $foo = $g->internal_test_rstructlisterr ();
+};
+like ($@, qr/error/, "rstructlisterr");
+
+# rhashtable
+my %sl = $g->internal_test_rhashtable ("0");
+my $sls = keys %sl;
+is ($sls, 0, "rhashtable/empty");
+%sl = $g->internal_test_rhashtable ("5");
+$sls = keys %sl;
+is ($sls, 5, "rhashtable/5/size");
+for (my $i = 0; $i < $sls; $i++) {
+ is ($sl{$i}, $i, "rhashtable/5/$i");
+}
+eval {
+ my $foo = $g->internal_test_rhashtableerr ();
+};
+like ($@, qr/error/, "rhashtableerr");
+
+# rbufferout
+is ($g->internal_test_rbufferout ("test"), "test", "rbufferout");
+eval {
+ my $foo = $g->internal_test_rbufferouterr ();
+};
+like ($@, qr/error/, "rbufferouterr");
diff --git a/php/extension/tests/guestfs_090_retvalues.phpt b/php/extension/tests/guestfs_090_retvalues.phpt
new file mode 100644
index 0000000..0be5755
--- /dev/null
+++ b/php/extension/tests/guestfs_090_retvalues.phpt
@@ -0,0 +1,294 @@
+--TEST--
+Check all the kind of return values.
+--FILE--
+<?php
+$g = guestfs_create ();
+
+# rint
+var_dump (guestfs_internal_test_rint ($g, "10"));
+var_dump (guestfs_internal_test_rinterr ($g));
+
+# rint64
+var_dump (guestfs_internal_test_rint64 ($g, "10"));
+var_dump (guestfs_internal_test_rint64err ($g));
+
+# rbool
+var_dump (guestfs_internal_test_rbool ($g, "true"));
+var_dump (guestfs_internal_test_rbool ($g, "false"));
+var_dump (guestfs_internal_test_rboolerr ($g));
+
+# rconststring
+var_dump (guestfs_internal_test_rconststring ($g, "test"));
+var_dump (guestfs_internal_test_rconststringerr ($g));
+
+# rconstoptstring
+var_dump (guestfs_internal_test_rconstoptstring ($g, "test"));
+var_dump (guestfs_internal_test_rconstoptstringerr ($g));
+
+# rstring
+var_dump (guestfs_internal_test_rstring ($g, "test"));
+var_dump (guestfs_internal_test_rstringerr ($g));
+
+# rstringlist
+var_dump (guestfs_internal_test_rstringlist ($g, "0"));
+var_dump (guestfs_internal_test_rstringlist ($g, "5"));
+var_dump (guestfs_internal_test_rstringlisterr ($g));
+
+# rstruct
+var_dump (guestfs_internal_test_rstruct ($g, "unused"));
+var_dump (guestfs_internal_test_rstructerr ($g));
+
+# rstructlist
+var_dump (guestfs_internal_test_rstructlist ($g, "0"));
+var_dump (guestfs_internal_test_rstructlist ($g, "5"));
+var_dump (guestfs_internal_test_rstructlisterr ($g));
+
+# rhashtable
+var_dump (guestfs_internal_test_rhashtable ($g, "0"));
+var_dump (guestfs_internal_test_rhashtable ($g, "5"));
+var_dump (guestfs_internal_test_rhashtableerr ($g));
+
+# rbufferout
+var_dump (guestfs_internal_test_rbufferout ($g, "test"));
+var_dump (guestfs_internal_test_rbufferouterr ($g));
+
+echo ("OK\n");
+?>
+--EXPECT--
+int(10)
+bool(false)
+int(10)
+bool(false)
+bool(true)
+bool(false)
+bool(false)
+string(13) "static string"
+bool(false)
+string(13) "static string"
+NULL
+string(4) "test"
+bool(false)
+array(0) {
+}
+array(5) {
+ [0]=>
+ string(1) "0"
+ [1]=>
+ string(1) "1"
+ [2]=>
+ string(1) "2"
+ [3]=>
+ string(1) "3"
+ [4]=>
+ string(1) "4"
+}
+bool(false)
+array(14) {
+ ["pv_name"]=>
+ string(3) "pv0"
+ ["pv_uuid"]=>
+ string(32) "12345678901234567890123456789012"
+ ["pv_fmt"]=>
+ string(7) "unknown"
+ ["pv_size"]=>
+ int(0)
+ ["dev_size"]=>
+ int(0)
+ ["pv_free"]=>
+ int(0)
+ ["pv_used"]=>
+ int(0)
+ ["pv_attr"]=>
+ string(5) "attr0"
+ ["pv_pe_count"]=>
+ int(0)
+ ["pv_pe_alloc_count"]=>
+ int(0)
+ ["pv_tags"]=>
+ string(4) "tag0"
+ ["pe_start"]=>
+ int(0)
+ ["pv_mda_count"]=>
+ int(0)
+ ["pv_mda_free"]=>
+ int(0)
+}
+bool(false)
+array(0) {
+}
+array(5) {
+ [0]=>
+ array(14) {
+ ["pv_name"]=>
+ string(3) "pv0"
+ ["pv_uuid"]=>
+ string(32) "12345678901234567890123456789012"
+ ["pv_fmt"]=>
+ string(7) "unknown"
+ ["pv_size"]=>
+ int(0)
+ ["dev_size"]=>
+ int(0)
+ ["pv_free"]=>
+ int(0)
+ ["pv_used"]=>
+ int(0)
+ ["pv_attr"]=>
+ string(5) "attr0"
+ ["pv_pe_count"]=>
+ int(0)
+ ["pv_pe_alloc_count"]=>
+ int(0)
+ ["pv_tags"]=>
+ string(4) "tag0"
+ ["pe_start"]=>
+ int(0)
+ ["pv_mda_count"]=>
+ int(0)
+ ["pv_mda_free"]=>
+ int(0)
+ }
+ [1]=>
+ array(14) {
+ ["pv_name"]=>
+ string(3) "pv1"
+ ["pv_uuid"]=>
+ string(32) "12345678901234567890123456789012"
+ ["pv_fmt"]=>
+ string(7) "unknown"
+ ["pv_size"]=>
+ int(1)
+ ["dev_size"]=>
+ int(1)
+ ["pv_free"]=>
+ int(1)
+ ["pv_used"]=>
+ int(1)
+ ["pv_attr"]=>
+ string(5) "attr1"
+ ["pv_pe_count"]=>
+ int(1)
+ ["pv_pe_alloc_count"]=>
+ int(1)
+ ["pv_tags"]=>
+ string(4) "tag1"
+ ["pe_start"]=>
+ int(1)
+ ["pv_mda_count"]=>
+ int(1)
+ ["pv_mda_free"]=>
+ int(1)
+ }
+ [2]=>
+ array(14) {
+ ["pv_name"]=>
+ string(3) "pv2"
+ ["pv_uuid"]=>
+ string(32) "12345678901234567890123456789012"
+ ["pv_fmt"]=>
+ string(7) "unknown"
+ ["pv_size"]=>
+ int(2)
+ ["dev_size"]=>
+ int(2)
+ ["pv_free"]=>
+ int(2)
+ ["pv_used"]=>
+ int(2)
+ ["pv_attr"]=>
+ string(5) "attr2"
+ ["pv_pe_count"]=>
+ int(2)
+ ["pv_pe_alloc_count"]=>
+ int(2)
+ ["pv_tags"]=>
+ string(4) "tag2"
+ ["pe_start"]=>
+ int(2)
+ ["pv_mda_count"]=>
+ int(2)
+ ["pv_mda_free"]=>
+ int(2)
+ }
+ [3]=>
+ array(14) {
+ ["pv_name"]=>
+ string(3) "pv3"
+ ["pv_uuid"]=>
+ string(32) "12345678901234567890123456789012"
+ ["pv_fmt"]=>
+ string(7) "unknown"
+ ["pv_size"]=>
+ int(3)
+ ["dev_size"]=>
+ int(3)
+ ["pv_free"]=>
+ int(3)
+ ["pv_used"]=>
+ int(3)
+ ["pv_attr"]=>
+ string(5) "attr3"
+ ["pv_pe_count"]=>
+ int(3)
+ ["pv_pe_alloc_count"]=>
+ int(3)
+ ["pv_tags"]=>
+ string(4) "tag3"
+ ["pe_start"]=>
+ int(3)
+ ["pv_mda_count"]=>
+ int(3)
+ ["pv_mda_free"]=>
+ int(3)
+ }
+ [4]=>
+ array(14) {
+ ["pv_name"]=>
+ string(3) "pv4"
+ ["pv_uuid"]=>
+ string(32) "12345678901234567890123456789012"
+ ["pv_fmt"]=>
+ string(7) "unknown"
+ ["pv_size"]=>
+ int(4)
+ ["dev_size"]=>
+ int(4)
+ ["pv_free"]=>
+ int(4)
+ ["pv_used"]=>
+ int(4)
+ ["pv_attr"]=>
+ string(5) "attr4"
+ ["pv_pe_count"]=>
+ int(4)
+ ["pv_pe_alloc_count"]=>
+ int(4)
+ ["pv_tags"]=>
+ string(4) "tag4"
+ ["pe_start"]=>
+ int(4)
+ ["pv_mda_count"]=>
+ int(4)
+ ["pv_mda_free"]=>
+ int(4)
+ }
+}
+bool(false)
+array(0) {
+}
+array(5) {
+ [0]=>
+ string(1) "0"
+ [1]=>
+ string(1) "1"
+ [2]=>
+ string(1) "2"
+ [3]=>
+ string(1) "3"
+ [4]=>
+ string(1) "4"
+}
+bool(false)
+string(4) "test"
+bool(false)
+OK
diff --git a/python/t/090-retvalues.py b/python/t/090-retvalues.py
new file mode 100644
index 0000000..8a5c912
--- /dev/null
+++ b/python/t/090-retvalues.py
@@ -0,0 +1,138 @@
+# libguestfs Python bindings
+# Copyright (C) 2013-2016 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.
+
+# Test all the different return values.
+
+import unittest
+import guestfs
+
+
+class Test090PythonRetValues (unittest.TestCase):
+ def test_rint (self):
+ g = guestfs.GuestFS ()
+
+ self.assertAlmostEqual (g.internal_test_rint ("10"), 10, places=1)
+
+ self.assertRaises (RuntimeError, g.internal_test_rinterr)
+
+
+ def test_rint64 (self):
+ g = guestfs.GuestFS ()
+
+ self.assertAlmostEqual (g.internal_test_rint64 ("10"), 10L, places=1)
+
+ self.assertRaises (RuntimeError, g.internal_test_rint64err)
+
+
+ def test_rbool (self):
+ g = guestfs.GuestFS ()
+
+ self.assertTrue (g.internal_test_rbool ("true"))
+ self.assertFalse (g.internal_test_rbool ("false"))
+
+ self.assertRaises (RuntimeError, g.internal_test_rboolerr)
+
+
+ def test_rconststring (self):
+ g = guestfs.GuestFS ()
+
+ self.assertEqual (g.internal_test_rconststring ("test"), "static string")
+
+ self.assertRaises (RuntimeError, g.internal_test_rconststringerr)
+
+
+ def test_rconstoptstring (self):
+ g = guestfs.GuestFS ()
+
+ self.assertEqual (g.internal_test_rconstoptstring ("test"), "static string")
+
+ # this never fails
+ self.assertIsNone (g.internal_test_rconstoptstringerr ())
+
+
+ def test_rstring (self):
+ g = guestfs.GuestFS ()
+
+ self.assertEqual (g.internal_test_rstring ("test"), "test")
+
+ self.assertRaises (RuntimeError, g.internal_test_rstringerr)
+
+
+ def test_rstringlist (self):
+ g = guestfs.GuestFS ()
+
+ self.assertEqual (g.internal_test_rstringlist ("0"), [])
+ self.assertEqual (g.internal_test_rstringlist ("5"), ["0", "1", "2", "3", "4"])
+
+ self.assertRaises (RuntimeError, g.internal_test_rstringlisterr)
+
+
+ def test_rstruct (self):
+ g = guestfs.GuestFS ()
+
+ s = g.internal_test_rstruct ("unused")
+ self.assertIsInstance (s, dict)
+ self.assertEqual (s["pv_name"], "pv0")
+
+ self.assertRaises (RuntimeError, g.internal_test_rstructerr)
+
+
+ def test_rstructlist (self):
+ g = guestfs.GuestFS ()
+
+ self.assertEqual (g.internal_test_rstructlist ("0"), [])
+ l = g.internal_test_rstructlist ("5")
+ self.assertIsInstance (l, list)
+ self.assertEqual (len (l), 5)
+ for i in range (0, 5):
+ self.assertIsInstance (l[i], dict)
+ self.assertEqual (l[i]["pv_name"], "pv%d" % i)
+
+ self.assertRaises (RuntimeError, g.internal_test_rstructlisterr)
+
+
+ def test_rhashtable_list (self):
+ g = guestfs.GuestFS (python_return_dict=False)
+
+ self.assertEqual (g.internal_test_rhashtable ("0"), [])
+ r = g.internal_test_rhashtable ("5")
+ self.assertEqual (r, [ ("0","0"), ("1","1"), ("2","2"),
+ ("3","3"), ("4","4") ])
+
+ self.assertRaises (RuntimeError, g.internal_test_rhashtableerr)
+
+
+ def test_rhashtable_dict (self):
+ g = guestfs.GuestFS (python_return_dict=True)
+
+ self.assertEqual (g.internal_test_rhashtable ("0"), {})
+ r = g.internal_test_rhashtable ("5")
+ self.assertEqual (r, {"0": "0", "1": "1", "2": "2", "3": "3", "4": "4"})
+
+ self.assertRaises (RuntimeError, g.internal_test_rhashtableerr)
+
+
+ def test_rbufferout (self):
+ g = guestfs.GuestFS ()
+
+ self.assertEqual (g.internal_test_rbufferout ("test"), b'test')
+
+ self.assertRaises (RuntimeError, g.internal_test_rbufferouterr)
+
+
+if __name__ == '__main__':
+ unittest.main ()
diff --git a/python/t/900-python-dict.py b/python/t/900-python-dict.py
deleted file mode 100644
index 5ea5a53..0000000
--- a/python/t/900-python-dict.py
+++ /dev/null
@@ -1,40 +0,0 @@
-# libguestfs Python bindings
-# Copyright (C) 2013 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.
-
-# Test python-specific python_return_dict parameter.
-
-from types import *
-import unittest
-import os
-import guestfs
-
-class Test900PythonDict (unittest.TestCase):
- def test_python_no_dict (self):
- g = guestfs.GuestFS (python_return_dict=False)
-
- r = g.internal_test_rhashtable ("5")
- self.assertEqual (r, [ ("0","0"), ("1","1"), ("2","2"),
- ("3","3"), ("4","4") ])
-
- def test_python_dict (self):
- g = guestfs.GuestFS (python_return_dict=True)
-
- r = g.internal_test_rhashtable ("5")
- self.assertEqual (r, {"0": "0", "1": "1", "2": "2", "3": "3", "4": "4"})
-
-if __name__ == '__main__':
- unittest.main ()
diff --git a/ruby/t/tc_090_retvalues.rb b/ruby/t/tc_090_retvalues.rb
new file mode 100644
index 0000000..1fcc12d
--- /dev/null
+++ b/ruby/t/tc_090_retvalues.rb
@@ -0,0 +1,141 @@
+# libguestfs Ruby bindings -*- ruby -*-
+# Copyright (C) 2016 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.
+
+require File::join(File::dirname(__FILE__), 'test_helper')
+
+class TestLoad < MiniTest::Unit::TestCase
+ def test_rint
+ g = Guestfs::Guestfs.new()
+
+ assert_equal 10, g.internal_test_rint("10")
+
+ assert_raises(Guestfs::Error) {
+ g.internal_test_rinterr()
+ }
+ end
+
+ def test_rint64
+ g = Guestfs::Guestfs.new()
+
+ assert_equal 10, g.internal_test_rint64("10")
+
+ assert_raises(Guestfs::Error) {
+ g.internal_test_rint64err()
+ }
+ end
+
+ def test_rbool
+ g = Guestfs::Guestfs.new()
+
+ assert_equal 1, g.internal_test_rbool("true")
+ assert_equal 0, g.internal_test_rbool("false")
+
+ assert_raises(Guestfs::Error) {
+ g.internal_test_rboolerr()
+ }
+ end
+
+ def test_rconststring
+ g = Guestfs::Guestfs.new()
+
+ assert_equal "static string", g.internal_test_rconststring("test")
+
+ assert_raises(Guestfs::Error) {
+ g.internal_test_rconststringerr()
+ }
+ end
+
+ def test_rconstoptstring
+ g = Guestfs::Guestfs.new()
+
+ assert_equal "static string", g.internal_test_rconstoptstring("test")
+
+ # this never fails
+ assert_nil g.internal_test_rconstoptstringerr()
+ end
+
+ def test_rstring
+ g = Guestfs::Guestfs.new()
+
+ assert_equal "test", g.internal_test_rstring("test")
+
+ assert_raises(Guestfs::Error) {
+ g.internal_test_rstringerr()
+ }
+ end
+
+ def test_rstringlist
+ g = Guestfs::Guestfs.new()
+
+ assert_equal [], g.internal_test_rstringlist("0")
+ assert_equal ["0", "1", "2", "3", "4"], g.internal_test_rstringlist("5")
+
+ assert_raises(Guestfs::Error) {
+ g.internal_test_rstringlisterr()
+ }
+ end
+
+ def test_rstruct
+ g = Guestfs::Guestfs.new()
+
+ s = g.internal_test_rstruct("unused")
+ assert_instance_of Hash, s
+ assert_equal "pv0", s["pv_name"]
+
+ assert_raises(Guestfs::Error) {
+ g.internal_test_rstructerr()
+ }
+ end
+
+ def test_rstructlist
+ g = Guestfs::Guestfs.new()
+
+ assert_equal [], g.internal_test_rstructlist("0")
+ l = g.internal_test_rstructlist("5")
+ assert_instance_of Array, l
+ assert_equal 5, l.length
+ for i in 0..4
+ assert_instance_of Hash, l[i]
+ assert_equal "pv#{i}", l[i]["pv_name"]
+ end
+
+ assert_raises(Guestfs::Error) {
+ g.internal_test_rstructlisterr()
+ }
+ end
+
+ def test_rhashtable
+ g = Guestfs::Guestfs.new()
+
+ assert_equal Hash[], g.internal_test_rhashtable("0")
+ assert_equal Hash["0"=>"0","1"=>"1","2"=>"2","3"=>"3","4"=>"4"], g.internal_test_rhashtable("5")
+
+ assert_raises(Guestfs::Error) {
+ g.internal_test_rhashtableerr()
+ }
+ end
+
+ def test_rbufferout
+ g = Guestfs::Guestfs.new()
+
+ assert_equal "test", g.internal_test_rbufferout("test")
+
+ assert_raises(Guestfs::Error) {
+ g.internal_test_rbufferouterr()
+ }
+ end
+end
--
2.5.0
8 years, 9 months
hivex lib: Add function hivex_node_num_children
by Kevin Haroldsen
Hello,
I've been working on a graphical registry hive editing tool in Qt
using the hivex C library.
While creating it, I noticed that in order to determine if an
expansion element should be shown on a node, you have to determine if
a node has any children.
Currently, in order to determine if a node has any children, you must
find every child with hivex_node_children, which is a relatively
expensive operation.
So, I have created a function called hivex_node_num_children that
isolates the first few lines of hivex_node_children to simply return
the number of child nodes a node has by accessing
ntreg_nk_record->nr_subkeys.
I'm a bit of a newer developer, so I'm not incredibly familiar with
the patching process through mailing lists, nor do I have any history
with libguestfs.
Please let me know if I am doing anything wrong or what can be improved.
This is the git branch:
https://github.com/kupiakos/hivex/tree/node_children_count
This is a patch of the difference:
diff --git a/generator/generator.ml b/generator/generator.ml
index be783ae..4f878ff 100755
--- a/generator/generator.ml
+++ b/generator/generator.ml
@@ -210,6 +210,11 @@ Return the child of node with the name C<name>,
if it exists.
The name is matched case insensitively.";
+ "node_num_children", (RSize, [AHive; ANode "node"]),
+ "return the number of children of a node",
+ "\
+Return the number of nodes as produced by C<hivex_node_children>.";
+
"node_parent", (RNode, [AHive; ANode "node"]),
"return the parent of node",
"\
diff --git a/lib/node.c b/lib/node.c
index 1fb48cf..fc3ca71 100644
--- a/lib/node.c
+++ b/lib/node.c
@@ -513,6 +513,22 @@ hivex_node_children (hive_h *h, hive_node_h node)
return children;
}
+size_t
+hivex_node_num_children (hive_h *h, hive_node_h node)
+{
+ if (!IS_VALID_BLOCK (h, node) || !block_id_eq(h, node, "nk")) {
+ SET_ERRNO( EINVAL, "invalid block or not an 'nk' block");
+ return 0;
+ }
+
+ struct ntreg_nk_record *nk =
+ (struct ntreg_nk_record *) ((char *) h->addr + node);
+
+ size_t nr_subkeys_in_nk = le32toh(nk->nr_subkeys);
+
+ return nr_subkeys_in_nk;
+}
+
/* Very inefficient, but at least having a separate API call
* allows us to make it more efficient in future.
*/
--
- Kevin Haroldsen (kupiakos)
8 years, 9 months
[PATCH] python: tests: use more targeted assert*() functions/checks
by Pino Toscano
- use assertIsInstance, assertNotEqual, and assertIsNotNone as more
specific checks (will produce better logging)
- use assertRaises when expecting exceptions being thrown
- when testing internal_test_rhashtable, instead of checking type and
elements of the return values just check the return value as a whole
(easier and already getting all the work needed by unittest)
---
python/t/080-version.py | 6 +++---
python/t/420-log-messages.py | 2 +-
python/t/800-explicit-close.py | 6 +-----
python/t/810-rhbz811650.py | 5 +----
python/t/820-rhbz912499.py | 2 +-
python/t/900-python-dict.py | 9 +--------
6 files changed, 8 insertions(+), 22 deletions(-)
diff --git a/python/t/080-version.py b/python/t/080-version.py
index e8e1e25..cda4872 100644
--- a/python/t/080-version.py
+++ b/python/t/080-version.py
@@ -34,13 +34,13 @@ class Test080Version (unittest.TestCase):
self.assertEqual (self.version['major'], 1)
def test_minor (self):
- self.assertTrue (isinstance (self.version['minor'], cl))
+ self.assertIsInstance (self.version['minor'], cl)
def test_release (self):
- self.assertTrue (isinstance (self.version['release'], cl))
+ self.assertIsInstance (self.version['release'], cl)
def test_extra (self):
- self.assertTrue (isinstance (self.version['extra'], str))
+ self.assertIsInstance (self.version['extra'], str)
if __name__ == '__main__':
unittest.main ()
diff --git a/python/t/420-log-messages.py b/python/t/420-log-messages.py
index 002098e..6b7c06c 100644
--- a/python/t/420-log-messages.py
+++ b/python/t/420-log-messages.py
@@ -51,7 +51,7 @@ class Test420LogMessages (unittest.TestCase):
g.close ()
- self.assertFalse (log_invoked == 0)
+ self.assertNotEqual (log_invoked, 0)
if __name__ == '__main__':
unittest.main ()
diff --git a/python/t/800-explicit-close.py b/python/t/800-explicit-close.py
index 9b425af..4086829 100644
--- a/python/t/800-explicit-close.py
+++ b/python/t/800-explicit-close.py
@@ -37,11 +37,7 @@ class Test800ExplicitClose (unittest.TestCase):
# Expect an exception if we call a method on a closed handle.
g = guestfs.GuestFS (python_return_dict=True)
g.close ()
- try:
- g.set_memsize (512)
- raise Exception("expected an exception from previous statement")
- except guestfs.ClosedHandle:
- pass
+ self.assertRaises (guestfs.ClosedHandle, g.set_memsize, 512)
del g
# Verify that the handle is really being closed by g.close, by
diff --git a/python/t/810-rhbz811650.py b/python/t/810-rhbz811650.py
index c812c30..c37abac 100644
--- a/python/t/810-rhbz811650.py
+++ b/python/t/810-rhbz811650.py
@@ -31,10 +31,7 @@ class Test810RHBZ811650 (unittest.TestCase):
# Because error() wasn't being called, guestfs_last_error
# would return NULL, causing a segfault in the Python bindings
# (RHBZ#811650).
- try:
- g.launch ()
- except:
- pass
+ self.assertRaises (RuntimeError, g.launch)
def tearDown (self):
os.unlink ("rhbz811650.img")
diff --git a/python/t/820-rhbz912499.py b/python/t/820-rhbz912499.py
index 3cf9bba..e8f1d4b 100644
--- a/python/t/820-rhbz912499.py
+++ b/python/t/820-rhbz912499.py
@@ -89,7 +89,7 @@ class Test820RHBZ912499 (unittest.TestCase):
def test_rhbz912499 (self):
dom = conn.createXML (self.xml,
libvirt.VIR_DOMAIN_START_AUTODESTROY)
- self.assertFalse (dom == None)
+ self.assertIsNotNone (dom)
print ("temporary domain %s is running" % self.domname)
diff --git a/python/t/900-python-dict.py b/python/t/900-python-dict.py
index 7d78e86..5ea5a53 100644
--- a/python/t/900-python-dict.py
+++ b/python/t/900-python-dict.py
@@ -27,7 +27,6 @@ class Test900PythonDict (unittest.TestCase):
g = guestfs.GuestFS (python_return_dict=False)
r = g.internal_test_rhashtable ("5")
- self.assertTrue (isinstance (r, list))
self.assertEqual (r, [ ("0","0"), ("1","1"), ("2","2"),
("3","3"), ("4","4") ])
@@ -35,13 +34,7 @@ class Test900PythonDict (unittest.TestCase):
g = guestfs.GuestFS (python_return_dict=True)
r = g.internal_test_rhashtable ("5")
- self.assertTrue (isinstance (r, dict))
- self.assertEqual (sorted (r.keys()), ["0","1","2","3","4"])
- self.assertEqual (r["0"], "0")
- self.assertEqual (r["1"], "1")
- self.assertEqual (r["2"], "2")
- self.assertEqual (r["3"], "3")
- self.assertEqual (r["4"], "4")
+ self.assertEqual (r, {"0": "0", "1": "1", "2": "2", "3": "3", "4": "4"})
if __name__ == '__main__':
unittest.main ()
--
2.5.0
8 years, 9 months
[PATCH] daemon: lvm: Ignore LVs with the activationskip flag set (RHBZ#1306666).
by Richard W.M. Jones
When listing logical volumes, ignore the ones which don't get
activated automatically. No /dev/VG/LV device node is created for
these ones which confuses APIs that attempt to do 'guestfs_lvs'
followed by opening the device node. Note that 'guestfs_lvs_full' is
unaffected by this change.
---
daemon/lvm.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/daemon/lvm.c b/daemon/lvm.c
index 8bef4d5..529e20d 100644
--- a/daemon/lvm.c
+++ b/daemon/lvm.c
@@ -157,6 +157,10 @@ filter_convert_old_lvs_output (char *out)
if (lv_attr[0] == 't')
goto skip_line;
+ /* Ignore activationskip (RHBZ#1306666). */
+ if (strlen (lv_attr) >= 10 && lv_attr[9] == 'k')
+ goto skip_line;
+
/* Ignore "unknown device" message (RHBZ#1054761). */
if (STRNEQ (p, "unknown device")) {
char buf[256];
@@ -260,7 +264,7 @@ do_lvs (void)
r = command (&out, &err,
str_lvm, "lvs",
"-o", "vg_name,lv_name",
- "-S", "lv_role=public",
+ "-S", "lv_role=public && lv_active=active",
"--noheadings",
"--separator", "/", NULL);
if (r == -1) {
--
2.5.0
8 years, 9 months
[PATCH] tests: Make '080' be an official test of the guestfs_version API.
by Richard W.M. Jones
Useful because it tests returning a single structure.
---
docs/guestfs-hacking.pod | 1 +
ocaml/Makefile.am | 2 ++
ocaml/t/guestfs_080_version.ml | 27 +++++++++++++++++++++++++++
perl/t/080-version.t | 36 ++++++++++++++++++++++++++++++++++++
4 files changed, 66 insertions(+)
create mode 100644 ocaml/t/guestfs_080_version.ml
create mode 100644 perl/t/080-version.t
diff --git a/docs/guestfs-hacking.pod b/docs/guestfs-hacking.pod
index ae667c9..ecd10bf 100644
--- a/docs/guestfs-hacking.pod
+++ b/docs/guestfs-hacking.pod
@@ -201,6 +201,7 @@ This is the numbering scheme used by the tests:
060 explicit close
065 implicit close (in GC'd languages)
070 optargs
+ 080 version
- 100 launch, create partitions and LVs and filesystems
diff --git a/ocaml/Makefile.am b/ocaml/Makefile.am
index b79bcad..bc1d130 100644
--- a/ocaml/Makefile.am
+++ b/ocaml/Makefile.am
@@ -116,6 +116,7 @@ test_progs_bc = \
t/guestfs_060_explicit_close.bc \
t/guestfs_065_implicit_close.bc \
t/guestfs_070_optargs.bc \
+ t/guestfs_080_version.bc \
t/guestfs_410_close_event.bc \
t/guestfs_420_log_messages.bc
@@ -128,6 +129,7 @@ test_progs_opt = \
t/guestfs_060_explicit_close.opt \
t/guestfs_065_implicit_close.opt \
t/guestfs_070_optargs.opt \
+ t/guestfs_080_version.opt \
t/guestfs_410_close_event.opt \
t/guestfs_420_log_messages.opt
diff --git a/ocaml/t/guestfs_080_version.ml b/ocaml/t/guestfs_080_version.ml
new file mode 100644
index 0000000..ff10485
--- /dev/null
+++ b/ocaml/t/guestfs_080_version.ml
@@ -0,0 +1,27 @@
+(* libguestfs OCaml tests
+ * Copyright (C) 2009-2016 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 () =
+ let g = new Guestfs.guestfs () in
+ let version = g#version () in
+ assert (version.Guestfs.major = 1_L)
+ (* In other bindings, we may do additional tests on dynamic types
+ * here, but those are not necessary in OCaml.
+ *)
+
+let () = Gc.compact ()
diff --git a/perl/t/080-version.t b/perl/t/080-version.t
new file mode 100644
index 0000000..6a80fe9
--- /dev/null
+++ b/perl/t/080-version.t
@@ -0,0 +1,36 @@
+# libguestfs Perl bindings -*- perl -*-
+# Copyright (C) 2016 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.
+
+use strict;
+use warnings;
+use Test::More tests => 5;
+
+use Sys::Guestfs;
+
+my $g = Sys::Guestfs->new ();
+ok ($g);
+
+my %version = $g->version;
+ok (1);
+
+is ($version{major}, 1);
+like ($version{minor}, qr/^\d+$/);
+like ($version{release}, qr/^\d+$/);
+
+# XXX We could try to check that $version{extra} is a string, but perl
+# doesn't have a distinction between string and int, and in any case
+# it's possible (although unusual) for $version{extra} to be an int.
--
2.5.0
8 years, 9 months
[PATCH] php: restructure and expand tests
by Pino Toscano
Rename the existing tests according to the naming/numbering described in
guestfs-hacking(1), and improve the current ones:
- guestfs_php_001.phpt: rename to guestfs_020_create.phpt
- guestfs_php_003.phpt: rename to guestfs_070_optargs.phpt
- guestfs_php_bindtests.phpt: rename to guestfs_090_bindtests.phpt
- guestfs_091_version.phpt: new, checks taken from the former
guestfs_php_002.phpt
- guestfs_100_launch.phpt: new, modelled after the equivalent in e.g.
OCaml/Perl/Python
- guestfs_php_002.phpt: remove, as what it did is now covered by
091_version and 100_launch
---
.gitignore | 14 ++---
generator/main.ml | 2 +-
php/Makefile.am | 2 +-
php/extension/tests/guestfs_020_create.phpt | 13 +++++
php/extension/tests/guestfs_070_optargs.phpt | 29 ++++++++++
php/extension/tests/guestfs_091_version.phpt | 20 +++++++
php/extension/tests/guestfs_100_launch.phpt | 82 ++++++++++++++++++++++++++++
php/extension/tests/guestfs_php_001.phpt | 13 -----
php/extension/tests/guestfs_php_002.phpt | 36 ------------
php/extension/tests/guestfs_php_003.phpt | 29 ----------
php/run-php-tests.sh | 2 +-
11 files changed, 154 insertions(+), 88 deletions(-)
create mode 100644 php/extension/tests/guestfs_020_create.phpt
create mode 100644 php/extension/tests/guestfs_070_optargs.phpt
create mode 100644 php/extension/tests/guestfs_091_version.phpt
create mode 100644 php/extension/tests/guestfs_100_launch.phpt
delete mode 100644 php/extension/tests/guestfs_php_001.phpt
delete mode 100644 php/extension/tests/guestfs_php_002.phpt
delete mode 100644 php/extension/tests/guestfs_php_003.phpt
diff --git a/.gitignore b/.gitignore
index e34edb5..db354bc 100644
--- a/.gitignore
+++ b/.gitignore
@@ -367,12 +367,6 @@ Makefile.in
/php/extension/configure.in
/php/extension/env
/php/extension/guestfs_php.c
-/php/extension/guestfs_php_*.diff
-/php/extension/guestfs_php_*.exp
-/php/extension/guestfs_php_*.log
-/php/extension/guestfs_php_*.out
-/php/extension/guestfs_php_*.php
-/php/extension/guestfs_php_*.sh
/php/extension/install-sh
/php/extension/libtool
/php/extension/ltmain.sh
@@ -385,7 +379,13 @@ Makefile.in
/php/extension/php-for-tests.sh
/php/extension/php_guestfs_php.h
/php/extension/run-tests.php
-/php/extension/tests/guestfs_php_bindtests.phpt
+/php/extension/tests/guestfs_*.diff
+/php/extension/tests/guestfs_*.exp
+/php/extension/tests/guestfs_*.log
+/php/extension/tests/guestfs_*.out
+/php/extension/tests/guestfs_*.php
+/php/extension/tests/guestfs_*.sh
+/php/extension/tests/guestfs_090_bindtests.phpt
/php/extension/tmp-php.ini
/pick-guests.pl
/po-docs/*/*.1
diff --git a/generator/main.ml b/generator/main.ml
index b209511..ca882b1 100644
--- a/generator/main.ml
+++ b/generator/main.ml
@@ -158,7 +158,7 @@ Run it from the top source directory using the command
output_to "csharp/Libguestfs.cs" generate_csharp;
output_to "php/extension/php_guestfs_php.h" generate_php_h;
output_to "php/extension/guestfs_php.c" generate_php_c;
- output_to "php/extension/tests/guestfs_php_bindtests.phpt" generate_php_bindtests;
+ output_to "php/extension/tests/guestfs_090_bindtests.phpt" generate_php_bindtests;
output_to "erlang/guestfs.erl" generate_erlang_erl;
output_to "erlang/erl-guestfs.c" generate_erlang_c;
output_to ~perm:0o555 "erlang/bindtests.erl" generate_erlang_bindtests;
diff --git a/php/Makefile.am b/php/Makefile.am
index 14b4219..836f4ba 100644
--- a/php/Makefile.am
+++ b/php/Makefile.am
@@ -24,7 +24,7 @@ generator_built = \
EXTRA_DIST = \
$(generator_built) \
run-php-tests.sh \
- extension/tests/guestfs_php_*.phpt \
+ extension/tests/guestfs_*.phpt \
extension/config.m4 \
README-PHP \
guestfs_php.ini
diff --git a/php/extension/tests/guestfs_020_create.phpt b/php/extension/tests/guestfs_020_create.phpt
new file mode 100644
index 0000000..013ebb5
--- /dev/null
+++ b/php/extension/tests/guestfs_020_create.phpt
@@ -0,0 +1,13 @@
+--TEST--
+Load the module and create a handle.
+--FILE--
+<?php
+$g = guestfs_create ();
+if ($g == false) {
+ echo ("Failed to create guestfs_php handle.\n");
+ exit;
+}
+echo ("Created guestfs_php handle.\n");
+?>
+--EXPECT--
+Created guestfs_php handle.
diff --git a/php/extension/tests/guestfs_070_optargs.phpt b/php/extension/tests/guestfs_070_optargs.phpt
new file mode 100644
index 0000000..e268e98
--- /dev/null
+++ b/php/extension/tests/guestfs_070_optargs.phpt
@@ -0,0 +1,29 @@
+--TEST--
+Check function with optional arguments.
+--FILE--
+<?php
+$g = guestfs_create ();
+if ($g == false) {
+ echo ("Failed to create guestfs_php handle.\n");
+ exit;
+}
+if (guestfs_add_drive ($g, "/dev/null") == false) {
+ echo ("Failed add_drive, no optional arguments: " . guestfs_last_error ($g) . "\n");
+ exit;
+}
+if (guestfs_add_drive ($g, "/dev/null", 0) == false) {
+ echo ("Failed add_drive, one optional argument: " . guestfs_last_error ($g) . "\n");
+ exit;
+}
+if (guestfs_add_drive ($g, "/dev/null", 1) == false) {
+ echo ("Failed add_drive, one optional argument: " . guestfs_last_error ($g) . "\n");
+ exit;
+}
+if (guestfs_add_drive ($g, "/dev/null", 1, "raw") == false) {
+ echo ("Failed add_drive, two optional arguments: " . guestfs_last_error ($g) . "\n");
+ exit;
+}
+echo ("Completed tests OK.\n");
+?>
+--EXPECT--
+Completed tests OK.
diff --git a/php/extension/tests/guestfs_091_version.phpt b/php/extension/tests/guestfs_091_version.phpt
new file mode 100644
index 0000000..365094c
--- /dev/null
+++ b/php/extension/tests/guestfs_091_version.phpt
@@ -0,0 +1,20 @@
+--TEST--
+Check the result of guestfs_version().
+--FILE--
+<?php
+$g = guestfs_create ();
+
+$version = guestfs_version ($g);
+echo (gettype ($version["major"]) . "\n");
+echo (gettype ($version["minor"]) . "\n");
+echo (gettype ($version["release"]) . "\n");
+echo (gettype ($version["extra"]) . "\n");
+
+echo ("OK\n");
+?>
+--EXPECT--
+integer
+integer
+integer
+string
+OK
diff --git a/php/extension/tests/guestfs_100_launch.phpt b/php/extension/tests/guestfs_100_launch.phpt
new file mode 100644
index 0000000..cd4661a
--- /dev/null
+++ b/php/extension/tests/guestfs_100_launch.phpt
@@ -0,0 +1,82 @@
+--TEST--
+Launch, create partitions and LVs and filesystems.
+--FILE--
+<?php
+$g = guestfs_create ();
+guestfs_add_drive_scratch ($g, 500 * 1024 * 1024);
+guestfs_launch ($g);
+
+guestfs_pvcreate ($g, "/dev/sda");
+guestfs_vgcreate ($g, "VG", array ("/dev/sda"));
+guestfs_lvcreate ($g, "LV1", "VG", 200);
+guestfs_lvcreate ($g, "LV2", "VG", 200);
+
+$lvs = guestfs_lvs ($g);
+var_dump ($lvs);
+
+guestfs_mkfs ($g, "ext2", "/dev/VG/LV1");
+guestfs_mount ($g, "/dev/VG/LV1", "/");
+guestfs_mkdir ($g, "/p");
+guestfs_touch ($g, "/q");
+
+function dir_cmp ($a, $b)
+{
+ return strcmp ($a["name"], $b["name"]);
+}
+function dir_extract ($n)
+{
+ return array ("name" => $n["name"], "ftyp" => $n["ftyp"]);
+}
+$dirs = guestfs_readdir ($g, "/");
+usort ($dirs, "dir_cmp");
+$dirs = array_map ("dir_extract", $dirs);
+var_dump ($dirs);
+
+guestfs_shutdown ($g);
+echo ("OK\n");
+?>
+--EXPECT--
+array(2) {
+ [0]=>
+ string(11) "/dev/VG/LV1"
+ [1]=>
+ string(11) "/dev/VG/LV2"
+}
+array(5) {
+ [0]=>
+ array(2) {
+ ["name"]=>
+ string(1) "."
+ ["ftyp"]=>
+ string(1) "d"
+ }
+ [1]=>
+ array(2) {
+ ["name"]=>
+ string(2) ".."
+ ["ftyp"]=>
+ string(1) "d"
+ }
+ [2]=>
+ array(2) {
+ ["name"]=>
+ string(10) "lost+found"
+ ["ftyp"]=>
+ string(1) "d"
+ }
+ [3]=>
+ array(2) {
+ ["name"]=>
+ string(1) "p"
+ ["ftyp"]=>
+ string(1) "d"
+ }
+ [4]=>
+ array(2) {
+ ["name"]=>
+ string(1) "q"
+ ["ftyp"]=>
+ string(1) "r"
+ }
+}
+OK
diff --git a/php/extension/tests/guestfs_php_001.phpt b/php/extension/tests/guestfs_php_001.phpt
deleted file mode 100644
index 013ebb5..0000000
--- a/php/extension/tests/guestfs_php_001.phpt
+++ /dev/null
@@ -1,13 +0,0 @@
---TEST--
-Load the module and create a handle.
---FILE--
-<?php
-$g = guestfs_create ();
-if ($g == false) {
- echo ("Failed to create guestfs_php handle.\n");
- exit;
-}
-echo ("Created guestfs_php handle.\n");
-?>
---EXPECT--
-Created guestfs_php handle.
diff --git a/php/extension/tests/guestfs_php_002.phpt b/php/extension/tests/guestfs_php_002.phpt
deleted file mode 100644
index 91b2067..0000000
--- a/php/extension/tests/guestfs_php_002.phpt
+++ /dev/null
@@ -1,36 +0,0 @@
---TEST--
-Launch the appliance and run basic tests.
---FILE--
-<?php
-$g = guestfs_create ();
-if ($g == false) {
- echo ("Failed to create guestfs_php handle.\n");
- exit;
-}
-
-if (! guestfs_add_drive_scratch ($g, 100 * 1024 * 1024) ||
- ! guestfs_launch ($g) ||
- ! guestfs_part_disk ($g, "/dev/sda", "mbr") ||
- ! guestfs_pvcreate ($g, "/dev/sda1") ||
- ! guestfs_vgcreate ($g, "VG", array ("/dev/sda1")) ||
- ! guestfs_lvcreate ($g, "LV", "VG", 64) ||
- ! guestfs_mkfs ($g, "ext2", "/dev/VG/LV")) {
- die ("Error: ".guestfs_last_error ($g)."\n");
-}
-
-$version = guestfs_version ($g);
-if ($version == false) {
- echo ("Error: ".guestfs_last_error ($g)."\n");
- exit;
-}
-if (!is_int ($version["major"]) ||
- !is_int ($version["minor"]) ||
- !is_int ($version["release"]) ||
- !is_string ($version["extra"])) {
- echo ("Error: incorrect return type from guestfs_version\n");
-}
-
-echo ("OK\n");
-?>
---EXPECT--
-OK
diff --git a/php/extension/tests/guestfs_php_003.phpt b/php/extension/tests/guestfs_php_003.phpt
deleted file mode 100644
index e268e98..0000000
--- a/php/extension/tests/guestfs_php_003.phpt
+++ /dev/null
@@ -1,29 +0,0 @@
---TEST--
-Check function with optional arguments.
---FILE--
-<?php
-$g = guestfs_create ();
-if ($g == false) {
- echo ("Failed to create guestfs_php handle.\n");
- exit;
-}
-if (guestfs_add_drive ($g, "/dev/null") == false) {
- echo ("Failed add_drive, no optional arguments: " . guestfs_last_error ($g) . "\n");
- exit;
-}
-if (guestfs_add_drive ($g, "/dev/null", 0) == false) {
- echo ("Failed add_drive, one optional argument: " . guestfs_last_error ($g) . "\n");
- exit;
-}
-if (guestfs_add_drive ($g, "/dev/null", 1) == false) {
- echo ("Failed add_drive, one optional argument: " . guestfs_last_error ($g) . "\n");
- exit;
-}
-if (guestfs_add_drive ($g, "/dev/null", 1, "raw") == false) {
- echo ("Failed add_drive, two optional arguments: " . guestfs_last_error ($g) . "\n");
- exit;
-}
-echo ("Completed tests OK.\n");
-?>
---EXPECT--
-Completed tests OK.
diff --git a/php/run-php-tests.sh b/php/run-php-tests.sh
index f2f80ea..4132927 100755
--- a/php/run-php-tests.sh
+++ b/php/run-php-tests.sh
@@ -41,7 +41,7 @@ rm -f env
echo "PATH=$PATH" > env
printenv | grep -E '^(LIBGUESTFS|LIBVIRT|LIBVIRTD|VIRTLOCKD|LD|MALLOC)_' >> env
-TESTS=$(echo tests/guestfs_php_*.phpt)
+TESTS=$(echo tests/guestfs_*.phpt)
echo TESTS: $TESTS
make test TESTS="$TESTS" PHP_EXECUTABLE="$PWD/php-for-tests.sh" REPORT_EXIT_STATUS=1 TEST_TIMEOUT=300
--
2.5.0
8 years, 9 months