Commit Graph

39 Commits

Author SHA1 Message Date
Michal Privoznik
0b8825c7ac virhostdevtest: Reset libvirt error on expected failure
If a libvirt error occurred during a test, then virTestRun()
reports it (regardless of test returning success or failure).
For instance, in this specific case, a hostdev is detached twice
and the second attempt is expected to fail. It does fail and
libvirt error is reported which is then printed onto stderr.
Insert virResetLastError() calls on appropriate places to avoid
that.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-08-27 16:10:21 +02:00
Michal Privoznik
5ede0b9b41 virhostdevtest: s/VIR_DEBUG/VIR_TEST_DEBUG/
There's no need to have VIR_DEBUG() really.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-08-27 16:10:21 +02:00
Michal Privoznik
71c5c4d8a2 virhostdevtest: Drop useless VIR_TEST_DEBUG
The virTestRun() already reports the same.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-08-27 16:10:21 +02:00
Michal Privoznik
50e6688733 virhostdevtest: Drop most of 'cleanup' and 'out' labels
In this test there is this macro CHECK_LIST_COUNT() which checks
if a list of PCI devices contains expected count. If it doesn't
an error is reported and 'goto cleanup' is invoked. There's no
real reason for that as even since its introduction there is no
cleanup done and all 'cleanup' labels contain nothing but
'return'.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-08-27 16:09:52 +02:00
Michal Privoznik
9409f6b724 virhostdevtest: Check for integer retval in more verbose way
There are few functions called from the test which return an
integer but their retval is compared as if it was a pointer.
Now, there is nothing wrong with that from machine POV, but
from readability perspective it's wrong.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-08-27 16:00:47 +02:00
Roman Bolshakov
fde361083d tests: Add lib- prefix to all mocks
In preparation libtool "-module" flag removal, add lib prefix to all
mock shared objects.

While at it, introduce VIR_TEST_MOCK macros that makes path out of mock
name to be used with VIR_TEST_PRELOAD or VIR_TEST_MAIN_PRELOAD.  That,
hopefully, improves readability, reduces line length and allows to
tailor VIR_TEST_MOCK for specific platform if it has shared library
suffix different from ".so".

Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
2019-08-23 11:26:26 +01:00
Michal Privoznik
62c4191336 virhostdevtest: Use modern VFIO
The pci-stub is so old school that no one uses it. All modern
systems have adapted VFIO. Switch our virhostdevtest too.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Tested-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2019-08-17 12:36:11 +02:00
John Ferlan
59a3b79506 tests: Fix memory leak in mymain
Commit d2899a648 added a new exit path, but didn't free @fakerootdir.
Let's just use VIR_AUTOFREE instead to make life easier.

Found by Coverity

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2019-08-07 11:44:17 -04:00
Michal Privoznik
84d11903e1 virhostdevtest: s/CHECK_LIST_COUNT/CHECK_PCI_LIST_COUNT/
In near future we will need to check for number of members of two
different types of lists: PCI and NVMe. Rename CHECK_LIST_COUNT
to CHECK_PCI_LIST_COUNT to mark explicitly what type of list it
is working with.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
2019-08-06 11:20:44 +02:00
Michal Privoznik
d2899a6485 virhostdevtest: Don't proceed to test cases if init failed
The myInit() function is called before any of the test cases
because it prepares all internal structures for individual cases.
Well, if it fails there's no point in proceeding with testing.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
ACKed-by: Peter Krempa <pkrempa@redhat.com>
2019-08-06 11:20:39 +02:00
Daniel Henrique Barboza
39d4f78a8e tests/virhostdevtest: remove virHostdevHostSupportsPassthroughKVM
virhostdevtest is using pci mock to emulate all PCI attach/detach
operations. This means that that this test does not rely on KVM
support of the host anymore and the tests in this file shouldn't
be affected by it.

Suggested-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2019-05-04 23:39:35 +02:00
Daniel P. Berrangé
600462834f Remove all Author(s): lines from source file headers
In many files there are header comments that contain an Author:
statement, supposedly reflecting who originally wrote the code.
In a large collaborative project like libvirt, any non-trivial
file will have been modified by a large number of different
contributors. IOW, the Author: comments are quickly out of date,
omitting people who have made significant contribitions.

In some places Author: lines have been added despite the person
merely being responsible for creating the file by moving existing
code out of another file. IOW, the Author: lines give an incorrect
record of authorship.

With this all in mind, the comments are useless as a means to identify
who to talk to about code in a particular file. Contributors will always
be better off using 'git log' and 'git blame' if they need to  find the
author of a particular bit of code.

