1 #include "qemu/osdep.h"
4 #include <glib/gstdio.h>
5 #include <sys/socket.h>
9 #include "qga/guest-agent-core.h"
18 static int connect_qga(char *path
)
20 int s
, ret
, len
, i
= 0;
21 struct sockaddr_un remote
;
23 s
= socket(AF_UNIX
, SOCK_STREAM
, 0);
26 remote
.sun_family
= AF_UNIX
;
28 strcpy(remote
.sun_path
, path
);
29 len
= strlen(remote
.sun_path
) + sizeof(remote
.sun_family
);
30 ret
= connect(s
, (struct sockaddr
*)&remote
, len
);
32 g_usleep(G_USEC_PER_SEC
);
42 static void qga_watch(GPid pid
, gint status
, gpointer user_data
)
44 TestFixture
*fixture
= user_data
;
46 g_assert_cmpint(status
, ==, 0);
47 g_main_loop_quit(fixture
->loop
);
51 fixture_setup(TestFixture
*fixture
, gconstpointer data
)
53 const gchar
*extra_arg
= data
;
55 gchar
*cwd
, *path
, *cmd
, **argv
= NULL
;
57 fixture
->loop
= g_main_loop_new(NULL
, FALSE
);
59 fixture
->test_dir
= g_strdup("/tmp/qgatest.XXXXXX");
60 g_assert_nonnull(mkdtemp(fixture
->test_dir
));
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",
66 fixture
->test_dir
, path
,
67 getenv("QTEST_LOG") ? "-v" : "",
69 g_shell_parse_argv(cmd
, NULL
, &argv
, &error
);
70 g_assert_no_error(error
);
72 g_spawn_async(fixture
->test_dir
, argv
, NULL
,
73 G_SPAWN_SEARCH_PATH
|G_SPAWN_DO_NOT_REAP_CHILD
,
74 NULL
, NULL
, &fixture
->pid
, &error
);
75 g_assert_no_error(error
);
77 g_child_watch_add(fixture
->pid
, qga_watch
, fixture
);
79 fixture
->fd
= connect_qga(path
);
80 g_assert_cmpint(fixture
->fd
, !=, -1);
89 fixture_tear_down(TestFixture
*fixture
, gconstpointer data
)
93 kill(fixture
->pid
, SIGTERM
);
95 g_main_loop_run(fixture
->loop
);
96 g_main_loop_unref(fixture
->loop
);
98 g_spawn_close_pid(fixture
->pid
);
100 tmp
= g_build_filename(fixture
->test_dir
, "foo", NULL
);
104 tmp
= g_build_filename(fixture
->test_dir
, "qga.state", NULL
);
108 tmp
= g_build_filename(fixture
->test_dir
, "sock", NULL
);
112 g_rmdir(fixture
->test_dir
);
113 g_free(fixture
->test_dir
);
116 static void qmp_assertion_message_error(const char *domain
,
123 const char *class, *desc
;
127 error
= qdict_get_qdict(dict
, "error");
128 class = qdict_get_try_str(error
, "class");
129 desc
= qdict_get_try_str(error
, "desc");
131 s
= g_strdup_printf("assertion failed %s: %s %s", expr
, class, desc
);
132 g_assertion_message(domain
, file
, line
, func
, s
);
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); \
143 static void test_qga_sync_delimited(gconstpointer fix
)
145 const TestFixture
*fixture
= fix
;
146 guint32 v
, r
= g_random_int();
151 cmd
= g_strdup_printf("%c{'execute': 'guest-sync-delimited',"
152 " 'arguments': {'id': %u } }", 0xff, r
);
153 qmp_fd_send(fixture
->fd
, cmd
);
156 v
= read(fixture
->fd
, &c
, 1);
157 g_assert_cmpint(v
, ==, 1);
158 g_assert_cmpint(c
, ==, 0xff);
160 ret
= qmp_fd_receive(fixture
->fd
);
161 g_assert_nonnull(ret
);
162 qmp_assert_no_error(ret
);
164 v
= qdict_get_int(ret
, "return");
165 g_assert_cmpint(r
, ==, v
);
170 static void test_qga_sync(gconstpointer fix
)
172 const TestFixture
*fixture
= fix
;
173 guint32 v
, r
= g_random_int();
177 cmd
= g_strdup_printf("%c{'execute': 'guest-sync',"
178 " 'arguments': {'id': %u } }", 0xff, r
);
179 ret
= qmp_fd(fixture
->fd
, cmd
);
182 g_assert_nonnull(ret
);
183 qmp_assert_no_error(ret
);
185 v
= qdict_get_int(ret
, "return");
186 g_assert_cmpint(r
, ==, v
);
191 static void test_qga_ping(gconstpointer fix
)
193 const TestFixture
*fixture
= fix
;
196 ret
= qmp_fd(fixture
->fd
, "{'execute': 'guest-ping'}");
197 g_assert_nonnull(ret
);
198 qmp_assert_no_error(ret
);
203 static void test_qga_invalid_cmd(gconstpointer fix
)
205 const TestFixture
*fixture
= fix
;
207 const gchar
*class, *desc
;
209 ret
= qmp_fd(fixture
->fd
, "{'execute': 'guest-invalid-cmd'}");
210 g_assert_nonnull(ret
);
212 error
= qdict_get_qdict(ret
, "error");
213 class = qdict_get_try_str(error
, "class");
214 desc
= qdict_get_try_str(error
, "desc");
216 g_assert_cmpstr(class, ==, "CommandNotFound");
217 g_assert_cmpint(strlen(desc
), >, 0);
222 static void test_qga_info(gconstpointer fix
)
224 const TestFixture
*fixture
= fix
;
226 const gchar
*version
;
228 ret
= qmp_fd(fixture
->fd
, "{'execute': 'guest-info'}");
229 g_assert_nonnull(ret
);
230 qmp_assert_no_error(ret
);
232 val
= qdict_get_qdict(ret
, "return");
233 version
= qdict_get_try_str(val
, "version");
234 g_assert_cmpstr(version
, ==, QEMU_VERSION
);
239 static void test_qga_get_vcpus(gconstpointer fix
)
241 const TestFixture
*fixture
= fix
;
244 const QListEntry
*entry
;
246 ret
= qmp_fd(fixture
->fd
, "{'execute': 'guest-get-vcpus'}");
247 g_assert_nonnull(ret
);
248 qmp_assert_no_error(ret
);
250 /* check there is at least a cpu */
251 list
= qdict_get_qlist(ret
, "return");
252 entry
= qlist_first(list
);
253 g_assert(qdict_haskey(qobject_to_qdict(entry
->value
), "online"));
254 g_assert(qdict_haskey(qobject_to_qdict(entry
->value
), "logical-id"));
259 static void test_qga_get_fsinfo(gconstpointer fix
)
261 const TestFixture
*fixture
= fix
;
264 const QListEntry
*entry
;
266 ret
= qmp_fd(fixture
->fd
, "{'execute': 'guest-get-fsinfo'}");
267 g_assert_nonnull(ret
);
268 qmp_assert_no_error(ret
);
270 /* sanity-check the response if there are any filesystems */
271 list
= qdict_get_qlist(ret
, "return");
272 entry
= qlist_first(list
);
274 g_assert(qdict_haskey(qobject_to_qdict(entry
->value
), "name"));
275 g_assert(qdict_haskey(qobject_to_qdict(entry
->value
), "mountpoint"));
276 g_assert(qdict_haskey(qobject_to_qdict(entry
->value
), "type"));
277 g_assert(qdict_haskey(qobject_to_qdict(entry
->value
), "disk"));
283 static void test_qga_get_memory_block_info(gconstpointer fix
)
285 const TestFixture
*fixture
= fix
;
289 ret
= qmp_fd(fixture
->fd
, "{'execute': 'guest-get-memory-block-info'}");
290 g_assert_nonnull(ret
);
292 /* some systems might not expose memory block info in sysfs */
293 if (!qdict_haskey(ret
, "error")) {
294 /* check there is at least some memory */
295 val
= qdict_get_qdict(ret
, "return");
296 size
= qdict_get_int(val
, "size");
297 g_assert_cmpint(size
, >, 0);
303 static void test_qga_get_memory_blocks(gconstpointer fix
)
305 const TestFixture
*fixture
= fix
;
308 const QListEntry
*entry
;
310 ret
= qmp_fd(fixture
->fd
, "{'execute': 'guest-get-memory-blocks'}");
311 g_assert_nonnull(ret
);
313 /* some systems might not expose memory block info in sysfs */
314 if (!qdict_haskey(ret
, "error")) {
315 list
= qdict_get_qlist(ret
, "return");
316 entry
= qlist_first(list
);
317 /* newer versions of qga may return empty list without error */
319 g_assert(qdict_haskey(qobject_to_qdict(entry
->value
), "phys-index"));
320 g_assert(qdict_haskey(qobject_to_qdict(entry
->value
), "online"));
327 static void test_qga_network_get_interfaces(gconstpointer fix
)
329 const TestFixture
*fixture
= fix
;
332 const QListEntry
*entry
;
334 ret
= qmp_fd(fixture
->fd
, "{'execute': 'guest-network-get-interfaces'}");
335 g_assert_nonnull(ret
);
336 qmp_assert_no_error(ret
);
338 /* check there is at least an interface */
339 list
= qdict_get_qlist(ret
, "return");
340 entry
= qlist_first(list
);
341 g_assert(qdict_haskey(qobject_to_qdict(entry
->value
), "name"));
346 static void test_qga_file_ops(gconstpointer fix
)
348 const TestFixture
*fixture
= fix
;
349 const unsigned char helloworld
[] = "Hello World!\n";
351 gchar
*cmd
, *path
, *enc
;
360 ret
= qmp_fd(fixture
->fd
, "{'execute': 'guest-file-open',"
361 " 'arguments': { 'path': 'foo', 'mode': 'w+' } }");
362 g_assert_nonnull(ret
);
363 qmp_assert_no_error(ret
);
364 id
= qdict_get_int(ret
, "return");
367 enc
= g_base64_encode(helloworld
, sizeof(helloworld
));
369 cmd
= g_strdup_printf("{'execute': 'guest-file-write',"
370 " 'arguments': { 'handle': %" PRId64
","
371 " 'buf-b64': '%s' } }", id
, enc
);
372 ret
= qmp_fd(fixture
->fd
, cmd
);
373 g_assert_nonnull(ret
);
374 qmp_assert_no_error(ret
);
376 val
= qdict_get_qdict(ret
, "return");
377 count
= qdict_get_int(val
, "count");
378 eof
= qdict_get_bool(val
, "eof");
379 g_assert_cmpint(count
, ==, sizeof(helloworld
));
380 g_assert_cmpint(eof
, ==, 0);
385 cmd
= g_strdup_printf("{'execute': 'guest-file-flush',"
386 " 'arguments': {'handle': %" PRId64
"} }",
388 ret
= qmp_fd(fixture
->fd
, cmd
);
393 cmd
= g_strdup_printf("{'execute': 'guest-file-close',"
394 " 'arguments': {'handle': %" PRId64
"} }",
396 ret
= qmp_fd(fixture
->fd
, cmd
);
401 path
= g_build_filename(fixture
->test_dir
, "foo", NULL
);
402 f
= fopen(path
, "r");
404 count
= fread(tmp
, 1, sizeof(tmp
), f
);
405 g_assert_cmpint(count
, ==, sizeof(helloworld
));
407 g_assert_cmpstr(tmp
, ==, (char *)helloworld
);
411 ret
= qmp_fd(fixture
->fd
, "{'execute': 'guest-file-open',"
412 " 'arguments': { 'path': 'foo', 'mode': 'r' } }");
413 g_assert_nonnull(ret
);
414 qmp_assert_no_error(ret
);
415 id
= qdict_get_int(ret
, "return");
419 cmd
= g_strdup_printf("{'execute': 'guest-file-read',"
420 " 'arguments': { 'handle': %" PRId64
"} }",
422 ret
= qmp_fd(fixture
->fd
, cmd
);
423 val
= qdict_get_qdict(ret
, "return");
424 count
= qdict_get_int(val
, "count");
425 eof
= qdict_get_bool(val
, "eof");
426 b64
= qdict_get_str(val
, "buf-b64");
427 g_assert_cmpint(count
, ==, sizeof(helloworld
));
429 g_assert_cmpstr(b64
, ==, enc
);
436 cmd
= g_strdup_printf("{'execute': 'guest-file-read',"
437 " 'arguments': { 'handle': %" PRId64
"} }",
439 ret
= qmp_fd(fixture
->fd
, cmd
);
440 val
= qdict_get_qdict(ret
, "return");
441 count
= qdict_get_int(val
, "count");
442 eof
= qdict_get_bool(val
, "eof");
443 b64
= qdict_get_str(val
, "buf-b64");
444 g_assert_cmpint(count
, ==, 0);
446 g_assert_cmpstr(b64
, ==, "");
451 cmd
= g_strdup_printf("{'execute': 'guest-file-seek',"
452 " 'arguments': { 'handle': %" PRId64
", "
453 " 'offset': %d, 'whence': %d } }",
454 id
, 6, QGA_SEEK_SET
);
455 ret
= qmp_fd(fixture
->fd
, cmd
);
456 qmp_assert_no_error(ret
);
457 val
= qdict_get_qdict(ret
, "return");
458 count
= qdict_get_int(val
, "position");
459 eof
= qdict_get_bool(val
, "eof");
460 g_assert_cmpint(count
, ==, 6);
466 cmd
= g_strdup_printf("{'execute': 'guest-file-read',"
467 " 'arguments': { 'handle': %" PRId64
"} }",
469 ret
= qmp_fd(fixture
->fd
, cmd
);
470 val
= qdict_get_qdict(ret
, "return");
471 count
= qdict_get_int(val
, "count");
472 eof
= qdict_get_bool(val
, "eof");
473 b64
= qdict_get_str(val
, "buf-b64");
474 g_assert_cmpint(count
, ==, sizeof(helloworld
) - 6);
476 dec
= g_base64_decode(b64
, &count
);
477 g_assert_cmpint(count
, ==, sizeof(helloworld
) - 6);
478 g_assert_cmpmem(dec
, count
, helloworld
+ 6, sizeof(helloworld
) - 6);
485 cmd
= g_strdup_printf("{'execute': 'guest-file-close',"
486 " 'arguments': {'handle': %" PRId64
"} }",
488 ret
= qmp_fd(fixture
->fd
, cmd
);
493 static void test_qga_file_write_read(gconstpointer fix
)
495 const TestFixture
*fixture
= fix
;
496 const unsigned char helloworld
[] = "Hello World!\n";
504 ret
= qmp_fd(fixture
->fd
, "{'execute': 'guest-file-open',"
505 " 'arguments': { 'path': 'foo', 'mode': 'w+' } }");
506 g_assert_nonnull(ret
);
507 qmp_assert_no_error(ret
);
508 id
= qdict_get_int(ret
, "return");
511 enc
= g_base64_encode(helloworld
, sizeof(helloworld
));
513 cmd
= g_strdup_printf("{'execute': 'guest-file-write',"
514 " 'arguments': { 'handle': %" PRId64
","
515 " 'buf-b64': '%s' } }", id
, enc
);
516 ret
= qmp_fd(fixture
->fd
, cmd
);
517 g_assert_nonnull(ret
);
518 qmp_assert_no_error(ret
);
520 val
= qdict_get_qdict(ret
, "return");
521 count
= qdict_get_int(val
, "count");
522 eof
= qdict_get_bool(val
, "eof");
523 g_assert_cmpint(count
, ==, sizeof(helloworld
));
524 g_assert_cmpint(eof
, ==, 0);
528 /* read (check implicit flush) */
529 cmd
= g_strdup_printf("{'execute': 'guest-file-read',"
530 " 'arguments': { 'handle': %" PRId64
"} }",
532 ret
= qmp_fd(fixture
->fd
, cmd
);
533 val
= qdict_get_qdict(ret
, "return");
534 count
= qdict_get_int(val
, "count");
535 eof
= qdict_get_bool(val
, "eof");
536 b64
= qdict_get_str(val
, "buf-b64");
537 g_assert_cmpint(count
, ==, 0);
539 g_assert_cmpstr(b64
, ==, "");
544 cmd
= g_strdup_printf("{'execute': 'guest-file-seek',"
545 " 'arguments': { 'handle': %" PRId64
", "
546 " 'offset': %d, 'whence': %d } }",
547 id
, 0, QGA_SEEK_SET
);
548 ret
= qmp_fd(fixture
->fd
, cmd
);
549 qmp_assert_no_error(ret
);
550 val
= qdict_get_qdict(ret
, "return");
551 count
= qdict_get_int(val
, "position");
552 eof
= qdict_get_bool(val
, "eof");
553 g_assert_cmpint(count
, ==, 0);
559 cmd
= g_strdup_printf("{'execute': 'guest-file-read',"
560 " 'arguments': { 'handle': %" PRId64
"} }",
562 ret
= qmp_fd(fixture
->fd
, cmd
);
563 val
= qdict_get_qdict(ret
, "return");
564 count
= qdict_get_int(val
, "count");
565 eof
= qdict_get_bool(val
, "eof");
566 b64
= qdict_get_str(val
, "buf-b64");
567 g_assert_cmpint(count
, ==, sizeof(helloworld
));
569 g_assert_cmpstr(b64
, ==, enc
);
575 cmd
= g_strdup_printf("{'execute': 'guest-file-close',"
576 " 'arguments': {'handle': %" PRId64
"} }",
578 ret
= qmp_fd(fixture
->fd
, cmd
);
583 static void test_qga_get_time(gconstpointer fix
)
585 const TestFixture
*fixture
= fix
;
589 ret
= qmp_fd(fixture
->fd
, "{'execute': 'guest-get-time'}");
590 g_assert_nonnull(ret
);
591 qmp_assert_no_error(ret
);
593 time
= qdict_get_int(ret
, "return");
594 g_assert_cmpint(time
, >, 0);
599 static void test_qga_set_time(gconstpointer fix
)
601 const TestFixture
*fixture
= fix
;
603 int64_t current
, time
;
606 /* get current time */
607 ret
= qmp_fd(fixture
->fd
, "{'execute': 'guest-get-time'}");
608 g_assert_nonnull(ret
);
609 qmp_assert_no_error(ret
);
610 current
= qdict_get_int(ret
, "return");
611 g_assert_cmpint(current
, >, 0);
614 /* set some old time */
615 ret
= qmp_fd(fixture
->fd
, "{'execute': 'guest-set-time',"
616 " 'arguments': { 'time': 1000 } }");
617 g_assert_nonnull(ret
);
618 qmp_assert_no_error(ret
);
622 ret
= qmp_fd(fixture
->fd
, "{'execute': 'guest-get-time'}");
623 g_assert_nonnull(ret
);
624 qmp_assert_no_error(ret
);
625 time
= qdict_get_int(ret
, "return");
626 g_assert_cmpint(time
/ 1000, <, G_USEC_PER_SEC
* 10);
629 /* set back current time */
630 cmd
= g_strdup_printf("{'execute': 'guest-set-time',"
631 " 'arguments': { 'time': %" PRId64
" } }",
632 current
+ time
* 1000);
633 ret
= qmp_fd(fixture
->fd
, cmd
);
635 g_assert_nonnull(ret
);
636 qmp_assert_no_error(ret
);
640 static void test_qga_fstrim(gconstpointer fix
)
642 const TestFixture
*fixture
= fix
;
645 const QListEntry
*entry
;
647 ret
= qmp_fd(fixture
->fd
, "{'execute': 'guest-fstrim',"
648 " arguments: { minimum: 4194304 } }");
649 g_assert_nonnull(ret
);
650 qmp_assert_no_error(ret
);
651 list
= qdict_get_qlist(ret
, "return");
652 entry
= qlist_first(list
);
653 g_assert(qdict_haskey(qobject_to_qdict(entry
->value
), "paths"));
658 static void test_qga_blacklist(gconstpointer data
)
662 const gchar
*class, *desc
;
664 fixture_setup(&fix
, "-b guest-ping,guest-get-time");
666 /* check blacklist */
667 ret
= qmp_fd(fix
.fd
, "{'execute': 'guest-ping'}");
668 g_assert_nonnull(ret
);
669 error
= qdict_get_qdict(ret
, "error");
670 class = qdict_get_try_str(error
, "class");
671 desc
= qdict_get_try_str(error
, "desc");
672 g_assert_cmpstr(class, ==, "GenericError");
673 g_assert_nonnull(g_strstr_len(desc
, -1, "has been disabled"));
676 ret
= qmp_fd(fix
.fd
, "{'execute': 'guest-get-time'}");
677 g_assert_nonnull(ret
);
678 error
= qdict_get_qdict(ret
, "error");
679 class = qdict_get_try_str(error
, "class");
680 desc
= qdict_get_try_str(error
, "desc");
681 g_assert_cmpstr(class, ==, "GenericError");
682 g_assert_nonnull(g_strstr_len(desc
, -1, "has been disabled"));
685 /* check something work */
686 ret
= qmp_fd(fix
.fd
, "{'execute': 'guest-get-fsinfo'}");
687 qmp_assert_no_error(ret
);
690 fixture_tear_down(&fix
, NULL
);
693 static void test_qga_config(gconstpointer data
)
695 GError
*error
= NULL
;
696 char *cwd
, *cmd
, *out
, *err
, *str
, **strv
, *conf
, **argv
= NULL
;
701 const char *qga_config
=
704 "method=virtio-serial\n"
705 "path=/path/to/org.qemu.guest_agent.0\n"
706 "pidfile=/var/foo/qemu-ga.pid\n"
707 "statedir=/var/state\n"
709 "blacklist=guest-ping;guest-get-time\n";
711 tmp
= g_file_open_tmp(NULL
, &conf
, &error
);
712 g_assert_no_error(error
);
713 g_assert_cmpint(tmp
, >=, 0);
714 g_assert_cmpstr(conf
, !=, "");
716 g_file_set_contents(conf
, qga_config
, -1, &error
);
717 g_assert_no_error(error
);
719 cwd
= g_get_current_dir();
720 cmd
= g_strdup_printf("%s%cqemu-ga -D",
721 cwd
, G_DIR_SEPARATOR
);
722 g_shell_parse_argv(cmd
, NULL
, &argv
, &error
);
723 g_assert_no_error(error
);
725 env
[0] = g_strdup_printf("QGA_CONF=%s", conf
);
727 g_spawn_sync(NULL
, argv
, env
, 0,
728 NULL
, NULL
, &out
, &err
, &status
, &error
);
729 g_assert_no_error(error
);
730 g_assert_cmpstr(err
, ==, "");
731 g_assert_cmpint(status
, ==, 0);
733 kf
= g_key_file_new();
734 g_key_file_load_from_data(kf
, out
, -1, G_KEY_FILE_NONE
, &error
);
735 g_assert_no_error(error
);
737 str
= g_key_file_get_start_group(kf
);
738 g_assert_cmpstr(str
, ==, "general");
741 g_assert_false(g_key_file_get_boolean(kf
, "general", "daemon", &error
));
742 g_assert_no_error(error
);
744 str
= g_key_file_get_string(kf
, "general", "method", &error
);
745 g_assert_no_error(error
);
746 g_assert_cmpstr(str
, ==, "virtio-serial");
749 str
= g_key_file_get_string(kf
, "general", "path", &error
);
750 g_assert_no_error(error
);
751 g_assert_cmpstr(str
, ==, "/path/to/org.qemu.guest_agent.0");
754 str
= g_key_file_get_string(kf
, "general", "pidfile", &error
);
755 g_assert_no_error(error
);
756 g_assert_cmpstr(str
, ==, "/var/foo/qemu-ga.pid");
759 str
= g_key_file_get_string(kf
, "general", "statedir", &error
);
760 g_assert_no_error(error
);
761 g_assert_cmpstr(str
, ==, "/var/state");
764 g_assert_true(g_key_file_get_boolean(kf
, "general", "verbose", &error
));
765 g_assert_no_error(error
);
767 strv
= g_key_file_get_string_list(kf
, "general", "blacklist", &n
, &error
);
768 g_assert_cmpint(n
, ==, 2);
769 #if GLIB_CHECK_VERSION(2, 44, 0)
770 g_assert_true(g_strv_contains((const char * const *)strv
,
772 g_assert_true(g_strv_contains((const char * const *)strv
,
775 g_assert_no_error(error
);
787 static void test_qga_fsfreeze_status(gconstpointer fix
)
789 const TestFixture
*fixture
= fix
;
793 ret
= qmp_fd(fixture
->fd
, "{'execute': 'guest-fsfreeze-status'}");
794 g_assert_nonnull(ret
);
795 qmp_assert_no_error(ret
);
797 status
= qdict_get_try_str(ret
, "return");
798 g_assert_cmpstr(status
, ==, "thawed");
803 static void test_qga_fsfreeze_and_thaw(gconstpointer fix
)
805 const TestFixture
*fixture
= fix
;
809 ret
= qmp_fd(fixture
->fd
, "{'execute': 'guest-fsfreeze-freeze'}");
810 g_assert_nonnull(ret
);
811 qmp_assert_no_error(ret
);
814 ret
= qmp_fd(fixture
->fd
, "{'execute': 'guest-fsfreeze-status'}");
815 g_assert_nonnull(ret
);
816 qmp_assert_no_error(ret
);
817 status
= qdict_get_try_str(ret
, "return");
818 g_assert_cmpstr(status
, ==, "frozen");
821 ret
= qmp_fd(fixture
->fd
, "{'execute': 'guest-fsfreeze-thaw'}");
822 g_assert_nonnull(ret
);
823 qmp_assert_no_error(ret
);
827 int main(int argc
, char **argv
)
832 setlocale (LC_ALL
, "");
833 g_test_init(&argc
, &argv
, NULL
);
834 fixture_setup(&fix
, NULL
);
836 g_test_add_data_func("/qga/sync-delimited", &fix
, test_qga_sync_delimited
);
837 g_test_add_data_func("/qga/sync", &fix
, test_qga_sync
);
838 g_test_add_data_func("/qga/ping", &fix
, test_qga_ping
);
839 g_test_add_data_func("/qga/info", &fix
, test_qga_info
);
840 g_test_add_data_func("/qga/network-get-interfaces", &fix
,
841 test_qga_network_get_interfaces
);
842 g_test_add_data_func("/qga/get-vcpus", &fix
, test_qga_get_vcpus
);
843 g_test_add_data_func("/qga/get-fsinfo", &fix
, test_qga_get_fsinfo
);
844 g_test_add_data_func("/qga/get-memory-block-info", &fix
,
845 test_qga_get_memory_block_info
);
846 g_test_add_data_func("/qga/get-memory-blocks", &fix
,
847 test_qga_get_memory_blocks
);
848 g_test_add_data_func("/qga/file-ops", &fix
, test_qga_file_ops
);
849 g_test_add_data_func("/qga/file-write-read", &fix
, test_qga_file_write_read
);
850 g_test_add_data_func("/qga/get-time", &fix
, test_qga_get_time
);
851 g_test_add_data_func("/qga/invalid-cmd", &fix
, test_qga_invalid_cmd
);
852 g_test_add_data_func("/qga/fsfreeze-status", &fix
,
853 test_qga_fsfreeze_status
);
855 g_test_add_data_func("/qga/blacklist", NULL
, test_qga_blacklist
);
856 g_test_add_data_func("/qga/config", NULL
, test_qga_config
);
858 if (g_getenv("QGA_TEST_SIDE_EFFECTING")) {
859 g_test_add_data_func("/qga/fsfreeze-and-thaw", &fix
,
860 test_qga_fsfreeze_and_thaw
);
861 g_test_add_data_func("/qga/set-time", &fix
, test_qga_set_time
);
862 g_test_add_data_func("/qga/fstrim", &fix
, test_qga_fstrim
);
867 fixture_tear_down(&fix
, NULL
);