From patchwork Tue Nov 6 12:40:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Artem Pisarenko X-Patchwork-Id: 10670293 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F228D15E9 for ; Tue, 6 Nov 2018 12:51:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E300F29DF8 for ; Tue, 6 Nov 2018 12:51:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D72A329E45; Tue, 6 Nov 2018 12:51: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=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 629222A117 for ; Tue, 6 Nov 2018 12:51:16 +0000 (UTC) Received: from localhost ([::1]:40777 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gK0p9-0002ZM-MJ for patchwork-qemu-devel@patchwork.kernel.org; Tue, 06 Nov 2018 07:51:15 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49383) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gK0kr-0004nZ-5p for qemu-devel@nongnu.org; Tue, 06 Nov 2018 07:46:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gK0fL-00012U-7h for qemu-devel@nongnu.org; Tue, 06 Nov 2018 07:41:11 -0500 Received: from mail-lf1-x143.google.com ([2a00:1450:4864:20::143]:46054) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gK0fJ-0000k8-Ft for qemu-devel@nongnu.org; Tue, 06 Nov 2018 07:41:06 -0500 Received: by mail-lf1-x143.google.com with SMTP id b20so8695142lfa.12 for ; Tue, 06 Nov 2018 04:41:03 -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=az1IiRn3sFcwMhYe0wZO/wCH+Zk9dbzvXcWc7oltQ2RP2ZgSJ8Bx0TXLc6ydN0Iu4b QcdJehbj1EY5ro8/h0nbJHr+NFlllmr6WfQnxanRxDfA8MBs169FLiP5MtAO7DBES74S 0qUvzmvQ8ocF1wlIHuzqIQsc2plOzdRVN2EO3vHcQvDPjv019Qe+6UWCUxPaZxrP8PQX 6S/YylrwxE5tN5LrHLDd5rB5Fec+mBEVleFElFXCg/kvTQTjb8ytSu0TzULbFY7NRamw YuqhtVkOyNVjRoqnYT0z15e4iq38Z45NeDQ8N5r2LmT3wh7y63y8Dpeqn/x8/nipHbM+ 12bA== 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=PcXhk4iMWt03KuLeI9sM3MMWQFzF4gPNA7bk2pG+CCNBOdV1laBAn39R9+Glq64cvF 57RGT/I/L7Za03ZImMRGesyi01iQrmGIHbqP2+4UdvvS6JG5O37eHnvboW7yN3x/3YwM SRrRj3Ew1BHqRGNsa+KplB+Mrf0aaj4kTs/AOMCThhUn+UZsMc66mhk4VsoeKIPNA9FY taFB1nzGi1eLwbmFJtAxkhHYY/qt/O39qGdPXDxbC4yyAsVVelMUDLaExfhrLRZFnhN5 VZVIz5H7gee+UrcZqNIo1vjCDf5EJw8fEui2Li6gnxjt+QJSnY4IQITED3MAosBnyys8 tb0Q== X-Gm-Message-State: AGRZ1gIJpZCCesKvxBMo3GOy0/JmP+WwuNPD8biuXEC7jUdfcvJjQNac eqoGnitWZzEV4YBsBOliHoftJUL1 X-Google-Smtp-Source: AJdET5fwplZjmS+I1HUL6CYUQf5dx0R1973a70ODhnd82jRuZQBYdwEr8SppuOmFVOyF/0e9Ya4vEg== X-Received: by 2002:a19:1f46:: with SMTP id f67mr14341745lff.1.1541508061483; Tue, 06 Nov 2018 04:41:01 -0800 (PST) Received: from localhost.localdomain ([77.221.221.49]) by smtp.gmail.com with ESMTPSA id r69sm829190lfi.15.2018.11.06.04.40.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 06 Nov 2018 04:41:00 -0800 (PST) From: Artem Pisarenko To: qemu-devel@nongnu.org Date: Tue, 6 Nov 2018 18:40:52 +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::143 Subject: [Qemu-devel] [PATCH v3 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_Lu?= =?utf-8?q?reau?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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é 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; 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, int size) static void fe_event(void *opaque, int event) { FeHandler *h = opaque; + bool new_open_state; h->last_event = event; - if (event != CHR_EVENT_BREAK) { + switch (event) { + case CHR_EVENT_BREAK: + break; + case CHR_EVENT_OPENED: + case CHR_EVENT_CLOSED: + h->openclose_count++; + new_open_state = (event == CHR_EVENT_OPENED); + if (h->is_open == new_open_state) { + h->openclose_mismatch = true; + } + h->is_open = new_open_state; + /* no break */ + default: quit = true; + break; } } @@ -161,7 +178,7 @@ static void char_mux_test(void) QemuOpts *opts; Chardev *chr, *base; char *data; - FeHandler h1 = { 0, }, h2 = { 0, }; + FeHandler h1 = { 0, false, 0, false, }, h2 = { 0, false, 0, false, }; CharBackend chr_be1, chr_be2; opts = 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, ==, CHR_EVENT_BREAK); g_assert_cmpint(h2.last_event, ==, CHR_EVENT_MUX_OUT); + /* 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 = h2.openclose_count = 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, ==, 0); + g_assert_cmpint(h2.openclose_count, ==, 0); + + h1.is_open = h2.is_open = 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, ==, 1); + g_assert_false(h1.openclose_mismatch); + g_assert_cmpint(h2.openclose_count, ==, 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, ==, 3); + g_assert_false(h1.openclose_mismatch); + g_assert_cmpint(h2.openclose_count, ==, 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);