This commit thus deletes all Author: comments from the source and adds
a rule to prevent them reappearing.

The Copyright headers are similarly misleading and inaccurate, however,
we cannot delete these as they have legal meaning, despite being largely
inaccurate. In addition only the copyright holder is permitted to change
their respective copyright statement.

Reviewed-by: Erik Skultety <eskultet@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2018-12-13 16:08:38 +00:00
Erik Skultety
5165ff0971 src: More cleanup of some system headers already contained in internal.h
All of the ones being removed are pulled in by internal.h. The only
exception is sanlock which expects the application to include <stdint.h>
before sanlock's headers, because sanlock prototypes use fixed width
int, but they don't include stdint.h themselves, so we have to leave
that one in place.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Acked-by: Michal Privoznik <mprivozn@redhat.com>
2018-09-20 10:16:39 +02:00
Erik Skultety
9403b63102 internal: Move <stdio.h> include to internal.h
It doesn't really make sense for us to have stdlib.h and string.h but
not stdio.h in the internal.h header.

Signed-off-by: Erik Skultety <eskultet@redhat.com>
Acked-by: Michal Privoznik <mprivozn@redhat.com>
2018-09-20 10:16:38 +02:00
John Ferlan
1d9108cf16 qemu: Remove private hostdev
Since it's not longer used to shuttle the @secinfo, let's remove
the private hostdev completely.
2017-11-24 11:47:26 -05:00
Andrea Bolognani
3e7db8d3e8 Remove backslash alignment attempts
Right-aligning backslashes when defining macros or using complex
commands in Makefiles looks cute, but as soon as any changes is
required to the code you end up with either distractingly broken
alignment or unnecessarily big diffs where most of the changes
are just pushing all backslashes a few characters to one side.

Generated using

  $ git grep -El '[[:blank:]][[:blank:]]\\$' | \
    grep -E '*\.([chx]|am|mk)$$' | \
    while read f; do \
      sed -Ei 's/[[:blank:]]*[[:blank:]]\\$/ \\/g' "$f"; \
    done

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2017-11-03 13:24:12 +01:00
Michal Privoznik
e02b5722ed virhostdevtest: Don't leak @mgr->activeSCSIHostdevs
So the hostdev manager has some lists to keep track which devices
are active (=assigned to a domain) or inactive. The manager and
its lists are allocated in myInit and freed in myCleanup but one
of them (activeSCSIHostdevs) was missing. Also, the order in
which the cleanup was done doesn't make it easy to spot it,
therefore reoder it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-08-10 11:22:27 +02:00
Andrea Bolognani
1d0c6f59b6 conf: Rename virDomainHostdevDefAlloc() to virDomainHostdevDefNew()
All other virDomain*Def follow this naming convention for
their allocation function.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2017-07-21 17:03:43 +02:00
Andrea Bolognani
4ceac4bf29 tests: Rename VIRT_TEST_* macros to VIR_TEST_*
We use the "vir" prefix pretty consistently in our
APIs, both external and internal, which made these
macros stood out.
2017-04-04 17:30:03 +02:00
Tomáš Ryšavý
cd7dd1508d tests: Rename virtTestRun to virTestRun.
This function doesn't follow our convention of naming functions.
2016-06-08 11:23:12 -04:00
John Ferlan
27726d8c21 qemu: Introduce qemuDomainHostdevPrivatePtr
Modeled after the qemuDomainDiskPrivatePtr logic, create a privateData
pointer in the _virDomainHostdevDef to allow storage of private data
for a hypervisor in order to at least temporarily store auth/secrets
data for usage during qemuBuildCommandLine.

NB: Since the qemu_parse_command (qemuParseCommandLine) code is not
expecting to restore the auth/secret data, there's no need to add
code to handle this new structure there.

Updated copyrights for modules touched. Some didn't have updates in a
couple years even though changes have been made.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-05-02 06:10:19 -04:00
Andrea Bolognani
ee07c9802b tests: hostdev: Add more tests
Ensure the code behaves properly even for situations that were not
being considered before, such as simply detaching devices from the
host without attaching them to a guest and attaching devices as
managed even though they had already been manually detached from
the host.
2016-03-23 11:38:20 +01:00
Andrea Bolognani
3632185617 tests: hostdev: Group test cases
Instead of considering each single step its own test case, create
high level test cases that reproduce a certain scenario.
2016-03-08 10:42:25 +01:00
Andrea Bolognani
f8388cdce4 tests: hostdev: Add more checks on list size
Always call CHECK_LIST_COUNT() to check the size of both the active
and inactive devices list.
2016-03-08 10:42:25 +01:00
Andrea Bolognani
4a9ea5048c tests: hostdev: Use size_t for count variables
virPCIDeviceListCount()'s return type is size_t, so variables that
store its return value should be of that type.
2016-03-08 10:42:22 +01:00
Andrea Bolognani
ff087d8dae tests: hostdev: Move variable declaration inside CHECK_LIST_COUNT()
The 'actualCount' variable, formerly just 'count', is only used
internally by the macro, so it's better to move its declaration
inside the macro as well: this way, it doesn't have to be declared
by every single user.

