Commit Graph

20 Commits

Author SHA1 Message Date
Peter Krempa
62a01d84a3 util: hash: Retire 'virHashTable' in favor of 'GHashTable'
Don't hide our use of GHashTable behind our typedef. This will also
promote the use of glibs hash function directly.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Reviewed-by: Matt Coleman <matt@datto.com>
2020-11-06 10:40:51 +01:00
Peter Krempa
63a25dd821 testutilsqemuschema: Add template checker for schema entries
We'll need to match that a certain part of the qemu schema hasn't grown
new properties unexpectedly. Add a helper which matches an 'object' QMP
schema entry against a template and reports errors if expected types
don't match or new entries are added.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2020-08-24 13:02:35 +02:00
Peter Krempa
b6246d9320 testutilsqemuschema: Allow loading non-latest schema
Add testQEMUSchemaLoad and refactor internals so that we can load the
QMP schema from an arbitrary caps replies file.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
2020-05-20 09:41:58 +02:00
Peter Krempa
18e9806c64 testQEMUSchemaLoad: Rename to testQEMUSchemaLoadLatest
It always loads the latest schema. Prepare for loading others as well.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
2020-05-20 09:41:58 +02:00
Peter Krempa
de8216af13 testQEMUSchemaValidate*: Reject usage of fields with 'deprecated' set
Make our QMP schema validator reject any use of schema entries which
were deprecated by QEMU except for those whitelisted.

This will allow us to catch this before qemu actually removed what we'd
still use.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-05-20 08:53:30 +02:00
Peter Krempa
4fcea23e6c testQEMUSchemaValidate(Command): Allow skipping validation of deprecated fields
Some test cases are used to validate interactions with old qemu. We need
to skip validation of deprecation with those once it will be added.

In case of commands which were already replaced by code based on
capabilities we can skip the full validation once the command is
removed.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-05-20 08:53:29 +02:00
Peter Krempa
2c44ea900e testutilsqemuschema: Pass in 'schema' and 'debug' variables to workers in a struct
Refactor the code so that we pass in the repeated 'schema' and 'debug'
arguments via a new struct testQEMUSchemaValidateCtxt. This will
simplify adding new parameters in the future.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-05-20 08:53:29 +02:00
Peter Krempa
47bc49879f testutilsqemuschema: Use automatic variable clearing where possible
Refactor all cleanup to avoid manual clearing, unnecessary labels and
return value variables.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-05-20 08:53:29 +02:00
Peter Krempa
23bd18dc75 testutilsqemuschema: Introduce testQEMUSchemaValidateCommand
The new helper splits out all steps necessary to validate a QMP command
against the schema.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2020-05-20 08:53:29 +02:00
Collin Walling
6523a7ea5d qemumonitorjsontest: load schema based on specified arch
There are some architectures that support capabilities that others
do not (e.g. s390x supports cpu comparison and baseline via QEMU).

Let's make testQEMUSchemaLoad accept a string to specify the schema
to load based on the specified arch.

Signed-off-by: Collin Walling <walling@linux.ibm.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2020-02-21 10:50:10 +01:00
Peter Krempa
5e8551fbc0 util: virbuffer: Remove @dynamic from virBufferGetIndent
After the conversion of all callers that would pass true as @dynamic to
a different function we can remove the unused argument now.

Additionally modify the return type to 'size_t' as indentation can't be
negative and remove checks whether @buf is passed as it's caller's duty
to do so.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-10-24 19:35:34 +02:00
Ján Tomko
0d94f02455 tests: use G_GNUC_UNUSED
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>
2019-10-15 11:25:25 +02:00
Michal Privoznik
e3511ee5ec tests: Always put '\n' at the end of VIR_TEST_VERBOSE
Similarly to the previous commit, VIR_TEST_VERBOSE should put
'\n' at the end of each call so that the output is not broken.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-08-27 15:56:17 +02:00
Michal Privoznik
d07ce21610 tests: Always put a '\n' after each debug print
There is an inconsistency with VIR_TEST_DEBUG() calls. One half
(roughly) of calls does have the newline character the other one
doesn't. Well, it doesn't have it because it assumed blindly that
new line will be printed, which is not the case.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2019-08-27 15:49:48 +02:00
Andrea Bolognani
3fe020a038 tests: Drop dirname argument from testQemuGetLatestCapsForArch()
As evidenced by all existing callers, the only directory it makes
sense to use is TEST_QEMU_CAPS_PATH, so let's just bake that into
the function.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Cole Robinson <crobinso@redhat.com>
2019-04-17 08:30:55 +02:00
Peter Krempa
e59dc14d1e tests: qemuschema: Add line break to debug message
Message stating which schema replies file is being used would be
squashed with other messages.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-07-13 14:15:59 +02:00
Peter Krempa
d682f90891 tests: qemuschema: Fix copy-paste error in function name
s/testQEMUSchemaValidateArrayBuiltin/testQEMUSchemaValidateBuiltin/

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-07-13 14:15:59 +02:00
Peter Krempa
92a18bb567 tests: qemu: Use qmp schema data from the qemucapabilities test
Add helpers that allow using the latest schema from the replies from an
actual qemu which are recorded for the purpose of the qemucapabilities
test instead of an unsynced copy stored in qemuqapischema.json.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2018-07-10 13:37:50 +02:00
John Ferlan
4a3d6ed5ee util: Clean up consumers of virJSONValueArraySize
Rather than have virJSONValueArraySize return a -1 when the input
is not an array and then splat an error message, let's check for
an array before calling and then change the return to be a size_t
instead of ssize_t.

That means using the helper virJSONValueIsArray as well as using a
more generic error message such as "Malformed <something> array".
In some cases we can remove stack variables and when we cannot,
those variables should be size_t not ssize_t. Alter a few references
of if (!value) to be if (value == 0) instead as well.

Some callers can already assume an array is being worked on based
on the previous call, so there's less to do.

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2018-05-10 14:59:15 -04:00
Peter Krempa
98b6087e83 tests: qemu: Add infrastructure for QAPI schema testing
Add a function which will allow to test whether a JSON object conforms
to the QAPI schema. This greatly helps when developing formatters for
new JSON objects and will help make sure that the code will not break in
cases which have unit tests but were actually not function-tested
(mostly various disk access protocols).

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2018-03-23 14:52:07 +01:00