From patchwork Tue May 24 13:48:41 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 9133743 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1D969607D5 for ; Tue, 24 May 2016 14:07:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F8052824F for ; Tue, 24 May 2016 14:07:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 025D128288; Tue, 24 May 2016 14:07:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0AC3F2824F for ; Tue, 24 May 2016 14:07:11 +0000 (UTC) Received: from localhost ([::1]:53584 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5CzG-00029A-8j for patchwork-qemu-devel@patchwork.kernel.org; Tue, 24 May 2016 10:07:10 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46414) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5Chg-00030R-8m for qemu-devel@nongnu.org; Tue, 24 May 2016 09:49:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b5Chc-0005Sf-Gp for qemu-devel@nongnu.org; Tue, 24 May 2016 09:48:59 -0400 Received: from mail-qk0-x242.google.com ([2607:f8b0:400d:c09::242]:36207) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b5Chc-0005SV-BX for qemu-devel@nongnu.org; Tue, 24 May 2016 09:48:56 -0400 Received: by mail-qk0-x242.google.com with SMTP id l68so1983687qkf.3 for ; Tue, 24 May 2016 06:48:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=18ZlHySVSxl/6/MXW/gVjKRgTiRyE8dTYBdcBnz+ibQ=; b=gDmyjxVxez3jWi4iGabO5GjYFkSoDNIDVvCsLCSXplVwNnJrE/lMW80hOn4GBw4wFu jkAiBo1URntLXl/u7ew2Aq4c2LmfSgN/XgX69j8Eqv5O+yT+R8m6SuBVk5Iy1gHYyJrP ++f52EUfRgfPDssCxZynAp+MIDEPHkQwQk8et6m78Ib1OAcP3tg9mswDrIowX4SZTEW9 MvWkEceEWP6tiACySavXk13cW8oIRIz30V4gDTmuvXAdX5LIPHgc5hDPsgmAmy5zuIpG SdwuDIMLpK+dk99FHdqdouY/MRQK3cgH6OPkThJrWEzVspSlrOioWC5VIoN2qwnamxGi 6K/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=18ZlHySVSxl/6/MXW/gVjKRgTiRyE8dTYBdcBnz+ibQ=; b=LPe2SVwF1IrjRvI/8nca9RssVOlHgoFIPESyPZfpms2cykWROqU+e0JIQqbbW0PMYZ VCxvLUawOoQwyD9PQtWHgHMCSSNDD42BLrEySV8ksQd+KBTsgmx64rZ4b9kCwG1g4rQq WlJ6j7+uFE8lZelZ8/6X8eSw2sVp0n5N2m8GyuFW0BfJCIhAA47LH/wc27J8Yc5MRDVb GyhWKVjVhJylQgaB4iJBZSsJm4qYawv2CY9iISNmGH5nk024x3CnFE97tc+aSZXCUS0w xOxFA10YeIfetk0zJNR8c++4QILwkdY3EdeJvlsjjBplo5qsfwRg0r/37sfg2ymRKsq/ 9zPw== X-Gm-Message-State: ALyK8tKPXR9ZyIHzAq98Hz7ZuvU9/gKUU5sSyVaKKkQnWZAUovPaZsSY0WHQzCNN79KdZw== X-Received: by 10.55.147.196 with SMTP id v187mr3356422qkd.7.1464097735803; Tue, 24 May 2016 06:48:55 -0700 (PDT) Received: from localhost (bne75-h02-31-39-163-232.dsl.sta.abo.bbox.fr. [31.39.163.232]) by smtp.gmail.com with ESMTPSA id y60sm15128415qgd.10.2016.05.24.06.48.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 24 May 2016 06:48:54 -0700 (PDT) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Date: Tue, 24 May 2016 15:48:41 +0200 Message-Id: <1464097721-18101-1-git-send-email-marcandre.lureau@redhat.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400d:c09::242 Subject: [Qemu-devel] [PATCH] tests: start a /qga/guest-exec test X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , yur@virtuozzo.com, mdroth@linux.vnet.ibm.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Marc-André Lureau Test a few guest-exec guest agent commands, added in qemu 2.5. Signed-off-by: Marc-André Lureau --- tests/test-qga.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/tests/test-qga.c b/tests/test-qga.c index 72a89de..42c9a89 100644 --- a/tests/test-qga.c +++ b/tests/test-qga.c @@ -823,6 +823,75 @@ static void test_qga_fsfreeze_and_thaw(gconstpointer fix) QDECREF(ret); } +static void test_qga_guest_exec(gconstpointer fix) +{ + const TestFixture *fixture = fix; + QDict *ret, *val, *error; + const gchar *class, *desc, *out; + gchar *decoded; + int64_t pid, now, exitcode; + gsize len; + bool exited; + + /* exec 'echo foo bar' */ + ret = qmp_fd(fixture->fd, "{'execute': 'guest-exec', 'arguments': {" + " 'path': '/bin/echo', 'arg': [ 'foo', 'bar' ]," + " 'capture-output': true } }"); + g_assert_nonnull(ret); + qmp_assert_no_error(ret); + val = qdict_get_qdict(ret, "return"); + pid = qdict_get_int(val, "pid"); + g_assert_cmpint(pid, >, 0); + QDECREF(ret); + + /* wait for completion */ + now = g_get_monotonic_time(); + do { + 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"); + if (!exited) { + QDECREF(ret); + } + } while (!exited && + g_get_monotonic_time() < now + 5 * G_TIME_SPAN_SECOND); + g_assert(exited); + + /* check stdout */ + exitcode = qdict_get_int(val, "exitcode"); + g_assert_cmpint(exitcode, ==, 0); + out = qdict_get_str(val, "out-data"); + decoded = g_base64_decode(out, &len); + g_assert_cmpint(len, ==, 8); + g_assert_cmpint(strncmp(decoded, "foo bar\n", 8), ==, 0); + g_free(decoded); + QDECREF(ret); + + /* invalid command */ + ret = qmp_fd(fixture->fd, "{'execute': 'guest-exec', 'arguments': {" + " 'path': '/bin/invalid-cmd42' } }"); + g_assert_nonnull(ret); + error = qdict_get_qdict(ret, "error"); + class = qdict_get_try_str(error, "class"); + desc = qdict_get_try_str(error, "desc"); + g_assert_cmpstr(class, ==, "GenericError"); + g_assert_cmpint(strlen(desc), >, 0); + QDECREF(ret); + + /* invalid pid */ + ret = qmp_fd(fixture->fd, "{'execute': 'guest-exec-status'," + " 'arguments': { 'pid': 0 } }"); + g_assert_nonnull(ret); + error = qdict_get_qdict(ret, "error"); + class = qdict_get_try_str(error, "class"); + desc = qdict_get_try_str(error, "desc"); + g_assert_cmpstr(class, ==, "GenericError"); + g_assert_cmpint(strlen(desc), >, 0); + QDECREF(ret); +} + int main(int argc, char **argv) { TestFixture fix; @@ -853,6 +922,7 @@ 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); if (g_getenv("QGA_TEST_SIDE_EFFECTING")) { g_test_add_data_func("/qga/fsfreeze-and-thaw", &fix,