guint32 v, r = g_random_int();
unsigned char c;
QDict *ret;
- gchar *cmd;
- cmd = g_strdup_printf("\xff{'execute': 'guest-sync-delimited',"
- " 'arguments': {'id': %u } }", r);
- qmp_fd_send(fixture->fd, cmd);
- g_free(cmd);
+ qmp_fd_send_raw(fixture->fd, "\xff");
+ qmp_fd_send(fixture->fd,
+ "{'execute': 'guest-sync-delimited',"
+ " 'arguments': {'id': %u } }",
+ r);
/*
* Read and ignore garbage until resynchronized.
const TestFixture *fixture = fix;
guint32 v, r = g_random_int();
QDict *ret;
- gchar *cmd;
/*
* TODO guest-sync is inherently limited: we cannot distinguish
* invalid JSON. Testing of '\xff' handling is done in
* guest-sync-delimited instead.
*/
- cmd = g_strdup_printf("{'execute': 'guest-sync',"
- " 'arguments': {'id': %u } }", r);
- ret = qmp_fd(fixture->fd, cmd);
- g_free(cmd);
+ ret = qmp_fd(fixture->fd,
+ "{'execute': 'guest-sync', 'arguments': {'id': %u } }",
+ r);
g_assert_nonnull(ret);
qmp_assert_no_error(ret);
qobject_unref(ret);
}
+static void test_qga_id(gconstpointer fix)
+{
+ const TestFixture *fixture = fix;
+ QDict *ret;
+
+ ret = qmp_fd(fixture->fd, "{'execute': 'guest-ping', 'id': 1}");
+ g_assert_nonnull(ret);
+ qmp_assert_no_error(ret);
+ g_assert_cmpint(qdict_get_int(ret, "id"), ==, 1);
+
+ qobject_unref(ret);
+}
+
+static void test_qga_invalid_oob(gconstpointer fix)
+{
+ const TestFixture *fixture = fix;
+ QDict *ret;
+
+ ret = qmp_fd(fixture->fd, "{'exec-oob': 'guest-ping'}");
+ g_assert_nonnull(ret);
+
+ qmp_assert_error_class(ret, "GenericError");
+}
+
static void test_qga_invalid_args(gconstpointer fix)
{
const TestFixture *fixture = fix;
const TestFixture *fixture = fix;
const unsigned char helloworld[] = "Hello World!\n";
const char *b64;
- gchar *cmd, *path, *enc;
+ gchar *path, *enc;
unsigned char *dec;
QDict *ret, *val;
int64_t id, eof;
enc = g_base64_encode(helloworld, sizeof(helloworld));
/* write */
- cmd = g_strdup_printf("{'execute': 'guest-file-write',"
- " 'arguments': { 'handle': %" PRId64 ","
- " 'buf-b64': '%s' } }", id, enc);
- ret = qmp_fd(fixture->fd, cmd);
+ ret = qmp_fd(fixture->fd,
+ "{'execute': 'guest-file-write',"
+ " 'arguments': { 'handle': %" PRId64 ", 'buf-b64': %s } }",
+ id, enc);
g_assert_nonnull(ret);
qmp_assert_no_error(ret);
g_assert_cmpint(count, ==, sizeof(helloworld));
g_assert_cmpint(eof, ==, 0);
qobject_unref(ret);
- g_free(cmd);
/* flush */
- cmd = g_strdup_printf("{'execute': 'guest-file-flush',"
- " 'arguments': {'handle': %" PRId64 "} }",
- id);
- ret = qmp_fd(fixture->fd, cmd);
+ ret = qmp_fd(fixture->fd,
+ "{'execute': 'guest-file-flush',"
+ " 'arguments': {'handle': %" PRId64 "} }",
+ id);
qobject_unref(ret);
- g_free(cmd);
/* close */
- cmd = g_strdup_printf("{'execute': 'guest-file-close',"
- " 'arguments': {'handle': %" PRId64 "} }",
- id);
- ret = qmp_fd(fixture->fd, cmd);
+ ret = qmp_fd(fixture->fd,
+ "{'execute': 'guest-file-close',"
+ " 'arguments': {'handle': %" PRId64 "} }",
+ id);
qobject_unref(ret);
- g_free(cmd);
/* check content */
path = g_build_filename(fixture->test_dir, "foo", NULL);
qobject_unref(ret);
/* read */
- cmd = g_strdup_printf("{'execute': 'guest-file-read',"
- " 'arguments': { 'handle': %" PRId64 "} }",
- id);
- ret = qmp_fd(fixture->fd, cmd);
+ ret = qmp_fd(fixture->fd,
+ "{'execute': 'guest-file-read',"
+ " 'arguments': { 'handle': %" PRId64 "} }",
+ id);
val = qdict_get_qdict(ret, "return");
count = qdict_get_int(val, "count");
eof = qdict_get_bool(val, "eof");
g_assert_cmpstr(b64, ==, enc);
qobject_unref(ret);
- g_free(cmd);
g_free(enc);
/* read eof */
- cmd = g_strdup_printf("{'execute': 'guest-file-read',"
- " 'arguments': { 'handle': %" PRId64 "} }",
- id);
- ret = qmp_fd(fixture->fd, cmd);
+ ret = qmp_fd(fixture->fd,
+ "{'execute': 'guest-file-read',"
+ " 'arguments': { 'handle': %" PRId64 "} }",
+ id);
val = qdict_get_qdict(ret, "return");
count = qdict_get_int(val, "count");
eof = qdict_get_bool(val, "eof");
g_assert(eof);
g_assert_cmpstr(b64, ==, "");
qobject_unref(ret);
- g_free(cmd);
/* seek */
- cmd = g_strdup_printf("{'execute': 'guest-file-seek',"
- " 'arguments': { 'handle': %" PRId64 ", "
- " 'offset': %d, 'whence': '%s' } }",
- id, 6, "set");
- ret = qmp_fd(fixture->fd, cmd);
+ ret = qmp_fd(fixture->fd,
+ "{'execute': 'guest-file-seek',"
+ " 'arguments': { 'handle': %" PRId64 ", "
+ " 'offset': %d, 'whence': %s } }",
+ id, 6, "set");
qmp_assert_no_error(ret);
val = qdict_get_qdict(ret, "return");
count = qdict_get_int(val, "position");
g_assert_cmpint(count, ==, 6);
g_assert(!eof);
qobject_unref(ret);
- g_free(cmd);
/* partial read */
- cmd = g_strdup_printf("{'execute': 'guest-file-read',"
- " 'arguments': { 'handle': %" PRId64 "} }",
- id);
- ret = qmp_fd(fixture->fd, cmd);
+ ret = qmp_fd(fixture->fd,
+ "{'execute': 'guest-file-read',"
+ " 'arguments': { 'handle': %" PRId64 "} }",
+ id);
val = qdict_get_qdict(ret, "return");
count = qdict_get_int(val, "count");
eof = qdict_get_bool(val, "eof");
g_free(dec);
qobject_unref(ret);
- g_free(cmd);
/* close */
- cmd = g_strdup_printf("{'execute': 'guest-file-close',"
- " 'arguments': {'handle': %" PRId64 "} }",
- id);
- ret = qmp_fd(fixture->fd, cmd);
+ ret = qmp_fd(fixture->fd,
+ "{'execute': 'guest-file-close',"
+ " 'arguments': {'handle': %" PRId64 "} }",
+ id);
qobject_unref(ret);
- g_free(cmd);
}
static void test_qga_file_write_read(gconstpointer fix)
const TestFixture *fixture = fix;
const unsigned char helloworld[] = "Hello World!\n";
const char *b64;
- gchar *cmd, *enc;
+ gchar *enc;
QDict *ret, *val;
int64_t id, eof;
gsize count;
enc = g_base64_encode(helloworld, sizeof(helloworld));
/* write */
- cmd = g_strdup_printf("{'execute': 'guest-file-write',"
- " 'arguments': { 'handle': %" PRId64 ","
- " 'buf-b64': '%s' } }", id, enc);
- ret = qmp_fd(fixture->fd, cmd);
+ ret = qmp_fd(fixture->fd,
+ "{'execute': 'guest-file-write',"
+ " 'arguments': { 'handle': %" PRId64 ","
+ " 'buf-b64': %s } }", id, enc);
g_assert_nonnull(ret);
qmp_assert_no_error(ret);
g_assert_cmpint(count, ==, sizeof(helloworld));
g_assert_cmpint(eof, ==, 0);
qobject_unref(ret);
- g_free(cmd);
/* read (check implicit flush) */
- cmd = g_strdup_printf("{'execute': 'guest-file-read',"
- " 'arguments': { 'handle': %" PRId64 "} }",
- id);
- ret = qmp_fd(fixture->fd, cmd);
+ ret = qmp_fd(fixture->fd,
+ "{'execute': 'guest-file-read',"
+ " 'arguments': { 'handle': %" PRId64 "} }",
+ id);
val = qdict_get_qdict(ret, "return");
count = qdict_get_int(val, "count");
eof = qdict_get_bool(val, "eof");
g_assert(eof);
g_assert_cmpstr(b64, ==, "");
qobject_unref(ret);
- g_free(cmd);
/* seek to 0 */
- cmd = g_strdup_printf("{'execute': 'guest-file-seek',"
- " 'arguments': { 'handle': %" PRId64 ", "
- " 'offset': %d, 'whence': '%s' } }",
- id, 0, "set");
- ret = qmp_fd(fixture->fd, cmd);
+ ret = qmp_fd(fixture->fd,
+ "{'execute': 'guest-file-seek',"
+ " 'arguments': { 'handle': %" PRId64 ", "
+ " 'offset': %d, 'whence': %s } }",
+ id, 0, "set");
qmp_assert_no_error(ret);
val = qdict_get_qdict(ret, "return");
count = qdict_get_int(val, "position");
g_assert_cmpint(count, ==, 0);
g_assert(!eof);
qobject_unref(ret);
- g_free(cmd);
/* read */
- cmd = g_strdup_printf("{'execute': 'guest-file-read',"
- " 'arguments': { 'handle': %" PRId64 "} }",
- id);
- ret = qmp_fd(fixture->fd, cmd);
+ ret = qmp_fd(fixture->fd,
+ "{'execute': 'guest-file-read',"
+ " 'arguments': { 'handle': %" PRId64 "} }",
+ id);
val = qdict_get_qdict(ret, "return");
count = qdict_get_int(val, "count");
eof = qdict_get_bool(val, "eof");
g_assert(eof);
g_assert_cmpstr(b64, ==, enc);
qobject_unref(ret);
- g_free(cmd);
g_free(enc);
/* close */
- cmd = g_strdup_printf("{'execute': 'guest-file-close',"
- " 'arguments': {'handle': %" PRId64 "} }",
- id);
- ret = qmp_fd(fixture->fd, cmd);
+ ret = qmp_fd(fixture->fd,
+ "{'execute': 'guest-file-close',"
+ " 'arguments': {'handle': %" PRId64 "} }",
+ id);
qobject_unref(ret);
- g_free(cmd);
}
static void test_qga_get_time(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': {"
/* 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, cmd);
+ ret = qmp_fd(fixture->fd,
+ "{'execute': 'guest-exec-status',"
+ " 'arguments': { 'pid': %" PRId64 " } }", pid);
g_assert_nonnull(ret);
val = qdict_get_qdict(ret, "return");
exited = qdict_get_bool(val, "exited");
} 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");
g_test_add_data_func("/qga/file-ops", &fix, test_qga_file_ops);
g_test_add_data_func("/qga/file-write-read", &fix, test_qga_file_write_read);
g_test_add_data_func("/qga/get-time", &fix, test_qga_get_time);
+ g_test_add_data_func("/qga/id", &fix, test_qga_id);
+ g_test_add_data_func("/qga/invalid-oob", &fix, test_qga_invalid_oob);
g_test_add_data_func("/qga/invalid-cmd", &fix, test_qga_invalid_cmd);
g_test_add_data_func("/qga/invalid-args", &fix, test_qga_invalid_args);
g_test_add_data_func("/qga/fsfreeze-status", &fix,