All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] ALSA: seq: ump: Fix a program change and test more conversions
@ 2026-12-02  7:32 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
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: HyeongJun An @ 2026-12-02  7:32 UTC (permalink / raw)
  To: Takashi Iwai
  Cc: Jaroslav Kysela, Mark Brown, Shuah Khan, linux-sound,
	linux-kselftest, linux-kernel, HyeongJun An

While adding tests for the sequencer UMP conversion of program changes,
SysEx and system messages, I found that a MIDI 2.0 program change with
a bank reaches a UMP MIDI 1.0 client with the bank LSB still in its
reserved byte. Patch 1 fixes it.

Patches 2-4 extend seq-ump-test. The tests cover conversions that
earlier commits fixed, and reverting any of the commits they name makes
at least one of them fail. ump_midi2_to_midi1_program in patch 2 also
needs patch 1. All 38 tests pass on sound/for-next with patch 1, run
under QEMU.

Prepared with Claude Code (Claude Opus 5.5).

HyeongJun An (4):
  ALSA: seq: ump: Don't leave the bank LSB in a MIDI 1.0 program change
  selftests/alsa: Test the sequencer UMP bank and program change
    conversion
  selftests/alsa: Test the sequencer UMP SysEx conversion
  selftests/alsa: Test the sequencer UMP system message conversion

 sound/core/seq/seq_ump_convert.c            |   1 +
 tools/testing/selftests/alsa/seq-ump-test.c | 159 +++++++++++++++++++-
 2 files changed, 158 insertions(+), 2 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/4] ALSA: seq: ump: Don't leave the bank LSB in a MIDI 1.0 program change
  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 ` HyeongJun An
  2026-12-02  7:32 ` [PATCH 2/4] selftests/alsa: Test the sequencer UMP bank and program change conversion HyeongJun An
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: HyeongJun An @ 2026-12-02  7:32 UTC (permalink / raw)
  To: Takashi Iwai
  Cc: Jaroslav Kysela, Mark Brown, Shuah Khan, linux-sound,
	linux-kselftest, linux-kernel, HyeongJun An

The cvt_ump_midi2_to_midi1() sends a MIDI 2.0 program change with a
valid bank as two bank select CCs and a program change, all built in the
same packet. The CC data byte is the reserved byte of a MIDI 1.0 program
change, so the program change keeps the bank LSB there:

  MIDI 2.0: 0x40c00001 0x05000102 (program 5, bank 1/2)
  MIDI 1.0: 0x20b00001, 0x20b02002, 0x20c00502

A UMP MIDI 1.0 client then gets a program change with a non-zero
reserved byte. Clear it before the program change is sent.

Fixes: 8a42886cae30 ("ALSA: seq: Fix missing bank setup between MIDI1/MIDI2 UMP conversion")
Signed-off-by: HyeongJun An <sammiee5311@gmail.com>
---
 sound/core/seq/seq_ump_convert.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sound/core/seq/seq_ump_convert.c b/sound/core/seq/seq_ump_convert.c
index e76fdb54df175..602afb5a0f285 100644
--- a/sound/core/seq/seq_ump_convert.c
+++ b/sound/core/seq/seq_ump_convert.c
@@ -520,6 +520,7 @@ static int cvt_ump_midi2_to_midi1(struct snd_seq_client *dest,
 			if (err < 0)
 				return err;
 			midi1->note.status = midi2->note.status;
+			midi1->cc.data = 0;
 		}
 		midi1->pg.program = midi2->pg.program;
 		break;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/4] selftests/alsa: Test the sequencer UMP bank and program change conversion
  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 ` HyeongJun An
  2026-12-02  7:32 ` [PATCH 3/4] selftests/alsa: Test the sequencer UMP SysEx conversion HyeongJun An
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: HyeongJun An @ 2026-12-02  7:32 UTC (permalink / raw)
  To: Takashi Iwai
  Cc: Jaroslav Kysela, Mark Brown, Shuah Khan, linux-sound,
	linux-kselftest, linux-kernel, HyeongJun An

