12 # include "internal.h"
13 # include "conf/domain_conf.h"
14 # include "qemu/qemu_domain.h"
16 # include "testutilsqemu.h"
18 # define VIR_FROM_THIS VIR_FROM_QEMU
20 static virQEMUDriver driver
;
24 unsigned long long memlock
;
28 testCompareMemLock(const void *data
)
30 const struct testInfo
*info
= data
;
31 g_autoptr(virDomainDef
) def
= NULL
;
32 g_autofree
char *xml
= NULL
;
34 xml
= g_strdup_printf("%s/qemumemlockdata/qemumemlock-%s.xml", abs_srcdir
,
37 if (!(def
= virDomainDefParseFile(xml
, driver
.xmlopt
, NULL
,
38 VIR_DOMAIN_DEF_PARSE_INACTIVE
))) {
42 return virTestCompareToULL(info
->memlock
, qemuDomainGetMemLockLimitBytes(def
));
48 g_autoptr(GHashTable
) capslatest
= testQemuGetLatestCaps();
49 g_autoptr(GHashTable
) capscache
= virHashNew(virObjectUnref
);
52 if (qemuTestDriverInit(&driver
) < 0)
55 # define DO_TEST(name, memlock) \
57 static struct testInfo info = { \
60 if (virTestRun("QEMU MEMLOCK " name, testCompareMemLock, &info) < 0) \
64 /* The tests below make sure that the memory locking limit is being
65 * calculated correctly in a number of situations. Each test is
66 * performed both on x86_64/pc and ppc64/pseries in order to account
67 * for some architecture-specific details.
69 * kvm: simple KMV guest
70 * tcg: simple TCG guest
72 * hardlimit: guest where <memtune><hard_limit> has been configured
73 * locked: guest where <memoryBacking><locked> has been enabled
74 * hostdev: guest that has some hostdev assigned
76 * The remaining tests cover different combinations of the above to
77 * ensure settings are prioritized as expected.
80 qemuTestSetHostArch(&driver
, VIR_ARCH_X86_64
);
82 if (testQemuInsertRealCaps(driver
.qemuCapsCache
, "x86_64", "latest", "",
83 capslatest
, capscache
, NULL
, NULL
) < 0) {
91 DO_TEST("pc-hardlimit", 2147483648);
92 DO_TEST("pc-locked", VIR_DOMAIN_MEMORY_PARAM_UNLIMITED
);
93 DO_TEST("pc-hostdev", 2147483648);
94 DO_TEST("pc-hostdev-nvme", 3221225472);
96 DO_TEST("pc-hardlimit+locked", 2147483648);
97 DO_TEST("pc-hardlimit+hostdev", 2147483648);
98 DO_TEST("pc-hardlimit+locked+hostdev", 2147483648);
99 DO_TEST("pc-locked+hostdev", VIR_DOMAIN_MEMORY_PARAM_UNLIMITED
);
101 qemuTestSetHostArch(&driver
, VIR_ARCH_PPC64
);
103 if (testQemuInsertRealCaps(driver
.qemuCapsCache
, "ppc64", "latest", "",
104 capslatest
, capscache
, NULL
, NULL
) < 0) {
109 DO_TEST("pseries-kvm", 20971520);
110 DO_TEST("pseries-tcg", 0);
112 DO_TEST("pseries-hardlimit", 2147483648);
113 DO_TEST("pseries-locked", VIR_DOMAIN_MEMORY_PARAM_UNLIMITED
);
114 DO_TEST("pseries-hostdev", 4320133120);
116 DO_TEST("pseries-hardlimit+locked", 2147483648);
117 DO_TEST("pseries-hardlimit+hostdev", 2147483648);
118 DO_TEST("pseries-hardlimit+locked+hostdev", 2147483648);
119 DO_TEST("pseries-locked+hostdev", VIR_DOMAIN_MEMORY_PARAM_UNLIMITED
);
122 qemuTestDriverFree(&driver
);
124 return ret
== 0 ? EXIT_SUCCESS
: EXIT_FAILURE
;
127 VIR_TEST_MAIN_PRELOAD(mymain
,
128 VIR_TEST_MOCK("virpci"),
129 VIR_TEST_MOCK("domaincaps"))
139 #endif /* WITH_QEMU */