From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48269) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bANzW-0004KN-Kp for qemu-devel@nongnu.org; Tue, 07 Jun 2016 16:52:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bANzS-0003ad-Dz for qemu-devel@nongnu.org; Tue, 07 Jun 2016 16:52:49 -0400 Received: from e18.ny.us.ibm.com ([129.33.205.208]:34291) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bANzS-0003a5-A6 for qemu-devel@nongnu.org; Tue, 07 Jun 2016 16:52:46 -0400 Received: from localhost by e18.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 7 Jun 2016 16:52:45 -0400 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Michael Roth In-Reply-To: <1464956870-23772-1-git-send-email-marcandre.lureau@redhat.com> References: <1464956870-23772-1-git-send-email-marcandre.lureau@redhat.com> Message-ID: <20160607205234.13720.88270@loki> Date: Tue, 07 Jun 2016 15:52:34 -0500 Subject: Re: [Qemu-devel] [PATCHv2] tests: start a /qga/guest-exec test List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: marcandre.lureau@redhat.com, qemu-devel@nongnu.org Cc: yur@virtuozzo.com Quoting marcandre.lureau@redhat.com (2016-06-03 07:27:50) > From: Marc-Andr=C3=A9 Lureau > = > Test a few guest-exec guest agent commands, added in qemu 2.5. > = > Signed-off-by: Marc-Andr=C3=A9 Lureau Thanks, applied to qga tree: https://github.com/mdroth/qemu/tree/qga > --- > tests/test-qga.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++= ++++++ > 1 file changed, 81 insertions(+) > = > diff --git a/tests/test-qga.c b/tests/test-qga.c > index 72a89de..10b29eb 100644 > --- a/tests/test-qga.c > +++ b/tests/test-qga.c > @@ -823,6 +823,84 @@ static void test_qga_fsfreeze_and_thaw(gconstpointer= fix) > QDECREF(ret); > } > = > +static void test_qga_guest_exec(gconstpointer fix) > +{ > + const TestFixture *fixture =3D fix; > + QDict *ret, *val; > + const gchar *out; > + guchar *decoded; > + int64_t pid, now, exitcode; > + gsize len; > + bool exited; > + > + /* exec 'echo foo bar' */ > + ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-exec', 'arguments': = {" > + " 'path': '/bin/echo', 'arg': [ '-n', '\" test_str \"' = ]," > + " 'capture-output': true } }"); > + g_assert_nonnull(ret); > + qmp_assert_no_error(ret); > + val =3D qdict_get_qdict(ret, "return"); > + pid =3D qdict_get_int(val, "pid"); > + g_assert_cmpint(pid, >, 0); > + QDECREF(ret); > + > + /* wait for completion */ > + now =3D g_get_monotonic_time(); > + do { > + ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-exec-status'," > + " 'arguments': { 'pid': %" PRId64 " } }", pid); > + g_assert_nonnull(ret); > + val =3D qdict_get_qdict(ret, "return"); > + exited =3D qdict_get_bool(val, "exited"); > + if (!exited) { > + QDECREF(ret); > + } > + } while (!exited && > + g_get_monotonic_time() < now + 5 * G_TIME_SPAN_SECOND); > + g_assert(exited); > + > + /* check stdout */ > + exitcode =3D qdict_get_int(val, "exitcode"); > + g_assert_cmpint(exitcode, =3D=3D, 0); > + out =3D qdict_get_str(val, "out-data"); > + decoded =3D g_base64_decode(out, &len); > + g_assert_cmpint(len, =3D=3D, 12); > + g_assert_cmpstr((char *)decoded, =3D=3D, "\" test_str \""); > + g_free(decoded); > + QDECREF(ret); > +} > + > +static void test_qga_guest_exec_invalid(gconstpointer fix) > +{ > + const TestFixture *fixture =3D fix; > + QDict *ret, *error; > + const gchar *class, *desc; > + > + /* invalid command */ > + ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-exec', 'arguments': = {" > + " 'path': '/bin/invalid-cmd42' } }"); > + g_assert_nonnull(ret); > + error =3D qdict_get_qdict(ret, "error"); > + g_assert_nonnull(error); > + class =3D qdict_get_str(error, "class"); > + desc =3D qdict_get_str(error, "desc"); > + g_assert_cmpstr(class, =3D=3D, "GenericError"); > + g_assert_cmpint(strlen(desc), >, 0); > + QDECREF(ret); > + > + /* invalid pid */ > + ret =3D qmp_fd(fixture->fd, "{'execute': 'guest-exec-status'," > + " 'arguments': { 'pid': 0 } }"); > + g_assert_nonnull(ret); > + error =3D qdict_get_qdict(ret, "error"); > + g_assert_nonnull(error); > + class =3D qdict_get_str(error, "class"); > + desc =3D qdict_get_str(error, "desc"); > + g_assert_cmpstr(class, =3D=3D, "GenericError"); > + g_assert_cmpint(strlen(desc), >, 0); > + QDECREF(ret); > +} > + > int main(int argc, char **argv) > { > TestFixture fix; > @@ -853,6 +931,9 @@ int main(int argc, char **argv) > = > g_test_add_data_func("/qga/blacklist", NULL, test_qga_blacklist); > g_test_add_data_func("/qga/config", NULL, test_qga_config); > + g_test_add_data_func("/qga/guest-exec", &fix, test_qga_guest_exec); > + g_test_add_data_func("/qga/guest-exec-invalid", &fix, > + test_qga_guest_exec_invalid); > = > if (g_getenv("QGA_TEST_SIDE_EFFECTING")) { > g_test_add_data_func("/qga/fsfreeze-and-thaw", &fix, > -- = > 2.7.4 >=20