The new name is less generic to make clashes less likely.
2016-03-08 10:34:13 +01:00
Andrea Bolognani
dd9f8e0292 tests: hostdev: Use better variable names
Change the extremely generic count1 and count2 to the more
descriptive active_count and inactive_count.
2016-03-08 10:16:43 +01:00
Andrea Bolognani
9f506fdb6b tests: hostdev: Remove magic numbers
When checking the number of devices added to a device list, use the
nhostdevs variable instead of its value, so that the test can keep
working even if more hostdevs are added.
2016-03-08 10:16:43 +01:00
Andrea Bolognani
73fc46511b tests: Fix typo oaque -> opaque
No functional changes.
2016-02-23 10:36:13 +01:00
Andrea Bolognani
6d9cdd2a57 pci: Introduce virPCIStubDriver enumeration
This replaces the virPCIKnownStubs string array that was used
internally for stub driver validation.

Advantages:

  * possible values are well-defined
  * typos in driver names will be detected at compile time
  * avoids having several copies of the same string around
  * no error checking required when setting / getting value

The names used mirror those in the
virDomainHostdevSubsysPCIBackendType enumeration.
2015-12-21 11:17:22 +01:00
Andrea Bolognani
46468c62ff tests: Rename LIBVIRT_FAKE_SYSFS_DIR to LIBVIRT_FAKE_ROOT_DIR
The old name is no longer accurate, since now we're using its value as
the root of the fake filesystem.

No functional changes.
2015-12-09 15:22:58 +01:00
Jiri Denemark
e4ee043636 Remove new lines from log messages
VIR_DEBUG and VIR_WARN will automatically add a new line to the message,
having "\n" at the end or at the beginning of the message results in
empty lines.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2015-11-04 13:09:35 +01:00
John Ferlan
b421a70811 virfile: Check for existence of dir in virFileDeleteTree
Commit id 'f1f68ca33' added code to remove the directory paths for
auto-generated sockets, but that code could be called before the
paths were created resulting in generating error messages from
virFileDeleteTree indicating that the file doesn't exist.

Rather than "enforce" all callers to make the non-NULL and existence
checks, modify the virFileDeleteTree API to silently ignore NULL on
input and non-existent directory trees.
2015-09-16 11:23:16 -04:00
Eric Blake
a396c11e92 maint: avoid static zero init in tests
C guarantees that static variables are zero-initialized.  Some older
compilers (and also gcc -fno-zero-initialized-in-bss) create larger
binaries if you explicitly zero-initialize a static variable.

* tests/eventtest.c: Fix initialization.
* tests/testutils.c: Likewise.
* tests/virhostdevtest.c: Likewise.
* tests/virportallocatortest.c: Likewise.
* tests/virscsitest.c: Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-10-29 09:55:09 -06:00
Martin Kletzander
fbcd9d3252 tests: remove hostdevmgr directory on cleanup
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2014-04-28 22:58:10 +02:00
Ján Tomko
2dcdb7f654 Indent top-level labels by one space in tests/ 2014-03-25 14:58:41 +01:00
Daniel P. Berrange
2835c1e730 Add virLogSource variables to all source files
Any source file which calls the logging APIs now needs
to have a VIR_LOG_INIT("source.name") declaration at
the start of the file. This provides a static variable
of the virLogSource type.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-03-18 14:29:22 +00:00
Martin Kletzander
cc9c62fef9 Require spaces around equality comparisons
Commit a1cbe4b5 added a check for spaces around assignments and this
patch extends it to checks for spaces around '=='.  One exception is
virAssertCmpInt where comma after '==' is acceptable (since it is a
macro and '==' is its argument).

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2014-03-18 11:29:44 +01:00
Chunyan Liu
cd618e0212 add unit test for new virhostdev common library
Add unit test for hostdev common library. Current tests are based on virpcimock.
2014-03-12 17:03:16 +00:00