mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-22 07:03:38 +00:00
tests: Add tests for the new journal APIs (RHBZ#988100).
This relies on the test data from
commit b502197ec4.
This commit is contained in:
@@ -58,6 +58,7 @@ SUBDIRS += tests/hotplug
|
||||
SUBDIRS += tests/nbd
|
||||
SUBDIRS += tests/http
|
||||
SUBDIRS += tests/syslinux
|
||||
SUBDIRS += tests/journal
|
||||
SUBDIRS += tests/fuzz
|
||||
SUBDIRS += tests/regressions
|
||||
endif
|
||||
|
||||
@@ -1669,6 +1669,7 @@ AC_CONFIG_FILES([Makefile
|
||||
tests/guests/guests.xml
|
||||
tests/hotplug/Makefile
|
||||
tests/http/Makefile
|
||||
tests/journal/Makefile
|
||||
tests/luks/Makefile
|
||||
tests/lvm/Makefile
|
||||
tests/md/Makefile
|
||||
|
||||
@@ -2973,6 +2973,7 @@ C<guestfs_add_drive>." };
|
||||
name = "journal_get";
|
||||
style = RStructList ("fields", "xattr"), [], [];
|
||||
optional = Some "journal";
|
||||
test_excuse = "tests in tests/journal subdirectory";
|
||||
shortdesc = "read the current journal entry";
|
||||
longdesc = "\
|
||||
Read the current journal entry. This returns all the fields
|
||||
@@ -11384,6 +11385,7 @@ To read the UUID on a filesystem, call C<guestfs_vfs_uuid>." };
|
||||
style = RErr, [Pathname "directory"], [];
|
||||
proc_nr = Some 404;
|
||||
optional = Some "journal";
|
||||
test_excuse = "tests in tests/journal subdirectory";
|
||||
shortdesc = "open the systemd journal";
|
||||
longdesc = "\
|
||||
Open the systemd journal located in C<directory>. Any previously
|
||||
@@ -11400,6 +11402,7 @@ handle by calling C<guestfs_journal_close>." };
|
||||
style = RErr, [], [];
|
||||
proc_nr = Some 405;
|
||||
optional = Some "journal";
|
||||
test_excuse = "tests in tests/journal subdirectory";
|
||||
shortdesc = "close the systemd journal";
|
||||
longdesc = "\
|
||||
Close the journal handle." };
|
||||
@@ -11409,6 +11412,7 @@ Close the journal handle." };
|
||||
style = RBool "more", [], [];
|
||||
proc_nr = Some 406;
|
||||
optional = Some "journal";
|
||||
test_excuse = "tests in tests/journal subdirectory";
|
||||
shortdesc = "move to the next journal entry";
|
||||
longdesc = "\
|
||||
Move to the next journal entry. You have to call this
|
||||
@@ -11425,6 +11429,7 @@ have reached the end of the journal." };
|
||||
style = RInt64 "rskip", [Int64 "skip"], [];
|
||||
proc_nr = Some 407;
|
||||
optional = Some "journal";
|
||||
test_excuse = "tests in tests/journal subdirectory";
|
||||
shortdesc = "skip forwards or backwards in the journal";
|
||||
longdesc = "\
|
||||
Skip forwards (C<skip E<ge> 0>) or backwards (C<skip E<lt> 0>) in the
|
||||
@@ -11441,6 +11446,7 @@ the start of the journal." };
|
||||
proc_nr = Some 408;
|
||||
visibility = VInternal;
|
||||
optional = Some "journal";
|
||||
test_excuse = "tests in tests/journal subdirectory";
|
||||
shortdesc = "internal journal reading operation";
|
||||
longdesc = "\
|
||||
This function is used internally when reading the journal." };
|
||||
@@ -11450,6 +11456,7 @@ This function is used internally when reading the journal." };
|
||||
style = RInt64 "threshold", [], [];
|
||||
proc_nr = Some 409;
|
||||
optional = Some "journal";
|
||||
test_excuse = "tests in tests/journal subdirectory";
|
||||
shortdesc = "get the data threshold for reading journal entries";
|
||||
longdesc = "\
|
||||
Get the current data threshold for reading journal entries.
|
||||
@@ -11464,6 +11471,7 @@ See also C<guestfs_journal_set_data_threshold>." };
|
||||
style = RErr, [Int64 "threshold"], [];
|
||||
proc_nr = Some 410;
|
||||
optional = Some "journal";
|
||||
test_excuse = "tests in tests/journal subdirectory";
|
||||
shortdesc = "set the data threshold for reading journal entries";
|
||||
longdesc = "\
|
||||
Set the data threshold for reading journal entries.
|
||||
|
||||
26
tests/journal/Makefile.am
Normal file
26
tests/journal/Makefile.am
Normal file
@@ -0,0 +1,26 @@
|
||||
# libguestfs
|
||||
# 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.
|
||||
|
||||
include $(top_srcdir)/subdir-rules.mk
|
||||
|
||||
TESTS = \
|
||||
test-journal.pl
|
||||
|
||||
TESTS_ENVIRONMENT = $(top_builddir)/run --test
|
||||
|
||||
EXTRA_DIST = \
|
||||
$(TESTS)
|
||||
87
tests/journal/test-journal.pl
Executable file
87
tests/journal/test-journal.pl
Executable file
@@ -0,0 +1,87 @@
|
||||
#!/usr/bin/perl
|
||||
# libguestfs
|
||||
# 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 journal using test data from ../guests/guest-aux/-
|
||||
# fedora-journal.tar.xz which is incorporated into the Fedora test
|
||||
# image in ../guests/fedora.img.
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Sys::Guestfs;
|
||||
|
||||
exit 77 if $ENV{SKIP_TEST_JOURNAL_PL};
|
||||
|
||||
my $g = Sys::Guestfs->new ();
|
||||
$g->add_drive ("../guests/fedora.img", readonly => 1, format => "raw");
|
||||
$g->launch ();
|
||||
|
||||
# If journal feature is not available, bail.
|
||||
unless ($g->feature_available (["journal"])) {
|
||||
warn "$0: skipping test because journal feature is not available\n";
|
||||
exit 77;
|
||||
}
|
||||
|
||||
# Mount the root filesystem.
|
||||
$g->mount_ro ("/dev/VG/Root", "/");
|
||||
|
||||
# Open the journal.
|
||||
$g->journal_open ("/var/log/journal");
|
||||
|
||||
eval {
|
||||
# Count the number of journal entries by iterating over them.
|
||||
# Save the first few.
|
||||
my $count = 0;
|
||||
my @entries = ();
|
||||
while ($g->journal_next ()) {
|
||||
$count++;
|
||||
my @fields = $g->journal_get ();
|
||||
# Turn the fields into a hash of field name -> data.
|
||||
my %fields = ();
|
||||
$fields{$_->{attrname}} = $_->{attrval} foreach @fields;
|
||||
push @entries, \%fields if $count <= 5;
|
||||
}
|
||||
|
||||
die "incorrect # journal entries (got $count, expecting 2459)"
|
||||
unless $count == 2459;
|
||||
|
||||
# Check a few fields.
|
||||
foreach ([0, "PRIORITY", "6"],
|
||||
[0, "MESSAGE_ID", "ec387f577b844b8fa948f33cad9a75e6"],
|
||||
[1, "_TRANSPORT", "driver"],
|
||||
[1, "_UID", "0"],
|
||||
[2, "_BOOT_ID", "1678ffea9ef14d87a96fa4aecd575842"],
|
||||
[2, "_HOSTNAME", "f20rawhidex64.home.annexia.org"],
|
||||
[4, "SYSLOG_IDENTIFIER", "kernel"]) {
|
||||
my %fields = %{$entries[$_->[0]]};
|
||||
my $fieldname = $_->[1];
|
||||
die "field ", $fieldname, " does not exist"
|
||||
unless exists $fields{$fieldname};
|
||||
my $expected = $_->[2];
|
||||
my $actual = $fields{$fieldname};
|
||||
die "unexpected data: got ", $fieldname, "=", $actual,
|
||||
", expected ", $fieldname, "=", $expected unless $actual eq $expected;
|
||||
}
|
||||
};
|
||||
my $error = $@;
|
||||
$g->journal_close ();
|
||||
$g->shutdown ();
|
||||
$g->close ();
|
||||
|
||||
die $error if $error;
|
||||
exit 0
|
||||
Reference in New Issue
Block a user