2018-12-13 21:32:06 +08:00
|
|
|
/*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2008-05-17 00:51:30 +08:00
|
|
|
|
2019-06-19 00:13:14 +08:00
|
|
|
#pragma once
|
2018-12-13 21:32:06 +08:00
|
|
|
|
2019-06-19 00:13:14 +08:00
|
|
|
#ifdef WITH_QEMU
|
2018-12-13 21:32:06 +08:00
|
|
|
|
2019-06-19 00:13:14 +08:00
|
|
|
# include "capabilities.h"
|
|
|
|
# include "virfilecache.h"
|
|
|
|
# include "domain_conf.h"
|
|
|
|
# include "qemu/qemu_capabilities.h"
|
|
|
|
# include "qemu/qemu_conf.h"
|
2008-05-17 00:51:30 +08:00
|
|
|
|
2019-06-19 00:13:14 +08:00
|
|
|
# define TEST_QEMU_CAPS_PATH abs_srcdir "/qemucapabilitiesdata"
|
2022-07-20 15:51:55 +08:00
|
|
|
# define TEST_TPM_ENV_VAR "VIR_TEST_MOCK_FAKE_TPM_VERSION"
|
|
|
|
# define TPM_VER_1_2 "1.2"
|
|
|
|
# define TPM_VER_2_0 "2.0"
|
2019-04-16 18:22:31 +08:00
|
|
|
|
2016-05-10 17:35:43 +08:00
|
|
|
enum {
|
|
|
|
GIC_NONE = 0,
|
|
|
|
GIC_V2,
|
|
|
|
GIC_V3,
|
|
|
|
GIC_BOTH,
|
|
|
|
};
|
|
|
|
|
2019-03-31 23:49:34 +08:00
|
|
|
typedef enum {
|
2021-08-17 19:51:11 +08:00
|
|
|
ARG_QEMU_CAPS = QEMU_CAPS_LAST + 1,
|
2023-03-03 20:11:51 +08:00
|
|
|
ARG_QEMU_CAPS_DEL,
|
2019-03-31 23:49:34 +08:00
|
|
|
ARG_GIC,
|
|
|
|
ARG_MIGRATE_FROM,
|
|
|
|
ARG_MIGRATE_FD,
|
|
|
|
ARG_FLAGS,
|
|
|
|
ARG_PARSEFLAGS,
|
|
|
|
ARG_CAPS_ARCH,
|
|
|
|
ARG_CAPS_VER,
|
2023-03-09 00:23:05 +08:00
|
|
|
ARG_CAPS_VARIANT,
|
testutilsqemu: introduce ARG_CAPS_HOST_CPU_MODEL
When loading a latest caps for an arch for the first time the following
occurs in testQemuInfoInitArgs():
- the caps file is located. It's not in the cache since it's the first time
it's being read;
- the cachecaps are retrieved using qemuTestParseCapabilitiesArch() and
stored in the capscache;
- FLAG_REAL_CAPS is set and regular flow continues.
Loading the same latest caps for the second time the caps are loaded from the
cache, skipping qemuTestParseCapabilitiesArch(). By skipping this function it
means that it also skips virQEMUCapsLoadCache() and, more relevant to
our case, virQEMUCapsInitHostCPUModel(). This function will use the
current arch and cpuModel settings to write the qemuCaps that are being
stored in the cache. And we're also setting FLAG_REAL_CAPS, meaning that
we won't be updating the qemucaps host model via testUpdateQEMUCaps() as
well.
This has side-effects such as:
- the first time the latest caps for an arch is loaded determines the
cpuModel it'll use during the current qemuxml2argvtest run. For
example, when running all tests, the first time the latest ppc64 caps
are read is on "disk-floppy-pseries" test. Since the current host arch
at this point is x86_64, the cpuModel that will be set for this
capability is "core2duo";
- every other latest arch test will use the same hostCPU as the first
one set since we read it from the cache after the first run.
qemuTestSetHostCPU() makes no difference because we won't update the
host model due to FLAG_REAL_CAPS being set. Using the previous example,
every other latest ppc64 test that will be run will be using the
"core2duo" cpuModel.
Using fake capabilities (e.g. using DO_TEST()) prevents FLAG_REAL_CAPS to
be set, meaning that the cpuModel will be updated using the current
settings the test is being ran due to testUpdateQEMUCaps().
Note that not all latest caps arch tests care about the cpuModel being
set to an unexpected default cpuModel. But some tests will care, e.g.
"pseries-cpu-compat-power9", and changing it from DO_TEST() to
DO_TEST_CAPS_ARCH_LATEST() will make it fail every time the
"disk-floppy-pseries" is being ran first.
One way of fixing it is to rethink all the existing logic, for example
not setting FLAG_REAL_CAPS for latest arch tests. Another way is
presented here. ARGS_CAPS_HOST_CPU_MODEL is a new testQemuInfo arg that
allow us to set any specific host CPU model we want when running latest
arch caps tests. This new arg can then be used when converting existing
DO_TEST() testcases to DO_TEST_CAPS_ARCH_LATEST() that requires a
specific host CPU setting to be successful, which we're going to do in
the next patch with "pseries-cpu-compat-power9".
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-20 21:58:23 +08:00
|
|
|
ARG_CAPS_HOST_CPU_MODEL,
|
2022-10-11 21:52:54 +08:00
|
|
|
ARG_FD_GROUP, /* name, nfds, fd[0], ... fd[n-1] */
|
2019-03-31 23:49:34 +08:00
|
|
|
ARG_END,
|
|
|
|
} testQemuInfoArgName;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
FLAG_EXPECT_FAILURE = 1 << 0,
|
|
|
|
FLAG_EXPECT_PARSE_ERROR = 1 << 1,
|
2020-10-21 16:08:11 +08:00
|
|
|
FLAG_FIPS_HOST = 1 << 2, /* simulate host with FIPS mode enabled */
|
2019-03-31 23:49:34 +08:00
|
|
|
FLAG_REAL_CAPS = 1 << 3,
|
|
|
|
FLAG_SKIP_LEGACY_CPUS = 1 << 4,
|
2019-08-08 22:55:14 +08:00
|
|
|
FLAG_SLIRP_HELPER = 1 << 5,
|
2019-03-31 23:49:34 +08:00
|
|
|
} testQemuInfoFlags;
|
|
|
|
|
2021-08-17 22:26:58 +08:00
|
|
|
struct testQemuConf {
|
|
|
|
GHashTable *capscache;
|
|
|
|
GHashTable *capslatest;
|
|
|
|
GHashTable *qapiSchemaCache;
|
|
|
|
};
|
|
|
|
|
testutilsqemu: introduce ARG_CAPS_HOST_CPU_MODEL
When loading a latest caps for an arch for the first time the following
occurs in testQemuInfoInitArgs():
- the caps file is located. It's not in the cache since it's the first time
it's being read;
- the cachecaps are retrieved using qemuTestParseCapabilitiesArch() and
stored in the capscache;
- FLAG_REAL_CAPS is set and regular flow continues.
Loading the same latest caps for the second time the caps are loaded from the
cache, skipping qemuTestParseCapabilitiesArch(). By skipping this function it
means that it also skips virQEMUCapsLoadCache() and, more relevant to
our case, virQEMUCapsInitHostCPUModel(). This function will use the
current arch and cpuModel settings to write the qemuCaps that are being
stored in the cache. And we're also setting FLAG_REAL_CAPS, meaning that
we won't be updating the qemucaps host model via testUpdateQEMUCaps() as
well.
This has side-effects such as:
- the first time the latest caps for an arch is loaded determines the
cpuModel it'll use during the current qemuxml2argvtest run. For
example, when running all tests, the first time the latest ppc64 caps
are read is on "disk-floppy-pseries" test. Since the current host arch
at this point is x86_64, the cpuModel that will be set for this
capability is "core2duo";
- every other latest arch test will use the same hostCPU as the first
one set since we read it from the cache after the first run.
qemuTestSetHostCPU() makes no difference because we won't update the
host model due to FLAG_REAL_CAPS being set. Using the previous example,
every other latest ppc64 test that will be run will be using the
"core2duo" cpuModel.
Using fake capabilities (e.g. using DO_TEST()) prevents FLAG_REAL_CAPS to
be set, meaning that the cpuModel will be updated using the current
settings the test is being ran due to testUpdateQEMUCaps().
Note that not all latest caps arch tests care about the cpuModel being
set to an unexpected default cpuModel. But some tests will care, e.g.
"pseries-cpu-compat-power9", and changing it from DO_TEST() to
DO_TEST_CAPS_ARCH_LATEST() will make it fail every time the
"disk-floppy-pseries" is being ran first.
One way of fixing it is to rethink all the existing logic, for example
not setting FLAG_REAL_CAPS for latest arch tests. Another way is
presented here. ARGS_CAPS_HOST_CPU_MODEL is a new testQemuInfo arg that
allow us to set any specific host CPU model we want when running latest
arch caps tests. This new arg can then be used when converting existing
DO_TEST() testcases to DO_TEST_CAPS_ARCH_LATEST() that requires a
specific host CPU setting to be successful, which we're going to do in
the next patch with "pseries-cpu-compat-power9".
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-20 21:58:23 +08:00
|
|
|
typedef enum {
|
|
|
|
QEMU_CPU_DEF_DEFAULT,
|
|
|
|
QEMU_CPU_DEF_HASWELL,
|
|
|
|
QEMU_CPU_DEF_POWER8,
|
|
|
|
QEMU_CPU_DEF_POWER9,
|
2022-05-04 04:15:05 +08:00
|
|
|
QEMU_CPU_DEF_POWER10,
|
testutilsqemu: introduce ARG_CAPS_HOST_CPU_MODEL
When loading a latest caps for an arch for the first time the following
occurs in testQemuInfoInitArgs():
- the caps file is located. It's not in the cache since it's the first time
it's being read;
- the cachecaps are retrieved using qemuTestParseCapabilitiesArch() and
stored in the capscache;
- FLAG_REAL_CAPS is set and regular flow continues.
Loading the same latest caps for the second time the caps are loaded from the
cache, skipping qemuTestParseCapabilitiesArch(). By skipping this function it
means that it also skips virQEMUCapsLoadCache() and, more relevant to
our case, virQEMUCapsInitHostCPUModel(). This function will use the
current arch and cpuModel settings to write the qemuCaps that are being
stored in the cache. And we're also setting FLAG_REAL_CAPS, meaning that
we won't be updating the qemucaps host model via testUpdateQEMUCaps() as
well.
This has side-effects such as:
- the first time the latest caps for an arch is loaded determines the
cpuModel it'll use during the current qemuxml2argvtest run. For
example, when running all tests, the first time the latest ppc64 caps
are read is on "disk-floppy-pseries" test. Since the current host arch
at this point is x86_64, the cpuModel that will be set for this
capability is "core2duo";
- every other latest arch test will use the same hostCPU as the first
one set since we read it from the cache after the first run.
qemuTestSetHostCPU() makes no difference because we won't update the
host model due to FLAG_REAL_CAPS being set. Using the previous example,
every other latest ppc64 test that will be run will be using the
"core2duo" cpuModel.
Using fake capabilities (e.g. using DO_TEST()) prevents FLAG_REAL_CAPS to
be set, meaning that the cpuModel will be updated using the current
settings the test is being ran due to testUpdateQEMUCaps().
Note that not all latest caps arch tests care about the cpuModel being
set to an unexpected default cpuModel. But some tests will care, e.g.
"pseries-cpu-compat-power9", and changing it from DO_TEST() to
DO_TEST_CAPS_ARCH_LATEST() will make it fail every time the
"disk-floppy-pseries" is being ran first.
One way of fixing it is to rethink all the existing logic, for example
not setting FLAG_REAL_CAPS for latest arch tests. Another way is
presented here. ARGS_CAPS_HOST_CPU_MODEL is a new testQemuInfo arg that
allow us to set any specific host CPU model we want when running latest
arch caps tests. This new arg can then be used when converting existing
DO_TEST() testcases to DO_TEST_CAPS_ARCH_LATEST() that requires a
specific host CPU setting to be successful, which we're going to do in
the next patch with "pseries-cpu-compat-power9".
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-20 21:58:23 +08:00
|
|
|
} qemuTestCPUDef;
|
|
|
|
|
2021-08-17 21:30:44 +08:00
|
|
|
struct testQemuArgs {
|
|
|
|
bool newargs;
|
2023-03-03 20:07:41 +08:00
|
|
|
virBitmap *fakeCapsAdd;
|
2023-03-03 20:11:51 +08:00
|
|
|
virBitmap *fakeCapsDel;
|
2021-08-17 21:30:44 +08:00
|
|
|
char *capsver;
|
|
|
|
char *capsarch;
|
2023-03-09 00:23:05 +08:00
|
|
|
const char *capsvariant;
|
testutilsqemu: introduce ARG_CAPS_HOST_CPU_MODEL
When loading a latest caps for an arch for the first time the following
occurs in testQemuInfoInitArgs():
- the caps file is located. It's not in the cache since it's the first time
it's being read;
- the cachecaps are retrieved using qemuTestParseCapabilitiesArch() and
stored in the capscache;
- FLAG_REAL_CAPS is set and regular flow continues.
Loading the same latest caps for the second time the caps are loaded from the
cache, skipping qemuTestParseCapabilitiesArch(). By skipping this function it
means that it also skips virQEMUCapsLoadCache() and, more relevant to
our case, virQEMUCapsInitHostCPUModel(). This function will use the
current arch and cpuModel settings to write the qemuCaps that are being
stored in the cache. And we're also setting FLAG_REAL_CAPS, meaning that
we won't be updating the qemucaps host model via testUpdateQEMUCaps() as
well.
This has side-effects such as:
- the first time the latest caps for an arch is loaded determines the
cpuModel it'll use during the current qemuxml2argvtest run. For
example, when running all tests, the first time the latest ppc64 caps
are read is on "disk-floppy-pseries" test. Since the current host arch
at this point is x86_64, the cpuModel that will be set for this
capability is "core2duo";
- every other latest arch test will use the same hostCPU as the first
one set since we read it from the cache after the first run.
qemuTestSetHostCPU() makes no difference because we won't update the
host model due to FLAG_REAL_CAPS being set. Using the previous example,
every other latest ppc64 test that will be run will be using the
"core2duo" cpuModel.
Using fake capabilities (e.g. using DO_TEST()) prevents FLAG_REAL_CAPS to
be set, meaning that the cpuModel will be updated using the current
settings the test is being ran due to testUpdateQEMUCaps().
Note that not all latest caps arch tests care about the cpuModel being
set to an unexpected default cpuModel. But some tests will care, e.g.
"pseries-cpu-compat-power9", and changing it from DO_TEST() to
DO_TEST_CAPS_ARCH_LATEST() will make it fail every time the
"disk-floppy-pseries" is being ran first.
One way of fixing it is to rethink all the existing logic, for example
not setting FLAG_REAL_CAPS for latest arch tests. Another way is
presented here. ARGS_CAPS_HOST_CPU_MODEL is a new testQemuInfo arg that
allow us to set any specific host CPU model we want when running latest
arch caps tests. This new arg can then be used when converting existing
DO_TEST() testcases to DO_TEST_CAPS_ARCH_LATEST() that requires a
specific host CPU setting to be successful, which we're going to do in
the next patch with "pseries-cpu-compat-power9".
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2022-05-20 21:58:23 +08:00
|
|
|
qemuTestCPUDef capsHostCPUModel;
|
2021-08-17 21:30:44 +08:00
|
|
|
int gic;
|
2022-10-11 21:52:54 +08:00
|
|
|
GHashTable *fds;
|
2021-08-17 21:30:44 +08:00
|
|
|
bool invalidarg;
|
|
|
|
};
|
|
|
|
|
2019-03-31 23:49:34 +08:00
|
|
|
struct testQemuInfo {
|
|
|
|
const char *name;
|
|
|
|
char *infile;
|
|
|
|
char *outfile;
|
2020-09-22 19:57:39 +08:00
|
|
|
char *errfile;
|
2021-03-11 15:16:13 +08:00
|
|
|
virQEMUCaps *qemuCaps;
|
2019-03-31 23:49:34 +08:00
|
|
|
const char *migrateFrom;
|
|
|
|
int migrateFd;
|
|
|
|
unsigned int flags;
|
|
|
|
unsigned int parseFlags;
|
2019-10-24 23:51:42 +08:00
|
|
|
virArch arch;
|
2023-03-09 22:15:40 +08:00
|
|
|
GHashTable *qmpSchema; /* borrowed pointer from the cache */
|
2021-08-17 22:26:58 +08:00
|
|
|
|
2021-08-17 21:30:44 +08:00
|
|
|
struct testQemuArgs args;
|
2021-08-17 22:26:58 +08:00
|
|
|
struct testQemuConf *conf;
|
2019-03-31 23:49:34 +08:00
|
|
|
};
|
|
|
|
|
2021-03-11 15:16:13 +08:00
|
|
|
virCaps *testQemuCapsInit(void);
|
|
|
|
virDomainXMLOption *testQemuXMLConfInit(void);
|
2014-06-27 22:39:27 +08:00
|
|
|
|
2018-04-04 15:17:52 +08:00
|
|
|
|
2021-03-11 15:16:13 +08:00
|
|
|
virQEMUCaps *qemuTestParseCapabilitiesArch(virArch arch,
|
2018-04-04 15:17:52 +08:00
|
|
|
const char *capsFile);
|
2022-05-05 22:27:55 +08:00
|
|
|
virCPUDef *qemuTestGetCPUDef(qemuTestCPUDef d);
|
2016-08-04 19:16:55 +08:00
|
|
|
|
2021-03-11 15:16:13 +08:00
|
|
|
void qemuTestSetHostArch(virQEMUDriver *driver,
|
2019-11-27 01:51:22 +08:00
|
|
|
virArch arch);
|
2021-03-11 15:16:13 +08:00
|
|
|
void qemuTestSetHostCPU(virQEMUDriver *driver,
|
2019-11-29 18:40:39 +08:00
|
|
|
virArch arch,
|
2021-03-11 15:16:13 +08:00
|
|
|
virCPUDef *cpu);
|
2015-03-24 00:19:28 +08:00
|
|
|
|
2015-09-15 14:16:02 +08:00
|
|
|
int qemuTestDriverInit(virQEMUDriver *driver);
|
|
|
|
void qemuTestDriverFree(virQEMUDriver *driver);
|
2021-03-11 15:16:13 +08:00
|
|
|
int qemuTestCapsCacheInsert(virFileCache *cache,
|
|
|
|
virQEMUCaps *caps);
|
2015-09-09 22:03:14 +08:00
|
|
|
|
2021-03-11 15:16:13 +08:00
|
|
|
int testQemuCapsSetGIC(virQEMUCaps *qemuCaps,
|
2016-05-10 17:35:43 +08:00
|
|
|
int gic);
|
2018-04-18 16:47:31 +08:00
|
|
|
|
2019-04-16 18:26:22 +08:00
|
|
|
char *testQemuGetLatestCapsForArch(const char *arch,
|
2018-04-18 16:47:31 +08:00
|
|
|
const char *suffix);
|
2020-10-23 01:04:18 +08:00
|
|
|
GHashTable *testQemuGetLatestCaps(void);
|
2018-04-18 16:47:31 +08:00
|
|
|
|
2019-10-22 21:34:10 +08:00
|
|
|
typedef int (*testQemuCapsIterateCallback)(const char *inputDir,
|
2019-10-22 22:08:10 +08:00
|
|
|
const char *prefix,
|
|
|
|
const char *version,
|
2019-03-07 22:54:55 +08:00
|
|
|
const char *archName,
|
2023-03-08 21:49:56 +08:00
|
|
|
const char *variant,
|
2019-10-22 21:44:37 +08:00
|
|
|
const char *suffix,
|
2019-03-07 22:54:55 +08:00
|
|
|
void *opaque);
|
2019-04-16 18:33:14 +08:00
|
|
|
int testQemuCapsIterate(const char *suffix,
|
2019-03-07 22:54:55 +08:00
|
|
|
testQemuCapsIterateCallback callback,
|
|
|
|
void *opaque);
|
|
|
|
|
2021-08-17 21:30:44 +08:00
|
|
|
void testQemuInfoSetArgs(struct testQemuInfo *info,
|
|
|
|
struct testQemuConf *conf,
|
|
|
|
...);
|
|
|
|
int testQemuInfoInitArgs(struct testQemuInfo *info);
|
2019-03-31 23:49:34 +08:00
|
|
|
void testQemuInfoClear(struct testQemuInfo *info);
|
|
|
|
|
2022-02-09 19:30:25 +08:00
|
|
|
int testQemuPrepareHostBackendChardevOne(virDomainDeviceDef *dev,
|
|
|
|
virDomainChrSourceDef *chardev,
|
|
|
|
void *opaque);
|
2023-03-09 21:24:45 +08:00
|
|
|
|
|
|
|
virQEMUCaps *
|
|
|
|
testQemuGetRealCaps(const char *arch,
|
|
|
|
const char *version,
|
|
|
|
const char *variant,
|
|
|
|
GHashTable *capsLatestFiles,
|
|
|
|
GHashTable *capsCache,
|
2023-03-09 22:15:40 +08:00
|
|
|
GHashTable *schemaCache,
|
|
|
|
GHashTable **schema);
|
2023-07-03 21:25:30 +08:00
|
|
|
|
|
|
|
int
|
|
|
|
testQemuInsertRealCaps(virFileCache *cache,
|
|
|
|
const char *arch,
|
|
|
|
const char *version,
|
|
|
|
const char *variant,
|
|
|
|
GHashTable *capsLatestFiles,
|
|
|
|
GHashTable *capsCache,
|
|
|
|
GHashTable *schemaCache,
|
|
|
|
GHashTable **schema);
|
2019-06-19 00:13:14 +08:00
|
|
|
#endif
|