Check that a bank select from a legacy client goes to a UMP MIDI 2.0
client with the next program change, sent as CCs and as CONTROL14. For
the CCs, also check that the program change after that has no bank, and
that a later bank select LSB keeps the MSB. The latter was fixed by
commit a200df7deb31 ("ALSA: seq: Don't clear bank selection at event ->
UMP MIDI2 conversion"). Also check the bank of a program change between
UMP MIDI 1.0 and MIDI 2.0 clients.

ump_midi2_to_midi1_program fails without "ALSA: seq: ump: Don't leave
the bank LSB in a MIDI 1.0 program change".

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

diff --git a/tools/testing/selftests/alsa/seq-ump-test.c b/tools/testing/selftests/alsa/seq-ump-test.c
index 7030d061dfae8..f2051777a9dc5 100644
--- a/tools/testing/selftests/alsa/seq-ump-test.c
+++ b/tools/testing/selftests/alsa/seq-ump-test.c
@@ -4,8 +4,8 @@
  * packets between MIDI 1.0 and MIDI 2.0 clients.
  *
  * A client sends events to a UMP client, and the test checks the packets
- * that the UMP client receives. The converter keeps its RPN/NRPN state
- * per destination port and channel, so each test uses new clients.
+ * that the UMP client receives. The converter keeps its RPN/NRPN and bank
+ * state per destination port and channel, so each test uses new clients.
  */
 #include <errno.h>
 #include <fcntl.h>
@@ -232,6 +232,8 @@ struct event {
 	{ SNDRV_SEQ_EVENT_CONTROLLER, ch, param, value }
 #define C14(ch, param, value) \
 	{ SNDRV_SEQ_EVENT_CONTROL14, ch, param, value }
+#define PGM(ch, value) \
+	{ SNDRV_SEQ_EVENT_PGMCHANGE, ch, 0, value }
 
 static int send_events(struct seq_client *src, struct seq_client *dst,
 		       const struct event *ev, int n)
@@ -482,6 +484,26 @@ TEST_F(seq_ump, key_pressure)
 	EXPECT_PACKETS({ 0x40a24000, 0 });
 }
 
+/*
+ * A bank select goes with the next program change only, and a later
+ * bank select LSB keeps the MSB
+ */
+TEST_F(seq_ump, program_bank)
+{
+	SEND(CC(0, 0, 1), CC(0, 32, 2), PGM(0, 5));
+	SEND(CC(0, 32, 3), PGM(0, 6), PGM(0, 7));
+	EXPECT_PACKETS({ 0x40c00001, 0x05000102 },
+		       { 0x40c00001, 0x06000103 },
+		       { 0x40c00000, 0x07000000 });
+}
+
+/* the same with the bank select sent as CONTROL14 */
+TEST_F(seq_ump, c14_program_bank)
+{
+	SEND(C14(7, 0, (3 << 7) | 4), PGM(7, 9));
+	EXPECT_PACKETS({ 0x40c70001, 0x09000304 });
+}
+
 /* a UMP MIDI 1.0 client gets the CCs as they are, RPN selection included */
 TEST(midi1_passthrough)
 {
@@ -640,4 +662,42 @@ TEST_F(seq_pair, ump_midi2_to_midi1_rpn)
 			  { 0x20b10609, 0 }, { 0x20b1260d, 0 });
 }
 
