2017-03-23 13:06:57 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
#include "testutils.h"
|
|
|
|
|
|
|
|
#ifdef WITH_QEMU
|
|
|
|
|
|
|
|
# include "datatypes.h"
|
|
|
|
# include "internal.h"
|
|
|
|
# include "virstring.h"
|
|
|
|
# include "conf/domain_conf.h"
|
|
|
|
# include "qemu/qemu_domain.h"
|
|
|
|
|
|
|
|
# include "testutilsqemu.h"
|
|
|
|
|
|
|
|
# define VIR_FROM_THIS VIR_FROM_QEMU
|
|
|
|
|
|
|
|
static virQEMUDriver driver;
|
|
|
|
|
|
|
|
struct testInfo {
|
|
|
|
const char *name;
|
|
|
|
unsigned long long memlock;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
testCompareMemLock(const void *data)
|
|
|
|
{
|
|
|
|
const struct testInfo *info = data;
|
|
|
|
virDomainDefPtr def = NULL;
|
|
|
|
char *xml = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
2019-10-22 13:26:14 +00:00
|
|
|
xml = g_strdup_printf("%s/qemumemlockdata/qemumemlock-%s.xml", abs_srcdir,
|
|
|
|
info->name);
|
2017-03-23 13:06:57 +00:00
|
|
|
|
2019-11-27 12:29:21 +00:00
|
|
|
if (!(def = virDomainDefParseFile(xml, driver.xmlopt, NULL,
|
2017-03-23 13:06:57 +00:00
|
|
|
VIR_DOMAIN_DEF_PARSE_INACTIVE))) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2019-09-26 11:15:47 +00:00
|
|
|
ret = virTestCompareToULL(info->memlock, qemuDomainGetMemLockLimitBytes(def, false));
|
2017-03-23 13:06:57 +00:00
|
|
|
|
|
|
|
cleanup:
|
2017-08-10 06:25:04 +00:00
|
|
|
virDomainDefFree(def);
|
2017-03-23 13:06:57 +00:00
|
|
|
VIR_FREE(xml);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-06-01 16:48:52 +00:00
|
|
|
# define FAKEROOTDIRTEMPLATE abs_builddir "/fakerootdir-XXXXXX"
|
2017-03-23 13:06:57 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
mymain(void)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
2017-06-01 16:48:52 +00:00
|
|
|
char *fakerootdir;
|
2017-11-28 21:00:52 +00:00
|
|
|
virQEMUCapsPtr qemuCaps = NULL;
|
2017-06-01 16:48:52 +00:00
|
|
|
|
2019-10-20 11:49:46 +00:00
|
|
|
fakerootdir = g_strdup(FAKEROOTDIRTEMPLATE);
|
2017-06-01 16:48:52 +00:00
|
|
|
|
2019-11-13 21:35:47 +00:00
|
|
|
if (!g_mkdtemp(fakerootdir)) {
|
2017-06-01 16:48:52 +00:00
|
|
|
fprintf(stderr, "Cannot create fakerootdir");
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
setenv("LIBVIRT_FAKE_ROOT_DIR", fakerootdir, 1);
|
2017-03-23 13:06:57 +00:00
|
|
|
|
2017-07-20 10:46:41 +00:00
|
|
|
if (qemuTestDriverInit(&driver) < 0) {
|
|
|
|
VIR_FREE(fakerootdir);
|
2017-03-23 13:06:57 +00:00
|
|
|
return EXIT_FAILURE;
|
2017-07-20 10:46:41 +00:00
|
|
|
}
|
2017-03-23 13:06:57 +00:00
|
|
|
|
|
|
|
driver.privileged = true;
|
|
|
|
|
|
|
|
# define DO_TEST(name, memlock) \
|
|
|
|
do { \
|
|
|
|
static struct testInfo info = { \
|
|
|
|
name, memlock \
|
|
|
|
}; \
|
|
|
|
if (virTestRun("QEMU MEMLOCK " name, testCompareMemLock, &info) < 0) \
|
|
|
|
ret = -1; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/* The tests below make sure that the memory locking limit is being
|
|
|
|
* calculated correctly in a number of situations. Each test is
|
|
|
|
* performed both on x86_64/pc and ppc64/pseries in order to account
|
|
|
|
* for some architecture-specific details.
|
|
|
|
*
|
|
|
|
* kvm: simple KMV guest
|
|
|
|
* tcg: simple TCG guest
|
|
|
|
*
|
|
|
|
* hardlimit: guest where <memtune><hard_limit> has been configured
|
|
|
|
* locked: guest where <memoryBacking><locked> has been enabled
|
|
|
|
* hostdev: guest that has some hostdev assigned
|
|
|
|
*
|
|
|
|
* The remaining tests cover different combinations of the above to
|
|
|
|
* ensure settings are prioritized as expected.
|
|
|
|
*/
|
|
|
|
|
2019-11-26 17:51:22 +00:00
|
|
|
qemuTestSetHostArch(&driver, VIR_ARCH_X86_64);
|
2017-03-23 13:06:57 +00:00
|
|
|
|
|
|
|
DO_TEST("pc-kvm", 0);
|
|
|
|
DO_TEST("pc-tcg", 0);
|
|
|
|
|
2019-12-09 23:15:18 +00:00
|
|
|
if (!(qemuCaps = virQEMUCapsNew())) {
|
|
|
|
ret = -1;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI);
|
|
|
|
|
|
|
|
if (qemuTestCapsCacheInsert(driver.qemuCapsCache, qemuCaps) < 0) {
|
|
|
|
ret = -1;
|
|
|
|
goto cleanup;
|
|
|
|
};
|
|
|
|
|
2017-03-23 13:06:57 +00:00
|
|
|
DO_TEST("pc-hardlimit", 2147483648);
|
|
|
|
DO_TEST("pc-locked", VIR_DOMAIN_MEMORY_PARAM_UNLIMITED);
|
|
|
|
DO_TEST("pc-hostdev", 2147483648);
|
|
|
|
|
|
|
|
DO_TEST("pc-hardlimit+locked", 2147483648);
|
|
|
|
DO_TEST("pc-hardlimit+hostdev", 2147483648);
|
|
|
|
DO_TEST("pc-hardlimit+locked+hostdev", 2147483648);
|
|
|
|
DO_TEST("pc-locked+hostdev", VIR_DOMAIN_MEMORY_PARAM_UNLIMITED);
|
|
|
|
|
2019-11-26 17:51:22 +00:00
|
|
|
qemuTestSetHostArch(&driver, VIR_ARCH_PPC64);
|
2017-11-28 21:00:52 +00:00
|
|
|
|
|
|
|
virQEMUCapsSet(qemuCaps, QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE);
|
|
|
|
if (qemuTestCapsCacheInsert(driver.qemuCapsCache, qemuCaps) < 0) {
|
|
|
|
ret = -1;
|
|
|
|
goto cleanup;
|
|
|
|
};
|
2017-03-23 13:06:57 +00:00
|
|
|
|
|
|
|
DO_TEST("pseries-kvm", 20971520);
|
|
|
|
DO_TEST("pseries-tcg", 0);
|
|
|
|
|
|
|
|
DO_TEST("pseries-hardlimit", 2147483648);
|
|
|
|
DO_TEST("pseries-locked", VIR_DOMAIN_MEMORY_PARAM_UNLIMITED);
|
2017-06-02 13:19:04 +00:00
|
|
|
DO_TEST("pseries-hostdev", 4320133120);
|
2017-03-23 13:06:57 +00:00
|
|
|
|
|
|
|
DO_TEST("pseries-hardlimit+locked", 2147483648);
|
|
|
|
DO_TEST("pseries-hardlimit+hostdev", 2147483648);
|
|
|
|
DO_TEST("pseries-hardlimit+locked+hostdev", 2147483648);
|
|
|
|
DO_TEST("pseries-locked+hostdev", VIR_DOMAIN_MEMORY_PARAM_UNLIMITED);
|
|
|
|
|
2017-11-28 21:00:52 +00:00
|
|
|
cleanup:
|
|
|
|
virObjectUnref(qemuCaps);
|
|
|
|
|
2017-06-01 16:48:52 +00:00
|
|
|
if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
|
|
|
|
virFileDeleteTree(fakerootdir);
|
|
|
|
|
2017-03-23 13:06:57 +00:00
|
|
|
qemuTestDriverFree(&driver);
|
2017-06-01 16:48:52 +00:00
|
|
|
VIR_FREE(fakerootdir);
|
2017-03-23 13:06:57 +00:00
|
|
|
|
|
|
|
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
|
2019-11-15 10:56:46 +00:00
|
|
|
VIR_TEST_MAIN_PRELOAD(mymain,
|
|
|
|
VIR_TEST_MOCK("virpci"),
|
|
|
|
VIR_TEST_MOCK("domaincaps"))
|
2017-03-23 13:06:57 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
|
|
|
return EXIT_AM_SKIP;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* WITH_QEMU */
|