summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2016-11-23 11:36:55 -0600
committerMarkus Armbruster <armbru@redhat.com>2016-12-05 17:09:34 +0100
commit1792d7d0a2dc18496e8fc52906163f9f73f3d931 (patch)
tree241b051335899971c49d1a2aed9329b3a0d1d52b /tests
parent043b5a49516f5037430e7864e23fc2fdd39f2b10 (diff)
downloadqemu-1792d7d0a2dc18496e8fc52906163f9f73f3d931.tar.gz
qemu-1792d7d0a2dc18496e8fc52906163f9f73f3d931.tar.bz2
qemu-1792d7d0a2dc18496e8fc52906163f9f73f3d931.zip
test-qga: Avoid qobject_from_jsonv("%"PRId64)
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>
Diffstat (limited to 'tests')
-rw-r--r--tests/test-qga.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/tests/test-qga.c b/tests/test-qga.c
index 40af64987a..868b02a40f 100644
--- a/tests/test-qga.c
+++ b/tests/test-qga.c
@@ -837,6 +837,7 @@ static void test_qga_guest_exec(gconstpointer fix)
int64_t pid, now, exitcode;
gsize len;
bool exited;
+ char *cmd;
/* exec 'echo foo bar' */
ret = qmp_fd(fixture->fd, "{'execute': 'guest-exec', 'arguments': {"
@@ -851,9 +852,10 @@ static void test_qga_guest_exec(gconstpointer fix)
/* wait for completion */
now = g_get_monotonic_time();
+ cmd = g_strdup_printf("{'execute': 'guest-exec-status',"
+ " 'arguments': { 'pid': %" PRId64 " } }", pid);
do {
- ret = qmp_fd(fixture->fd, "{'execute': 'guest-exec-status',"
- " 'arguments': { 'pid': %" PRId64 " } }", pid);
+ ret = qmp_fd(fixture->fd, cmd);
g_assert_nonnull(ret);
val = qdict_get_qdict(ret, "return");
exited = qdict_get_bool(val, "exited");
@@ -863,6 +865,7 @@ static void test_qga_guest_exec(gconstpointer fix)
} while (!exited &&
g_get_monotonic_time() < now + 5 * G_TIME_SPAN_SECOND);
g_assert(exited);
+ g_free(cmd);
/* check stdout */
exitcode = qdict_get_int(val, "exitcode");