summaryrefslogtreecommitdiff
path: root/tests/virhostdevtest.c
Commit message (Collapse)AuthorAgeFilesLines
* tests: Move fakerootdir handling to common logicAndrea Bolognani2023-03-031-7/+0
| | | | | | | | | | | | | | | | | Instead of having each test manually initialize and cleanup its own fakerootdir, do that as part of the common test initialization logic in virTestMain(). In most cases we can simply drop the relevant code from the test program, but scsihosttest uses the value of fakerootdir as a starting point to build another path, so we need to do things slightly differently. In order to keep things working, we retrieve the value from the LIBVIRT_FAKE_ROOT_DIR environment variable, same as all the mock libraries are already doing. Signed-off-by: Andrea Bolognani <abologna@redhat.com> Reviewed-by: Laine Stump <laine@redhat.com>
* tests: Adopt fakerootdir helpersAndrea Bolognani2023-03-031-13/+4
| | | | | | | | | | | Most replacements are completely straightforward but vircgrouptest requires slightly different handling because, instead of initializing a single fakerootdir at the start of the test program and cleaning it up at the end, it creates multiple different ones one after the other. Signed-off-by: Andrea Bolognani <abologna@redhat.com> Reviewed-by: Laine Stump <laine@redhat.com>
* virhostdevtest: Decrease possibility of uninitialized @subsysMichal Privoznik2023-02-061-10/+10
| | | | | | | | | | | | | | | With the current way the myInit() is written, it's fairly easy to miss initialization of @subsys variable as the variable is allocated firstly on the stack and then it's assigned to hostdev[i] which was allocated using g_new0() (this it is containing nothing but all zeroes). Make the subsys point to the corresponding member in hostdev[i] from the start. This way only the important bits are overwritten and the rest stays initialized to zero. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
* virhostdevtest: Initialize hostdev @subsysMichal Privoznik2023-02-061-1/+1
| | | | | | | | | | | | With recent work on storing original PCI stats in _virDomainHostdevSubsysPCI struct, the virhostdevtest can across a latent bug we had. Only some parts of the virDomainHostdevSubsys structure are initialized. Incidentally, subsys->u.pci.origstates is not one of them. This lead to unexpected crashes at runtime. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
* lib: Drop internal virXXXPtr typedefsMichal Privoznik2021-04-131-4/+4
| | | | | | | | | | | | | | | | | | | | | | Historically, we declared pointer type to our types: typedef struct _virXXX virXXX; typedef virXXX *virXXXPtr; But usefulness of such declaration is questionable, at best. Unfortunately, we can't drop every such declaration - we have to carry some over, because they are part of public API (e.g. virDomainPtr). But for internal types - we can do drop them and use what every other C project uses 'virXXX *'. This change was generated by a very ugly shell script that generated sed script which was then called over each file in the repository. For the shell script refer to the cover letter: https://listman.redhat.com/archives/libvir-list/2021-March/msg00537.html Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
* lib: Replace virFileMakePath() with g_mkdir_with_parents()Michal Privoznik2021-03-041-1/+1
| | | | | | | | | | | | | | | | | Generated using the following spatch: @@ expression path; @@ - virFileMakePath(path) + g_mkdir_with_parents(path, 0777) However, 14 occurrences were not replaced, e.g. in virHostdevManagerNew(). I don't really understand why. Fixed by hand afterwards. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
* hostdevmgr: remove unneeded oldStateDirLaine Stump2021-02-021-5/+5
| | | | | | | | | | | | | | | | | | Back in commit 2c71d3826, which appeared in libvirt-1.2.3 in April 2014, the location used to store saved MAC addresses and vlan tags of SRIOV VFs was changed from /var/run/libvirt/qemu to /var/run/libvirt/hostdevmgr. For backward compatibility the code was made to continue looking in the old location for the files when it didn't find them in the new location. It's now been 6 years, and even if there was somebody still running libvirt-1.2.3 on their system, that system would now be out of support for libvirt, so there would be no way for them to upgrade to a new libvirt that no longer looks in "oldStateDir" for the files. So let's no longer look in "oldStateDir" for the files! Signed-off-by: Laine Stump <laine@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* virpci.c: simplify virPCIDeviceNew() signatureDaniel Henrique Barboza2021-01-291-1/+2
| | | | | | | | | | | | | | | | | | | | | | | The current virPCIDeviceNew() signature, receiving 4 uints in sequence (domain, bus, slot, function), is not neat. We already have a way to represent a PCI address in virPCIDeviceAddress that is used in the code. Aside from the test files, most of virPCIDeviceNew() callers have access to a virPCIDeviceAddress reference, but then we need to retrieve the 4 required uints (addr.domain, addr.bus, addr.slot, addr.function) to satisfy virPCIDeviceNew(). The result is that we have extra verbosity/boilerplate to retrieve an information that is already available in virPCIDeviceAddress. A better way is presented by virNVMEDeviceNew(), where the caller just supplies a virPCIDeviceAddress pointer and the function handles the details internally. This patch changes virPCIDeviceNew() to receive a virPCIDeviceAddress pointer instead of 4 uints. Reviewed-by: Laine Stump <laine@redhat.com> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
* tests: use g_new0 instead of VIR_ALLOCJán Tomko2020-09-231-2/+1
| | | | | Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
* tests: Introduce virhostdevmockAndrea Bolognani2020-05-061-1/+3
| | | | | | | | | | | | | | | | | We need this for all tests that use virHostdevManager, because during creation of this object for unprivileged connections like those used in the test suite we would end up writing inside the user's home directory. That's bad manners in general, but when running the test suite inside a purposefully constrained environment such as the one exposed by pbuilder, it turns into an outright test failure: Could not initialize HostdevManager - operation failed: Failed to create state dir '/nonexistent/.cache/libvirt/hostdevmgr' Signed-off-by: Andrea Bolognani <abologna@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* tests: remove unneeded labelsDaniel Henrique Barboza2020-01-071-9/+5
| | | | | Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
* src: switch to use g_setenv/g_unsetenvDaniel P. Berrangé2020-01-031-1/+1
| | | | | | | | | Eliminate direct use of normal setenv/unsetenv calls in favour of GLib's wrapper. This eliminates two gnulib modules Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
* virhostdevtest: Test virNVMeDevice assignmentMichal Privoznik2019-12-171-0/+97
| | | | | | Signed-off-by: Michal Privoznik <mprivozn@redhat.com> ACKed-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Cole Robinson <crobinso@redhat.com>
* Use g_mkdtemp instead of mkdtempJán Tomko2019-11-141-1/+1
| | | | | | | Prefer the GLib version to the one from gnulib. Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
* tests: use g_strdup instead of VIR_STRDUPJán Tomko2019-10-211-6/+2
| | | | | | | | | | | Replace all occurrences of if (VIR_STRDUP(a, b) < 0) /* effectively dead code */ with: a = g_strdup(b); Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* Use g_autofree instead of VIR_AUTOFREEJán Tomko2019-10-161-1/+1
| | | | | | | | | | | Since commit 44e7f029159ed701b4a1739ac711507ee53790ed util: rewrite auto cleanup macros to use glib's equivalent VIR_AUTOFREE is just an alias for g_autofree. Use the GLib macros directly instead of our custom aliases. Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* tests: use G_GNUC_UNUSEDJán Tomko2019-10-151-5/+5
| | | | | | | Use G_GNUC_UNUSED from GLib instead of ATTRIBUTE_UNUSED. Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* virhostdevtest: Reset libvirt error on expected failureMichal Privoznik2019-08-271-0/+6
| | | | | | | | | | | | | 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>
* virhostdevtest: s/VIR_DEBUG/VIR_TEST_DEBUG/Michal Privoznik2019-08-271-17/+17
| | | | | | | 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>
* virhostdevtest: Drop useless VIR_TEST_DEBUGMichal Privoznik2019-08-271-1/+0
| | | | | | | The virTestRun() already reports the same. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
* virhostdevtest: Drop most of 'cleanup' and 'out' labelsMichal Privoznik2019-08-271-105/+42
| | | | | | | | | | | | 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>
* virhostdevtest: Check for integer retval in more verbose wayMichal Privoznik2019-08-271-12/+12
| | | | | | | | | | 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>
* tests: Add lib- prefix to all mocksRoman Bolshakov2019-08-231-1/+1
| | | | | | | | | | | | | 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>
* virhostdevtest: Use modern VFIOMichal Privoznik2019-08-171-2/+2
| | | | | | | | | 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>
* tests: Fix memory leak in mymainJohn Ferlan2019-08-071-3/+1
| | | | | | | | | | 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>
* virhostdevtest: s/CHECK_LIST_COUNT/CHECK_PCI_LIST_COUNT/Michal Privoznik2019-08-061-40/+43
| | | | | | | | | | 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>
* virhostdevtest: Don't proceed to test cases if init failedMichal Privoznik2019-08-061-1/+4
| | | | | | | | | 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>
* tests/virhostdevtest: remove virHostdevHostSupportsPassthroughKVMDaniel Henrique Barboza2019-05-041-49/+12
| | | | | | | | | | 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>
* Remove all Author(s): lines from source file headersDaniel P. Berrangé2018-12-131-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* src: More cleanup of some system headers already contained in internal.hErik Skultety2018-09-201-1/+0
| | | | | | | | | | | 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>
* internal: Move <stdio.h> include to internal.hErik Skultety2018-09-201-1/+0
| | | | | | | | 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>
* qemu: Remove private hostdevJohn Ferlan2017-11-241-1/+1
| | | | | Since it's not longer used to shuttle the @secinfo, let's remove the private hostdev completely.
* Remove backslash alignment attemptsAndrea Bolognani2017-11-031-14/+14
| | | | | | | | | | | | | | | | | | 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>
* virhostdevtest: Don't leak @mgr->activeSCSIHostdevsMichal Privoznik2017-08-101-1/+2
| | | | | | | | | | | 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>
* conf: Rename virDomainHostdevDefAlloc() to virDomainHostdevDefNew()Andrea Bolognani2017-07-211-1/+1
| | | | | | | All other virDomain*Def follow this naming convention for their allocation function. Signed-off-by: Andrea Bolognani <abologna@redhat.com>
* tests: Rename VIRT_TEST_* macros to VIR_TEST_*Andrea Bolognani2017-04-041-1/+1
| | | | | | We use the "vir" prefix pretty consistently in our APIs, both external and internal, which made these macros stood out.
* tests: Rename virtTestRun to virTestRun.Tomáš Ryšavý2016-06-081-1/+1
| | | | This function doesn't follow our convention of naming functions.
* qemu: Introduce qemuDomainHostdevPrivatePtrJohn Ferlan2016-05-021-1/+2
| | | | | | | | | | | | | | | | 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>
* tests: hostdev: Add more testsAndrea Bolognani2016-03-231-6/+78
| | | | | | | | 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.
* tests: hostdev: Group test casesAndrea Bolognani2016-03-081-22/+97
| | | | | Instead of considering each single step its own test case, create high level test cases that reproduce a certain scenario.
* tests: hostdev: Add more checks on list sizeAndrea Bolognani2016-03-081-6/+28
| | | | | Always call CHECK_LIST_COUNT() to check the size of both the active and inactive devices list.
* tests: hostdev: Use size_t for count variablesAndrea Bolognani2016-03-081-15/+9
| | | | | virPCIDeviceListCount()'s return type is size_t, so variables that store its return value should be of that type.
* tests: hostdev: Move variable declaration inside CHECK_LIST_COUNT()Andrea Bolognani2016-03-081-14/+17
| | | | | | | | | 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.
* tests: hostdev: Use better variable namesAndrea Bolognani2016-03-081-41/+41
| | | | | Change the extremely generic count1 and count2 to the more descriptive active_count and inactive_count.
* tests: hostdev: Remove magic numbersAndrea Bolognani2016-03-081-7/+7
| | | | | | 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.
* tests: Fix typo oaque -> opaqueAndrea Bolognani2016-02-231-8/+8
| | | | No functional changes.
* pci: Introduce virPCIStubDriver enumerationAndrea Bolognani2015-12-211-2/+3
| | | | | | | | | | | | | | | 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.
* tests: Rename LIBVIRT_FAKE_SYSFS_DIR to LIBVIRT_FAKE_ROOT_DIRAndrea Bolognani2015-12-091-8/+8
| | | | | | | The old name is no longer accurate, since now we're using its value as the root of the fake filesystem. No functional changes.
* Remove new lines from log messagesJiri Denemark2015-11-041-18/+18
| | | | | | | | 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>
* virfile: Check for existence of dir in virFileDeleteTreeJohn Ferlan2015-09-161-1/+1
| | | | | | | | | | | 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.