Skip to contentSkip to conversation

tools/tester: update TX timestamping tests for COMPLETION

PATCH Superseded Pauli Virtanen 3 participants 6 messages Feb 9, 2025 – Feb 15, 2025 Bluetooth drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover tools/tester: update TX timestamping tests for COMPLETION

This updates TX timestamping tests for the new kernel patchset.

Pauli Virtanen (3):
tools/tester: test COMPLETION timestamps
l2cap-tester: add test for stream socket TX timestamping tools/tester: enable TX timestamping tests by default

 configure.ac         |  7 ++++++
 tools/iso-tester.c   | 42 ++++++++++++----------------------
 tools/l2cap-tester.c | 52 +++++++++++++++++++++++++++++-------------
 tools/sco-tester.c   | 18 +++++----------
 tools/tester.h       | 54 ++++++++++++++++++++++++++++++++++++--------
 5 files changed, 107 insertions(+), 66 deletions(-)
Signature · 1 line
2.48.1
#1 lore raw

PATCH 1/3 tools/tester: test COMPLETION timestamps

Add support for SOF_TIMESTAMPING_TX_COMPLETION also in cases where errqueue.h is old and doesn't define it.

Support timestamps of different types arriving out of order, as multiple SND may well arrive before COMPLETION. Also allow TX timestamp arriving before bthost receives data, as that may well happen.

Remove tests SCHED timestamps, as those won't be generated for now.

Don't test COMPLETION for SCO, since it's not supported now either.

---
 configure.ac         |  7 +++++++
 tools/iso-tester.c   | 36 +++++++++++-------------------------
 tools/l2cap-tester.c | 14 ++++++++------
 tools/sco-tester.c   |  8 ++++----
 tools/tester.h       | 42 +++++++++++++++++++++++++++++++++++-------
 5 files changed, 65 insertions(+), 42 deletions(-)
