From patchwork Tue May 30 13:57:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 9754667 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 168DD602B9 for ; Tue, 30 May 2017 14:15:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 075212684F for ; Tue, 30 May 2017 14:15:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EFB7F274B4; Tue, 30 May 2017 14:15:16 +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=BAD_ENC_HEADER,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 AD1862684F for ; Tue, 30 May 2017 14:15:15 +0000 (UTC) Received: from localhost ([::1]:54073 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFhvX-0001fF-01 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 30 May 2017 10:15:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46036) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dFhfa-0005EU-Px for qemu-devel@nongnu.org; Tue, 30 May 2017 09:58:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dFhfW-0007Hs-TQ for qemu-devel@nongnu.org; Tue, 30 May 2017 09:58:46 -0400 Received: from mail-he1eur01on0136.outbound.protection.outlook.com ([104.47.0.136]:15171 helo=EUR01-HE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dFhfW-0007GL-H3 for qemu-devel@nongnu.org; Tue, 30 May 2017 09:58:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=3BNUS/2ReyQZRxhIXvgNOtwP7lLbLiPM/xfP8E0v0gM=; b=QwQc/Z3R/0SJKsMA2jdgpeDi6bvX4jR7HP/l6x9RshCrAu40BMc5Q1g+SVyN/+NddmvPut/QyCTSUe1ecKf2r3559TBqLyMpTbTsuzBzj3LabAl2qjleKBu9Lk8VbUPcz2Zo8tmhzzoQAdMvPave4lLZBSsCAfEul6MVPJEO/cE= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none; nongnu.org; dmarc=none action=none header.from=virtuozzo.com; Received: from xantnef-ws.sw.ru (195.214.232.6) by HE1PR0801MB1993.eurprd08.prod.outlook.com (2603:10a6:3:4f::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1124.9; Tue, 30 May 2017 13:58:32 +0000 From: Anton Nefedov To: Date: Tue, 30 May 2017 16:57:58 +0300 Message-ID: <1496152683-102751-9-git-send-email-anton.nefedov@virtuozzo.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1496152683-102751-1-git-send-email-anton.nefedov@virtuozzo.com> References: <1496152683-102751-1-git-send-email-anton.nefedov@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: DB6PR02CA0033.eurprd02.prod.outlook.com (2603:10a6:6:15::46) To HE1PR0801MB1993.eurprd08.prod.outlook.com (2603:10a6:3:4f::23) X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HE1PR0801MB1993: X-MS-Office365-Filtering-Correlation-Id: 1d10c8da-42e3-487c-de85-08d4a763f59b X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201703131423075)(201703031133081); SRVR:HE1PR0801MB1993; X-Microsoft-Exchange-Diagnostics: 1; HE1PR0801MB1993; 3:vGpdCAQ/88EP0HmPdfTWVZSOIrFnlrBiYDgKtnOnif0xynCVqAHV4a2dXdi576g940HEoaaivdZt1XfhujzFdsH4tDNUA1Q4e+mgga4/W2vxCc/dUshfIN2HMM/O/01+oFSEc/P8N0w/zqS5D5ZHTyKSKbYdpCuH3EXH9BDMCtOapP8ZN6x+MfbW6yZeXQwzFmmq/46nN28oqZKUYxDu0CqpnEEFliknmsOYuJZN43heBlQeI7HQ2aDjtHoeqRxevz+DWFYdLV75htM+jWSyWuyZmdi4JgW9qjFtpzFu4gpnmUoIp38LRS6ng2NpKw3OmBVkNiioFPcDZGpemvGWMg==; 25:uuKzyWVRXRBHmgpX+F2TS+1CoqbRJHOyUTXuTcmAjUe/u8C4Bvq14HdYVqKIK5WIRFie2LOwttj+K9dnUaetCwyo1Jlr54LocoUmItSRkNecbZIe5gnUoerWDJn70vpTD7p0RP9Pd9O8dydr0JaUdRGGove8TgA+LrlxcI0UDRkMDFjRTM/pwkwUsuttsIIjhlY/dckUSNkX0T9ZRBQpkdWaxXUrJuUqtn/Dll1xpA8Jh0pb0nTsk7WrxzoMkt6ANbF2/pkmvDn45TXC2bEIozC3hJYz9d/V3bFycbGg3I8f3lxWw0j9TOSlkmCeCaeDKA5GPona1Bb+KBCrxsdZGXK/rj9w0A3JrljxjmNMz+AfBEHeeqdKtjE/X1uu/BPS2VPYtkisWi7wvfOZdAAWwub+17hVBfGdgCEftK9poxwuLicAyxmWZEcpL3wdOoC0UYk3h6HkUJkFtb7OnUObqXNJ62UfEG6hmZKGPLA2jP8= X-Microsoft-Exchange-Diagnostics: 1; HE1PR0801MB1993; 31:52YkUAZYSAwV2bESqEa4JR0DBF7juu7fa8SCupJV9Wkt9b0JQrBYLv7CXBW1MJmpTEKrprqQI1hw/4QtS2WDcBoIjP3VY1XRwMG9fKgFs3awaPdS8F/WeQsWJNk5jmdmpwUeDjHwuC/lLG9o6xrx+KBiRMZFQBfNYK+7GphcDOhmE6+JCxKzPivFwBV9DQKov4VIuQ7YwAFauh3GheVgN+1ktaJTK3JBpLza+FSdLNY=; 20:pB60g9Ko0aMh/2vahGJwV4ctgxl8TRy4kHlslYsSw9y323E0jaHXgoOmIvw9cCjcvR1DSwey3GUIRsfREDmFjJHyQFI+w7aI+IorGADGmBrI14gUttMzisqNHgORVHVy+EWJk6K5vtT6khI98YqJf7NSJOob6LGLfweIVrnuAUvRryptXge7602ReeMuwVueRSS7Nr5CslQ9RvINPKZsNcFds9Mim/S3GUswgRb3YadPkc553wJAGn9jVBUkb9/FS60MFKpGeP27J1u6oYuhuNvjdYmNGRaPkE+GoOQFnFg3liHo32VXqnF+HSiFO6w6ZUc7ePp3zctr3Xq6qRT2f9R/Nao+jhG0qFliTib5GDeLuGzq+LqZPEwcNPcfUmiIXRYuf7ylZZS0qxc+K/pkxUk2kQkZyspE89pUbNr3Kzg= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(227227094722967); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700073)(100105000095)(100000701073)(100105300095)(100000702073)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(93006095)(93001095)(3002001)(100000703073)(100105400095)(10201501046)(6041248)(20161123564025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123560025)(20161123562025)(20161123558100)(20161123555025)(6072148)(100000704073)(100105200095)(100000705073)(100105500095); SRVR:HE1PR0801MB1993; BCL:0; PCL:0; RULEID:(100000800073)(100110000095)(100000801073)(100110300095)(100000802073)(100110100095)(100000803073)(100110400095)(100000804073)(100110200095)(100000805073)(100110500095); SRVR:HE1PR0801MB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dCXHbUdGbk5fAoi5xO0NQbta++AcclZci+esO2FsIjNe+dMoS0Pkb8fzz9r?= =?us-ascii?Q?+dqmUJYXxn2dK3gzPvqD+KZCwlF5Hj/d+NxhWN3Fhs/IEkYf1MfPKB/6umIk?= =?us-ascii?Q?B6ZibH2jWYyaZoMsrDvrBvDKdhp7Xe33gt1e0Nuj+l2bek5zcdWyBYRmN5vx?= =?us-ascii?Q?D+2pmOlk0+ZELLGYN6j2WXq+QxbSf9qDT9YS5EnUifSSU7x/jQqpuZfLhG0g?= =?us-ascii?Q?ty47Nazsh2K5JK2suu4QdTf4chvCg2z8v3SlodDqRqy7NnFw1RdRro3dQA/u?= =?us-ascii?Q?B2LVSfD2SwGRsw7mJdF1kyn8/S/ziYkAESvdGPd8SqvDBWSBOSyVlzUwMLRI?= =?us-ascii?Q?dQmfxySuv7cZTlE=3D?= X-Forefront-PRVS: 032334F434 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(39830400002)(39450400003)(39410400002)(39400400002)(6506006)(6486002)(86362001)(6916009)(2950100002)(6666003)(54906002)(38730400002)(53936002)(6512007)(25786009)(478600001)(5660300001)(47776003)(305945005)(7736002)(66066001)(107886003)(5003940100001)(110136004)(189998001)(2906002)(4326008)(50226002)(3846002)(8676002)(81166006)(6116002)(53416004)(50466002)(2351001)(48376002)(76176999)(42186005)(50986999)(33646002)(36756003); DIR:OUT; SFP:1102; SCL:1; SRVR:HE1PR0801MB1993; H:xantnef-ws.sw.ru; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; HE1PR0801MB1993; 23:LNfSPUfcFxAfFJtzwKqdgSxJ3CtjIn4K/7VJ/vf?= =?us-ascii?Q?FtalqvV0AgRM3sOVcBPi3Ie8vSwqNxlE1wxR4v+rhCQbIScEVMwalfVyt8eH?= =?us-ascii?Q?9AnRhjwWv4QhMgGDFQ1wrEKoJpOG3TsZlPdF3RSL1XCe7C1lL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i5n1SqcuhQqHc8B8DZ5G8VAoKKxTSSibR0Oq/SyBObSZOL5h6JRp?= =?us-ascii?Q?6mj+x14EmDu7uA4aBV7R2aVX74T9V?= X-Microsoft-Exchange-Diagnostics: 1; HE1PR0801MB1993; 6:Tt/ZgbxcieuUYx/FBSXLUY8yqvXpjQJE9RLK8I/GaWe3h+CeThaP2PGuhEl7NE0jVf8YbIa6ESaFOX0dJS11bV/8eycdlVaBR91gE0MdHpRgNpsC9S3m+qBtr4T0XwnR15o+4u9hLYBefUHGw5HvCohNxypK1RdqeOWcMYjF4KTERBE97rg2KC3cPWCxHjF7g2Aa+WdliL3WSP3BEVtU8Pp02Me284TZEp728U5N//jCJiQwQhVMj5ybYA2EuOSP8q+zloAafn6KVx9xux4pRjFbAQTNgM3AuplmduFp+AMA4SqPFX4oiqKjfVFfwJRqSR1B2MbC09IedL5xnf0S8mBtS/ztw3w/4z/3H9pDd72A8ODpnegGTaUROWg9pzW+1PV9BoZI+1G+98wg70IdkReWOasD/zx7MjhZg9I5IArRlo2NOS3VDox+uuA9p5GfaA5DVCIoCCtF+qquZAVmhbUVE+6cNbZcimeV+rJkbFs1/zDFkgVMcdI3fIWgVXiadI58xmYKkLE2CYRsGWPBoA== X-Microsoft-Exchange-Diagnostics: 1; HE1PR0801MB1993; 5:YwGHMsO4remxEtl3foyUKWOaAw/cGHgtGb3X7Nn7hYzhM4LLTWUYeiVpoiW3GOFmX+lSmXjVSdKaH1P8QzLDTKMptKdhmhKf6FHERqwykfm+yH8UL5/dqAjdiGUluWx0X4t8TKt+BcbHenUxFJC+n8OkP/2gdkTYzCdYa63wtD5idJbvIe7PxwkquildC1MPyKGbgJu5p59scLAJtd1fFsOCX2wtIDwQeV6VdzK2fVcidgN4qTb/7BqtyX2s15BudRxiUairNWOSpB+2zviJ92ChwjpalcNf5PJC/o8q4PrBhawH4BEFnIJMmEj7enrsAG5N5sIGqGpEid9s73VerBwEIgmBo0wLKLvN74+HRQdwkcBZHh3uDejb4O5jeWkhdE7l5mzWPtPnGTNbObCqdCworhvHbRGvaGXuvg92zNcCjbLGJX5EUlnCq/Qkep4z5gN5tXAOEjRhPKK7YzHELrxItFkkdOrmPjSjHI7VWwoy8PtiEWGlR6HZFbdwqEm8; 24:VgdB5D7gerPn4YTGFGmISpWx0EKXA3rjQGh05FbEeNM5VpP5FFz+pNCtB9dDQCjx5mmbZjK7Deht1WwOKfc/fIC3PErgnmUCDGW+LXZrtXc= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; HE1PR0801MB1993; 7:uQv1IlBDT2G2HX4bNYsZEYaxvkjccOAn3WBehOBzmC2xQ6mBrhljITV8yAB5LjKnOPIbw7JZb82bv4OgNM2IUenEHjyhYOPwObdz4q2xX8BS6z1vRA/T/l9NXNcEEWaSsOxB++WnLXY+yzbbs1/1gCA/8GYUP3pbMxn5azl8xWRwI72A/VrAxKBTX3t/3cDaA23KalYxozTSqE9PcX+y1VlQfsaQEj0MaI6qnS1oar39ilw0CGipDcOkb5Pv5kpAsPP8TguwvVPbk5FQuts3YjBNwKATKsRxJzUHzUrbgIsz/yWfu+bBDnj1sqLjNjj0H9/sKzIi+RgMrqn+8MkVog==; 20:SapS0LyDEzOgaZqJI3t5vlAuEcWmEhh33nbLQzIwP9baN07/oCMdjuOyotm8IeZ+bUwWMDPIfLcehSfqeRzXRtA80CIHRYIoktMFjMuNXYfB+5198h38LID2YGTf3RB2wAgAIFskeo12SNnH3iMg7c5xY5ds8VbasG/tQQb7FkY= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 May 2017 13:58:32.2559 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0801MB1993 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.0.136 Subject: [Qemu-devel] [PATCH v3 08/13] test-char: split char_file_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: pbonzini@redhat.com, Anton Nefedov , den@virtuozzo.com, marcandre.lureau@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP makes it possible to test the existing chardev-file Signed-off-by: Anton Nefedov Reviewed-by: Marc-André Lureau --- tests/test-char.c | 127 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 79 insertions(+), 48 deletions(-) diff --git a/tests/test-char.c b/tests/test-char.c index ad0752a..ed6b18f 100644 --- a/tests/test-char.c +++ b/tests/test-char.c @@ -484,75 +484,103 @@ static void char_udp_test(void) char_udp_test_internal(NULL, 0); } -static void char_file_test(void) +#ifndef _WIN32 +static void char_file_fifo_test(void) { + Chardev *chr; + CharBackend be; char *tmp_path = g_dir_make_tmp("qemu-test-char.XXXXXX", NULL); + char *fifo = g_build_filename(tmp_path, "fifo", NULL); char *out = g_build_filename(tmp_path, "out", NULL); - char *contents = NULL; - ChardevFile file = { .out = out }; + ChardevFile file = { .in = fifo, + .has_in = true, + .out = out }; ChardevBackend backend = { .type = CHARDEV_BACKEND_KIND_FILE, .u.file.data = &file }; + FeHandler fe = { 0, }; + int fd, ret; + + if (mkfifo(fifo, 0600) < 0) { + abort(); + } + + fd = open(fifo, O_RDWR); + ret = write(fd, "fifo-in", 8); + g_assert_cmpint(ret, ==, 8); + + chr = qemu_chardev_new(NULL, TYPE_CHARDEV_FILE, &backend, + &error_abort); + + qemu_chr_fe_init(&be, chr, &error_abort); + qemu_chr_fe_set_handlers(&be, + fe_can_read, + fe_read, + fe_event, + NULL, + &fe, NULL, true); + + main_loop(); + + close(fd); + + g_assert_cmpint(fe.read_count, ==, 8); + g_assert_cmpstr(fe.read_buf, ==, "fifo-in"); + + qemu_chr_fe_deinit(&be); + object_unref(OBJECT(chr)); + + g_unlink(fifo); + g_free(fifo); + g_unlink(out); + g_free(out); + g_rmdir(tmp_path); + g_free(tmp_path); +} +#endif + +static void char_file_test_internal(Chardev *ext_chr, const char *filepath) +{ + char *tmp_path = g_dir_make_tmp("qemu-test-char.XXXXXX", NULL); + char *out; Chardev *chr; + char *contents = NULL; + ChardevFile file = {}; + ChardevBackend backend = { .type = CHARDEV_BACKEND_KIND_FILE, + .u.file.data = &file }; gsize length; int ret; - chr = qemu_chardev_new(NULL, TYPE_CHARDEV_FILE, &backend, - &error_abort); + if (ext_chr) { + chr = ext_chr; + out = g_strdup(filepath); + file.out = out; + } else { + out = g_build_filename(tmp_path, "out", NULL); + file.out = out; + chr = qemu_chardev_new(NULL, TYPE_CHARDEV_FILE, &backend, + &error_abort); + } ret = qemu_chr_write_all(chr, (uint8_t *)"hello!", 6); g_assert_cmpint(ret, ==, 6); - object_unref(OBJECT(chr)); ret = g_file_get_contents(out, &contents, &length, NULL); g_assert(ret == TRUE); g_assert_cmpint(length, ==, 6); g_assert(strncmp(contents, "hello!", 6) == 0); - g_free(contents); - -#ifndef _WIN32 - { - CharBackend be; - FeHandler fe = { 0, }; - char *fifo = g_build_filename(tmp_path, "fifo", NULL); - int fd; - - if (mkfifo(fifo, 0600) < 0) { - abort(); - } - - fd = open(fifo, O_RDWR); - ret = write(fd, "fifo-in", 8); - g_assert_cmpint(ret, ==, 8); - - file.in = fifo; - file.has_in = true; - chr = qemu_chardev_new(NULL, TYPE_CHARDEV_FILE, &backend, - &error_abort); - - qemu_chr_fe_init(&be, chr, &error_abort); - qemu_chr_fe_set_handlers(&be, - fe_can_read, - fe_read, - fe_event, - NULL, - &fe, NULL, true); - - main_loop(); - close(fd); - - g_assert_cmpint(fe.read_count, ==, 8); - g_assert_cmpstr(fe.read_buf, ==, "fifo-in"); - qemu_chr_fe_deinit(&be); + if (!ext_chr) { object_unref(OBJECT(chr)); - g_unlink(fifo); - g_free(fifo); + g_unlink(out); + g_free(out); } -#endif - - g_unlink(out); + g_free(contents); g_rmdir(tmp_path); g_free(tmp_path); - g_free(out); +} + +static void char_file_test(void) +{ + char_file_test_internal(NULL, NULL); } static void char_null_test(void) @@ -633,6 +661,9 @@ int main(int argc, char **argv) g_test_add_func("/char/pipe", char_pipe_test); #endif g_test_add_func("/char/file", char_file_test); +#ifndef _WIN32 + g_test_add_func("/char/file-fifo", char_file_fifo_test); +#endif g_test_add_func("/char/socket", char_socket_test); g_test_add_func("/char/udp", char_udp_test);