Lines Matching +full:remote +full:- +full:pid
15 GPid pid; member
21 struct sockaddr_un remote; in connect_qga() local
24 g_assert(s != -1); in connect_qga()
26 remote.sun_family = AF_UNIX; in connect_qga()
28 strcpy(remote.sun_path, path); in connect_qga()
29 len = strlen(remote.sun_path) + sizeof(remote.sun_family); in connect_qga()
30 ret = connect(s, (struct sockaddr *)&remote, len); in connect_qga()
31 if (ret == -1) { in connect_qga()
36 return -1; in connect_qga()
38 } while (ret == -1); in connect_qga()
43 static void qga_watch(GPid pid, gint status, gpointer user_data) in qga_watch() argument
48 g_main_loop_quit(fixture->loop); in qga_watch()
61 fixture->loop = g_main_loop_new(NULL, FALSE); in fixture_setup()
63 fixture->test_dir = g_strdup_printf("%s/qgatest.XXXXXX", g_get_tmp_dir()); in fixture_setup()
64 g_assert_nonnull(g_mkdtemp(fixture->test_dir)); in fixture_setup()
66 path = g_build_filename(fixture->test_dir, "sock", NULL); in fixture_setup()
68 cmd = g_strdup_printf("%s%cqga%cqemu-ga -m unix-listen -t %s -p %s %s %s", in fixture_setup()
70 fixture->test_dir, path, in fixture_setup()
71 getenv("QTEST_LOG") ? "-v" : "", in fixture_setup()
76 g_spawn_async(fixture->test_dir, argv, envp, in fixture_setup()
78 NULL, NULL, &fixture->pid, &error); in fixture_setup()
81 g_child_watch_add(fixture->pid, qga_watch, fixture); in fixture_setup()
83 fixture->fd = connect_qga(path); in fixture_setup()
84 g_assert_cmpint(fixture->fd, !=, -1); in fixture_setup()
92 kill(fixture->pid, SIGTERM); in fixture_tear_down()
94 g_main_loop_run(fixture->loop); in fixture_tear_down()
95 g_main_loop_unref(fixture->loop); in fixture_tear_down()
97 g_spawn_close_pid(fixture->pid); in fixture_tear_down()
99 tmp = g_build_filename(fixture->test_dir, "foo", NULL); in fixture_tear_down()
103 tmp = g_build_filename(fixture->test_dir, "qga.state", NULL); in fixture_tear_down()
107 tmp = g_build_filename(fixture->test_dir, "sock", NULL); in fixture_tear_down()
110 g_rmdir(fixture->test_dir); in fixture_tear_down()
111 g_free(fixture->test_dir); in fixture_tear_down()
112 close(fixture->fd); in fixture_tear_down()
148 qmp_fd_send_raw(fixture->fd, "\xff"); in test_qga_sync_delimited()
149 qmp_fd_send(fixture->fd, in test_qga_sync_delimited()
150 "{'execute': 'guest-sync-delimited'," in test_qga_sync_delimited()
158 * response of guest-sync-delimited and repeating the loop if in test_qga_sync_delimited()
170 v = read(fixture->fd, &c, 1); in test_qga_sync_delimited()
174 ret = qmp_fd_receive(fixture->fd); in test_qga_sync_delimited()
189 * TODO guest-sync is inherently limited: we cannot distinguish in test_qga_sync()
193 * re-synchronize the server's parser prior to this command, but in test_qga_sync()
197 * guest-sync-delimited instead. in test_qga_sync()
199 ret = qmp_fd(fixture->fd, in test_qga_sync()
200 "{'execute': 'guest-sync', 'arguments': {'id': %u } }", in test_qga_sync()
215 ret = qmp_fd(fixture->fd, "{'execute': 'guest-ping'}"); in test_qga_ping()
225 ret = qmp_fd(fixture->fd, "{'execute': 'guest-ping', 'id': 1}"); in test_qga_id()
236 ret = qmp_fd(fixture->fd, "{'exec-oob': 'guest-ping'}"); in test_qga_invalid_oob()
249 ret = qmp_fd(fixture->fd, "{'execute': 'guest-ping', " in test_qga_invalid_args()
268 ret = qmp_fd(fixture->fd, "{'execute': 'guest-invalid-cmd'}"); in test_qga_invalid_cmd()
286 ret = qmp_fd(fixture->fd, "{'execute': 'guest-info'}"); in test_qga_info()
302 ret = qmp_fd(fixture->fd, "{'execute': 'guest-get-vcpus'}"); in test_qga_get_vcpus()
309 g_assert(qdict_haskey(qobject_to(QDict, entry->value), "online")); in test_qga_get_vcpus()
310 g_assert(qdict_haskey(qobject_to(QDict, entry->value), "logical-id")); in test_qga_get_vcpus()
320 ret = qmp_fd(fixture->fd, "{'execute': 'guest-get-fsinfo'}"); in test_qga_get_fsinfo()
324 /* sanity-check the response if there are any filesystems */ in test_qga_get_fsinfo()
328 g_assert(qdict_haskey(qobject_to(QDict, entry->value), "name")); in test_qga_get_fsinfo()
329 g_assert(qdict_haskey(qobject_to(QDict, entry->value), "mountpoint")); in test_qga_get_fsinfo()
330 g_assert(qdict_haskey(qobject_to(QDict, entry->value), "type")); in test_qga_get_fsinfo()
331 g_assert(qdict_haskey(qobject_to(QDict, entry->value), "disk")); in test_qga_get_fsinfo()
342 ret = qmp_fd(fixture->fd, "{'execute': 'guest-get-memory-block-info'}"); in test_qga_get_memory_block_info()
361 ret = qmp_fd(fixture->fd, "{'execute': 'guest-get-memory-blocks'}"); in test_qga_get_memory_blocks()
370 g_assert(qdict_haskey(qobject_to(QDict, entry->value), in test_qga_get_memory_blocks()
371 "phys-index")); in test_qga_get_memory_blocks()
372 g_assert(qdict_haskey(qobject_to(QDict, entry->value), "online")); in test_qga_get_memory_blocks()
384 ret = qmp_fd(fixture->fd, "{'execute': 'guest-network-get-interfaces'}"); in test_qga_network_get_interfaces()
391 g_assert(qdict_haskey(qobject_to(QDict, entry->value), "name")); in test_qga_network_get_interfaces()
408 ret = qmp_fd(fixture->fd, "{'execute': 'guest-file-open'," in test_qga_file_ops()
417 ret = qmp_fd(fixture->fd, in test_qga_file_ops()
418 "{'execute': 'guest-file-write'," in test_qga_file_ops()
419 " 'arguments': { 'handle': %" PRId64 ", 'buf-b64': %s } }", in test_qga_file_ops()
432 ret = qmp_fd(fixture->fd, in test_qga_file_ops()
433 "{'execute': 'guest-file-flush'," in test_qga_file_ops()
439 ret = qmp_fd(fixture->fd, in test_qga_file_ops()
440 "{'execute': 'guest-file-close'," in test_qga_file_ops()
446 path = g_build_filename(fixture->test_dir, "foo", NULL); in test_qga_file_ops()
457 ret = qmp_fd(fixture->fd, "{'execute': 'guest-file-open'," in test_qga_file_ops()
465 ret = qmp_fd(fixture->fd, in test_qga_file_ops()
466 "{'execute': 'guest-file-read'," in test_qga_file_ops()
472 b64 = qdict_get_str(val, "buf-b64"); in test_qga_file_ops()
481 ret = qmp_fd(fixture->fd, in test_qga_file_ops()
482 "{'execute': 'guest-file-read'," in test_qga_file_ops()
488 b64 = qdict_get_str(val, "buf-b64"); in test_qga_file_ops()
495 ret = qmp_fd(fixture->fd, in test_qga_file_ops()
496 "{'execute': 'guest-file-seek'," in test_qga_file_ops()
509 ret = qmp_fd(fixture->fd, in test_qga_file_ops()
510 "{'execute': 'guest-file-read'," in test_qga_file_ops()
516 b64 = qdict_get_str(val, "buf-b64"); in test_qga_file_ops()
517 g_assert_cmpint(count, ==, sizeof(helloworld) - 6); in test_qga_file_ops()
520 g_assert_cmpint(count, ==, sizeof(helloworld) - 6); in test_qga_file_ops()
521 g_assert_cmpmem(dec, count, helloworld + 6, sizeof(helloworld) - 6); in test_qga_file_ops()
527 ret = qmp_fd(fixture->fd, in test_qga_file_ops()
528 "{'execute': 'guest-file-close'," in test_qga_file_ops()
545 ret = qmp_fd(fixture->fd, "{'execute': 'guest-file-open'," in test_qga_file_write_read()
554 ret = qmp_fd(fixture->fd, in test_qga_file_write_read()
555 "{'execute': 'guest-file-write'," in test_qga_file_write_read()
557 " 'buf-b64': %s } }", id, enc); in test_qga_file_write_read()
569 ret = qmp_fd(fixture->fd, in test_qga_file_write_read()
570 "{'execute': 'guest-file-read'," in test_qga_file_write_read()
576 b64 = qdict_get_str(val, "buf-b64"); in test_qga_file_write_read()
583 ret = qmp_fd(fixture->fd, in test_qga_file_write_read()
584 "{'execute': 'guest-file-seek'," in test_qga_file_write_read()
597 ret = qmp_fd(fixture->fd, in test_qga_file_write_read()
598 "{'execute': 'guest-file-read'," in test_qga_file_write_read()
604 b64 = qdict_get_str(val, "buf-b64"); in test_qga_file_write_read()
612 ret = qmp_fd(fixture->fd, in test_qga_file_write_read()
613 "{'execute': 'guest-file-close'," in test_qga_file_write_read()
625 ret = qmp_fd(fixture->fd, "{'execute': 'guest-get-time'}"); in test_qga_get_time()
639 fixture_setup(&fix, "-b guest-ping,guest-get-time", NULL); in test_qga_blockedrpcs()
642 ret = qmp_fd(fix.fd, "{'execute': 'guest-ping'}"); in test_qga_blockedrpcs()
648 g_assert_nonnull(g_strstr_len(desc, -1, "has been disabled")); in test_qga_blockedrpcs()
651 ret = qmp_fd(fix.fd, "{'execute': 'guest-get-time'}"); in test_qga_blockedrpcs()
657 g_assert_nonnull(g_strstr_len(desc, -1, "has been disabled")); in test_qga_blockedrpcs()
661 ret = qmp_fd(fix.fd, "{'execute': 'guest-get-fsinfo'}"); in test_qga_blockedrpcs()
674 fixture_setup(&fix, "-a guest-ping,guest-get-time", NULL); in test_qga_allowedrpcs()
677 ret = qmp_fd(fix.fd, "{'execute': 'guest-ping'}"); in test_qga_allowedrpcs()
681 ret = qmp_fd(fix.fd, "{'execute': 'guest-get-time'}"); in test_qga_allowedrpcs()
686 ret = qmp_fd(fix.fd, "{'execute': 'guest-get-fsinfo'}"); in test_qga_allowedrpcs()
692 g_assert_nonnull(g_strstr_len(desc, -1, "has been disabled")); in test_qga_allowedrpcs()
714 cmd = g_strdup_printf("%s%cqga%cqemu-ga -D", in test_qga_config()
719 env[0] = g_strdup_printf("QGA_CONF=tests%cdata%ctest-qga-config", in test_qga_config()
730 g_key_file_load_from_data(kf, out, -1, G_KEY_FILE_NONE, &error); in test_qga_config()
742 g_assert_cmpstr(str, ==, "virtio-serial"); in test_qga_config()
752 g_assert_cmpstr(str, ==, "/var/foo/qemu-ga.pid"); in test_qga_config()
763 strv = g_key_file_get_string_list(kf, "general", "block-rpcs", &n, &error); in test_qga_config()
766 "guest-ping")); in test_qga_config()
768 "guest-get-time")); in test_qga_config()
780 ret = qmp_fd(fixture->fd, "{'execute': 'guest-fsfreeze-status'}"); in test_qga_fsfreeze_status()
788 static QDict *wait_for_guest_exec_completion(int fd, int64_t pid) in wait_for_guest_exec_completion() argument
798 "{'execute': 'guest-exec-status'," in wait_for_guest_exec_completion()
799 " 'arguments': { 'pid': %" PRId64 " } }", pid); in wait_for_guest_exec_completion()
820 int64_t pid, exitcode; in test_qga_guest_exec() local
824 ret = qmp_fd(fixture->fd, "{'execute': 'guest-exec', 'arguments': {" in test_qga_guest_exec()
825 " 'path': 'echo', 'arg': [ '-n', '\" test_str \"' ]," in test_qga_guest_exec()
826 " 'capture-output': true } }"); in test_qga_guest_exec()
830 pid = qdict_get_int(val, "pid"); in test_qga_guest_exec()
831 g_assert_cmpint(pid, >, 0); in test_qga_guest_exec()
834 ret = wait_for_guest_exec_completion(fixture->fd, pid); in test_qga_guest_exec()
840 out = qdict_get_str(val, "out-data"); in test_qga_guest_exec()
859 ret = qmp_fd(fixture->fd, "{'execute': 'guest-exec', 'arguments': {" in test_qga_guest_exec_merged()
862 " 'capture-output': 'merged' } }"); in test_qga_guest_exec_merged()
881 int64_t pid, exitcode; in test_qga_guest_exec_separated() local
885 ret = qmp_fd(fixture->fd, "{'execute': 'guest-exec', 'arguments': {" in test_qga_guest_exec_separated()
887 …" 'arg': [ '-c', 'for i in $(seq 4); do if (( $i %% 2 )); then echo stdout; else echo stderr 1>&2;… in test_qga_guest_exec_separated()
888 " 'capture-output': 'separated' } }"); in test_qga_guest_exec_separated()
892 pid = qdict_get_int(val, "pid"); in test_qga_guest_exec_separated()
893 g_assert_cmpint(pid, >, 0); in test_qga_guest_exec_separated()
896 ret = wait_for_guest_exec_completion(fixture->fd, pid); in test_qga_guest_exec_separated()
903 out = qdict_get_str(val, "out-data"); in test_qga_guest_exec_separated()
909 err = qdict_get_try_str(val, "err-data"); in test_qga_guest_exec_separated()
922 int64_t pid, exitcode; in test_qga_guest_exec_merged() local
926 ret = qmp_fd(fixture->fd, "{'execute': 'guest-exec', 'arguments': {" in test_qga_guest_exec_merged()
928 …" 'arg': [ '-c', 'for i in $(seq 4); do if (( $i %% 2 )); then echo stdout; else echo stderr 1>&2;… in test_qga_guest_exec_merged()
929 " 'capture-output': 'merged' } }"); in test_qga_guest_exec_merged()
933 pid = qdict_get_int(val, "pid"); in test_qga_guest_exec_merged()
934 g_assert_cmpint(pid, >, 0); in test_qga_guest_exec_merged()
937 ret = wait_for_guest_exec_completion(fixture->fd, pid); in test_qga_guest_exec_merged()
944 out = qdict_get_str(val, "out-data"); in test_qga_guest_exec_merged()
950 err = qdict_get_try_str(val, "err-data"); in test_qga_guest_exec_merged()
963 ret = qmp_fd(fixture->fd, "{'execute': 'guest-exec', 'arguments': {" in test_qga_guest_exec_invalid()
964 " 'path': '/bin/invalid-cmd42' } }"); in test_qga_guest_exec_invalid()
974 /* invalid pid */ in test_qga_guest_exec_invalid()
975 ret = qmp_fd(fixture->fd, "{'execute': 'guest-exec-status'," in test_qga_guest_exec_invalid()
976 " 'arguments': { 'pid': 0 } }"); in test_qga_guest_exec_invalid()
992 ret = qmp_fd(fixture->fd, "{'execute': 'guest-get-host-name'}"); in test_qga_guest_get_host_name()
997 g_assert(qdict_haskey(val, "host-name")); in test_qga_guest_get_host_name()
1006 ret = qmp_fd(fixture->fd, "{'execute': 'guest-get-timezone'}"); in test_qga_guest_get_timezone()
1021 ret = qmp_fd(fixture->fd, "{'execute': 'guest-get-users'}"); in test_qga_guest_get_users()
1039 "QGA_OS_RELEASE=%s%c..%cdata%ctest-qga-os-release", in test_qga_guest_get_osinfo()
1044 ret = qmp_fd(fixture.fd, "{'execute': 'guest-get-osinfo'}"); in test_qga_guest_get_osinfo()
1052 g_assert_cmpstr(str, ==, "qemu-ga-test"); in test_qga_guest_get_osinfo()
1056 g_assert_cmpstr(str, ==, "QEMU-GA"); in test_qga_guest_get_osinfo()
1058 str = qdict_get_try_str(val, "pretty-name"); in test_qga_guest_get_osinfo()
1066 str = qdict_get_try_str(val, "version-id"); in test_qga_guest_get_osinfo()
1074 str = qdict_get_try_str(val, "variant-id"); in test_qga_guest_get_osinfo()
1076 g_assert_cmpstr(str, ==, "unit-test"); in test_qga_guest_get_osinfo()
1098 g_test_add_data_func("/qga/sync-delimited", &fix, test_qga_sync_delimited); in main()
1102 g_test_add_data_func("/qga/network-get-interfaces", &fix, in main()
1105 g_test_add_data_func("/qga/get-vcpus", &fix, test_qga_get_vcpus); in main()
1107 g_test_add_data_func("/qga/get-fsinfo", &fix, test_qga_get_fsinfo); in main()
1108 g_test_add_data_func("/qga/get-memory-block-info", &fix, in main()
1110 g_test_add_data_func("/qga/get-memory-blocks", &fix, in main()
1112 g_test_add_data_func("/qga/file-ops", &fix, test_qga_file_ops); in main()
1113 g_test_add_data_func("/qga/file-write-read", &fix, test_qga_file_write_read); in main()
1114 g_test_add_data_func("/qga/get-time", &fix, test_qga_get_time); in main()
1116 g_test_add_data_func("/qga/invalid-oob", &fix, test_qga_invalid_oob); in main()
1117 g_test_add_data_func("/qga/invalid-cmd", &fix, test_qga_invalid_cmd); in main()
1118 g_test_add_data_func("/qga/invalid-args", &fix, test_qga_invalid_args); in main()
1119 g_test_add_data_func("/qga/fsfreeze-status", &fix, in main()
1125 g_test_add_data_func("/qga/guest-exec", &fix, test_qga_guest_exec); in main()
1126 g_test_add_data_func("/qga/guest-exec-separated", &fix, in main()
1128 g_test_add_data_func("/qga/guest-exec-merged", &fix, in main()
1130 g_test_add_data_func("/qga/guest-exec-invalid", &fix, in main()
1132 g_test_add_data_func("/qga/guest-get-osinfo", &fix, in main()
1134 g_test_add_data_func("/qga/guest-get-host-name", &fix, in main()
1136 g_test_add_data_func("/qga/guest-get-timezone", &fix, in main()
1138 g_test_add_data_func("/qga/guest-get-users", &fix, in main()