From nobody Thu Nov 6 14:42:00 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.zohomail.com; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1541422072862129.57473235066448; Mon, 5 Nov 2018 04:47:52 -0800 (PST) Received: from localhost ([::1]:34841 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJeIJ-0007rd-K3 for importer@patchew.org; Mon, 05 Nov 2018 07:47:51 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35381) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gJeGD-0006oH-Kx for qemu-devel@nongnu.org; Mon, 05 Nov 2018 07:45:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gJeG9-0000tN-N5 for qemu-devel@nongnu.org; Mon, 05 Nov 2018 07:45:39 -0500 Received: from mail-lj1-x242.google.com ([2a00:1450:4864:20::242]:38335) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gJeG6-0000Dj-16 for qemu-devel@nongnu.org; Mon, 05 Nov 2018 07:45:35 -0500 Received: by mail-lj1-x242.google.com with SMTP id q186-v6so7872471ljb.5 for ; Mon, 05 Nov 2018 04:45:21 -0800 (PST) Received: from localhost.localdomain ([77.221.221.49]) by smtp.gmail.com with ESMTPSA id 4-v6sm3967415ljw.84.2018.11.05.04.45.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 05 Nov 2018 04:45:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=9yPWeS0puioAFhW75zifQm7ZQFapUItZ159YEl59KMw=; b=r9XRBXt9BjgWTJNJ5eTwMSNjJRQcge+dq39jo3aMnxmIxvK/nJCYI/tgMPGPhC0E2X vMNuXs5jBVIsRcbqw/FOmq2JKMyR3sOa0o2jNsx+08xFso7TsKICkem9d/2y3tdOBq96 IV3i13ugPrSPN1R3/iyv3aefuWjE1HK5Zv+uvv3I7Et7U+B30rG1HivX21rTGko5YT8x NM4pnwQTuJQnpWz3jtYMKd9k/fXIVREEHB1dtxo4JoPvgUUyS/3xV97tGb6rL8WH/SOK 9nDIoXkV3v+BOIMp/cMCmOaxW3+VECRExIB9TCuCMmBxaYXGVZSiVkZ3AsLLSHv5KpSK hXZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=9yPWeS0puioAFhW75zifQm7ZQFapUItZ159YEl59KMw=; b=cUm8bY4VSk/HLlgjMUrzwD7kzJ+Gs0q3hFEsyBAMb55nuk+KXfWYBcnh8vCHBApGS3 rkFbRwBXCzFnYqwnkegF/Yr0TGBnkNmqEYtti6fHuT/zItvry+kR9SmUBeJR6iLcLu5A Va6tWuWyM3qXBKz0Ritd4MsRugPxQuwsEQwOf9wO3oXtwge3jbfYSecLMbx5pXkRTaof bD/YIIMKY4oeWA0SIQijlaFG5g0Z8URe1fO87Mx8Km1BMTFQoI/SXZxWbxDzMeMHmHOp 9Uc0bJWUoa/B9YsDO4aYBcM2x2vBQHmj6e35y2r6GsD8TtwlIqZ/g3j8ZrI/VYneGOD5 BDIg== X-Gm-Message-State: AGRZ1gLonKJAOCyymwpR05se6yF8OMDIasZZuObcIQxjahENoZo2u0ky 0kpSri6zrwiYBE68bIFIXLIMJpOQ X-Google-Smtp-Source: AJdET5dbxlHLTM9LaF9YIQom5PhoA1FdIRJ6nj+w2kq8PX3A/W5vuWKHY8RpoBGRmFiI//UNLbaKMA== X-Received: by 2002:a2e:710a:: with SMTP id m10-v6mr10455946ljc.66.1541421920285; Mon, 05 Nov 2018 04:45:20 -0800 (PST) From: Artem Pisarenko To: qemu-devel@nongnu.org Date: Mon, 5 Nov 2018 18:45:10 +0600 Message-Id: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::242 Subject: [Qemu-devel] [PATCH v2 2/2] tests/test-char: add muxed chardev testing for open/close 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: Paolo Bonzini , Artem Pisarenko , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Validate that frontend callbacks for CHR_EVENT_OPENED/CHR_EVENT_CLOSED events are being issued when expected and in strictly pairing order. Signed-off-by: Artem Pisarenko Reviewed-by: Marc-Andr=C3=A9 Lureau --- tests/test-char.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++= ++-- 1 file changed, 78 insertions(+), 2 deletions(-) diff --git a/tests/test-char.c b/tests/test-char.c index 831e37f..657cb4c 100644 --- a/tests/test-char.c +++ b/tests/test-char.c @@ -16,6 +16,9 @@ static bool quit; =20 typedef struct FeHandler { int read_count; + bool is_open; + int openclose_count; + bool openclose_mismatch; int last_event; char read_buf[128]; } FeHandler; @@ -49,10 +52,24 @@ static void fe_read(void *opaque, const uint8_t *buf, i= nt size) static void fe_event(void *opaque, int event) { FeHandler *h =3D opaque; + bool new_open_state; =20 h->last_event =3D event; - if (event !=3D CHR_EVENT_BREAK) { + switch (event) { + case CHR_EVENT_BREAK: + break; + case CHR_EVENT_OPENED: + case CHR_EVENT_CLOSED: + h->openclose_count++; + new_open_state =3D (event =3D=3D CHR_EVENT_OPENED); + if (h->is_open =3D=3D new_open_state) { + h->openclose_mismatch =3D true; + } + h->is_open =3D new_open_state; + /* no break */ + default: quit =3D true; + break; } } =20 @@ -161,7 +178,7 @@ static void char_mux_test(void) QemuOpts *opts; Chardev *chr, *base; char *data; - FeHandler h1 =3D { 0, }, h2 =3D { 0, }; + FeHandler h1 =3D { 0, false, 0, false, }, h2 =3D { 0, false, 0, false,= }; CharBackend chr_be1, chr_be2; =20 opts =3D qemu_opts_create(qemu_find_opts("chardev"), "mux-label", @@ -233,6 +250,65 @@ static void char_mux_test(void) g_assert_cmpint(h1.last_event, =3D=3D, CHR_EVENT_BREAK); g_assert_cmpint(h2.last_event, =3D=3D, CHR_EVENT_MUX_OUT); =20 + /* open/close state and corresponding events */ + g_assert_true(qemu_chr_fe_backend_open(&chr_be1)); + g_assert_true(qemu_chr_fe_backend_open(&chr_be2)); + g_assert_true(h1.is_open); + g_assert_false(h1.openclose_mismatch); + g_assert_true(h2.is_open); + g_assert_false(h2.openclose_mismatch); + + h1.openclose_count =3D h2.openclose_count =3D 0; + + qemu_chr_fe_set_handlers(&chr_be1, NULL, NULL, NULL, NULL, + NULL, NULL, false); + qemu_chr_fe_set_handlers(&chr_be2, NULL, NULL, NULL, NULL, + NULL, NULL, false); + g_assert_cmpint(h1.openclose_count, =3D=3D, 0); + g_assert_cmpint(h2.openclose_count, =3D=3D, 0); + + h1.is_open =3D h2.is_open =3D false; + qemu_chr_fe_set_handlers(&chr_be1, + NULL, + NULL, + fe_event, + NULL, + &h1, + NULL, false); + qemu_chr_fe_set_handlers(&chr_be2, + NULL, + NULL, + fe_event, + NULL, + &h2, + NULL, false); + g_assert_cmpint(h1.openclose_count, =3D=3D, 1); + g_assert_false(h1.openclose_mismatch); + g_assert_cmpint(h2.openclose_count, =3D=3D, 1); + g_assert_false(h2.openclose_mismatch); + + qemu_chr_be_event(base, CHR_EVENT_CLOSED); + qemu_chr_be_event(base, CHR_EVENT_OPENED); + g_assert_cmpint(h1.openclose_count, =3D=3D, 3); + g_assert_false(h1.openclose_mismatch); + g_assert_cmpint(h2.openclose_count, =3D=3D, 3); + g_assert_false(h2.openclose_mismatch); + + qemu_chr_fe_set_handlers(&chr_be2, + fe_can_read, + fe_read, + fe_event, + NULL, + &h2, + NULL, false); + qemu_chr_fe_set_handlers(&chr_be1, + fe_can_read, + fe_read, + fe_event, + NULL, + &h1, + NULL, false); + /* remove first handler */ qemu_chr_fe_set_handlers(&chr_be1, NULL, NULL, NULL, NULL, NULL, NULL, true); --=20 2.7.4