From nobody Sat Jul 12 18:02:03 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488204861190577.75379689388; Mon, 27 Feb 2017 06:14:21 -0800 (PST) Received: from localhost ([::1]:53068 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciM4A-0003PY-OQ for importer@patchew.org; Mon, 27 Feb 2017 09:14:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53771) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciLaV-0002Z8-I3 for qemu-devel@nongnu.org; Mon, 27 Feb 2017 08:43:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciLaU-0001ph-JN for qemu-devel@nongnu.org; Mon, 27 Feb 2017 08:43:39 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55462) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ciLaU-0001p8-Cq for qemu-devel@nongnu.org; Mon, 27 Feb 2017 08:43:38 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7F3977E9D1 for ; Mon, 27 Feb 2017 13:43:38 +0000 (UTC) Received: from localhost (ovpn-116-62.phx2.redhat.com [10.3.116.62]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1RDhang018498; Mon, 27 Feb 2017 08:43:37 -0500 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= To: qemu-devel@nongnu.org Date: Mon, 27 Feb 2017 17:42:01 +0400 Message-Id: <20170227134202.2991-21-marcandre.lureau@redhat.com> In-Reply-To: <20170227134202.2991-1-marcandre.lureau@redhat.com> References: <20170227134202.2991-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 27 Feb 2017 13:43:38 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 20/21] tests: add /char/udp 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, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Marc-Andr=C3=A9 Lureau --- tests/test-char.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tests/test-char.c b/tests/test-char.c index 9971498391..19707bfcda 100644 --- a/tests/test-char.c +++ b/tests/test-char.c @@ -385,6 +385,51 @@ static void char_pipe_test(void) } #endif =20 +static void char_udp_test(void) +{ + struct sockaddr_in addr =3D { 0, }, other; + SocketIdleData d =3D { 0, }; + Chardev *chr; + CharBackend be; + socklen_t alen =3D sizeof(addr); + int ret, sock =3D qemu_socket(PF_INET, SOCK_DGRAM, 0); + char buf[10]; + char *tmp; + + g_assert_cmpint(sock, >, 0); + addr.sin_family =3D AF_INET ; + addr.sin_addr.s_addr =3D htonl(INADDR_ANY); + addr.sin_port =3D 0; + ret =3D bind(sock, (struct sockaddr *)&addr, sizeof(addr)); + g_assert_cmpint(ret, =3D=3D, 0); + ret =3D getsockname(sock, (struct sockaddr *)&addr, &alen); + g_assert_cmpint(ret, =3D=3D, 0); + + tmp =3D g_strdup_printf("udp:127.0.0.1:%d", + ntohs(addr.sin_port)); + chr =3D qemu_chr_new("client", tmp); + g_assert_nonnull(chr); + + d.chr =3D chr; + qemu_chr_fe_init(&be, chr, &error_abort); + qemu_chr_fe_set_handlers(&be, socket_can_read_hello, socket_read_hello, + NULL, &d, NULL, true); + ret =3D qemu_chr_write_all(chr, (uint8_t *)"hello", 5); + g_assert_cmpint(ret, =3D=3D, 5); + + alen =3D sizeof(addr); + ret =3D recvfrom(sock, buf, sizeof(buf), 0, + (struct sockaddr *)&other, &alen); + g_assert_cmpint(ret, =3D=3D, 5); + ret =3D sendto(sock, buf, 5, 0, (struct sockaddr *)&other, alen); + g_assert_cmpint(ret, =3D=3D, 5); + + main_loop(); + + close(sock); + g_free(tmp); +} + static void char_file_test(void) { char *tmp_path =3D g_dir_make_tmp("qemu-test-char.XXXXXX", NULL); @@ -529,6 +574,7 @@ int main(int argc, char **argv) #endif g_test_add_func("/char/file", char_file_test); g_test_add_func("/char/socket", char_socket_test); + g_test_add_func("/char/udp", char_udp_test); =20 return g_test_run(); } --=20 2.12.0.rc2.3.gc93709801