Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4167613rdb; Thu, 14 Sep 2023 14:02:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHjjhFJnKTfGw43GqlKh/Zid/R0eAD3YmFW0uAGre1z8+iBhKVM28UiRZnGjWaSYW39/3Tx X-Received: by 2002:a05:6a20:dd88:b0:13d:d5bd:7593 with SMTP id kw8-20020a056a20dd8800b0013dd5bd7593mr5594870pzb.12.1694725377141; Thu, 14 Sep 2023 14:02:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694725377; cv=none; d=google.com; s=arc-20160816; b=hMUT+wE0DQhZFRlnBEX+bOVS9GmdaisWrrdo7pbtt5LtC7I03Pagxu5EOjBnX5V5xj WfZ/LkO7ox7Zc/pFFHynJtVzDqwnbDXpfFEuMCQk3m8tEJHmiBtQBPkxI2+e3jwcqVYY rvWB76AOmLnNqN4BZ/6NDR8iM3+DYTLOCaMxGwcmoy0Xc0L95vwwxB1wwlkQN2vXPqYs n/zfysgmpZEBr8IRGF9ggZcXLMGnbm11r18KvkL5SpkSG6HJ0BvA+hG33eoH5h02yniF 7FLopL8My0nVlAwULnts+IzsHyTDBa1ZK8fW6S1BgBOp4wtd9M/TbVdXCiD++wmTMA9s TmRA== 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 :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=IqKHbbes1gZ7xOcjb2J4XO9bZrI7ScLNJSAy2Zza/K0=; fh=4lGQI6056MBa4/oovMyIYaKLn+Wz/24RGvUivMmQP8E=; b=UdB1huVg2RWtcA00+jciMBeM8ytcPhfYyVNYZ99sMYe5UOTGmo4dt5P6JEcfeOCFG6 o50eZlOT4yTwlANK/tZ16tDKFlUm+IEPeZlIiKlt3bx4W2QyooG/oh2gF4Nt6JLsEkle fRpHhEp3qIkm9o/JOEcUkC4So7WHBURNw+bWzhcgFsKw5ypgmWcqtBiTPoutUuPBNEtq GwVksgXF0IMU056g5pGzPLpnAEGlShj12RxAPcJBYWFxL2C1v3Ujsy5hzFNfSx2hBq8n RT30UAuv1VKXpBpQ44MR6mV5Yk28hN2oQfU/UCpA65Rdf/sL7YcxZ/Jb2TJF2r1vih7N +YGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=W4J5rDHe; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id y3-20020a636403000000b005694f4b9e85si2111834pgb.229.2023.09.14.14.02.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 14:02:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=W4J5rDHe; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id DA18182A5B26; Thu, 14 Sep 2023 13:59:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229629AbjINU77 (ORCPT + 99 others); Thu, 14 Sep 2023 16:59:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbjINU76 (ORCPT ); Thu, 14 Sep 2023 16:59:58 -0400 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D7691FE5 for ; Thu, 14 Sep 2023 13:59:54 -0700 (PDT) Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1c4194f769fso7456495ad.3 for ; Thu, 14 Sep 2023 13:59:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694725193; x=1695329993; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=IqKHbbes1gZ7xOcjb2J4XO9bZrI7ScLNJSAy2Zza/K0=; b=W4J5rDHepoRee4j2zAdmWmWhGKidjTdfnvHqtfkEW2icGt3HnVvBXgZ7JAqjq9FW9a SQ0sBCem52keYhnyEbwxHwNxUCeBz1gVE4NDej1dcCBHPQvUoWIZun5uo+ANIGO1gku0 G21xpogwh1Xu411D+l39Pm+SIe5LuNDB93hRa0E0E8ksC1Rf0fSwmxvNgfeTRdwKqQgG vtOH4YpwSv3wS/gNur06UcKTfoIwbn/CHS+Sa/TX5NSOpQukskZagRShGwzm2X14HZ/O PAEoBvNQD+7TLekdUfHGWJVorNdmdEDYbQR41HMxHuOZTO6GjqIH9quetHsuBobMLST6 B+Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694725193; x=1695329993; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IqKHbbes1gZ7xOcjb2J4XO9bZrI7ScLNJSAy2Zza/K0=; b=GDzmhcvLPUfjlsbxh22WF3TS5gBjl4UL/M+dqGLfATN7iIxnGlnfLjf10UbudOIvEZ J2eXBiMbXJynTce+eykCPeGhu3eSSNxpzphByowGh59AQMAgUuoyGGR3Jsk6Vn8/bTVo VRBm/4i4NHBXEtQ8i/GRl80/NAQuhzIUttU0SnZhw+EN8PkItVWYekPzDT8pTJr/O6mf amZGPiziZacIhXeVCS/R6iHa2/ru27mHciIegoR15fdU4DHwnDglaDWAIlh6E3dm71FE z4fNADGHqNZqhsaOb1Bw3wev0ckvTtGHXVW0U4R0FBDo0etLNkHoSyAIszs04wx90eYf MmbA== X-Gm-Message-State: AOJu0Ywa+ZpQH47fH3bLrzBbpArPlTbfItV1s9uJUlLBTNN3PVu9y+Ei A9BUFH+M6P44tncnWF7zO+pf/zbpN+fxGg== X-Received: by 2002:a17:902:f689:b0:1c4:1cd3:803a with SMTP id l9-20020a170902f68900b001c41cd3803amr2050244plg.54.1694725192931; Thu, 14 Sep 2023 13:59:52 -0700 (PDT) Received: from lvondent-mobl4.. (c-98-232-221-87.hsd1.or.comcast.net. [98.232.221.87]) by smtp.gmail.com with ESMTPSA id kg14-20020a170903060e00b001c41e1e9ca7sm1189885plb.215.2023.09.14.13.59.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Sep 2023 13:59:51 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 2/2] l2cap-tester: Add tests for connection timeout Date: Thu, 14 Sep 2023 13:59:49 -0700 Message-ID: <20230914205949.3334335-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230914205949.3334335-1-luiz.dentz@gmail.com> References: <20230914205949.3334335-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 14 Sep 2023 13:59:56 -0700 (PDT) X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email From: Luiz Augusto von Dentz This adds the following tests which attempts to use SO_SNDTIMEO so the socket times out before the connection completes: L2CAP BR/EDR Client - Timeout L2CAP LE Client - Timeout L2CAP Ext-Flowctl Client - Timeout --- tools/l2cap-tester.c | 82 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 2 deletions(-) diff --git a/tools/l2cap-tester.c b/tools/l2cap-tester.c index f4810e3eacea..d4bbf2105e19 100644 --- a/tools/l2cap-tester.c +++ b/tools/l2cap-tester.c @@ -52,6 +52,7 @@ struct l2cap_data { uint16_t cid; uint8_t mode; int expect_err; + int timeout; uint8_t send_cmd_code; const void *send_cmd; @@ -275,6 +276,11 @@ static const struct l2cap_data client_connect_close_test = { .client_psm = 0x1001, }; +static const struct l2cap_data client_connect_timeout_test = { + .client_psm = 0x1001, + .timeout = 1 +}; + static const struct l2cap_data client_connect_ssp_success_test_1 = { .client_psm = 0x1001, .server_psm = 0x1001, @@ -446,6 +452,11 @@ static const struct l2cap_data le_client_connect_close_test_1 = { .client_psm = 0x0080, }; +static const struct l2cap_data le_client_connect_timeout_test_1 = { + .client_psm = 0x0080, + .timeout = 1, +}; + static const struct l2cap_data le_client_connect_adv_success_test_1 = { .client_psm = 0x0080, .server_psm = 0x0080, @@ -691,6 +702,12 @@ static const struct l2cap_data ext_flowctl_client_connect_close_test_1 = { .mode = BT_MODE_EXT_FLOWCTL, }; +static const struct l2cap_data ext_flowctl_client_connect_timeout_test_1 = { + .client_psm = 0x0080, + .mode = BT_MODE_EXT_FLOWCTL, + .timeout = 1, +}; + static const struct l2cap_data ext_flowctl_client_connect_adv_success_test_1 = { .client_psm = 0x0080, .server_psm = 0x0080, @@ -793,6 +810,11 @@ static void setup_powered_client_callback(uint8_t status, uint16_t length, tester_print("Controller powered on"); + if (!l2data->server_psm && !l2data->cid) { + tester_setup_complete(); + return; + } + bthost = hciemu_client_get_host(data->hciemu); bthost_set_cmd_complete_cb(bthost, client_cmd_complete, user_data); @@ -1133,9 +1155,11 @@ static gboolean socket_closed_cb(GIOChannel *io, GIOCondition cond, else err = -sk_err; - if (-err != l2data->expect_err) + if (!l2data->timeout && -err != l2data->expect_err) { + tester_print("err %d != %d expected_err", -err, + l2data->expect_err); tester_test_failed(); - else + } else tester_test_passed(); return FALSE; @@ -1517,6 +1541,50 @@ static void test_connect_close(const void *test_data) shutdown(sk, SHUT_RDWR); } +static void test_connect_timeout(const void *test_data) +{ + struct test_data *data = tester_get_data(); + const struct l2cap_data *l2data = data->test_data; + GIOChannel *io; + int sk; + struct timeval sndto; + socklen_t len; + + sk = create_l2cap_sock(data, 0, l2data->cid, l2data->sec_level, + l2data->mode); + if (sk < 0) { + if (sk == -ENOPROTOOPT) + tester_test_abort(); + else + tester_test_failed(); + return; + } + + memset(&sndto, 0, sizeof(sndto)); + + sndto.tv_sec = l2data->timeout; + len = sizeof(sndto); + if (setsockopt(sk, SOL_SOCKET, SO_SNDTIMEO, &sndto, len) < 0) { + tester_print("Can't set SO_SNDTIMEO: %s (%d)", strerror(errno), + errno); + close(sk); + tester_test_failed(); + return; + } + + if (connect_l2cap_sock(data, sk, l2data->client_psm, + l2data->cid) < 0) { + close(sk); + tester_test_failed(); + return; + } + + 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_HUP, socket_closed_cb, NULL); + g_io_channel_unref(io); +} + static void test_connect_reject(const void *test_data) { struct test_data *data = tester_get_data(); @@ -2189,6 +2257,10 @@ int main(int argc, char *argv[]) &client_connect_close_test, setup_powered_client, test_connect_close); + test_l2cap_bredr("L2CAP BR/EDR Client - Timeout", + &client_connect_timeout_test, + setup_powered_client, + test_connect_timeout); test_l2cap_bredr("L2CAP BR/EDR Client SSP - Success 1", &client_connect_ssp_success_test_1, @@ -2259,6 +2331,9 @@ int main(int argc, char *argv[]) test_l2cap_le("L2CAP LE Client - Close", &le_client_connect_close_test_1, setup_powered_client, test_connect_close); + test_l2cap_le("L2CAP LE Client - Timeout", + &le_client_connect_timeout_test_1, + setup_powered_client, test_connect_timeout); test_l2cap_le("L2CAP LE Client, Direct Advertising - Success", &le_client_connect_adv_success_test_1, setup_powered_client, test_connect); @@ -2307,6 +2382,9 @@ int main(int argc, char *argv[]) test_l2cap_le("L2CAP Ext-Flowctl Client - Close", &ext_flowctl_client_connect_close_test_1, setup_powered_client, test_connect_close); + test_l2cap_le("L2CAP Ext-Flowctl Client - Timeout", + &ext_flowctl_client_connect_timeout_test_1, + setup_powered_client, test_connect_timeout); test_l2cap_le("L2CAP Ext-Flowctl Client, Direct Advertising - Success", &ext_flowctl_client_connect_adv_success_test_1, setup_powered_client, test_connect); -- 2.41.0