Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp156594lqp; Thu, 4 Apr 2024 09:21:54 -0700 (PDT) X-Forwarded-Encrypted: i=4; AJvYcCXA0HnVPRDImnes5paXlV4vRrycKryxACTmhbKfHfZ40PaL4Fu/9cHuIZWyLtiXrInbezMSQ0AXhVZHzVjZGz4bjgsuocFHtWj0hVYeOg== X-Google-Smtp-Source: AGHT+IEvWtq78eKkNdnYm7WRiEzT6B7PQWYqn7SJJ7M+mxIMfo82BDdnXo2XqfEX9jTEKWpVwyTd X-Received: by 2002:a17:906:7d3:b0:a4e:8c19:2ceb with SMTP id m19-20020a17090607d300b00a4e8c192cebmr2004937ejc.6.1712247713889; Thu, 04 Apr 2024 09:21:53 -0700 (PDT) ARC-Seal: i=3; a=rsa-sha256; t=1712247713; cv=pass; d=google.com; s=arc-20160816; b=qA913tVSN4okgFIs02ejOkMzvcRZ45uMIkCsfC5wAHDCyaPTr6OYnxauho32SroD+3 PkRUMBi2ogKTf77+nFLlnjsOyPrvPjQMrMjX1WV8LR5PoGl/1RXlA2KCapVrIkgNOost jLZQMYzIzXVBzrhsU6/9GAALOCHgUIu91oMnCqX0L5k55aOFfs+3/jMA5a4/5I8lN7DC MELeHFU/gNm2BeQ51lPWhEK2qEJRJUHEa9eEeTxvBvNOCJfH9KmN7oS1J7cH7ph3gcvH 56sOpbKDiPSFaAWvLKrsc7arn0QRLc5w0Z/6yxl1a05tAZK2MDmVWxcS3pEEwRFEMFI+ nX4g== ARC-Message-Signature: i=3; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=v7TQLnR6F+9sRt9uphya0SMZPbennG+mfKO57PtPSb8=; fh=ExGhjNQEFJgRqHmYATVc5UXZbS7abAmaHDitrfHKOuE=; b=PQDu/OrWHh0K+7vM7Iv8ZesTjLqkaHMpE8//6ADFv3a5dU0kEJOYaCOWpQdGyRVfdE WTiw1iTlK5LoFZwMOLPS6AJ+EhYpBo1SDnyJhHoNclZaT1W7ulAs2XRgk0qEZz9B5LbV YhzFMOIf2ZgH6PKAKGBA9GXzI5ylz/slhbRu6TGZX3paDqe0c9JkWBEpYIfygiqkLXTu 1f9bCjQHMvpfZNmE8io3jRw8LboPD0+/Hyz6FT+0yEkk925S0O4fej9tDV0Bk7ogF7XL 8RB5No7KCxreC/4VLjYS59+XUk/5vCDrkMf0FHpip65kAlSH83KmzJ0+uiLlk5UsbxsF xNSA==; dara=google.com ARC-Authentication-Results: i=3; mx.google.com; dkim=pass header.i=@iki.fi header.s=lahtoruutu header.b=n4BmHLS5; arc=pass (i=2 spf=pass spfdomain=iki.fi dkim=pass dkdomain=iki.fi); spf=pass (google.com: domain of linux-bluetooth+bounces-3215-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-3215-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id gs37-20020a1709072d2500b00a4e88e37c84si3310002ejc.316.2024.04.04.09.21.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 09:21:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-3215-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@iki.fi header.s=lahtoruutu header.b=n4BmHLS5; arc=pass (i=2 spf=pass spfdomain=iki.fi dkim=pass dkdomain=iki.fi); spf=pass (google.com: domain of linux-bluetooth+bounces-3215-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-3215-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 53DC11F251F0 for ; Thu, 4 Apr 2024 16:21:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0A90512C81F; Thu, 4 Apr 2024 16:21:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=iki.fi header.i=@iki.fi header.b="n4BmHLS5" X-Original-To: linux-bluetooth@vger.kernel.org Received: from lahtoruutu.iki.fi (lahtoruutu.iki.fi [185.185.170.37]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6068512AAF8 for ; Thu, 4 Apr 2024 16:21:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=185.185.170.37 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712247696; cv=pass; b=iDPpSXQfV0jyhuKqygPYhaH21s+0P7Ext4N2qjeCuXYTdQdH7sBtKONELnclJKxtVOJkh3Q175MkL9/xF1pBfgCMz/GZKK3hfsstriCY1z1BqzdSgJHwpH8GkZPW1tajFKjAXQypVBbPa6b1GbYtmeS6n9/fnr3IjIJGkq1HXik= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712247696; c=relaxed/simple; bh=TBTq1/pgDhwcGI4CajQNhPEXompuuII3oKojAvLbc/w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JYIBsHpitw0SutwVvQaoXEilI8lBCVLThILENIofCflloXQU3xYajD3A4nbG3Bzel0mxY5bZSI0XOqmbvk3BTZjA/B7pM6wL6obXg5O7iDfedCP0qXePeG3Pvfe/X5xDjyQ4pmFt4wFwFanAlL49/Q5zOWG+7qecdB8B+8MN9JU= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iki.fi; spf=pass smtp.mailfrom=iki.fi; dkim=pass (2048-bit key) header.d=iki.fi header.i=@iki.fi header.b=n4BmHLS5; arc=pass smtp.client-ip=185.185.170.37 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iki.fi Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iki.fi Received: from monolith.lan (unknown [193.138.7.178]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: pav) by lahtoruutu.iki.fi (Postfix) with ESMTPSA id 4V9RhC6W9Wz49Q5c; Thu, 4 Apr 2024 19:21:31 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1712247692; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=v7TQLnR6F+9sRt9uphya0SMZPbennG+mfKO57PtPSb8=; b=n4BmHLS5/8VhgrhLdk/m3qm+/MZ1IIc2FwIPwLZBTJAo4lEKxujRR2lDNkxNLNgFZVsd/R 9nVXCtN9WUMvK9tZ5NhpaDA4FHbgGyKdRu9SkaCEhEiWPK+DVc1/gQUyIAhsbJ1OqL+g+U LeDHfrQS011jK+83pJDJKkMo0ty6cV0aHIljR51e9wo8Q0VJf4icaX3jcf9sWMrzghJFe0 p5q/LnRA8A+A2YfJszRhygS2JROCynlWM++Lo71iyWaqm6ctzq4ls3O2iMTPod7JO8oYSx +9uLof58KuG6UrO68Wmu+ts30tpxP72fMq66XKaragCdGbc0yoaZJ7jH1/RZww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1712247692; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=v7TQLnR6F+9sRt9uphya0SMZPbennG+mfKO57PtPSb8=; b=KqcE1u6XxA07TMW+uCrcgN6hzJaisoYTtM9HwG2ZDAR0W1LN6bnW+YyCwhqN2aT2+YpQWT +WQMdZUudxXlRjwl35hTpQ1Ckd6KR4l/5CqU22kCJ+907T37Mh7kpWleqqocleT2rEX/WT uqWdOidMn5eN3eTEw6Sr236HwN9TdM0AcRcyO1e8TGwato2h+Mld6EBOcJ94hk4wzns4QI KkEUPeafn3CtuRIfBfmkJkOywrwrq/SrTLTXSbZumrazSch4tqPBDc7K64xUWjtqGz/217 Wzv19kUQVuD/tNjjJskYxTB1sqsUJSmAjNWNF3SuioiyMKfYMxbobI9tDuL4UA== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=pav smtp.mailfrom=pav@iki.fi ARC-Seal: i=1; s=lahtoruutu; d=iki.fi; t=1712247692; a=rsa-sha256; cv=none; b=ECBwLq/FyU0mwR2F6AlerwVtZovmKzAHOCPa06pJcIQ3ghbFko1U0TbaT9RPxYoBsBd5ow OqbTjP6FVfEYWjdf4twzGGYlJDI6M3dq2FABjkNqexs5bbXA6I7n2UR9FFHkXJI6Va6h1c NKHT3LB4k8jzwPhH311Ni23ql/EqBKt959QWhZDZKNjRHE2zKDF7vzUxjBL3N25HD0JdBQ /cel+A/2FqR6/Lfi69OyT4dWwGOHYX/ttPH7SjciXr/lWKcl+/SLz4CM9s1sbaW1/6H9WZ wW+DaXMmnjS1myIClCW7P6moEAr1wbNyiqX9KgF2CBBZvPq1J5meJvxMjltNzg== From: Pauli Virtanen To: linux-bluetooth@vger.kernel.org Cc: Pauli Virtanen Subject: [PATCH BlueZ v7 3/7] l2cap-tester: Add test for TX timestamping Date: Thu, 4 Apr 2024 19:21:19 +0300 Message-ID: <458e7f16c66e9988d625cb0dd083e1219b849dcf.1712243675.git.pav@iki.fi> X-Mailer: git-send-email 2.44.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Add test L2CAP BR/EDR Client - TX Timestamping --- tools/l2cap-tester.c | 107 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 102 insertions(+), 5 deletions(-) diff --git a/tools/l2cap-tester.c b/tools/l2cap-tester.c index 461f2c27c..375ff767b 100644 --- a/tools/l2cap-tester.c +++ b/tools/l2cap-tester.c @@ -30,6 +30,9 @@ #include "src/shared/tester.h" #include "src/shared/mgmt.h" +#include "src/shared/util.h" + +#include "tester.h" struct test_data { const void *test_data; @@ -38,12 +41,15 @@ struct test_data { struct hciemu *hciemu; enum hciemu_type hciemu_type; unsigned int io_id; + unsigned int err_io_id; uint16_t handle; uint16_t scid; uint16_t dcid; int sk; int sk2; bool host_disconnected; + int step; + struct tx_tstamp_data tx_ts; }; struct l2cap_data { @@ -86,6 +92,12 @@ struct l2cap_data { bool defer; bool shut_sock_wr; + + /* Enable SO_TIMESTAMPING with these flags */ + uint32_t so_timestamping; + + /* Number of additional packets to send. */ + unsigned int repeat_send; }; static void print_debug(const char *str, void *user_data) @@ -226,6 +238,11 @@ static void test_post_teardown(const void *test_data) data->io_id = 0; } + if (data->err_io_id > 0) { + g_source_remove(data->err_io_id); + data->err_io_id = 0; + } + hciemu_unref(data->hciemu); data->hciemu = NULL; } @@ -245,6 +262,7 @@ static void test_data_free(void *test_data) break; \ user->hciemu_type = HCIEMU_TYPE_BREDR; \ user->io_id = 0; \ + user->err_io_id = 0; \ user->test_data = data; \ tester_add_full(name, data, \ test_pre_setup, setup, func, NULL, \ @@ -259,6 +277,7 @@ static void test_data_free(void *test_data) break; \ user->hciemu_type = HCIEMU_TYPE_LE; \ user->io_id = 0; \ + user->err_io_id = 0; \ user->test_data = data; \ tester_add_full(name, data, \ test_pre_setup, setup, func, NULL, \ @@ -321,6 +340,17 @@ static const struct l2cap_data client_connect_write_success_test = { .data_len = sizeof(l2_data), }; +static const struct l2cap_data client_connect_tx_timestamping_test = { + .client_psm = 0x1001, + .server_psm = 0x1001, + .write_data = l2_data, + .data_len = sizeof(l2_data), + .so_timestamping = (SOF_TIMESTAMPING_SOFTWARE | + SOF_TIMESTAMPING_OPT_ID | + SOF_TIMESTAMPING_TX_SOFTWARE), + .repeat_send = 2, +}; + static const struct l2cap_data client_connect_shut_wr_success_test = { .client_psm = 0x1001, .server_psm = 0x1001, @@ -1096,6 +1126,8 @@ static void bthost_received_data(const void *buf, uint16_t len, struct test_data *data = tester_get_data(); const struct l2cap_data *l2data = data->test_data; + --data->step; + if (len != l2data->data_len) { tester_test_failed(); return; @@ -1103,7 +1135,7 @@ static void bthost_received_data(const void *buf, uint16_t len, if (memcmp(buf, l2data->write_data, l2data->data_len)) tester_test_failed(); - else + else if (!data->step) tester_test_passed(); } @@ -1207,6 +1239,59 @@ static bool check_mtu(struct test_data *data, int sk) return true; } +static gboolean recv_errqueue(GIOChannel *io, GIOCondition cond, + gpointer user_data) +{ + struct test_data *data = user_data; + const struct l2cap_data *l2data = data->test_data; + int sk = g_io_channel_unix_get_fd(io); + int err; + + data->step--; + + err = tx_tstamp_recv(&data->tx_ts, sk, l2data->data_len); + if (err > 0) + return TRUE; + else if (!err && !data->step) + tester_test_passed(); + else + tester_test_failed(); + + data->err_io_id = 0; + return FALSE; +} + +static void l2cap_tx_timestamping(struct test_data *data, GIOChannel *io) +{ + const struct l2cap_data *l2data = data->test_data; + int so = l2data->so_timestamping; + int sk; + int err; + unsigned int count; + + if (!(l2data->so_timestamping & SOF_TIMESTAMPING_TX_RECORD_MASK)) + return; + + sk = g_io_channel_unix_get_fd(io); + + tester_print("Enabling TX timestamping"); + + tx_tstamp_init(&data->tx_ts, l2data->so_timestamping); + + for (count = 0; count < l2data->repeat_send + 1; ++count) + data->step += tx_tstamp_expect(&data->tx_ts); + + err = setsockopt(sk, SOL_SOCKET, SO_TIMESTAMPING, &so, sizeof(so)); + if (err < 0) { + tester_warn("setsockopt SO_TIMESTAMPING: %s (%d)", + strerror(errno), errno); + tester_test_failed(); + return; + } + + data->err_io_id = g_io_add_watch(io, G_IO_ERR, recv_errqueue, data); +} + static gboolean l2cap_connect_cb(GIOChannel *io, GIOCondition cond, gpointer user_data) { @@ -1249,15 +1334,23 @@ static gboolean l2cap_connect_cb(GIOChannel *io, GIOCondition cond, } else if (l2data->write_data) { struct bthost *bthost; ssize_t ret; + unsigned int count; + + data->step = 0; bthost = hciemu_client_get_host(data->hciemu); bthost_add_cid_hook(bthost, data->handle, data->dcid, bthost_received_data, NULL); - ret = write(sk, l2data->write_data, l2data->data_len); - if (ret != l2data->data_len) { - tester_warn("Unable to write all data"); - tester_test_failed(); + l2cap_tx_timestamping(data, io); + + for (count = 0; count < l2data->repeat_send + 1; ++count) { + ret = write(sk, l2data->write_data, l2data->data_len); + if (ret != l2data->data_len) { + tester_warn("Unable to write all data"); + tester_test_failed(); + } + ++data->step; } return FALSE; @@ -2280,6 +2373,10 @@ int main(int argc, char *argv[]) &client_connect_write_success_test, setup_powered_client, test_connect); + test_l2cap_bredr("L2CAP BR/EDR Client - TX Timestamping", + &client_connect_tx_timestamping_test, + setup_powered_client, test_connect); + test_l2cap_bredr("L2CAP BR/EDR Client - Invalid PSM 1", &client_connect_nval_psm_test_1, setup_powered_client, test_connect); -- 2.44.0