mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: HyeongJun An <sammiee5311@gmail.com>
To: Takashi Iwai <tiwai@suse.com>
Cc: Jaroslav Kysela <perex@perex.cz>, Mark Brown <broonie@kernel.org>,
	Shuah Khan <shuah@kernel.org>,
	linux-sound@vger.kernel.org, linux-kselftest@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	HyeongJun An <sammiee5311@gmail.com>
Subject: [PATCH 3/4] selftests/alsa: Test the sequencer UMP SysEx conversion
Date: Wed,  2 Dec 2026 16:32:14 +0900	[thread overview]
Message-ID: <20261202073215.2588603-4-sammiee5311@gmail.com> (raw)
In-Reply-To: <20261202073215.2588603-1-sammiee5311@gmail.com>

Check that a SysEx event from a legacy client reaches a UMP client as
one packet with up to six data bytes, and as start, continue and end
packets when it is longer. Also check that a SysEx split over two events
continues in the second one. The six data bytes in the first packet come
from commit 952b13c21523 ("ALSA: seq: ump: Optimize conversions from
SysEx to UMP").

Signed-off-by: HyeongJun An <sammiee5311@gmail.com>
---
 tools/testing/selftests/alsa/seq-ump-test.c | 67 +++++++++++++++++++++
 1 file changed, 67 insertions(+)

diff --git a/tools/testing/selftests/alsa/seq-ump-test.c b/tools/testing/selftests/alsa/seq-ump-test.c
index f2051777a9dc5..a0855dd451c2a 100644
--- a/tools/testing/selftests/alsa/seq-ump-test.c
+++ b/tools/testing/selftests/alsa/seq-ump-test.c
@@ -145,6 +145,34 @@ static int send_note(struct seq_client *src, struct seq_client *dst,
 	return 0;
 }
 
+/* send a SYSEX event, with the data after the event in the same write */
+static int send_sysex(struct seq_client *src, struct seq_client *dst,
+		      const unsigned char *data, int len)
+{
+	struct {
+		struct snd_seq_event ev;
+		unsigned char data[32];
+	} buf;
+	int size = sizeof(buf.ev) + len;
+
+	if (len > (int)sizeof(buf.data))
+		return -EINVAL;
+	memset(&buf, 0, sizeof(buf));
+	buf.ev.type = SNDRV_SEQ_EVENT_SYSEX;
+	buf.ev.flags = SNDRV_SEQ_TIME_STAMP_TICK |
+		       SNDRV_SEQ_EVENT_LENGTH_VARIABLE;
+	buf.ev.queue = SNDRV_SEQ_QUEUE_DIRECT;
+	buf.ev.source.client = src->id;
+	buf.ev.source.port = src->port;
+	buf.ev.dest.client = dst->id;
+	buf.ev.dest.port = dst->port;
+	buf.ev.data.ext.len = len;
+	memcpy(buf.data, data, len);
+	if (write(src->fd, &buf, size) != size)
+		return -errno;
+	return 0;
+}
+
 /* send a UMP packet from a UMP client */
 static int send_ump(struct seq_client *src, struct seq_client *dst,
 		    unsigned int w0, unsigned int w1)
@@ -286,6 +314,13 @@ static int send_events(struct seq_client *src, struct seq_client *dst,
 #define SEND_UMP(w0, w1) \
 	ASSERT_EQ(0, send_ump(&self->src, &self->dst, w0, w1))
 
+#define SEND_SYSEX(...) do {						\
+	const unsigned char data[] = { __VA_ARGS__ };			\
+									\
+	ASSERT_EQ(0, send_sysex(&self->src, &self->dst, data,		\
+				sizeof(data)));				\
+} while (0)
+
 /* RPN 0/1 with Data Entry */
 TEST_F(seq_ump, rpn)
 {
@@ -504,6 +539,38 @@ TEST_F(seq_ump, c14_program_bank)
 	EXPECT_PACKETS({ 0x40c70001, 0x09000304 });
 }
 
+/* SysEx of up to six data bytes goes in one packet */
+TEST_F(seq_ump, sysex_short)
+{
+	SEND_SYSEX(0xf0, 0x01, 0x02, 0x03, 0xf7);
+	SEND_SYSEX(0xf0, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0xf7);
+	EXPECT_MT_PACKETS(3, { 0x30030102, 0x03000000 },
+			  { 0x30060102, 0x03040506 });
+}
+
+/* longer SysEx goes in start, continue and end packets of six data bytes */
+TEST_F(seq_ump, sysex_long)
+{
+	SEND_SYSEX(0xf0, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0xf7);
+	SEND_SYSEX(0xf0, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
+		   0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0xf7);
+	EXPECT_MT_PACKETS(3, { 0x30160102, 0x03040506 },
+			  { 0x30310700, 0 },
+			  { 0x30160102, 0x03040506 },
+			  { 0x30260708, 0x090a0b0c },
+			  { 0x30310d00, 0 });
+}
+
+/* SysEx sent in two events continues in the second one */
+TEST_F(seq_ump, sysex_split)
+{
+	SEND_SYSEX(0xf0, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08);
+	SEND_SYSEX(0x09, 0x0a, 0xf7);
+	EXPECT_MT_PACKETS(3, { 0x30160102, 0x03040506 },
+			  { 0x30220708, 0 },
+			  { 0x3032090a, 0 });
+}
+
 /* a UMP MIDI 1.0 client gets the CCs as they are, RPN selection included */
 TEST(midi1_passthrough)
 {
-- 
2.43.0


  parent reply	other threads:[~2026-12-02  7:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  7:32 [PATCH 0/4] ALSA: seq: ump: Fix a program change and test more conversions HyeongJun An
2026-12-02  7:32 ` [PATCH 1/4] ALSA: seq: ump: Don't leave the bank LSB in a MIDI 1.0 program change HyeongJun An
2026-12-02  7:32 ` [PATCH 2/4] selftests/alsa: Test the sequencer UMP bank and program change conversion HyeongJun An
2026-12-02  7:32 ` HyeongJun An [this message]
2026-12-02  7:32 ` [PATCH 4/4] selftests/alsa: Test the sequencer UMP system message conversion HyeongJun An

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261202073215.2588603-4-sammiee5311@gmail.com \
    --to=sammiee5311@gmail.com \
    --cc=broonie@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=shuah@kernel.org \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®