summaryrefslogtreecommitdiff
path: root/tests/test-qga.c
AgeCommit message (Collapse)AuthorFilesLines
2018-03-19qapi: Replace qobject_to_X(o) by qobject_to(X, o)Max Reitz1-9/+10
This patch was generated using the following Coccinelle script: @@ expression Obj; @@ ( - qobject_to_qnum(Obj) + qobject_to(QNum, Obj) | - qobject_to_qstring(Obj) + qobject_to(QString, Obj) | - qobject_to_qdict(Obj) + qobject_to(QDict, Obj) | - qobject_to_qlist(Obj) + qobject_to(QList, Obj) | - qobject_to_qbool(Obj) + qobject_to(QBool, Obj) ) and a bit of manual fix-up for overly long lines and three places in tests/check-qjson.c that Coccinelle did not find. Signed-off-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Alberto Garcia <berto@igalia.com> Message-Id: <20180224154033.29559-4-mreitz@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> [eblake: swap order from qobject_to(o, X), rebase to master, also a fix to latent false-positive compiler complaint about hw/i386/acpi-build.c] Signed-off-by: Eric Blake <eblake@redhat.com>
2018-02-09Include qapi/qmp/qdict.h exactly where neededMarkus Armbruster1-0/+1
This cleanup makes the number of objects depending on qapi/qmp/qdict.h drop from 4550 (out of 4743) to 368 in my "build everything" tree. For qapi/qmp/qobject.h, the number drops from 4552 to 390. While there, separate #include from file comment with a blank line. Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20180201111846.21846-13-armbru@redhat.com>
2018-02-09Include qapi/qmp/qlist.h exactly where neededMarkus Armbruster1-0/+1
This cleanup makes the number of objects depending on qapi/qmp/qlist.h drop from 4551 (out of 4743) to 16 in my "build everything" tree. While there, separate #include from file comment with a blank line. Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20180201111846.21846-12-armbru@redhat.com>
2017-09-15test-qga: Kill broken and dead QGA_TEST_SIDE_EFFECTING codeEric Blake1-90/+0
Back when the test was introduced, in commit 62c39b307, the test was set up to run qemu-ga directly on the host performing the test, and defaults to limiting itself to safe commands. At the time, it was envisioned that setting QGA_TEST_SIDE_EFFECTING in the environment could cover a few more commands, while noting the potential danger of those side effects running in the host. But this has NEVER been tested: if you enable the environment variable, the test WILL fail. One obvious reason: if you are not running as root, you'll probably get a permission failure when trying to freeze the file systems, or when changing system time. Less obvious: if you run the test as root (wow, you're brave), you could end up hanging if the test tries to log things to a temporarily frozen filesystem. But the cutest reason of all: if you get past the above hurdles, the test uses invalid JSON in test_qga_fstrim() (missing '' around the dictionary key 'minimum'), and will thus fail an assertion in qmp_fd(). Rather than leave this untested time-bomb in place, rip it out. Hopefully, as originally envisioned, we can find an opportunity to test an actual sandboxed guest where the guest-agent has full permissions and will not unduly affect the host running the test - if so, 'git revert' can be used if desired, for salvaging any useful parts of this attempt. Signed-off-by: Eric Blake <eblake@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Thomas Huth <thuth@redhat.com>
2017-07-18test-qga: add test for guest-get-osinfoTomáš Golembiovský1-0/+56
Add test for guest-get-osinfo command. Qemu-ga was modified to accept QGA_OS_RELEASE environment variable. If the variable is defined it is interpreted as path to the os-release file and it is parsed instead of the default paths. Signed-off-by: Tomáš Golembiovský <tgolembi@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> * move declarations to beginning of functions Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
2017-07-18test-qga: pass environemnt to qemu-gaTomáš Golembiovský1-4/+4
Modify fixture_setup() to pass environemnt variables to spawned qemu-ga instance. Signed-off-by: Tomáš Golembiovský <tgolembi@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
2017-05-09test-qga: Actually test 0xff sync bytesEric Blake1-7/+34
Commit 62c39b3 introduced test-qga, and at face value, appears to be testing the 'guest-sync' behavior that is recommended for guests in sending 0xff to QGA to force the parser to reset. But this aspect of the test has never actually done anything: the qmp_fd() call chain converts its string argument into QObject, then converts that QObject back to the actual string that is sent over the wire - and the conversion process silently drops the 0xff byte from the string sent to QGA, thus never resetting the QGA parser. An upcoming patch will get rid of the wasteful round trip through QObject, at which point the string in test-qga will be directly sent over the wire. But fixing qmp_fd() to actually send 0xff over the wire is not all we have to do - the actual QMP parser loudly complains that 0xff is not valid JSON, and sends an error message _prior_ to actually parsing the 'guest-sync' or 'guest-sync-delimited' command. With 'guest-sync', we cannot easily tell if this error message is a result of our command - which is WHY we invented the 'guest-sync-delimited' command. So for the testsuite, fix things to only check 0xff behavior on 'guest-sync-delimited', and to loop until we've consumed all garbage prior to the requested delimiter, which is compatible with the documented actions that a real QGA client is supposed to do. Ideally, we'd fix the QGA JSON parser to silently ignore 0xff rather than sending an error message back, at which point we could enhance this test for 'guest-sync' as well as for 'guest-sync-delimited'. But for the sake of this patch, our testing of 'guest-sync' is no worse than it was pre-patch, because we have never been sending 0xff over the wire in the first place. Signed-off-by: Eric Blake <eblake@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20170427215821.19397-11-eblake@redhat.com> Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com> [Additional comment squashed in, along with matching commit message update] Signed-off-by: Markus Armbruster <armbru@redhat.com>
2017-03-07Merge remote-tracking branch 'remotes/mdroth/tags/qga-pull-2017-03-06-tag' ↵Peter Maydell1-1/+3
into staging qemu-ga patch queue for 2.9 * fix fsfreeze for filesystems mounted in multiple locations * fix test failure when running in a chroot * support for socket-based activation # gpg: Signature made Mon 06 Mar 2017 07:54:17 GMT # gpg: using RSA key 0x3353C9CEF108B584 # gpg: Good signature from "Michael Roth <flukshun@gmail.com>" # gpg: aka "Michael Roth <mdroth@utexas.edu>" # gpg: aka "Michael Roth <mdroth@linux.vnet.ibm.com>" # Primary key fingerprint: CEAC C9E1 5534 EBAB B82D 3FA0 3353 C9CE F108 B584 * remotes/mdroth/tags/qga-pull-2017-03-06-tag: tests: check path to avoid a failing qga/get-vcpus test qga: ignore EBUSY when freezing a filesystem qga: add systemd socket activation support Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
2017-03-06tests: check path to avoid a failing qga/get-vcpus testBruce Rogers1-1/+3
The qga/get-vcpus test fails in a simple chroot environment, as used in an openSUSE Build Service local build, so first check that the sysfs based path exists in order to avoid calling this test in an environment where it won't work right. Signed-off-by: Bruce Rogers <brogers@suse.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
2017-03-05qapi: Improve a QObject input visitor error messageMarkus Armbruster1-1/+1
The QObject input visitor has three error message formats: * Parameter '%s' is missing * "Invalid parameter type for '%s', expected: %s" * "QMP input object member '%s' is unexpected" The '%s' are member names (or "null", but I'll fix that later). The last error message calls the thing "QMP input object member" instead of "parameter". Misleading when the visitor is used on QObjects that don't come from QMP. Change it to "Parameter '%s' is unexpected". Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-Id: <1488544368-30622-12-git-send-email-armbru@redhat.com>
2016-12-05test-qga: Avoid qobject_from_jsonv("%"PRId64)Eric Blake1-2/+5
The qobject_from_jsonv() function implements a pseudo-printf language for creating a QObject; however, it is hard-coded to only parse a subset of formats understood by -Wformat, and is not a straight synonym to bare printf(). In particular, any use of an int64_t integer works only if the system's definition of PRId64 matches what the parser expects; which works on glibc (%lld or %ld depending on 32- vs. 64-bit) and mingw (%I64d), but not on Mac OS (%qd). Rather than enhance the parser, it is just as easy to use normal printf() for this particular conversion, matching what is done elsewhere in this file [1], which is safe in this instance because the format does not contain any of the problematic differences (bare '%' or the '%s' format). The use of PRId64 for a variable named 'pid' is gross, but it is a sad reality of the 64-bit mingw environment, which mistakenly defines pid_t as a 64-bit type even though getpid() returns 'int' on that platform [2]. Our definition of the QGA GuestExec type defines 'pid' as a 64-bit entity, and we can't tighten it to 'int32' unless the mingw header is fixed. Using 'long long' instead of 'int64_t' just so that we can stick with qobject_from_jsonv("%lld") instead of printf() is not any prettier, since we may have later type churn anyways. [1] see 'git grep -A2 strdup_printf tests/test-qga.c' [2] https://bugzilla.redhat.com/show_bug.cgi?id=1397787 Reported by: G 3 <programmingkidx@gmail.com> Signed-off-by: Eric Blake <eblake@redhat.com> Message-Id: <1479922617-4400-3-git-send-email-eblake@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-09-19tests: add a test to check invalid argsMarc-André Lureau1-0/+21
Check that invalid args on commands without arguments returns an error. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20160912091913.15831-15-marcandre.lureau@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
2016-09-08tests: fix test-qga leaksMarc-André Lureau1-0/+5
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
2016-07-25tests: use static qga config fileMarc-André Lureau1-23/+4
Do not create a leaking temporary file, but use a static file instead. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reported-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
2016-06-07tests: start a /qga/guest-exec testMarc-André Lureau1-0/+81
Test a few guest-exec guest agent commands, added in qemu 2.5. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
2016-06-07tests: Remove unnecessary glib.h includesPeter Maydell1-1/+0
Remove glib.h includes, as it is provided by osdep.h. This commit was created with scripts/clean-includes. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Eric Blake <eblake@redhat.com> Tested-by: Eric Blake <eblake@redhat.com> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
2016-02-25qga: Support enum names in guest-file-seekEric Blake1-5/+4
Magic constants are a pain to use, especially when we run the risk that our choice of '1' for QGA_SEEK_CUR might differ from the host or guest's choice of SEEK_CUR. Better is to use an enum value, via a qapi alternate type for back-compatibility. With this, {"command":"guest-file-seek", "arguments":{"handle":1, "offset":0, "whence":"cur"}} becomes a synonym for the older {"command":"guest-file-seek", "arguments":{"handle":1, "offset":0, "whence":1}} Signed-off-by: Eric Blake <eblake@redhat.com> Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com> Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
2016-02-16tests: Clean up includesPeter Maydell1-8/+1
Clean up includes so that osdep.h is included first and headers which it implies are not included manually. This commit was created with scripts/clean-includes. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Eric Blake <eblake@redhat.com> Tested-by: Eric Blake <eblake@redhat.com>
2015-11-25qga: Better mapping of SEEK_* in guest-file-seekEric Blake1-2/+3
Exposing OS-specific SEEK_ constants in our qapi was a mistake (if the host has SEEK_CUR as 1, but the guest has it as 2, then the semantics are unclear what should happen); if we had a time machine, we would instead expose only a symbolic enum. It's too late to change the fact that we have an integer in qapi, but we can at least document what mapping we want to enforce for all qga clients (and luckily, it happens to be the mapping that both Linux and Windows use); then fix the code to match that mapping. It also helps us filter out unsupported SEEK_DATA and SEEK_HOLE. In the future, we may wish to move our QGA_SEEK_* constants into qga/qapi-schema.json, along with updating the schema to take an alternate type (either the integer, or the string value of the enum name) - but that's too much risk during hard freeze. Signed-off-by: Eric Blake <eblake@redhat.com> Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
2015-11-25tests: add file-write-read testMarc-André Lureau1-2/+93
This test exhibits a POSIX behaviour regarding switching between write and read. It's undefined result if the application doesn't ensure a flush between the two operations (with glibc, the flush can be implicit when the buffer size is relatively small). The previous commit fixes this test. Related to: https://bugzilla.redhat.com/show_bug.cgi?id=1210246 Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
2015-10-23tests: test-qga, loosen assumptions about host filesystemsMichael Roth1-5/+7
QGA skips pseudo-filesystems when querying filesystems via guest-get-fsinfo. On some hosts, such as travis-ci which uses containers with simfs filesystems, QGA might not report *any* filesystems. Our test case assumes there would be at least one, leading to false error messages in these situations. Instead, sanity-check values iff we get at least one filesystem. Cc: Marc-André Lureau <marcandre.lureau@redhat.com> Cc: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
2015-10-19tests: add a local test for guest agentMarc-André Lureau1-0/+783
Add some local guest agent tests, as it is better than nothing, only when CONFIG_POSIX (using unix sockets). With the QGA_TEST_SIDE_EFFECTING environment variable, it will include tests with side effects, such as freezing/thawing the FS or changing the time. (a better test would involve a managed VM (or container), but it might be better to leave that off to autotest/avocado) Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> * use mkdtemp() in placeof g_mkdtemp() for glib 2.22 compat * drop redundant/conflicting compat defines for g_assert_{true,false}, since glib-compat has them now. * build fixes for OSX: use PRId64 instead of glib formats, drop g_spawn_default usage for glib compat * assert connect_qga() doesn't fail * only enable test-qga for linux hosts * allow get-memory-block-info* to fail Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>