blob: d2b2435bb46e28181866a3704ad10803402cb210 [file] [log] [blame]
Peter Maydell681c28a2016-02-08 18:08:51 +00001#include "qemu/osdep.h"
Marc-André Lureau62c39b32015-10-02 14:58:18 +02002#include <locale.h>
Marc-André Lureau62c39b32015-10-02 14:58:18 +02003#include <glib/gstdio.h>
Marc-André Lureau62c39b32015-10-02 14:58:18 +02004#include <sys/socket.h>
5#include <sys/un.h>
Marc-André Lureau62c39b32015-10-02 14:58:18 +02006
7#include "libqtest.h"
Markus Armbruster452fcdb2018-02-01 12:18:39 +01008#include "qapi/qmp/qdict.h"
Markus Armbruster47e6b292018-02-01 12:18:38 +01009#include "qapi/qmp/qlist.h"
Marc-André Lureau62c39b32015-10-02 14:58:18 +020010
11typedef struct {
12 char *test_dir;
13 GMainLoop *loop;
14 int fd;
15 GPid pid;
16} TestFixture;
17
18static int connect_qga(char *path)
19{
20 int s, ret, len, i = 0;
21 struct sockaddr_un remote;
22
23 s = socket(AF_UNIX, SOCK_STREAM, 0);
24 g_assert(s != -1);
25
26 remote.sun_family = AF_UNIX;
27 do {
28 strcpy(remote.sun_path, path);
29 len = strlen(remote.sun_path) + sizeof(remote.sun_family);
30 ret = connect(s, (struct sockaddr *)&remote, len);
31 if (ret == -1) {
32 g_usleep(G_USEC_PER_SEC);
33 }
34 if (i++ == 10) {
35 return -1;
36 }
37 } while (ret == -1);
38
39 return s;
40}
41
42static void qga_watch(GPid pid, gint status, gpointer user_data)
43{
44 TestFixture *fixture = user_data;
45
46 g_assert_cmpint(status, ==, 0);
47 g_main_loop_quit(fixture->loop);
48}
49
50static void
Tomáš Golembiovskýc28afa72017-07-14 16:28:57 +020051fixture_setup(TestFixture *fixture, gconstpointer data, gchar **envp)
Marc-André Lureau62c39b32015-10-02 14:58:18 +020052{
53 const gchar *extra_arg = data;
54 GError *error = NULL;
55 gchar *cwd, *path, *cmd, **argv = NULL;
56
57 fixture->loop = g_main_loop_new(NULL, FALSE);
58
59 fixture->test_dir = g_strdup("/tmp/qgatest.XXXXXX");
60 g_assert_nonnull(mkdtemp(fixture->test_dir));
61
62 path = g_build_filename(fixture->test_dir, "sock", NULL);
63 cwd = g_get_current_dir();
64 cmd = g_strdup_printf("%s%cqemu-ga -m unix-listen -t %s -p %s %s %s",
65 cwd, G_DIR_SEPARATOR,
66 fixture->test_dir, path,
67 getenv("QTEST_LOG") ? "-v" : "",
68 extra_arg ?: "");
69 g_shell_parse_argv(cmd, NULL, &argv, &error);
70 g_assert_no_error(error);
71
Tomáš Golembiovskýc28afa72017-07-14 16:28:57 +020072 g_spawn_async(fixture->test_dir, argv, envp,
Marc-André Lureau62c39b32015-10-02 14:58:18 +020073 G_SPAWN_SEARCH_PATH|G_SPAWN_DO_NOT_REAP_CHILD,
74 NULL, NULL, &fixture->pid, &error);
75 g_assert_no_error(error);
76
77 g_child_watch_add(fixture->pid, qga_watch, fixture);
78
79 fixture->fd = connect_qga(path);
80 g_assert_cmpint(fixture->fd, !=, -1);
81
82 g_strfreev(argv);
83 g_free(cmd);
84 g_free(cwd);
85 g_free(path);
86}
87
88static void
89fixture_tear_down(TestFixture *fixture, gconstpointer data)
90{
91 gchar *tmp;
92
93 kill(fixture->pid, SIGTERM);
94
95 g_main_loop_run(fixture->loop);
96 g_main_loop_unref(fixture->loop);
97
98 g_spawn_close_pid(fixture->pid);
99
100 tmp = g_build_filename(fixture->test_dir, "foo", NULL);
101 g_unlink(tmp);
102 g_free(tmp);
103
104 tmp = g_build_filename(fixture->test_dir, "qga.state", NULL);
105 g_unlink(tmp);
106 g_free(tmp);
107
108 tmp = g_build_filename(fixture->test_dir, "sock", NULL);
109 g_unlink(tmp);
110 g_free(tmp);
111
112 g_rmdir(fixture->test_dir);
113 g_free(fixture->test_dir);
114}
115
116static void qmp_assertion_message_error(const char *domain,
117 const char *file,
118 int line,
119 const char *func,
120 const char *expr,
121 QDict *dict)
122{
123 const char *class, *desc;
124 char *s;
125 QDict *error;
126
127 error = qdict_get_qdict(dict, "error");
128 class = qdict_get_try_str(error, "class");
129 desc = qdict_get_try_str(error, "desc");
130
131 s = g_strdup_printf("assertion failed %s: %s %s", expr, class, desc);
132 g_assertion_message(domain, file, line, func, s);
133 g_free(s);
134}
135
136#define qmp_assert_no_error(err) do { \
137 if (qdict_haskey(err, "error")) { \
138 qmp_assertion_message_error(G_LOG_DOMAIN, __FILE__, __LINE__, \
139 G_STRFUNC, #err, err); \
140 } \
141} while (0)
142
143static void test_qga_sync_delimited(gconstpointer fix)
144{
145 const TestFixture *fixture = fix;
Paolo Bonzini0f555602019-12-12 02:17:58 +0100146 guint32 v, r = g_test_rand_int();
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200147 unsigned char c;
148 QDict *ret;
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200149
Markus Armbrustere2f64a62018-08-23 18:39:34 +0200150 qmp_fd_send_raw(fixture->fd, "\xff");
Markus Armbruster015715f2018-08-06 08:53:33 +0200151 qmp_fd_send(fixture->fd,
Markus Armbrustere2f64a62018-08-23 18:39:34 +0200152 "{'execute': 'guest-sync-delimited',"
Markus Armbruster015715f2018-08-06 08:53:33 +0200153 " 'arguments': {'id': %u } }",
154 r);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200155
Eric Blake52295642017-04-27 16:58:21 -0500156 /*
157 * Read and ignore garbage until resynchronized.
158 *
159 * Note that the full reset sequence would involve checking the
160 * response of guest-sync-delimited and repeating the loop if
161 * 'id' field of the response does not match the 'id' field of
162 * the request. Testing this fully would require inserting
163 * garbage in the response stream and is left as a future test
164 * to implement.
165 *
166 * TODO: The server shouldn't emit so much garbage (among other
167 * things, it loudly complains about the client's \xff being
168 * invalid JSON, even though it is a documented part of the
169 * handshake.
170 */
171 do {
172 v = read(fixture->fd, &c, 1);
173 g_assert_cmpint(v, ==, 1);
174 } while (c != 0xff);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200175
176 ret = qmp_fd_receive(fixture->fd);
177 g_assert_nonnull(ret);
178 qmp_assert_no_error(ret);
179
180 v = qdict_get_int(ret, "return");
181 g_assert_cmpint(r, ==, v);
182
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200183 qobject_unref(ret);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200184}
185
186static void test_qga_sync(gconstpointer fix)
187{
188 const TestFixture *fixture = fix;
Paolo Bonzini0f555602019-12-12 02:17:58 +0100189 guint32 v, r = g_test_rand_int();
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200190 QDict *ret;
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200191
Eric Blake52295642017-04-27 16:58:21 -0500192 /*
193 * TODO guest-sync is inherently limited: we cannot distinguish
194 * failure caused by reacting to garbage on the wire prior to this
195 * command, from failure of this actual command. Clients are
196 * supposed to be able to send a raw '\xff' byte to at least
197 * re-synchronize the server's parser prior to this command, but
198 * we are not in a position to test that here because (at least
199 * for now) it causes the server to issue an error message about
200 * invalid JSON. Testing of '\xff' handling is done in
201 * guest-sync-delimited instead.
202 */
Markus Armbruster015715f2018-08-06 08:53:33 +0200203 ret = qmp_fd(fixture->fd,
204 "{'execute': 'guest-sync', 'arguments': {'id': %u } }",
205 r);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200206
207 g_assert_nonnull(ret);
208 qmp_assert_no_error(ret);
209
210 v = qdict_get_int(ret, "return");
211 g_assert_cmpint(r, ==, v);
212
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200213 qobject_unref(ret);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200214}
215
216static void test_qga_ping(gconstpointer fix)
217{
218 const TestFixture *fixture = fix;
219 QDict *ret;
220
221 ret = qmp_fd(fixture->fd, "{'execute': 'guest-ping'}");
222 g_assert_nonnull(ret);
223 qmp_assert_no_error(ret);
224
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200225 qobject_unref(ret);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200226}
227
Marc-André Lureau4eaca8d2019-02-20 16:42:53 +0100228static void test_qga_id(gconstpointer fix)
Markus Armbrusterb5f84312018-07-03 10:53:34 +0200229{
Markus Armbrusterb5f84312018-07-03 10:53:34 +0200230 const TestFixture *fixture = fix;
Marc-André Lureau4eaca8d2019-02-20 16:42:53 +0100231 QDict *ret;
Markus Armbrusterb5f84312018-07-03 10:53:34 +0200232
233 ret = qmp_fd(fixture->fd, "{'execute': 'guest-ping', 'id': 1}");
234 g_assert_nonnull(ret);
Marc-André Lureau4eaca8d2019-02-20 16:42:53 +0100235 qmp_assert_no_error(ret);
236 g_assert_cmpint(qdict_get_int(ret, "id"), ==, 1);
Markus Armbrusterb5f84312018-07-03 10:53:34 +0200237
238 qobject_unref(ret);
239}
240
Markus Armbrusterd4d7ed72018-07-03 10:53:36 +0200241static void test_qga_invalid_oob(gconstpointer fix)
242{
Markus Armbrusterd4d7ed72018-07-03 10:53:36 +0200243 const TestFixture *fixture = fix;
Marc-André Lureauebb4d822018-08-30 17:58:07 +0200244 QDict *ret;
Markus Armbrusterd4d7ed72018-07-03 10:53:36 +0200245
Markus Armbruster00ecec12018-07-03 10:53:38 +0200246 ret = qmp_fd(fixture->fd, "{'exec-oob': 'guest-ping'}");
Markus Armbrusterd4d7ed72018-07-03 10:53:36 +0200247 g_assert_nonnull(ret);
Markus Armbrusterd4d7ed72018-07-03 10:53:36 +0200248
Marc-André Lureauebb4d822018-08-30 17:58:07 +0200249 qmp_assert_error_class(ret, "GenericError");
Markus Armbrusterd4d7ed72018-07-03 10:53:36 +0200250}
251
Marc-André Lureau4bdadd82016-09-12 13:19:09 +0400252static void test_qga_invalid_args(gconstpointer fix)
253{
254 const TestFixture *fixture = fix;
255 QDict *ret, *error;
256 const gchar *class, *desc;
257
258 ret = qmp_fd(fixture->fd, "{'execute': 'guest-ping', "
259 "'arguments': {'foo': 42 }}");
260 g_assert_nonnull(ret);
261
262 error = qdict_get_qdict(ret, "error");
263 class = qdict_get_try_str(error, "class");
264 desc = qdict_get_try_str(error, "desc");
265
266 g_assert_cmpstr(class, ==, "GenericError");
Markus Armbruster910f7382017-03-03 13:32:31 +0100267 g_assert_cmpstr(desc, ==, "Parameter 'foo' is unexpected");
Marc-André Lureau4bdadd82016-09-12 13:19:09 +0400268
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200269 qobject_unref(ret);
Marc-André Lureau4bdadd82016-09-12 13:19:09 +0400270}
271
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200272static void test_qga_invalid_cmd(gconstpointer fix)
273{
274 const TestFixture *fixture = fix;
275 QDict *ret, *error;
276 const gchar *class, *desc;
277
278 ret = qmp_fd(fixture->fd, "{'execute': 'guest-invalid-cmd'}");
279 g_assert_nonnull(ret);
280
281 error = qdict_get_qdict(ret, "error");
282 class = qdict_get_try_str(error, "class");
283 desc = qdict_get_try_str(error, "desc");
284
285 g_assert_cmpstr(class, ==, "CommandNotFound");
286 g_assert_cmpint(strlen(desc), >, 0);
287
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200288 qobject_unref(ret);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200289}
290
291static void test_qga_info(gconstpointer fix)
292{
293 const TestFixture *fixture = fix;
294 QDict *ret, *val;
295 const gchar *version;
296
297 ret = qmp_fd(fixture->fd, "{'execute': 'guest-info'}");
298 g_assert_nonnull(ret);
299 qmp_assert_no_error(ret);
300
301 val = qdict_get_qdict(ret, "return");
302 version = qdict_get_try_str(val, "version");
303 g_assert_cmpstr(version, ==, QEMU_VERSION);
304
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200305 qobject_unref(ret);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200306}
307
308static void test_qga_get_vcpus(gconstpointer fix)
309{
310 const TestFixture *fixture = fix;
311 QDict *ret;
312 QList *list;
313 const QListEntry *entry;
314
315 ret = qmp_fd(fixture->fd, "{'execute': 'guest-get-vcpus'}");
316 g_assert_nonnull(ret);
317 qmp_assert_no_error(ret);
318
319 /* check there is at least a cpu */
320 list = qdict_get_qlist(ret, "return");
321 entry = qlist_first(list);
Max Reitz7dc847e2018-02-24 16:40:29 +0100322 g_assert(qdict_haskey(qobject_to(QDict, entry->value), "online"));
323 g_assert(qdict_haskey(qobject_to(QDict, entry->value), "logical-id"));
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200324
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200325 qobject_unref(ret);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200326}
327
328static void test_qga_get_fsinfo(gconstpointer fix)
329{
330 const TestFixture *fixture = fix;
331 QDict *ret;
332 QList *list;
333 const QListEntry *entry;
334
335 ret = qmp_fd(fixture->fd, "{'execute': 'guest-get-fsinfo'}");
336 g_assert_nonnull(ret);
337 qmp_assert_no_error(ret);
338
Michael Rothb3e9e582015-10-20 11:17:36 -0500339 /* sanity-check the response if there are any filesystems */
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200340 list = qdict_get_qlist(ret, "return");
341 entry = qlist_first(list);
Michael Rothb3e9e582015-10-20 11:17:36 -0500342 if (entry) {
Max Reitz7dc847e2018-02-24 16:40:29 +0100343 g_assert(qdict_haskey(qobject_to(QDict, entry->value), "name"));
344 g_assert(qdict_haskey(qobject_to(QDict, entry->value), "mountpoint"));
345 g_assert(qdict_haskey(qobject_to(QDict, entry->value), "type"));
346 g_assert(qdict_haskey(qobject_to(QDict, entry->value), "disk"));
Michael Rothb3e9e582015-10-20 11:17:36 -0500347 }
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200348
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200349 qobject_unref(ret);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200350}
351
352static void test_qga_get_memory_block_info(gconstpointer fix)
353{
354 const TestFixture *fixture = fix;
355 QDict *ret, *val;
356 int64_t size;
357
358 ret = qmp_fd(fixture->fd, "{'execute': 'guest-get-memory-block-info'}");
359 g_assert_nonnull(ret);
360
361 /* some systems might not expose memory block info in sysfs */
362 if (!qdict_haskey(ret, "error")) {
363 /* check there is at least some memory */
364 val = qdict_get_qdict(ret, "return");
365 size = qdict_get_int(val, "size");
366 g_assert_cmpint(size, >, 0);
367 }
368
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200369 qobject_unref(ret);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200370}
371
372static void test_qga_get_memory_blocks(gconstpointer fix)
373{
374 const TestFixture *fixture = fix;
375 QDict *ret;
376 QList *list;
377 const QListEntry *entry;
378
379 ret = qmp_fd(fixture->fd, "{'execute': 'guest-get-memory-blocks'}");
380 g_assert_nonnull(ret);
381
382 /* some systems might not expose memory block info in sysfs */
383 if (!qdict_haskey(ret, "error")) {
384 list = qdict_get_qlist(ret, "return");
385 entry = qlist_first(list);
386 /* newer versions of qga may return empty list without error */
387 if (entry) {
Max Reitz7dc847e2018-02-24 16:40:29 +0100388 g_assert(qdict_haskey(qobject_to(QDict, entry->value),
389 "phys-index"));
390 g_assert(qdict_haskey(qobject_to(QDict, entry->value), "online"));
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200391 }
392 }
393
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200394 qobject_unref(ret);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200395}
396
397static void test_qga_network_get_interfaces(gconstpointer fix)
398{
399 const TestFixture *fixture = fix;
400 QDict *ret;
401 QList *list;
402 const QListEntry *entry;
403
404 ret = qmp_fd(fixture->fd, "{'execute': 'guest-network-get-interfaces'}");
405 g_assert_nonnull(ret);
406 qmp_assert_no_error(ret);
407
408 /* check there is at least an interface */
409 list = qdict_get_qlist(ret, "return");
410 entry = qlist_first(list);
Max Reitz7dc847e2018-02-24 16:40:29 +0100411 g_assert(qdict_haskey(qobject_to(QDict, entry->value), "name"));
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200412
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200413 qobject_unref(ret);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200414}
415
416static void test_qga_file_ops(gconstpointer fix)
417{
418 const TestFixture *fixture = fix;
Marc-André Lureau4eaab852015-11-25 13:59:12 +0100419 const unsigned char helloworld[] = "Hello World!\n";
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200420 const char *b64;
Markus Armbruster015715f2018-08-06 08:53:33 +0200421 gchar *path, *enc;
Marc-André Lureau4eaab852015-11-25 13:59:12 +0100422 unsigned char *dec;
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200423 QDict *ret, *val;
424 int64_t id, eof;
425 gsize count;
426 FILE *f;
427 char tmp[100];
428
429 /* open */
430 ret = qmp_fd(fixture->fd, "{'execute': 'guest-file-open',"
431 " 'arguments': { 'path': 'foo', 'mode': 'w+' } }");
432 g_assert_nonnull(ret);
433 qmp_assert_no_error(ret);
434 id = qdict_get_int(ret, "return");
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200435 qobject_unref(ret);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200436
437 enc = g_base64_encode(helloworld, sizeof(helloworld));
438 /* write */
Markus Armbruster015715f2018-08-06 08:53:33 +0200439 ret = qmp_fd(fixture->fd,
440 "{'execute': 'guest-file-write',"
441 " 'arguments': { 'handle': %" PRId64 ", 'buf-b64': %s } }",
442 id, enc);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200443 g_assert_nonnull(ret);
444 qmp_assert_no_error(ret);
445
446 val = qdict_get_qdict(ret, "return");
447 count = qdict_get_int(val, "count");
448 eof = qdict_get_bool(val, "eof");
449 g_assert_cmpint(count, ==, sizeof(helloworld));
450 g_assert_cmpint(eof, ==, 0);
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200451 qobject_unref(ret);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200452
453 /* flush */
Markus Armbruster015715f2018-08-06 08:53:33 +0200454 ret = qmp_fd(fixture->fd,
455 "{'execute': 'guest-file-flush',"
456 " 'arguments': {'handle': %" PRId64 "} }",
457 id);
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200458 qobject_unref(ret);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200459
460 /* close */
Markus Armbruster015715f2018-08-06 08:53:33 +0200461 ret = qmp_fd(fixture->fd,
462 "{'execute': 'guest-file-close',"
463 " 'arguments': {'handle': %" PRId64 "} }",
464 id);
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200465 qobject_unref(ret);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200466
467 /* check content */
468 path = g_build_filename(fixture->test_dir, "foo", NULL);
469 f = fopen(path, "r");
Marc-André Lureau1e271332016-07-15 18:00:18 +0200470 g_free(path);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200471 g_assert_nonnull(f);
472 count = fread(tmp, 1, sizeof(tmp), f);
473 g_assert_cmpint(count, ==, sizeof(helloworld));
474 tmp[count] = 0;
475 g_assert_cmpstr(tmp, ==, (char *)helloworld);
476 fclose(f);
477
478 /* open */
479 ret = qmp_fd(fixture->fd, "{'execute': 'guest-file-open',"
480 " 'arguments': { 'path': 'foo', 'mode': 'r' } }");
481 g_assert_nonnull(ret);
482 qmp_assert_no_error(ret);
483 id = qdict_get_int(ret, "return");
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200484 qobject_unref(ret);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200485
486 /* read */
Markus Armbruster015715f2018-08-06 08:53:33 +0200487 ret = qmp_fd(fixture->fd,
488 "{'execute': 'guest-file-read',"
489 " 'arguments': { 'handle': %" PRId64 "} }",
490 id);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200491 val = qdict_get_qdict(ret, "return");
492 count = qdict_get_int(val, "count");
493 eof = qdict_get_bool(val, "eof");
494 b64 = qdict_get_str(val, "buf-b64");
495 g_assert_cmpint(count, ==, sizeof(helloworld));
496 g_assert(eof);
497 g_assert_cmpstr(b64, ==, enc);
498
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200499 qobject_unref(ret);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200500 g_free(enc);
501
502 /* read eof */
Markus Armbruster015715f2018-08-06 08:53:33 +0200503 ret = qmp_fd(fixture->fd,
504 "{'execute': 'guest-file-read',"
505 " 'arguments': { 'handle': %" PRId64 "} }",
506 id);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200507 val = qdict_get_qdict(ret, "return");
508 count = qdict_get_int(val, "count");
509 eof = qdict_get_bool(val, "eof");
510 b64 = qdict_get_str(val, "buf-b64");
511 g_assert_cmpint(count, ==, 0);
512 g_assert(eof);
513 g_assert_cmpstr(b64, ==, "");
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200514 qobject_unref(ret);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200515
516 /* seek */
Markus Armbruster015715f2018-08-06 08:53:33 +0200517 ret = qmp_fd(fixture->fd,
518 "{'execute': 'guest-file-seek',"
519 " 'arguments': { 'handle': %" PRId64 ", "
520 " 'offset': %d, 'whence': %s } }",
521 id, 6, "set");
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200522 qmp_assert_no_error(ret);
523 val = qdict_get_qdict(ret, "return");
524 count = qdict_get_int(val, "position");
525 eof = qdict_get_bool(val, "eof");
526 g_assert_cmpint(count, ==, 6);
527 g_assert(!eof);
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200528 qobject_unref(ret);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200529
530 /* partial read */
Markus Armbruster015715f2018-08-06 08:53:33 +0200531 ret = qmp_fd(fixture->fd,
532 "{'execute': 'guest-file-read',"
533 " 'arguments': { 'handle': %" PRId64 "} }",
534 id);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200535 val = qdict_get_qdict(ret, "return");
536 count = qdict_get_int(val, "count");
537 eof = qdict_get_bool(val, "eof");
538 b64 = qdict_get_str(val, "buf-b64");
539 g_assert_cmpint(count, ==, sizeof(helloworld) - 6);
540 g_assert(eof);
541 dec = g_base64_decode(b64, &count);
542 g_assert_cmpint(count, ==, sizeof(helloworld) - 6);
543 g_assert_cmpmem(dec, count, helloworld + 6, sizeof(helloworld) - 6);
544 g_free(dec);
545
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200546 qobject_unref(ret);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200547
548 /* close */
Markus Armbruster015715f2018-08-06 08:53:33 +0200549 ret = qmp_fd(fixture->fd,
550 "{'execute': 'guest-file-close',"
551 " 'arguments': {'handle': %" PRId64 "} }",
552 id);
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200553 qobject_unref(ret);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200554}
555
Marc-André Lureau4eaab852015-11-25 13:59:12 +0100556static void test_qga_file_write_read(gconstpointer fix)
557{
558 const TestFixture *fixture = fix;
559 const unsigned char helloworld[] = "Hello World!\n";
560 const char *b64;
Markus Armbruster015715f2018-08-06 08:53:33 +0200561 gchar *enc;
Marc-André Lureau4eaab852015-11-25 13:59:12 +0100562 QDict *ret, *val;
563 int64_t id, eof;
564 gsize count;
565
566 /* open */
567 ret = qmp_fd(fixture->fd, "{'execute': 'guest-file-open',"
568 " 'arguments': { 'path': 'foo', 'mode': 'w+' } }");
569 g_assert_nonnull(ret);
570 qmp_assert_no_error(ret);
571 id = qdict_get_int(ret, "return");
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200572 qobject_unref(ret);
Marc-André Lureau4eaab852015-11-25 13:59:12 +0100573
574 enc = g_base64_encode(helloworld, sizeof(helloworld));
575 /* write */
Markus Armbruster015715f2018-08-06 08:53:33 +0200576 ret = qmp_fd(fixture->fd,
577 "{'execute': 'guest-file-write',"
578 " 'arguments': { 'handle': %" PRId64 ","
579 " 'buf-b64': %s } }", id, enc);
Marc-André Lureau4eaab852015-11-25 13:59:12 +0100580 g_assert_nonnull(ret);
581 qmp_assert_no_error(ret);
582
583 val = qdict_get_qdict(ret, "return");
584 count = qdict_get_int(val, "count");
585 eof = qdict_get_bool(val, "eof");
586 g_assert_cmpint(count, ==, sizeof(helloworld));
587 g_assert_cmpint(eof, ==, 0);
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200588 qobject_unref(ret);
Marc-André Lureau4eaab852015-11-25 13:59:12 +0100589
590 /* read (check implicit flush) */
Markus Armbruster015715f2018-08-06 08:53:33 +0200591 ret = qmp_fd(fixture->fd,
592 "{'execute': 'guest-file-read',"
593 " 'arguments': { 'handle': %" PRId64 "} }",
594 id);
Marc-André Lureau4eaab852015-11-25 13:59:12 +0100595 val = qdict_get_qdict(ret, "return");
596 count = qdict_get_int(val, "count");
597 eof = qdict_get_bool(val, "eof");
598 b64 = qdict_get_str(val, "buf-b64");
599 g_assert_cmpint(count, ==, 0);
600 g_assert(eof);
601 g_assert_cmpstr(b64, ==, "");
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200602 qobject_unref(ret);
Marc-André Lureau4eaab852015-11-25 13:59:12 +0100603
604 /* seek to 0 */
Markus Armbruster015715f2018-08-06 08:53:33 +0200605 ret = qmp_fd(fixture->fd,
606 "{'execute': 'guest-file-seek',"
607 " 'arguments': { 'handle': %" PRId64 ", "
608 " 'offset': %d, 'whence': %s } }",
609 id, 0, "set");
Marc-André Lureau4eaab852015-11-25 13:59:12 +0100610 qmp_assert_no_error(ret);
611 val = qdict_get_qdict(ret, "return");
612 count = qdict_get_int(val, "position");
613 eof = qdict_get_bool(val, "eof");
614 g_assert_cmpint(count, ==, 0);
615 g_assert(!eof);
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200616 qobject_unref(ret);
Marc-André Lureau4eaab852015-11-25 13:59:12 +0100617
618 /* read */
Markus Armbruster015715f2018-08-06 08:53:33 +0200619 ret = qmp_fd(fixture->fd,
620 "{'execute': 'guest-file-read',"
621 " 'arguments': { 'handle': %" PRId64 "} }",
622 id);
Marc-André Lureau4eaab852015-11-25 13:59:12 +0100623 val = qdict_get_qdict(ret, "return");
624 count = qdict_get_int(val, "count");
625 eof = qdict_get_bool(val, "eof");
626 b64 = qdict_get_str(val, "buf-b64");
627 g_assert_cmpint(count, ==, sizeof(helloworld));
628 g_assert(eof);
629 g_assert_cmpstr(b64, ==, enc);
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200630 qobject_unref(ret);
Marc-André Lureau4eaab852015-11-25 13:59:12 +0100631 g_free(enc);
632
633 /* close */
Markus Armbruster015715f2018-08-06 08:53:33 +0200634 ret = qmp_fd(fixture->fd,
635 "{'execute': 'guest-file-close',"
636 " 'arguments': {'handle': %" PRId64 "} }",
637 id);
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200638 qobject_unref(ret);
Marc-André Lureau4eaab852015-11-25 13:59:12 +0100639}
640
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200641static void test_qga_get_time(gconstpointer fix)
642{
643 const TestFixture *fixture = fix;
644 QDict *ret;
645 int64_t time;
646
647 ret = qmp_fd(fixture->fd, "{'execute': 'guest-get-time'}");
648 g_assert_nonnull(ret);
649 qmp_assert_no_error(ret);
650
651 time = qdict_get_int(ret, "return");
652 g_assert_cmpint(time, >, 0);
653
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200654 qobject_unref(ret);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200655}
656
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200657static void test_qga_blacklist(gconstpointer data)
658{
659 TestFixture fix;
660 QDict *ret, *error;
661 const gchar *class, *desc;
662
Tomáš Golembiovskýc28afa72017-07-14 16:28:57 +0200663 fixture_setup(&fix, "-b guest-ping,guest-get-time", NULL);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200664
665 /* check blacklist */
666 ret = qmp_fd(fix.fd, "{'execute': 'guest-ping'}");
667 g_assert_nonnull(ret);
668 error = qdict_get_qdict(ret, "error");
669 class = qdict_get_try_str(error, "class");
670 desc = qdict_get_try_str(error, "desc");
Michal Privoznik2546be12019-08-30 15:29:45 +0200671 g_assert_cmpstr(class, ==, "CommandNotFound");
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200672 g_assert_nonnull(g_strstr_len(desc, -1, "has been disabled"));
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200673 qobject_unref(ret);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200674
675 ret = qmp_fd(fix.fd, "{'execute': 'guest-get-time'}");
676 g_assert_nonnull(ret);
677 error = qdict_get_qdict(ret, "error");
678 class = qdict_get_try_str(error, "class");
679 desc = qdict_get_try_str(error, "desc");
Michal Privoznik2546be12019-08-30 15:29:45 +0200680 g_assert_cmpstr(class, ==, "CommandNotFound");
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200681 g_assert_nonnull(g_strstr_len(desc, -1, "has been disabled"));
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200682 qobject_unref(ret);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200683
684 /* check something work */
685 ret = qmp_fd(fix.fd, "{'execute': 'guest-get-fsinfo'}");
686 qmp_assert_no_error(ret);
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200687 qobject_unref(ret);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200688
689 fixture_tear_down(&fix, NULL);
690}
691
692static void test_qga_config(gconstpointer data)
693{
694 GError *error = NULL;
Marc-André Lureau1741b942016-06-15 13:06:01 +0200695 char *cwd, *cmd, *out, *err, *str, **strv, **argv = NULL;
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200696 char *env[2];
Marc-André Lureau1741b942016-06-15 13:06:01 +0200697 int status;
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200698 gsize n;
699 GKeyFile *kf;
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200700
701 cwd = g_get_current_dir();
702 cmd = g_strdup_printf("%s%cqemu-ga -D",
703 cwd, G_DIR_SEPARATOR);
Marc-André Lureau1e271332016-07-15 18:00:18 +0200704 g_free(cwd);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200705 g_shell_parse_argv(cmd, NULL, &argv, &error);
Marc-André Lureau1e271332016-07-15 18:00:18 +0200706 g_free(cmd);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200707 g_assert_no_error(error);
708
Marc-André Lureau1741b942016-06-15 13:06:01 +0200709 env[0] = g_strdup_printf("QGA_CONF=tests%cdata%ctest-qga-config",
710 G_DIR_SEPARATOR, G_DIR_SEPARATOR);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200711 env[1] = NULL;
712 g_spawn_sync(NULL, argv, env, 0,
713 NULL, NULL, &out, &err, &status, &error);
Marc-André Lureau1e271332016-07-15 18:00:18 +0200714 g_strfreev(argv);
715
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200716 g_assert_no_error(error);
717 g_assert_cmpstr(err, ==, "");
718 g_assert_cmpint(status, ==, 0);
719
720 kf = g_key_file_new();
721 g_key_file_load_from_data(kf, out, -1, G_KEY_FILE_NONE, &error);
722 g_assert_no_error(error);
723
724 str = g_key_file_get_start_group(kf);
725 g_assert_cmpstr(str, ==, "general");
726 g_free(str);
727
728 g_assert_false(g_key_file_get_boolean(kf, "general", "daemon", &error));
729 g_assert_no_error(error);
730
731 str = g_key_file_get_string(kf, "general", "method", &error);
732 g_assert_no_error(error);
733 g_assert_cmpstr(str, ==, "virtio-serial");
734 g_free(str);
735
736 str = g_key_file_get_string(kf, "general", "path", &error);
737 g_assert_no_error(error);
738 g_assert_cmpstr(str, ==, "/path/to/org.qemu.guest_agent.0");
739 g_free(str);
740
741 str = g_key_file_get_string(kf, "general", "pidfile", &error);
742 g_assert_no_error(error);
743 g_assert_cmpstr(str, ==, "/var/foo/qemu-ga.pid");
744 g_free(str);
745
746 str = g_key_file_get_string(kf, "general", "statedir", &error);
747 g_assert_no_error(error);
748 g_assert_cmpstr(str, ==, "/var/state");
749 g_free(str);
750
751 g_assert_true(g_key_file_get_boolean(kf, "general", "verbose", &error));
752 g_assert_no_error(error);
753
754 strv = g_key_file_get_string_list(kf, "general", "blacklist", &n, &error);
755 g_assert_cmpint(n, ==, 2);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200756 g_assert_true(g_strv_contains((const char * const *)strv,
757 "guest-ping"));
758 g_assert_true(g_strv_contains((const char * const *)strv,
759 "guest-get-time"));
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200760 g_assert_no_error(error);
761 g_strfreev(strv);
762
763 g_free(out);
764 g_free(err);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200765 g_free(env[0]);
766 g_key_file_free(kf);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200767}
768
769static void test_qga_fsfreeze_status(gconstpointer fix)
770{
771 const TestFixture *fixture = fix;
772 QDict *ret;
773 const gchar *status;
774
775 ret = qmp_fd(fixture->fd, "{'execute': 'guest-fsfreeze-status'}");
776 g_assert_nonnull(ret);
777 qmp_assert_no_error(ret);
778
779 status = qdict_get_try_str(ret, "return");
780 g_assert_cmpstr(status, ==, "thawed");
781
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200782 qobject_unref(ret);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200783}
784
Marc-André Lureau3dab9fa2016-06-03 14:27:50 +0200785static void test_qga_guest_exec(gconstpointer fix)
786{
787 const TestFixture *fixture = fix;
788 QDict *ret, *val;
789 const gchar *out;
790 guchar *decoded;
791 int64_t pid, now, exitcode;
792 gsize len;
793 bool exited;
794
795 /* exec 'echo foo bar' */
796 ret = qmp_fd(fixture->fd, "{'execute': 'guest-exec', 'arguments': {"
797 " 'path': '/bin/echo', 'arg': [ '-n', '\" test_str \"' ],"
798 " 'capture-output': true } }");
799 g_assert_nonnull(ret);
800 qmp_assert_no_error(ret);
801 val = qdict_get_qdict(ret, "return");
802 pid = qdict_get_int(val, "pid");
803 g_assert_cmpint(pid, >, 0);
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200804 qobject_unref(ret);
Marc-André Lureau3dab9fa2016-06-03 14:27:50 +0200805
806 /* wait for completion */
807 now = g_get_monotonic_time();
808 do {
Markus Armbruster015715f2018-08-06 08:53:33 +0200809 ret = qmp_fd(fixture->fd,
810 "{'execute': 'guest-exec-status',"
811 " 'arguments': { 'pid': %" PRId64 " } }", pid);
Marc-André Lureau3dab9fa2016-06-03 14:27:50 +0200812 g_assert_nonnull(ret);
813 val = qdict_get_qdict(ret, "return");
814 exited = qdict_get_bool(val, "exited");
815 if (!exited) {
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200816 qobject_unref(ret);
Marc-André Lureau3dab9fa2016-06-03 14:27:50 +0200817 }
818 } while (!exited &&
819 g_get_monotonic_time() < now + 5 * G_TIME_SPAN_SECOND);
820 g_assert(exited);
821
822 /* check stdout */
823 exitcode = qdict_get_int(val, "exitcode");
824 g_assert_cmpint(exitcode, ==, 0);
825 out = qdict_get_str(val, "out-data");
826 decoded = g_base64_decode(out, &len);
827 g_assert_cmpint(len, ==, 12);
828 g_assert_cmpstr((char *)decoded, ==, "\" test_str \"");
829 g_free(decoded);
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200830 qobject_unref(ret);
Marc-André Lureau3dab9fa2016-06-03 14:27:50 +0200831}
832
833static void test_qga_guest_exec_invalid(gconstpointer fix)
834{
835 const TestFixture *fixture = fix;
836 QDict *ret, *error;
837 const gchar *class, *desc;
838
839 /* invalid command */
840 ret = qmp_fd(fixture->fd, "{'execute': 'guest-exec', 'arguments': {"
841 " 'path': '/bin/invalid-cmd42' } }");
842 g_assert_nonnull(ret);
843 error = qdict_get_qdict(ret, "error");
844 g_assert_nonnull(error);
845 class = qdict_get_str(error, "class");
846 desc = qdict_get_str(error, "desc");
847 g_assert_cmpstr(class, ==, "GenericError");
848 g_assert_cmpint(strlen(desc), >, 0);
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200849 qobject_unref(ret);
Marc-André Lureau3dab9fa2016-06-03 14:27:50 +0200850
851 /* invalid pid */
852 ret = qmp_fd(fixture->fd, "{'execute': 'guest-exec-status',"
853 " 'arguments': { 'pid': 0 } }");
854 g_assert_nonnull(ret);
855 error = qdict_get_qdict(ret, "error");
856 g_assert_nonnull(error);
857 class = qdict_get_str(error, "class");
858 desc = qdict_get_str(error, "desc");
859 g_assert_cmpstr(class, ==, "GenericError");
860 g_assert_cmpint(strlen(desc), >, 0);
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200861 qobject_unref(ret);
Marc-André Lureau3dab9fa2016-06-03 14:27:50 +0200862}
863
Tomáš Golembiovský509b97f2018-04-20 20:04:34 +0200864static void test_qga_guest_get_host_name(gconstpointer fix)
865{
866 const TestFixture *fixture = fix;
867 QDict *ret, *val;
868
869 ret = qmp_fd(fixture->fd, "{'execute': 'guest-get-host-name'}");
870 g_assert_nonnull(ret);
871 qmp_assert_no_error(ret);
872
873 val = qdict_get_qdict(ret, "return");
874 g_assert(qdict_haskey(val, "host-name"));
875
876 qobject_unref(ret);
877}
878
879static void test_qga_guest_get_timezone(gconstpointer fix)
880{
881 const TestFixture *fixture = fix;
882 QDict *ret, *val;
883
884 ret = qmp_fd(fixture->fd, "{'execute': 'guest-get-timezone'}");
885 g_assert_nonnull(ret);
886 qmp_assert_no_error(ret);
887
888 /* Make sure there's at least offset */
889 val = qdict_get_qdict(ret, "return");
890 g_assert(qdict_haskey(val, "offset"));
891
892 qobject_unref(ret);
893}
894
895static void test_qga_guest_get_users(gconstpointer fix)
896{
897 const TestFixture *fixture = fix;
898 QDict *ret;
899 QList *val;
900
901 ret = qmp_fd(fixture->fd, "{'execute': 'guest-get-users'}");
902 g_assert_nonnull(ret);
903 qmp_assert_no_error(ret);
904
905 /* There is not much to test here */
906 val = qdict_get_qlist(ret, "return");
907 g_assert_nonnull(val);
908
909 qobject_unref(ret);
910}
911
Tomáš Golembiovský339ca682017-07-14 16:28:58 +0200912static void test_qga_guest_get_osinfo(gconstpointer data)
913{
914 TestFixture fixture;
915 const gchar *str;
916 gchar *cwd, *env[2];
917 QDict *ret, *val;
918
919 cwd = g_get_current_dir();
920 env[0] = g_strdup_printf(
921 "QGA_OS_RELEASE=%s%ctests%cdata%ctest-qga-os-release",
922 cwd, G_DIR_SEPARATOR, G_DIR_SEPARATOR, G_DIR_SEPARATOR);
923 env[1] = NULL;
924 g_free(cwd);
925 fixture_setup(&fixture, NULL, env);
926
927 ret = qmp_fd(fixture.fd, "{'execute': 'guest-get-osinfo'}");
928 g_assert_nonnull(ret);
929 qmp_assert_no_error(ret);
930
931 val = qdict_get_qdict(ret, "return");
932
933 str = qdict_get_try_str(val, "id");
934 g_assert_nonnull(str);
935 g_assert_cmpstr(str, ==, "qemu-ga-test");
936
937 str = qdict_get_try_str(val, "name");
938 g_assert_nonnull(str);
939 g_assert_cmpstr(str, ==, "QEMU-GA");
940
941 str = qdict_get_try_str(val, "pretty-name");
942 g_assert_nonnull(str);
943 g_assert_cmpstr(str, ==, "QEMU Guest Agent test");
944
945 str = qdict_get_try_str(val, "version");
946 g_assert_nonnull(str);
947 g_assert_cmpstr(str, ==, "Test 1");
948
949 str = qdict_get_try_str(val, "version-id");
950 g_assert_nonnull(str);
951 g_assert_cmpstr(str, ==, "1");
952
953 str = qdict_get_try_str(val, "variant");
954 g_assert_nonnull(str);
955 g_assert_cmpstr(str, ==, "Unit test \"'$`\\ and \\\\ etc.");
956
957 str = qdict_get_try_str(val, "variant-id");
958 g_assert_nonnull(str);
959 g_assert_cmpstr(str, ==, "unit-test");
960
Marc-André Lureaucb3e7f02018-04-19 17:01:43 +0200961 qobject_unref(ret);
Tomáš Golembiovský339ca682017-07-14 16:28:58 +0200962 g_free(env[0]);
963 fixture_tear_down(&fixture, NULL);
964}
965
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200966int main(int argc, char **argv)
967{
968 TestFixture fix;
969 int ret;
970
971 setlocale (LC_ALL, "");
972 g_test_init(&argc, &argv, NULL);
Tomáš Golembiovskýc28afa72017-07-14 16:28:57 +0200973 fixture_setup(&fix, NULL, NULL);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200974
975 g_test_add_data_func("/qga/sync-delimited", &fix, test_qga_sync_delimited);
976 g_test_add_data_func("/qga/sync", &fix, test_qga_sync);
977 g_test_add_data_func("/qga/ping", &fix, test_qga_ping);
978 g_test_add_data_func("/qga/info", &fix, test_qga_info);
979 g_test_add_data_func("/qga/network-get-interfaces", &fix,
980 test_qga_network_get_interfaces);
Bruce Rogersec72c0e2017-03-02 12:44:37 -0700981 if (!access("/sys/devices/system/cpu/cpu0", F_OK)) {
982 g_test_add_data_func("/qga/get-vcpus", &fix, test_qga_get_vcpus);
983 }
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200984 g_test_add_data_func("/qga/get-fsinfo", &fix, test_qga_get_fsinfo);
985 g_test_add_data_func("/qga/get-memory-block-info", &fix,
986 test_qga_get_memory_block_info);
987 g_test_add_data_func("/qga/get-memory-blocks", &fix,
988 test_qga_get_memory_blocks);
989 g_test_add_data_func("/qga/file-ops", &fix, test_qga_file_ops);
Marc-André Lureau4eaab852015-11-25 13:59:12 +0100990 g_test_add_data_func("/qga/file-write-read", &fix, test_qga_file_write_read);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200991 g_test_add_data_func("/qga/get-time", &fix, test_qga_get_time);
Marc-André Lureau4eaca8d2019-02-20 16:42:53 +0100992 g_test_add_data_func("/qga/id", &fix, test_qga_id);
Markus Armbrusterd4d7ed72018-07-03 10:53:36 +0200993 g_test_add_data_func("/qga/invalid-oob", &fix, test_qga_invalid_oob);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200994 g_test_add_data_func("/qga/invalid-cmd", &fix, test_qga_invalid_cmd);
Marc-André Lureau4bdadd82016-09-12 13:19:09 +0400995 g_test_add_data_func("/qga/invalid-args", &fix, test_qga_invalid_args);
Marc-André Lureau62c39b32015-10-02 14:58:18 +0200996 g_test_add_data_func("/qga/fsfreeze-status", &fix,
997 test_qga_fsfreeze_status);
998
999 g_test_add_data_func("/qga/blacklist", NULL, test_qga_blacklist);
1000 g_test_add_data_func("/qga/config", NULL, test_qga_config);
Marc-André Lureau3dab9fa2016-06-03 14:27:50 +02001001 g_test_add_data_func("/qga/guest-exec", &fix, test_qga_guest_exec);
1002 g_test_add_data_func("/qga/guest-exec-invalid", &fix,
1003 test_qga_guest_exec_invalid);
Tomáš Golembiovský339ca682017-07-14 16:28:58 +02001004 g_test_add_data_func("/qga/guest-get-osinfo", &fix,
1005 test_qga_guest_get_osinfo);
Tomáš Golembiovský509b97f2018-04-20 20:04:34 +02001006 g_test_add_data_func("/qga/guest-get-host-name", &fix,
1007 test_qga_guest_get_host_name);
1008 g_test_add_data_func("/qga/guest-get-timezone", &fix,
1009 test_qga_guest_get_timezone);
1010 g_test_add_data_func("/qga/guest-get-users", &fix,
1011 test_qga_guest_get_users);
Marc-André Lureau62c39b32015-10-02 14:58:18 +02001012
Marc-André Lureau62c39b32015-10-02 14:58:18 +02001013 ret = g_test_run();
1014
1015 fixture_tear_down(&fix, NULL);
1016
1017 return ret;
1018}