Commit Graph

468 Commits

Author SHA1 Message Date
Richard W.M. Jones
d6c42a6c58 valgrind: Don't use "nested" run scripts.
When TESTS_ENVIRONMENT already uses 'run', the VG variable
doesn't also need to use 'run'.

The specific problem is that if the command contains newlines
then double invocations of the 'run' script fails (in libtool).
ie the following command failed causing errors in check-valgrind:

  $VG virt-builder phony-fedora \
      -v --no-cache --no-check-signature $no_network \
  ...
      --write '/etc/append4:line1
  ' \
  ...
2016-10-11 18:08:49 +01:00
Pino Toscano
4c3968f262 libvirt: read disk paths from pools (RHBZ#1366049)
A disk of type 'volume' is stored as
  <source pool='pool_name' volume='volume_name'/>
and its real location is inside the 'volume_name', as 'pool_name': in
this case, query libvirt for the actual path of the specified volume in
the specified pool.

Adjust the code so that:
- for_each_disk gets the virConnectPtr, needed to do operations with
  libvirt
- when extracting the disk filename depending on the type, the code
  snippet doing it can directly set 'filename', without setting an XPath
  result variable

Only file-based volumes are supported for now; more types can be added
(with proper testing) later on.
2016-09-22 17:36:09 +02:00
Matteo Cafasso
79fdc9ad47 find_inode: added API tests
NTFS file system always has the MFT file at inode 0. This reliable
information helps testing the API.

Signed-off-by: Matteo Cafasso <noxdafox@gmail.com>
2016-09-19 19:53:07 +02:00
Pino Toscano
8335af37fa tests: do not assume '.' is in Perl's @INC
Upstream Perl is going to remove '.' from @INC (the include path for
modules) by default for the next major release (= 5.26) [1], as measure
to fix security issues.  Debian already started backporting the fixes
for this [2], thus behaving this way in current Sid installations.

Since the affected Perl sources are only the local daemon testing
scripts, a simple fix is to force the 'requires' for the local
captive-daemon.pm module to start from the current directory: this way
there is no need to manually augment @INC, and only our local module is
loaded automatically.

[1] https://rt.perl.org/Public/Bug/Display.html?id=127810
[2] https://lists.debian.org/debian-devel-announce/2016/08/msg00013.html
2016-09-09 14:42:05 +02:00
Pino Toscano
eea210dbf7 Use the getprogname gnulib module
Make use of the recently added 'getprogname' module in gnulib: replace
our guestfs_int_program_name with the getprogname() provided by the
module, since it does the same thing, and in a portable way.
As consequence of the above, use gnulib in a couple of tests that use
getprogname().

Since guestfs_int_program_name is gone, drop the configure checks
associated with it.
2016-09-08 09:57:15 +02:00
Pino Toscano
03032e2419 tests: make test-noexec-stack.pl work in non-English locales
Set C as language when running the script, as the output of readelf is
parsed: this way the parsing works also when the system locale is not
English.
2016-09-08 09:57:14 +02:00
Pino Toscano
f14dd26d36 tests: add rhbz1370424.xml to EXTRA_DIST
Fixes commit 98aa78f288.
2016-08-29 10:18:00 +02:00
Richard W.M. Jones
98aa78f288 tests: Add a regression test for RHBZ#1370424.
Regression test for previous commit which just tests that
guestfs_add_domain doesn't assert-fail on guests with no port
attribute.
2016-08-27 12:59:14 +01:00
Richard W.M. Jones
76c0a67d30 build: Add common CLEANFILES and DISTCLEANFILES to common-rules.mk.
By adding common CLEANFILES and DISTCLEANFILES variables to
common-rules.mk, we can remove these from most other Makefiles, and
also clean files more consistently.

Note that bin_PROGRAMS are already cleaned by 'make clean', so I
removed cases where these were unnecessarily added to CLEANFILES.
2016-08-25 16:54:34 +01:00
Richard W.M. Jones
d5a8f82887 Use 'const' for stack integers where possible.
May improve optimization possibilities in a few cases.
2016-07-26 10:43:45 +01:00
Matteo Cafasso
a77c6aac81 Added download_blocks API test
The test shows how the function can be used to retrieve deleted data
from a disk partition.

Signed-off-by: Matteo Cafasso <noxdafox@gmail.com>
2016-07-20 15:26:50 +02:00
Richard W.M. Jones
35bac3a650 lib: Deprecate old SELinux APIs, rewrite SELinux documentation (RHBZ#1152825).
Also turns the --selinux option of guestfish, guestmount and
virt-rescue into a no-op -- it didn't work before so this is
effectively no change.
2016-07-14 15:28:10 +01:00
Richard W.M. Jones
6ec75f8cfe tests: Add a test of the setfiles API. 2016-07-14 15:28:10 +01:00
Matteo Cafasso
abf85b050e filesystem_walk: more information into tsk_dirent
Access, modification, last status change and creation time in
Unix format as for statns.

Number of links pointing to a given entry.

If the entry is a symbolic link, report the its target path.

A new flag (DIRENT_COMPRESSED 0x04) indicating whether the file is
compressed using native filesystem compression support.

Signed-off-by: Matteo Cafasso <noxdafox@gmail.com>
2016-07-08 12:08:17 +02:00
Matteo Cafasso
2d65129e7e Reserve entries to tsk_dirent struct
Already implemented entries.

tsk_inode
tsk_type
tsk_size
tsk_name
tsk_flags

Easy ones to add.

tsk_atime_sec
tsk_atime_nsec
tsk_mtime_sec
tsk_mtime_nsec
tsk_ctime_sec
tsk_ctime_nsec
tsk_blksize
tsk_blocks

Further ideas.

tsk_nlink
tsk_link_name

Signed-off-by: Matteo Cafasso <noxdafox@gmail.com>
2016-06-28 22:09:36 +01:00
Pino Toscano
de5c00eebf automake2junit.ml: sanitize logs, make it more conformant
- sanitize the logs, removing terminal color codes and carriage returns
- add an empty "properties" node
- put the log for skipped tests as "message" attribute, hoping it is
  read from there
- do not blacklist the log of test-virt-rescue.pl, which should not
  cause issues now
2016-06-27 11:52:35 +02:00
Matteo Cafasso
7d8fbde4b2 lib: Added filesystem_walk command tests
The tests check whether the filesystem_walk command is able to retrieve
information regarding both existing and deleted files.

A NTFS image is used as Ext3+ filesystems deletion is more aggressive
in terms of metadata removal.

Signed-off-by: Matteo Cafasso <noxdafox@gmail.com>
2016-06-22 18:43:51 +01:00
Pino Toscano
64bb9edd52 tests: specify the image format when possible
When possible, make the disk image format explicit when invoking tools
or using add-drive. This avoids warnings from qemu about the unspecified
format for the image, and also makes qemu slightly faster (skipping the
disk image probing).
Tests checking the image probing are not touched.

This changes also:
- old-style invocations of tools (`$tool $filename`) into new style
  (`$tool -a $filename`)
- add-drive-ro/add-drive-with-if guestfish commands into add/add-drive
  with explicit readonly/iface arguments

There should be no change in the tests results.
2016-05-19 19:06:00 +02:00
Pino Toscano
6e34396661 python: PEP 8: avoid too long lines
Reindent Python scripts to make sure lines are not longer than 80
columns.

Regarding autogenerated code (guestfs.py and bindtests.py): add an
helper function to make sure comma-separated lists are wrapped at the
wanted length.

This produces only differences in the indentation of long Python lines,
with no behaviour changes.
2016-05-04 18:56:01 +02:00
Pino Toscano
f85e18f62f python: PEP 8: adapt empty lines
Add or remove empty lines to match the needed ones around
blocks/functions/etc.

This is just formatting, no behaviour changes.
2016-05-04 18:56:01 +02:00
Pino Toscano
6105ee0c71 python: PEP 8: adapt whitespaces in lines
Add (after comma) or remove (before opening round bracket, and around
'=' in arguments) whitespaces according to the PEP 8 specification.

This is just code reformatting, with no behaviour changes; no content
changed beside whitespaces, so "git diff -w" gives an empty diff.
2016-05-04 18:56:01 +02:00
Richard W.M. Jones
3b581a727c utils: Move tests/qemu/ boot-analysis etc tools to new utils top level directory.
Create a new top level directory called 'utils' and move the
following programs there:

  tests/qemu/boot-analysis -> utils/boot-analysis/
  tests/qemu/boot-benchmark -> utils/boot-benchmark/
  tests/qemu/qemu-boot -> utils/qemu-boot/
  tests/qemu/qemu-speed-test -> utils/qemu-speed-test/

Also we only build the boot-analysis program on x86-64 and aarch64,
since it requires custom porting to each architecture.
2016-05-03 13:21:34 +01:00
Richard W.M. Jones
9cd00805b0 tests/qemu: boot-analysis: Display libvirt as distinct source.
Don't display libvirt events as '[library]', but as '[libvirt]'.
2016-04-30 16:42:24 +01:00
Richard W.M. Jones
2fd05203e4 tests/qemu: boot-analysis: Dump pass data times in ms, with diffs.
When (in --verbose mode) we dump the pass data, dump the times in
milliseconds (instead of nanoseconds) so they are consistent with
other output.  Also dump the time difference from the previous event.

Useful for detailed debugging/analysis of problems.
2016-04-30 16:02:30 +01:00
Richard W.M. Jones
d5c40262fa tests/qemu: boot-analysis: Port this program to aarch64 (using UEFI). 2016-04-30 12:45:54 +01:00
Richard W.M. Jones
606f158606 tests/qemu: boot-analysis: Add analysis of initcalls before entering userspace. 2016-04-28 13:35:27 +01:00
Richard W.M. Jones
7f572434f0 tests: Add tests/qemu/boot-benchmark-range.pl to EXTRA_DIST.
Updates commit 8299d7087a.
2016-04-24 19:21:34 +01:00
Richard W.M. Jones
8299d7087a tests: Add boot-benchmark-range script.
Add a script we can use to benchmark performance across a range of
commits in another project.
2016-04-22 17:10:43 +01:00
Richard W.M. Jones
45f84601b0 tests: boot analysis: Add text to describe how to change settings. 2016-04-22 16:39:49 +01:00
Richard W.M. Jones
0108240364 tests: Fix 'make check-slow'.
Since we started to use the parallel tests framework in automake,
'make check-slow' has been broken.  This is because parallel tests
doesn't allow you to run 'make check TESTS=...' with a set of test
scripts which do not also appear in the static list of tests in the
Makefile.am.  We would like to list and run only "fast" tests in the
Makefile.am, and have other scripts for slow tests.

The solution is to add the slow tests to Makefile.am, but condition
those tests on an environment variable SLOW=1 being set.

This commit fixes all the existing slow tests in this way, and updates
the documentation (guestfs-hacking(1)) to document how slow tests
should be written in future.
2016-04-16 20:40:49 +01:00
Richard W.M. Jones
f24753ebb0 tests/qemu: boot-analysis: (Don't) set LIBVIRT_LOG_FILTERS.
Setting LIBVIRT_LOG_FILTERS is supposed to be better than setting
LIBVIRT_DEBUG, but I couldn't get it to work.

This updates commit b332d91bc9.
2016-04-06 17:49:38 +01:00
Richard W.M. Jones
b332d91bc9 tests/qemu: boot-analysis: Add support for logging libvirt events. 2016-04-06 13:06:23 +01:00
Richard W.M. Jones
0008d794cf tests/qemu: Don't leak backend variable in boot-analysis/boot-benchmark programs. 2016-04-06 10:42:21 +01:00
Richard W.M. Jones
fdfedcb4ef Use 'error' function for fprintf followed by exit.
Like with the previous commit, this replaces instances of:

  if (something_bad) {
    fprintf (stderr, "%s: error message\n", guestfs_int_program_name);
    exit (EXIT_FAILURE);
  }

with:

  if (something_bad)
    error (EXIT_FAILURE, 0, "error message");

(except in a few cases were errno was incorrectly being ignored, in
which case I have fixed that).

It's slightly more complex than the previous commit because we must be
careful to:

 - Remove the program name (since error(3) prints it).

 - Remove any trailing \n character from the message.

Candidates for replacement were found using:

  pcregrep --buffer-size 10M -M '\bfprintf\b.*\n.*\bexit\b' `git ls-files`
2016-04-04 17:57:38 +01:00
Richard W.M. Jones
129e4938ba Use 'error' function consistently throughout.
Wherever we had code which did:

  if (something_bad) {
    perror (...);
    exit (EXIT_FAILURE);
  }

replace this with use of the error(3) function:

  if (something_bad)
    error (EXIT_FAILURE, errno, ...);

The error(3) function is supplied by glibc, or by gnulib on platforms
which don't have it, and is much more flexible than perror(3).  Since
we already use error(3), there seems to be no downside to mandating it
everywhere.

Note there is one nasty catch with error(3): error (EXIT_SUCCESS, ...)
does *not* exit!  This is also the reason why error(3) cannot be
marked as __attribute__((noreturn)).

Because the examples can't use gnulib, I did not change them.

To search for multiline patterns of the above form, pcregrep -M turns
out to be very useful:

  pcregrep --buffer-size 10M -M '\bperror\b.*\n.*\bexit\b' `git ls-files`
2016-04-04 13:14:26 +01:00
Richard W.M. Jones
03b68d436c tests/qemu: boot-analysis: Don't force backend direct.
Current libvirt overhead is 220ms.  That didn't matter when our launch
time was 4000ms.  Now we're launching in 900ms, it really does.
2016-04-02 11:59:39 +01:00
Richard W.M. Jones
014b7c0ced tests/qemu: Standardize test info printed by boot-* tests.
It now looks like:

test version: libguestfs 1.33.16
 test passes: 5
host version: Linux moo 4.4.4-301.fc23.x86_64 #1 SMP Fri Mar 4 17:42:42 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
    host CPU: Intel(R) Core(TM) i7-5600U CPU @ 2.60GHz
     backend: direct
        qemu: /home/rjones/d/qemu/x86_64-softmmu/qemu-system-x86_64
qemu version: QEMU emulator version 2.5.90, Copyright (c) 2003-2008 Fabrice Bellard
         smp: 1
     memsize: 500
      append: guestfs_boot_analysis=1 ignore_loglevel initcall_debug
2016-04-02 11:01:30 +01:00
Richard W.M. Jones
d470480b35 tests/qemu: boot-analysis: Display all times in ms.
It was confusing to have a mix of seconds and milliseconds.  For all
upstream testing (eg. with SeaBIOS) we are discussing everything in
milliseconds, so use those exclusively.
2016-04-02 10:42:12 +01:00
Richard W.M. Jones
96ce2f9afe tests/qemu: Add boot-benchmark.
Add a new test program called 'boot-benchmark'.  This is similar to
'boot-analysis' but it simply boots and shuts down the appliance
several times in a row and measures how long it takes, calculating
mean and standard deviation.
2016-04-01 19:22:56 +01:00
Matteo Cafasso
5fd0819ebc Rename icat command in download_inode
The "icat" name comes from the employed command line tool which might be
replaced at any time with a different implementation.

The command name is a bit confusing because it's similar to "cat" but
act as "download".

download_inode is more clear and descriptive.

Signed-off-by: Matteo Cafasso <noxdafox@gmail.com>
2016-03-31 10:50:42 +02:00
Richard W.M. Jones
da7e22b648 boot-analysis: Add --memsize, --smp and --append options.
These options allow you to control the appliance memory size, number
of vCPUs, and extra kernel options respectively.

Note that using --smp is not usually a good idea.  Not only does it
slow down the appliance, but it tends to break the boot analysis
program because it makes runs (more) non-deterministic.
2016-03-29 12:01:42 +01:00
Richard W.M. Jones
0ba59db611 tests/qemu: Add program for tracing and analyzing boot times. 2016-03-23 13:25:46 +00:00
Pino Toscano
e2457d0773 Reduce GUESTFS_PRIVATE usage
Remove the GUESTFS_PRIVATE=1 define for some tools and tests which don't
really use any private API.
2016-03-22 22:30:59 +00:00
Pino Toscano
5f24d45ab5 build: check the path of true, and use it in tests
Check for the full path of true, and use it instead of hardcoding
/bin/true (which is still left as fallback).
2016-03-22 09:45:41 +01:00
Pino Toscano
41795a1c98 tests: move guestfs-md5.sh to test-data
Move it to the test-data directory, giving it a more generic name so it
can be used also for more than just md5; adjust qemu tests accordingly.

This is just code motion, no behaviour change.
2016-03-22 09:45:41 +01:00
Matteo Cafasso
d314d10e1f sleuthkit availability check renamed
>From 'available icat' to 'available sleuthkit'.

Signed-off-by: Matteo Cafasso <noxdafox@gmail.com>
2016-03-08 21:13:10 +00:00
Matteo Cafasso
ac0d2adf56 added icat API tests
Signed-off-by: Matteo Cafasso <noxdafox@gmail.com>
2016-03-07 19:33:53 +00:00
Richard W.M. Jones
07c496c53c Use less stack.
GCC has two warnings related to large stack frames.  We were already
using the -Wframe-larger-than warning, but this reduces the threshold
from 10000 to 5000 bytes.

However that warning only covers the static part of frames (not
alloca).  So this change also enables -Wstack-usage=10000 which covers
both the static and dynamic usage (alloca and variable length arrays).

Multiple changes are made throughout the code to reduce frames to fit
within these new limits.

Note that stack allocation of large strings can be a security issue.
For example, we had code like:

 size_t len = strlen (fs->windows_systemroot) + 64;
 char software[len];
 snprintf (software, len, "%s/system32/config/software",
           fs->windows_systemroot);

where fs->windows_systemroot is guest controlled.  It's not clear what
the effects might be of allowing the guest to allocate potentially
very large stack frames, but at best it allows the guest to cause
libguestfs to segfault.  It turns out we are very lucky that
fs->windows_systemroot cannot be set arbitrarily large (see checks in
is_systemroot).

This commit changes those to large heap allocations instead.
2016-03-07 17:36:24 +00:00
Pino Toscano
1d5af46a44 tests: move ntfs tests in a single directory
Move test-ntfscat.sh and test-ntfsclone.sh in a single ntfs directory,
much like the tests for other filesystems.
2016-03-01 14:20:46 +01:00
Matteo Cafasso
a7ea3b577f tests: Added test for ntfscat_i.
Test is based on file signature, it checks whether the extracted file
is the $MFT.

Signed-off-by: Matteo Cafasso <noxdafox@gmail.com>
2016-03-01 09:06:10 +00:00