[PATCH 3/4] selftests/alsa: Test the sequencer UMP SysEx conversion

From: HyeongJun An

Date: Wed Dec 02 2026 - 02:32:40 EST


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@xxxxxxxxx>
---
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