From patchwork Fri Jun 3 12:27:50 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: 9152997 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 0812F60751 for ; Fri, 3 Jun 2016 12:28:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC5382780C for ; Fri, 3 Jun 2016 12:28:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E0E3C28309; Fri, 3 Jun 2016 12:28:39 +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 DA3172780C for ; Fri, 3 Jun 2016 12:28:37 +0000 (UTC) Received: from localhost ([::1]:54691 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8oDM-0001HB-90 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 03 Jun 2016 08:28:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53320) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8oD6-0001Gu-9a for qemu-devel@nongnu.org; Fri, 03 Jun 2016 08:28:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8oCw-0007Fp-VM for qemu-devel@nongnu.org; Fri, 03 Jun 2016 08:28:19 -0400 Received: from mail-qt0-x243.google.com ([2607:f8b0:400d:c0d::243]:34556) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8oCw-0007Fi-Q3 for qemu-devel@nongnu.org; Fri, 03 Jun 2016 08:28:10 -0400 Received: by mail-qt0-x243.google.com with SMTP id d51so2199378qte.1 for ; Fri, 03 Jun 2016 05:28:10 -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=BBhItdJ33UkDd9ERdialUrsurZu6Usddt/lX9xeY66g=; b=VWFFxIW7a8x6UmNzhPu6CG7kYONNe4REAnuDkRt91l+ZubtE8dW8raiFIWCiD67a7p ZK3C0nrL012HpDIbm6G0oZngqOzzvfzDt5kCXSKVLhqR1XHUtJiBzKfRTUCUuPL/Hmbh +jQfa1neYY1g0+27CduGeQL5heNWN/oVeOHDg32z7BGA5oA8tovFjQxEg80PujS5A//o wKLjoGWmmtc/Xn8Nb5oe0mY7KLQIpSTCfL0knr9yYJPGyRj1esWpd/uUlEf7hakzc7iy rjrHAKYFDBAQeLCzBKMEn3reRzDjRgS1L7UDuJr/LIbqusdYXoq0Q1NNhPZ8KPRt/ij4 +aJg== 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=BBhItdJ33UkDd9ERdialUrsurZu6Usddt/lX9xeY66g=; b=WvyLr/75XJkaFLb5N9Td6tipxAnoVWmS/MbbvcXtX2wyBN0Gxih/yo4qhkhR+eq/3O RkArgz/PkjyJ7Q0akYJ0EvHSTfGWd/mtmUT0tFamsNcmSv+S4oDoWUoQSO+7MwgzjElB f/oeKRX3o01rZJu+fqyDIE9TBLjWTosJgdKq/UQIYQTFffKTpgH4nh/BPVCsWvWx9Eta sxR/PSDv94kvgPponT5Tt8UbZWkqZvByPi61GIMlCjlfoAMZI9/gnO9rgHDtjHp/7hNM k6wHlolL/nSBZx8NF793e3v7kwSgMkt+yLN3P6LaWogpubz+ANjcQ1E4S9uPKI8Rw93t nz7Q== X-Gm-Message-State: ALyK8tImfpQVyGdaEtaheISjo7wAUyNDyzV6xaAHvyzZhROEPV8B7ELVQGMzwYQKC8YajA== X-Received: by 10.200.51.246 with SMTP id d51mr2907752qtb.61.1464956890156; Fri, 03 Jun 2016 05:28:10 -0700 (PDT) Received: from localhost (APoitiers-110-1-1-140.w193-248.abo.wanadoo.fr. [193.248.103.140]) by smtp.gmail.com with ESMTPSA id o21sm977896qge.23.2016.06.03.05.28.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Jun 2016 05:28:09 -0700 (PDT) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Date: Fri, 3 Jun 2016 14:27:50 +0200 Message-Id: <1464956870-23772-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:c0d::243 Subject: [Qemu-devel] [PATCHv2] 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 | 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 = fix; + QDict *ret, *val; + const gchar *out; + guchar *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': [ '-n', '\" test_str \"' ]," + " '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, ==, 12); + g_assert_cmpstr((char *)decoded, ==, "\" test_str \""); + g_free(decoded); + QDECREF(ret); +} + +static void test_qga_guest_exec_invalid(gconstpointer fix) +{ + const TestFixture *fixture = fix; + QDict *ret, *error; + const gchar *class, *desc; + + /* 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"); + g_assert_nonnull(error); + class = qdict_get_str(error, "class"); + desc = qdict_get_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"); + g_assert_nonnull(error); + class = qdict_get_str(error, "class"); + desc = qdict_get_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 +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,