+/* UMP MIDI 1.0 to MIDI 2.0: the bank select CCs go into the program change */
+TEST_F(seq_pair, ump_midi1_to_midi2_program)
+{
+	int skip = 0;
+	int err;
+
+	err = open_pair(&self->dst, SNDRV_SEQ_CLIENT_UMP_MIDI_2_0,
+			&self->src, SNDRV_SEQ_CLIENT_UMP_MIDI_1_0, &skip);
+	if (skip)
+		SKIP(return, "UMP sequencer client unavailable: %s",
+		     strerror(-err));
+	ASSERT_EQ(0, err);
+
+	SEND_UMP(0x20b00001, 0);
+	SEND_UMP(0x20b02002, 0);
+	SEND_UMP(0x20c00500, 0);
+	EXPECT_PACKETS({ 0x40c00001, 0x05000102 });
+}
+
+/* UMP MIDI 2.0 to MIDI 1.0: a program change with a bank is three messages */
+TEST_F(seq_pair, ump_midi2_to_midi1_program)
+{
+	int skip = 0;
+	int err;
+
+	err = open_pair(&self->dst, SNDRV_SEQ_CLIENT_UMP_MIDI_1_0,
+			&self->src, SNDRV_SEQ_CLIENT_UMP_MIDI_2_0, &skip);
+	if (skip)
+		SKIP(return, "UMP sequencer client unavailable: %s",
+		     strerror(-err));
+	ASSERT_EQ(0, err);
+
+	SEND_UMP(0x40c00001, 0x05000102);
+	SEND_UMP(0x40c00000, 0x06000000);
+	EXPECT_MT_PACKETS(2, { 0x20b00001, 0 }, { 0x20b02002, 0 },
+			  { 0x20c00500, 0 }, { 0x20c00600, 0 });
+}
+
 TEST_HARNESS_MAIN
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/4] selftests/alsa: Test the sequencer UMP SysEx conversion
  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
  2026-12-02  7:32 ` [PATCH 4/4] selftests/alsa: Test the sequencer UMP system message conversion HyeongJun An
  2026-12-02 16:08 ` [PATCH 0/4] ALSA: seq: ump: Fix a program change and test more conversions Takashi Iwai
  4 siblings, 0 replies; 6+ messages in thread
From: HyeongJun An @ 2026-12-02  7:32 UTC (permalink / raw)
  To: Takashi Iwai
  Cc: Jaroslav Kysela, Mark Brown, Shuah Khan, linux-sound,
	linux-kselftest, linux-kernel, HyeongJun An

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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/4] selftests/alsa: Test the sequencer UMP system message conversion
  2026-12-02  7:32 [PATCH 0/4] ALSA: seq: ump: Fix a program change and test more conversions HyeongJun An
                   ` (2 preceding siblings ...)
  2026-12-02  7:32 ` [PATCH 3/4] selftests/alsa: Test the sequencer UMP SysEx conversion HyeongJun An
@ 2026-12-02  7:32 ` HyeongJun An
  2026-12-02 16:08 ` [PATCH 0/4] ALSA: seq: ump: Fix a program change and test more conversions Takashi Iwai
  4 siblings, 0 replies; 6+ messages in thread
From: HyeongJun An @ 2026-12-02  7:32 UTC (permalink / raw)
  To: Takashi Iwai
  Cc: Jaroslav Kysela, Mark Brown, Shuah Khan, linux-sound,
	linux-kselftest, linux-kernel, HyeongJun An

Check that a song position, a song select and a system reset from a
legacy client reach UMP MIDI 1.0 and MIDI 2.0 clients as UMP system
packets, with the song position LSB first and both of its bytes.

