[PATCH 2/4] selftests/alsa: Test the sequencer UMP bank and program change conversion

From: HyeongJun An

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


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