Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp7233349rwn; Tue, 13 Sep 2022 16:41:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM798VGmbBO5NXlGSMXhEPuxZ7m1D0oZaRV+1lAI2qRtIrc6GqlvnfJ0zKkVBnXbK0TIy2+W X-Received: by 2002:a17:90a:8911:b0:1fa:c8f7:1450 with SMTP id u17-20020a17090a891100b001fac8f71450mr1628969pjn.123.1663112505081; Tue, 13 Sep 2022 16:41:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663112505; cv=none; d=google.com; s=arc-20160816; b=qnBZF/Es9rnVfoke1QzguU3x9GX5A58HM/6B6Tj+j/aDYhqBRukPXooPmL2Ls3mfJl C/wXsT6aCQjjRju99cqe/aGmJajQzzxx/6kU8Rt2M5V6LVbTHvdh7v9EDcobA8Pc3SH+ VcUlD+xZ8jQ6qUkfvaI0eKsWde3oIFPa7ZYceWYqpj5wWNh6WpulMrX1htZNSBWA6Nxl u389PTCpdJl3P/bBaQURs1oLLMGiCrxtaCFziu0XUKlBTXrHBOpDVdXDJq5WxzP2qTc7 N1K1yl9Kh6L91n51YBzyiksIl/DWiruPX0ATtFz3i1EM651qi3XAmPzB/1/QX7zMn/DW gIAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:to:from:dkim-signature; bh=cO4S3HGMCW2bmXO2A1nH9xumywBS+ZKXPEO1bh8+Hic=; b=xpTSmL3EMn5SbhDMMVmCNZci1PObhD6c6Y4Zm3GJqh6p6eb8NyFpPtKrowy09ZM+h3 2f/qbkILC2qRN2yS4xAP8s9pWCKvBzJ6BCYTQ1Y8YlH6e6MDRgn6snrptz36em7mPZO3 nX3WTmfeZtsm/q8yB9BS3zyUD5lYLBbZSEX0HeNBurO0WeU5xObcKF315Vv3r+6MgeMs 4e43YrAUea/6WW37DcjujNGe1N4n96+YkX8BiFGpU1Au8LJJgTMXcQ+TgKZ8ajaOtask 2LTb2U3BbjiOvt0rWnDH0MLGQC1UPycaWLn55TUC9NvwIpITszfFq0HQBYgr7lDO5zdG WcJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=n7af0qC0; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s16-20020a056a0008d000b00540b0099d40si12572916pfu.367.2022.09.13.16.41.30; Tue, 13 Sep 2022 16:41:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=n7af0qC0; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229639AbiIMXdy (ORCPT + 99 others); Tue, 13 Sep 2022 19:33:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229521AbiIMXdx (ORCPT ); Tue, 13 Sep 2022 19:33:53 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6ED3571BD9 for ; Tue, 13 Sep 2022 16:33:52 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id d82so13177706pfd.10 for ; Tue, 13 Sep 2022 16:33:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date; bh=cO4S3HGMCW2bmXO2A1nH9xumywBS+ZKXPEO1bh8+Hic=; b=n7af0qC04QCSg7XfEE9wufuFvoxRTCLNTBngQ/eAoO6ljfGQT1VbFQ5GIPwo16ehwH L+HQlFnvkFmsPiBRd2MXDXtxeKOzG7GyEODArpNAeyw2cqLfW1buQF1uYFRbshOKPbE0 opI8upANrvtw0f/vz6BQAZpy/bY4qGYactfafRfyuWQJVLr9p6I8xuTl2ipmjMg8rUfj 6jAyk2wpRRSo0Na2afZPL+nDC7WJfLH0Ci48CowKvWzRemehOb6j17XjF5ctEkoOyiUA 12OdfHwBQahb3JrJ//FTZDusF/ewmMt2x2Yxzq3EURAy1U54VNGTdoKGRJuxvnnUpInK bvkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date; bh=cO4S3HGMCW2bmXO2A1nH9xumywBS+ZKXPEO1bh8+Hic=; b=Pkx/BqvyNFO839fIsOcnMtyRvk7E0SH/6dQZnOynfi5Gi93IjwNtzJtc/5elttYTpt rE/bPTRsb9aFoh6HKRQzhlU6N909uh5cjE9c8alv9XHRmCSByx/RtviHaBgMLpICjv3y BMeVPdePoyZ2xSS4BVv4rHbQwuHatxRM6chvOkfpPecaVeE5LYDRFRvBi+D6+uYeq3Mf Da4I5ipwahVP/P1qQRGh9MsRiCnG0wBQQ42ya0F/mZ+HyNlzALikr95dClbbjtOIDCan +GjK+w1jcBJ/L6w57atyfP1fVch4aQou9W7UPTL718QPcf+fuY8aaVmg3f2EN/wGStUs GhRA== X-Gm-Message-State: ACgBeo1STbr82bEe25JijN58oNqajeEuOymNKy/Lc42KmJqP9e9VHN3/ hiT9WB+O/9elLQVozZOiaOcYYKzhp9N5QYLY X-Received: by 2002:a63:e055:0:b0:438:cd8e:f263 with SMTP id n21-20020a63e055000000b00438cd8ef263mr14431373pgj.378.1663112031335; Tue, 13 Sep 2022 16:33:51 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id ce9-20020a17090aff0900b001f1f5e812e9sm7963245pjb.20.2022.09.13.16.33.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Sep 2022 16:33:50 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ] rfcomm-tester: Add test to close socket while connecting Date: Tue, 13 Sep 2022 16:33:49 -0700 Message-Id: <20220913233349.526675-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This adds Basic RFCOMM Socket Client - Close test which attempt to close socket while connecting. --- tools/rfcomm-tester.c | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/tools/rfcomm-tester.c b/tools/rfcomm-tester.c index d594ebf345ce..a9adf7f0f52d 100644 --- a/tools/rfcomm-tester.c +++ b/tools/rfcomm-tester.c @@ -47,6 +47,7 @@ struct test_data { struct rfcomm_client_data { uint8_t server_channel; uint8_t client_channel; + bool close; int expected_connect_err; const uint8_t *send_data; const uint8_t *read_data; @@ -297,6 +298,12 @@ const struct rfcomm_client_data connect_success = { .client_channel = 0x0c }; +const struct rfcomm_client_data connect_close = { + .server_channel = 0x0c, + .client_channel = 0x0c, + .close = true +}; + const uint8_t data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8}; const struct rfcomm_client_data connect_send_success = { @@ -519,6 +526,8 @@ static gboolean rc_connect_cb(GIOChannel *io, GIOCondition cond, return false; } + data->io = NULL; + if (err < 0) tester_test_failed(); else @@ -527,6 +536,20 @@ static gboolean rc_connect_cb(GIOChannel *io, GIOCondition cond, return false; } +static gboolean rc_close_cb(GIOChannel *io, GIOCondition cond, + gpointer user_data) +{ + struct test_data *data = tester_get_data(); + + data->io_id = 0; + + tester_print("Closed"); + + tester_test_passed(); + + return false; +} + static void client_hook_func(const void *data, uint16_t len, void *user_data) { @@ -627,13 +650,20 @@ static void test_connect(const void *test_data) } io = g_io_channel_unix_new(sk); - g_io_channel_set_close_on_unref(io, TRUE); - - data->io_id = g_io_add_watch(io, G_IO_OUT, rc_connect_cb, NULL); - - g_io_channel_unref(io); tester_print("Connect in progress %d", sk); + + if (cli->close) { + data->io_id = g_io_add_watch(io, G_IO_NVAL, rc_close_cb, NULL); + close(sk); + tester_print("Close socket %d", sk); + } else { + g_io_channel_set_close_on_unref(io, TRUE); + data->io_id = g_io_add_watch(io, G_IO_OUT, rc_connect_cb, + NULL); + } + + g_io_channel_unref(io); } static gboolean server_received_data(GIOChannel *io, GIOCondition cond, @@ -815,6 +845,9 @@ int main(int argc, char *argv[]) test_connect); test_rfcomm("Basic RFCOMM Socket Client - Conn Refused", &connect_nval, setup_powered_client, test_connect); + test_rfcomm("Basic RFCOMM Socket Client - Close", + &connect_close, setup_powered_client, + test_connect); test_rfcomm("Basic RFCOMM Socket Server - Success", &listen_success, setup_powered_server, test_server); test_rfcomm("Basic RFCOMM Socket Server - Write Success", -- 2.37.3