These were fixed by commit edb32776196a ("ALSA: seq: Fix incorrect UMP
type for system messages"), commit 700fe6fd093d ("ALSA: seq: Fix yet
another spot for system message conversion"),
commit 310fa3ec2859 ("ALSA: seq: ump: Fix swapped song position pointer
data"), commit 9d65ab6050d2 ("ALSA: seq: Fix missing MSB in MIDI2 SPP
conversion") for the MIDI 2.0 client, and commit 55fac50ea46f ("ALSA:
seq: ump: Fix missing System Reset message handling").

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

diff --git a/tools/testing/selftests/alsa/seq-ump-test.c b/tools/testing/selftests/alsa/seq-ump-test.c
index a0855dd451c2a..5745cfd522972 100644
--- a/tools/testing/selftests/alsa/seq-ump-test.c
+++ b/tools/testing/selftests/alsa/seq-ump-test.c
@@ -262,6 +262,8 @@ struct event {
 	{ SNDRV_SEQ_EVENT_CONTROL14, ch, param, value }
 #define PGM(ch, value) \
 	{ SNDRV_SEQ_EVENT_PGMCHANGE, ch, 0, value }
+#define SYS(type, value) \
+	{ SNDRV_SEQ_EVENT_##type, 0, 0, value }
 
 static int send_events(struct seq_client *src, struct seq_client *dst,
 		       const struct event *ev, int n)
@@ -571,6 +573,14 @@ TEST_F(seq_ump, sysex_split)
 			  { 0x3032090a, 0 });
 }
 
+/* system messages are UMP system packets, with both song position bytes */
+TEST_F(seq_ump, system)
+{
+	SEND(SYS(SONGPOS, 0x1234), SYS(SONGSEL, 5), SYS(RESET, 0));
+	EXPECT_MT_PACKETS(1, { 0x10f23424, 0 }, { 0x10f30500, 0 },
+			  { 0x10ff0000, 0 });
+}
+
 /* a UMP MIDI 1.0 client gets the CCs as they are, RPN selection included */
 TEST(midi1_passthrough)
 {
@@ -729,6 +739,24 @@ TEST_F(seq_pair, ump_midi2_to_midi1_rpn)
 			  { 0x20b10609, 0 }, { 0x20b1260d, 0 });
 }
 
+/* the same system messages to a UMP MIDI 1.0 client */
+TEST_F(seq_pair, midi1_system)
+{
+	int skip = 0;
+	int err;
+
+	err = open_pair(&self->dst, SNDRV_SEQ_CLIENT_UMP_MIDI_1_0,
+			&self->src, 0, &skip);
+	if (skip)
+		SKIP(return, "UMP sequencer client unavailable: %s",
+		     strerror(-err));
+	ASSERT_EQ(0, err);
+
+	SEND(SYS(SONGPOS, 0x1234), SYS(SONGSEL, 5), SYS(RESET, 0));
+	EXPECT_MT_PACKETS(1, { 0x10f23424, 0 }, { 0x10f30500, 0 },
+			  { 0x10ff0000, 0 });
+}
+
 /* UMP MIDI 1.0 to MIDI 2.0: the bank select CCs go into the program change */
 TEST_F(seq_pair, ump_midi1_to_midi2_program)
 {
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/4] ALSA: seq: ump: Fix a program change and test more conversions
  2026-12-02  7:32 [PATCH 0/4] ALSA: seq: ump: Fix a program change and test more conversions HyeongJun An
                   ` (3 preceding siblings ...)
  2026-12-02  7:32 ` [PATCH 4/4] selftests/alsa: Test the sequencer UMP system message conversion HyeongJun An
@ 2026-12-02 16:08 ` Takashi Iwai
  4 siblings, 0 replies; 6+ messages in thread
From: Takashi Iwai @ 2026-12-02 16:08 UTC (permalink / raw)
  To: HyeongJun An
  Cc: Takashi Iwai, Jaroslav Kysela, Mark Brown, Shuah Khan,
	linux-sound, linux-kselftest, linux-kernel

On Wed, 02 Dec 2026 08:32:11 +0100,
HyeongJun An wrote:
> 
> While adding tests for the sequencer UMP conversion of program changes,
> SysEx and system messages, I found that a MIDI 2.0 program change with
> a bank reaches a UMP MIDI 1.0 client with the bank LSB still in its
> reserved byte. Patch 1 fixes it.
> 
> Patches 2-4 extend seq-ump-test. The tests cover conversions that
> earlier commits fixed, and reverting any of the commits they name makes
> at least one of them fail. ump_midi2_to_midi1_program in patch 2 also
> needs patch 1. All 38 tests pass on sound/for-next with patch 1, run
> under QEMU.
> 
> Prepared with Claude Code (Claude Opus 5.5).
> 
> HyeongJun An (4):
>   ALSA: seq: ump: Don't leave the bank LSB in a MIDI 1.0 program change
>   selftests/alsa: Test the sequencer UMP bank and program change
>     conversion
>   selftests/alsa: Test the sequencer UMP SysEx conversion
>   selftests/alsa: Test the sequencer UMP system message conversion

Applied to for-next branch.  Thanks.


Takashi

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-12-02 16:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH 3/4] selftests/alsa: Test the sequencer UMP SysEx conversion HyeongJun An
2026-12-02  7:32 ` [PATCH 4/4] selftests/alsa: Test the sequencer UMP system message conversion HyeongJun An
2026-12-02 16:08 ` [PATCH 0/4] ALSA: seq: ump: Fix a program change and test more conversions Takashi Iwai

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.