configure.ac +7 -0
index 6a19487f6..75841e4c9 100644
@@ -389,6 +389,13 @@ AC_ARG_ENABLE(testing, AS_HELP_STRING([--enable-testing],
 					[enable_testing=${enableval}])
 AM_CONDITIONAL(TESTING, test "${enable_testing}" = "yes")
 
+if (test "${enable_testing}" = "yes"); then
+   AC_CHECK_DECLS([SOF_TIMESTAMPING_TX_COMPLETION, SCM_TSTAMP_COMPLETION],
+	[], [], [[#include <time.h>
+		#include <linux/errqueue.h>
+		#include <linux/net_tstamp.h>]])
+fi
+
 AC_ARG_ENABLE(experimental, AS_HELP_STRING([--enable-experimental],
 			[enable experimental tools]),
 					[enable_experimental=${enableval}])
tools/iso-tester.c +11 -25
index c30c44ce9..b5e638808 100644
@@ -1066,20 +1066,10 @@ static const struct iso_client_data connect_send_tx_timestamping = {
 	.send = &send_16_2_1,
 	.so_timestamping = (SOF_TIMESTAMPING_SOFTWARE |
 					SOF_TIMESTAMPING_OPT_ID |
-					SOF_TIMESTAMPING_TX_SOFTWARE),
-	.repeat_send = 1,
-	.repeat_send_pre_ts = 2,
-};
-
-static const struct iso_client_data connect_send_tx_sched_timestamping = {
-	.qos = QOS_16_2_1,
-	.expect_err = 0,
-	.send = &send_16_2_1,
-	.so_timestamping = (SOF_TIMESTAMPING_SOFTWARE |
 					SOF_TIMESTAMPING_TX_SOFTWARE |
-					SOF_TIMESTAMPING_OPT_TSONLY |
-					SOF_TIMESTAMPING_TX_SCHED),
+					SOF_TIMESTAMPING_TX_COMPLETION),
 	.repeat_send = 1,
+	.repeat_send_pre_ts = 2,
 };
 
 static const struct iso_client_data connect_send_tx_cmsg_timestamping = {
@@ -1087,7 +1077,8 @@ static const struct iso_client_data connect_send_tx_cmsg_timestamping = {
 	.expect_err = 0,
 	.send = &send_16_2_1,
 	.so_timestamping = (SOF_TIMESTAMPING_SOFTWARE |
-					SOF_TIMESTAMPING_TX_SOFTWARE),
+					SOF_TIMESTAMPING_OPT_TSONLY |
+					SOF_TIMESTAMPING_TX_COMPLETION),
 	.repeat_send = 1,
 	.cmsg_timestamping = true,
 };
@@ -1097,7 +1088,7 @@ static const struct iso_client_data connect_send_tx_no_poll_timestamping = {
 	.expect_err = 0,
 	.send = &send_16_2_1,
 	.so_timestamping = (SOF_TIMESTAMPING_SOFTWARE |
-					SOF_TIMESTAMPING_TX_SOFTWARE),
+					SOF_TIMESTAMPING_TX_COMPLETION),
 	.repeat_send = 1,
 	.no_poll_errqueue = true,
 };
@@ -2241,10 +2232,10 @@ static gboolean iso_recv_errqueue(GIOChannel *io, GIOCondition cond,
 	err = tx_tstamp_recv(&data->tx_ts, sk, isodata->send->iov_len);
 	if (err > 0)
 		return TRUE;
-	else if (!err && !data->step)
-		tester_test_passed();
-	else
+	else if (err)
 		tester_test_failed();
+	else if (!data->step)
+		tester_test_passed();
 
 	data->io_id[2] = 0;
 	return FALSE;
@@ -2289,7 +2280,7 @@ static void iso_tx_timestamping(struct test_data *data, GIOChannel *io)
 	int err;
 	unsigned int count;
 
-	if (!(isodata->so_timestamping & SOF_TIMESTAMPING_TX_RECORD_MASK))
+	if (!(isodata->so_timestamping & TS_TX_RECORD_MASK))
 		return;
 
 	tester_print("Enabling TX timestamping");
@@ -2336,7 +2327,7 @@ static void iso_tx_timestamping(struct test_data *data, GIOChannel *io)
 	}
 
 	if (isodata->cmsg_timestamping)
-		so &= ~SOF_TIMESTAMPING_TX_RECORD_MASK;
+		so &= ~TS_TX_RECORD_MASK;
 
 	err = setsockopt(sk, SOL_SOCKET, SO_TIMESTAMPING, &so, sizeof(so));
 	if (err < 0) {
@@ -2374,7 +2365,7 @@ static void iso_send_data(struct test_data *data, GIOChannel *io)
 		cmsg->cmsg_len = CMSG_LEN(sizeof(uint32_t));
 
 		*((uint32_t *)CMSG_DATA(cmsg)) = (isodata->so_timestamping &
-					SOF_TIMESTAMPING_TX_RECORD_MASK);
+					TS_TX_RECORD_MASK);
 	}
 
 	ret = sendmsg(sk, &msg, 0);
@@ -3645,11 +3636,6 @@ int main(int argc, char *argv[])
 	test_iso("ISO Send - TX Timestamping", &connect_send_tx_timestamping,
 						setup_powered, test_connect);
 
-	/* Test schedule-time TX timestamps are emitted */
-	test_iso("ISO Send - TX Sched Timestamping",
-			&connect_send_tx_sched_timestamping, setup_powered,
-			test_connect);
-
 	/* Test TX timestamping with flags set via per-packet CMSG */
 	test_iso("ISO Send - TX CMSG Timestamping",
 			&connect_send_tx_cmsg_timestamping, setup_powered,
tools/l2cap-tester.c +8 -6
index 1780c9fbd..7f3be6c0f 100644
@@ -381,7 +381,8 @@ static const struct l2cap_data client_connect_tx_timestamping_test = {
 	.data_len = sizeof(l2_data),
 	.so_timestamping = (SOF_TIMESTAMPING_SOFTWARE |
 					SOF_TIMESTAMPING_OPT_ID |
-					SOF_TIMESTAMPING_TX_SOFTWARE),
+					SOF_TIMESTAMPING_TX_SOFTWARE |
+					SOF_TIMESTAMPING_TX_COMPLETION),
 	.repeat_send = 2,
 };
 
@@ -594,7 +595,8 @@ static const struct l2cap_data le_client_connect_tx_timestamping_test = {
 	.data_len = sizeof(l2_data),
 	.so_timestamping = (SOF_TIMESTAMPING_SOFTWARE |
 					SOF_TIMESTAMPING_OPT_ID |
-					SOF_TIMESTAMPING_TX_SOFTWARE),
+					SOF_TIMESTAMPING_TX_SOFTWARE |
+					SOF_TIMESTAMPING_TX_COMPLETION),
 };
 
 static const struct l2cap_data le_client_connect_adv_success_test_1 = {
@@ -1345,10 +1347,10 @@ static gboolean recv_errqueue(GIOChannel *io, GIOCondition cond,
 	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
+	else if (err)
 		tester_test_failed();
+	else if (!data->step)
+		tester_test_passed();
 
 	data->err_io_id = 0;
 	return FALSE;
@@ -1362,7 +1364,7 @@ static void l2cap_tx_timestamping(struct test_data *data, GIOChannel *io)
 	int err;
 	unsigned int count;
 
-	if (!(l2data->so_timestamping & SOF_TIMESTAMPING_TX_RECORD_MASK))
+	if (!(l2data->so_timestamping & TS_TX_RECORD_MASK))
 		return;
 
 	sk = g_io_channel_unix_get_fd(io);
tools/sco-tester.c +4 -4
index 6fc26b7af..130ab526d 100644
@@ -665,10 +665,10 @@ static gboolean recv_errqueue(GIOChannel *io, GIOCondition cond,
 	err = tx_tstamp_recv(&data->tx_ts, sk, scodata->data_len);
 	if (err > 0)
 		return TRUE;
-	else if (!err && !data->step)
-		tester_test_passed();
-	else
+	else if (err)
 		tester_test_failed();
+	else if (!data->step)
+		tester_test_passed();
 
 	data->err_io_id = 0;
 	return FALSE;
@@ -682,7 +682,7 @@ static void sco_tx_timestamping(struct test_data *data, GIOChannel *io)
 	int err;
 	unsigned int count;
 
-	if (!(scodata->so_timestamping & SOF_TIMESTAMPING_TX_RECORD_MASK))
+	if (!(scodata->so_timestamping & TS_TX_RECORD_MASK))
 		return;
 
 	sk = g_io_channel_unix_get_fd(io);
tools/tester.h +35 -7

78 lines not on this page · raw message

Signature · 1 line
2.48.1
#2 lore raw

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=931990

---Test result---

Test Summary:

CheckPatch                    PENDING   0.22 seconds
GitLint                       PENDING   0.24 seconds
BuildEll                      PASS      20.89 seconds
BluezMake                     PASS      1465.37 seconds
MakeCheck                     PASS      13.16 seconds
MakeDistcheck                 PASS      159.50 seconds
CheckValgrind                 PASS      214.74 seconds
CheckSmatch                   WARNING   285.83 seconds
bluezmakeextell               PASS      98.78 seconds
IncrementalBuild              PENDING   0.25 seconds
ScanBuild                     PASS      878.47 seconds

Details
##############################
Test: CheckPatch - PENDING
Desc: Run checkpatch.pl script Output:

##############################
Test: GitLint - PENDING
Desc: Run gitlint
Output:

##############################
Test: CheckSmatch - WARNING
Desc: Run smatch tool with source
Output:
tools/sco-tester.c: note: in included file:./lib/bluetooth.h:232:15: warning: array of flexible structures./lib/bluetooth.h:237:31: warning: array of flexible structurestools/sco-tester.c: note: in included file:./lib/bluetooth.h:232:15: warning: array of flexible structures./lib/bluetooth.h:237:31: warning: array of flexible structurestools/sco-tester.c: note: in included file:./lib/bluetooth.h:232:15: warning: array of flexible structures./lib/bluetooth.h:237:31: warning: array of flexible structures
##############################
Test: IncrementalBuild - PENDING
Desc: Incremental build with the patches in the series
Output:

---
Regards,
Linux Bluetooth

#3 lore raw

Re: [PATCH BlueZ 1/3] tools/tester: test COMPLETION timestamps

In reply to Pauli Virtanen

unsubscribe

Quoted 301 lines · Pauli Virtanen

Add support for SOF_TIMESTAMPING_TX_COMPLETION also in cases where errqueue.h is old and doesn't define it.

Support timestamps of different types arriving out of order, as multiple SND may well arrive before COMPLETION. Also allow TX timestamp arriving before bthost receives data, as that may well happen.

Remove tests SCHED timestamps, as those won't be generated for now.

Don't test COMPLETION for SCO, since it's not supported now either.

---
 configure.ac         |  7 +++++++
 tools/iso-tester.c   | 36 +++++++++++-------------------------
 tools/l2cap-tester.c | 14 ++++++++------
 tools/sco-tester.c   |  8 ++++----
 tools/tester.h       | 42 +++++++++++++++++++++++++++++++++++-------
 5 files changed, 65 insertions(+), 42 deletions(-)
configure.ac +7 -0
index 6a19487f6..75841e4c9 100644
@@ -389,6 +389,13 @@ AC_ARG_ENABLE(testing, AS_HELP_STRING([--enable-testing],
                                        [enable_testing=${enableval}])
 AM_CONDITIONAL(TESTING, test "${enable_testing}" = "yes")
 
+if (test "${enable_testing}" = "yes"); then
+   AC_CHECK_DECLS([SOF_TIMESTAMPING_TX_COMPLETION, SCM_TSTAMP_COMPLETION],
+       [], [], [[#include <time.h>
+               #include <linux/errqueue.h>
+               #include <linux/net_tstamp.h>]])
+fi
+
 AC_ARG_ENABLE(experimental, AS_HELP_STRING([--enable-experimental],
                        [enable experimental tools]),
                                        [enable_experimental=${enableval}])
tools/iso-tester.c +11 -25
index c30c44ce9..b5e638808 100644
@@ -1066,20 +1066,10 @@ static const struct iso_client_data connect_send_tx_timestamping = {
        .send = &send_16_2_1,
        .so_timestamping = (SOF_TIMESTAMPING_SOFTWARE |
                                        SOF_TIMESTAMPING_OPT_ID |
-                                       SOF_TIMESTAMPING_TX_SOFTWARE),
-       .repeat_send = 1,
-       .repeat_send_pre_ts = 2,
-};
-
-static const struct iso_client_data connect_send_tx_sched_timestamping = {
-       .qos = QOS_16_2_1,
-       .expect_err = 0,
-       .send = &send_16_2_1,
-       .so_timestamping = (SOF_TIMESTAMPING_SOFTWARE |
                                        SOF_TIMESTAMPING_TX_SOFTWARE |
-                                       SOF_TIMESTAMPING_OPT_TSONLY |
-                                       SOF_TIMESTAMPING_TX_SCHED),
+                                       SOF_TIMESTAMPING_TX_COMPLETION),
        .repeat_send = 1,
+       .repeat_send_pre_ts = 2,
 };
 
 static const struct iso_client_data connect_send_tx_cmsg_timestamping = {
@@ -1087,7 +1077,8 @@ static const struct iso_client_data connect_send_tx_cmsg_timestamping = {
        .expect_err = 0,
        .send = &send_16_2_1,
        .so_timestamping = (SOF_TIMESTAMPING_SOFTWARE |
-                                       SOF_TIMESTAMPING_TX_SOFTWARE),
+                                       SOF_TIMESTAMPING_OPT_TSONLY |
+                                       SOF_TIMESTAMPING_TX_COMPLETION),
        .repeat_send = 1,
        .cmsg_timestamping = true,
 };
@@ -1097,7 +1088,7 @@ static const struct iso_client_data connect_send_tx_no_poll_timestamping = {
        .expect_err = 0,
        .send = &send_16_2_1,
        .so_timestamping = (SOF_TIMESTAMPING_SOFTWARE |
-                                       SOF_TIMESTAMPING_TX_SOFTWARE),
+                                       SOF_TIMESTAMPING_TX_COMPLETION),
        .repeat_send = 1,
        .no_poll_errqueue = true,
 };
@@ -2241,10 +2232,10 @@ static gboolean iso_recv_errqueue(GIOChannel *io, GIOCondition cond,
        err = tx_tstamp_recv(&data->tx_ts, sk, isodata->send->iov_len);
        if (err > 0)
                return TRUE;
-       else if (!err && !data->step)
-               tester_test_passed();
-       else
+       else if (err)
                tester_test_failed();
+       else if (!data->step)
+               tester_test_passed();
 
        data->io_id[2] = 0;
        return FALSE;
@@ -2289,7 +2280,7 @@ static void iso_tx_timestamping(struct test_data *data, GIOChannel *io)
        int err;
        unsigned int count;
 
-       if (!(isodata->so_timestamping & SOF_TIMESTAMPING_TX_RECORD_MASK))
+       if (!(isodata->so_timestamping & TS_TX_RECORD_MASK))
                return;
 
        tester_print("Enabling TX timestamping");
@@ -2336,7 +2327,7 @@ static void iso_tx_timestamping(struct test_data *data, GIOChannel *io)
        }
 
        if (isodata->cmsg_timestamping)
-               so &= ~SOF_TIMESTAMPING_TX_RECORD_MASK;
+               so &= ~TS_TX_RECORD_MASK;
 
        err = setsockopt(sk, SOL_SOCKET, SO_TIMESTAMPING, &so, sizeof(so));
        if (err < 0) {
@@ -2374,7 +2365,7 @@ static void iso_send_data(struct test_data *data, GIOChannel *io)
                cmsg->cmsg_len = CMSG_LEN(sizeof(uint32_t));
 
                *((uint32_t *)CMSG_DATA(cmsg)) = (isodata->so_timestamping &
-                                       SOF_TIMESTAMPING_TX_RECORD_MASK);
+                                       TS_TX_RECORD_MASK);
        }
 
        ret = sendmsg(sk, &msg, 0);
@@ -3645,11 +3636,6 @@ int main(int argc, char *argv[])
        test_iso("ISO Send - TX Timestamping", &connect_send_tx_timestamping,
                                                setup_powered, test_connect);
 
-       /* Test schedule-time TX timestamps are emitted */
-       test_iso("ISO Send - TX Sched Timestamping",
-                       &connect_send_tx_sched_timestamping, setup_powered,
-                       test_connect);
-
        /* Test TX timestamping with flags set via per-packet CMSG */
        test_iso("ISO Send - TX CMSG Timestamping",
                        &connect_send_tx_cmsg_timestamping, setup_powered,
tools/l2cap-tester.c +8 -6
index 1780c9fbd..7f3be6c0f 100644
@@ -381,7 +381,8 @@ static const struct l2cap_data client_connect_tx_timestamping_test = {
        .data_len = sizeof(l2_data),
        .so_timestamping = (SOF_TIMESTAMPING_SOFTWARE |
                                        SOF_TIMESTAMPING_OPT_ID |
-                                       SOF_TIMESTAMPING_TX_SOFTWARE),
+                                       SOF_TIMESTAMPING_TX_SOFTWARE |
+                                       SOF_TIMESTAMPING_TX_COMPLETION),
        .repeat_send = 2,
 };
 
@@ -594,7 +595,8 @@ static const struct l2cap_data le_client_connect_tx_timestamping_test = {
        .data_len = sizeof(l2_data),
        .so_timestamping = (SOF_TIMESTAMPING_SOFTWARE |
                                        SOF_TIMESTAMPING_OPT_ID |
-                                       SOF_TIMESTAMPING_TX_SOFTWARE),
+                                       SOF_TIMESTAMPING_TX_SOFTWARE |
+                                       SOF_TIMESTAMPING_TX_COMPLETION),
 };
 
 static const struct l2cap_data le_client_connect_adv_success_test_1 = {
@@ -1345,10 +1347,10 @@ static gboolean recv_errqueue(GIOChannel *io, GIOCondition cond,
        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
+       else if (err)
                tester_test_failed();
+       else if (!data->step)
+               tester_test_passed();
 
        data->err_io_id = 0;
        return FALSE;
@@ -1362,7 +1364,7 @@ static void l2cap_tx_timestamping(struct test_data *data, GIOChannel *io)
        int err;
        unsigned int count;
 
-       if (!(l2data->so_timestamping & SOF_TIMESTAMPING_TX_RECORD_MASK))
+       if (!(l2data->so_timestamping & TS_TX_RECORD_MASK))
                return;
 
        sk = g_io_channel_unix_get_fd(io);
tools/sco-tester.c +4 -4
index 6fc26b7af..130ab526d 100644
@@ -665,10 +665,10 @@ static gboolean recv_errqueue(GIOChannel *io, GIOCondition cond,
        err = tx_tstamp_recv(&data->tx_ts, sk, scodata->data_len);
        if (err > 0)
                return TRUE;
-       else if (!err && !data->step)
-               tester_test_passed();
-       else
+       else if (err)
                tester_test_failed();
+       else if (!data->step)
+               tester_test_passed();
 
        data->err_io_id = 0;
        return FALSE;
@@ -682,7 +682,7 @@ static void sco_tx_timestamping(struct test_data *data, GIOChannel *io)
        int err;
        unsigned int count;
 
-       if (!(scodata->so_timestamping & SOF_TIMESTAMPING_TX_RECORD_MASK))
+       if (!(scodata->so_timestamping & TS_TX_RECORD_MASK))
                return;
 
        sk = g_io_channel_unix_get_fd(io);
tools/tester.h +35 -8
index b6de084a4..82770014f 100644
@@ -20,6 +20,15 @@
 #define SEC_NSEC(_t)  ((_t) * 1000000000LL)
 #define TS_NSEC(_ts)  (SEC_NSEC((_ts)->tv_sec) + (_ts)->tv_nsec)
 
+#if !HAVE_DECL_SOF_TIMESTAMPING_TX_COMPLETION
+#define SOF_TIMESTAMPING_TX_COMPLETION (SOF_TIMESTAMPING_LAST << 1)
+#endif
+#if !HAVE_DECL_SCM_TSTAMP_COMPLETION
+#define SCM_TSTAMP_COMPLETION          (SCM_TSTAMP_ACK + 1)
+#endif
+#define TS_TX_RECORD_MASK              (SOF_TIMESTAMPING_TX_RECORD_MASK | \
+                                               SOF_TIMESTAMPING_TX_COMPLETION)
+
 struct tx_tstamp_data {
        struct {
                uint32_t id;
@@ -59,6 +68,13 @@ static inline int tx_tstamp_expect(struct tx_tstamp_data *data)
                pos++;
        }
 
+       if (data->so_timestamping & SOF_TIMESTAMPING_TX_COMPLETION) {
+               g_assert(pos < ARRAY_SIZE(data->expect));
+               data->expect[pos].type = SCM_TSTAMP_COMPLETION;
+               data->expect[pos].id = data->sent;
+               pos++;
+       }
+
        data->sent++;
 
        steps = pos - data->count;
@@ -77,6 +93,7 @@ static inline int tx_tstamp_recv(struct tx_tstamp_data *data, int sk, int len)
        struct scm_timestamping *tss = NULL;
        struct sock_extended_err *serr = NULL;
        struct timespec now;
+       unsigned int i;
 
        iov.iov_base = buf;
        iov.iov_len = sizeof(buf);
@@ -89,7 +106,7 @@ static inline int tx_tstamp_recv(struct tx_tstamp_data *data, int sk, int len)
 
        ret = recvmsg(sk, &msg, MSG_ERRQUEUE);
        if (ret < 0) {
-               if (ret == EAGAIN || ret == EWOULDBLOCK)
+               if (errno == EAGAIN || errno == EWOULDBLOCK)
                        return data->count - data->pos;
 
                tester_warn("Failed to read from errqueue: %s (%d)",
@@ -147,18 +164,29 @@ static inline int tx_tstamp_recv(struct tx_tstamp_data *data, int sk, int len)
                return -EINVAL;
        }
 
-       if ((data->so_timestamping & SOF_TIMESTAMPING_OPT_ID) &&
-                               serr->ee_data != data->expect[data->pos].id) {
-               tester_warn("Bad timestamp id %u", serr->ee_data);
+       /* Find first unreceived timestamp of the right type */
+       for (i = 0; i < data->count; ++i) {
+               if (data->expect[i].type >= 0xffff)
+                       continue;
+
+               if (serr->ee_info == data->expect[i].type) {
+                       data->expect[i].type = 0xffff;
+                       break;
+               }
+       }
+       if (i == data->count) {
+               tester_warn("Bad timestamp type %u", serr->ee_info);
                return -EINVAL;
        }
 
-       if (serr->ee_info != data->expect[data->pos].type) {
-               tester_warn("Bad timestamp type %u", serr->ee_info);
+       if ((data->so_timestamping & SOF_TIMESTAMPING_OPT_ID) &&
+                               serr->ee_data != data->expect[i].id) {
+               tester_warn("Bad timestamp id %u", serr->ee_data);
                return -EINVAL;
        }
 
-       tester_print("Got valid TX timestamp %u", data->pos);
+       tester_print("Got valid TX timestamp %u (type %u, id %u)", i,
+                                               serr->ee_info, serr->ee_data);
 
        ++data->pos;
 
--

2.48.1

#4 lore raw

PATCH 2/3 l2cap-tester: add test for stream socket TX timestamping

In reply to Pauli Virtanen

Stream socket TX timestamp ids shall refer to the byte positions. Add test:

L2CAP BR/EDR Client - Stream TX Timestamping

---
 tools/iso-tester.c   |  4 ++--
 tools/l2cap-tester.c | 32 ++++++++++++++++++++++++++++----
 tools/sco-tester.c   |  4 ++--
 tools/tester.h       | 12 +++++++++---
 4 files changed, 41 insertions(+), 11 deletions(-)
tools/iso-tester.c +2 -2
index b5e638808..ad0738091 100644
@@ -2285,10 +2285,10 @@ static void iso_tx_timestamping(struct test_data *data, GIOChannel *io)
 
 	tester_print("Enabling TX timestamping");
 
-	tx_tstamp_init(&data->tx_ts, isodata->so_timestamping);
+	tx_tstamp_init(&data->tx_ts, isodata->so_timestamping, false);
 
 	for (count = 0; count < isodata->repeat_send + 1; ++count)
-		data->step += tx_tstamp_expect(&data->tx_ts);
+		data->step += tx_tstamp_expect(&data->tx_ts, 0);
 
 	sk = g_io_channel_unix_get_fd(io);
 
tools/l2cap-tester.c +28 -4
index 7f3be6c0f..395e76dbc 100644
@@ -102,6 +102,9 @@ struct l2cap_data {
 
 	/* Number of additional packets to send. */
 	unsigned int repeat_send;
+
+	/* Socket type (0 means SOCK_SEQPACKET) */
+	int sock_type;
 };
 
 static void print_debug(const char *str, void *user_data)
@@ -386,6 +389,19 @@ static const struct l2cap_data client_connect_tx_timestamping_test = {
 	.repeat_send = 2,
 };
 
+static const struct l2cap_data client_connect_stream_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 |
+					SOF_TIMESTAMPING_TX_COMPLETION),
+	.repeat_send = 2,
+	.sock_type = SOCK_STREAM,
+};
+
 static const struct l2cap_data client_connect_shut_wr_success_test = {
 	.client_psm = 0x1001,
 	.server_psm = 0x1001,
@@ -1371,10 +1387,11 @@ static void l2cap_tx_timestamping(struct test_data *data, GIOChannel *io)
 
 	tester_print("Enabling TX timestamping");
 
-	tx_tstamp_init(&data->tx_ts, l2data->so_timestamping);
+	tx_tstamp_init(&data->tx_ts, l2data->so_timestamping,
+					l2data->sock_type == SOCK_STREAM);
 
 	for (count = 0; count < l2data->repeat_send + 1; ++count)
-		data->step += tx_tstamp_expect(&data->tx_ts);
+		data->step += tx_tstamp_expect(&data->tx_ts, l2data->data_len);
 
 	err = setsockopt(sk, SOL_SOCKET, SO_TIMESTAMPING, &so, sizeof(so));
 	if (err < 0) {
@@ -1523,9 +1540,12 @@ static int create_l2cap_sock(struct test_data *data, uint16_t psm,
 	const uint8_t *central_bdaddr;
 	struct sockaddr_l2 addr;
 	int sk, err;
+	int sock_type = SOCK_SEQPACKET;
 
-	sk = socket(PF_BLUETOOTH, SOCK_SEQPACKET | SOCK_NONBLOCK,
-							BTPROTO_L2CAP);
+	if (l2data && l2data->sock_type)
+		sock_type = l2data->sock_type;
+
+	sk = socket(PF_BLUETOOTH, sock_type | SOCK_NONBLOCK, BTPROTO_L2CAP);
 	if (sk < 0) {
 		err = -errno;
 		tester_warn("Can't create socket: %s (%d)", strerror(errno),
@@ -2523,6 +2543,10 @@ int main(int argc, char *argv[])
 					&client_connect_tx_timestamping_test,
 					setup_powered_client, test_connect);
 
+	test_l2cap_bredr("L2CAP BR/EDR Client - Stream TX Timestamping",
+				&client_connect_stream_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);
tools/sco-tester.c +2 -2
index 130ab526d..ae76b1ddd 100644
@@ -689,10 +689,10 @@ static void sco_tx_timestamping(struct test_data *data, GIOChannel *io)
 
 	tester_print("Enabling TX timestamping");
 
-	tx_tstamp_init(&data->tx_ts, scodata->so_timestamping);
+	tx_tstamp_init(&data->tx_ts, scodata->so_timestamping, false);
 
 	for (count = 0; count < scodata->repeat_send + 1; ++count)
-		data->step += tx_tstamp_expect(&data->tx_ts);
+		data->step += tx_tstamp_expect(&data->tx_ts, 0);
 
 	err = setsockopt(sk, SOL_SOCKET, SO_TIMESTAMPING, &so, sizeof(so));
 	if (err < 0) {
tools/tester.h +9 -3
index 82770014f..14aa1e3ab 100644
@@ -38,22 +38,27 @@ struct tx_tstamp_data {
 	unsigned int count;
 	unsigned int sent;
 	uint32_t so_timestamping;
+	bool stream;
 };
 
 static inline void tx_tstamp_init(struct tx_tstamp_data *data,
-				uint32_t so_timestamping)
+				uint32_t so_timestamping, bool stream)
 {
 	memset(data, 0, sizeof(*data));
 	memset(data->expect, 0xff, sizeof(data->expect));
 
 	data->so_timestamping = so_timestamping;
+	data->stream = stream;
 }
 
-static inline int tx_tstamp_expect(struct tx_tstamp_data *data)
+static inline int tx_tstamp_expect(struct tx_tstamp_data *data, size_t len)
 {
 	unsigned int pos = data->count;
 	int steps;
 
+	if (data->stream && len)
+		data->sent += len - 1;
+
 	if (data->so_timestamping & SOF_TIMESTAMPING_TX_SCHED) {
 		g_assert(pos < ARRAY_SIZE(data->expect));
 		data->expect[pos].type = SCM_TSTAMP_SCHED;
@@ -75,7 +80,8 @@ static inline int tx_tstamp_expect(struct tx_tstamp_data *data)
 		pos++;
 	}
 
-	data->sent++;
+	if (!data->stream || len)
+		data->sent++;
 
 	steps = pos - data->count;
 	data->count = pos;
Signature · 1 line
2.48.1
#5 lore raw

PATCH 3/3 tools/tester: enable TX timestamping tests by default

In reply to Pauli Virtanen
---
 tools/iso-tester.c   | 2 +-
 tools/l2cap-tester.c | 6 ------
 tools/sco-tester.c   | 6 ------
 3 files changed, 1 insertion(+), 13 deletions(-)
tools/iso-tester.c +1 -1
index ad0738091..640692b77 100644
@@ -691,7 +691,7 @@ static void test_pre_setup(const void *test_data)
 	struct test_data *data = tester_get_data();
 	const struct iso_client_data *isodata = test_data;
 
-	if (isodata && isodata->so_timestamping) {
+	if (isodata && isodata->no_poll_errqueue) {
 		if (tester_pre_setup_skip_by_default())
 			return;
 	}
tools/l2cap-tester.c +0 -6
index 395e76dbc..e56773d13 100644
@@ -221,12 +221,6 @@ static void read_index_list_callback(uint8_t status, uint16_t length,
 static void test_pre_setup(const void *test_data)
 {
 	struct test_data *data = tester_get_data();
-	const struct l2cap_data *l2data = test_data;
-
-	if (l2data && l2data->so_timestamping) {
-		if (tester_pre_setup_skip_by_default())
-			return;
-	}
 
 	data->mgmt = mgmt_new_default();
 	if (!data->mgmt) {
tools/sco-tester.c +0 -6
index ae76b1ddd..1c07eec2d 100644
@@ -197,12 +197,6 @@ static void read_index_list_callback(uint8_t status, uint16_t length,
 static void test_pre_setup(const void *test_data)
 {
 	struct test_data *data = tester_get_data();
-	const struct sco_client_data *scodata = test_data;
-
-	if (scodata && scodata->so_timestamping) {
-		if (tester_pre_setup_skip_by_default())
-			return;
-	}
 
 	data->mgmt = mgmt_new_default();
 	if (!data->mgmt) {
Signature · 1 line
2.48.1