diff --git a/tests/integration.c b/tests/integration.c index 9314afe..ac3acde 100644 --- a/tests/integration.c +++ b/tests/integration.c @@ -276,10 +276,8 @@ static int test_audio_pass_through(void) { /* Helper: send a MIDI note‑on using the persistent client */ static int send_jack_note_on(const char *target_port, unsigned char note, unsigned char velocity) { (void)target_port; /* connection is already made to looper:control */ - /* Ensure persistent client is initialised */ - if (!persistent_midi_client && init_persistent_midi_client() != 0) { - return -1; - } + /* Persistent client must be initialised by the calling test */ + if (!persistent_midi_client) return -1; midi_inject_note = note; midi_inject_velocity = velocity; midi_inject_pending = 1; @@ -305,6 +303,12 @@ static int test_looper_looping(void) { pid_t pid = start_looper(); if (pid < 0) return 1; + /* Create persistent MIDI client for this looper instance */ + if (init_persistent_midi_client() != 0) { + kill(pid, SIGTERM); waitpid(pid, NULL, 0); + fprintf(stderr, " FAIL: cannot initialise persistent MIDI client\n"); + return 1; + } jack_client_t *client; jack_status_t status; @@ -383,6 +387,7 @@ static int test_looper_looping(void) { jack_deactivate(client); jack_client_close(client); + cleanup_persistent_midi_client(); kill(pid, SIGTERM); waitpid(pid, NULL, 0); @@ -402,6 +407,11 @@ static int test_multiple_channels(void) { printf("Test: dynamic channel creation via MIDI command\n"); pid_t pid = start_looper(); if (pid < 0) return 1; + if (init_persistent_midi_client() != 0) { + kill(pid, SIGTERM); waitpid(pid, NULL, 0); + fprintf(stderr, " FAIL: cannot initialise persistent MIDI client\n"); + return 1; + } jack_client_t *client; jack_status_t status; @@ -437,6 +447,7 @@ static int test_multiple_channels(void) { port_found: ; jack_client_close(client); + cleanup_persistent_midi_client(); kill(pid, SIGTERM); waitpid(pid, NULL, 0); @@ -453,6 +464,11 @@ static int test_control_key_modifier(void) { printf("Test: control‑key modifier triggers state transition via note 62\n"); pid_t pid = start_looper(); if (pid < 0) return 1; + if (init_persistent_midi_client() != 0) { + kill(pid, SIGTERM); waitpid(pid, NULL, 0); + fprintf(stderr, " FAIL: cannot initialise persistent MIDI client\n"); + return 1; + } jack_client_t *client; jack_status_t status; client = jack_client_open("test_ctrl_key", JackNoStartServer, &status); @@ -536,6 +552,7 @@ static int test_control_key_modifier(void) { safe_usleep(2000000); jack_deactivate(client); jack_client_close(client); + cleanup_persistent_midi_client(); kill(pid, SIGTERM); waitpid(pid, NULL, 0); int got_bursts = bursts; @@ -553,6 +570,11 @@ static int test_bind_channel(void) { printf("Test: control‑key bind channel (note 0) and toggle\n"); pid_t pid = start_looper(); if (pid < 0) return 1; + if (init_persistent_midi_client() != 0) { + kill(pid, SIGTERM); waitpid(pid, NULL, 0); + fprintf(stderr, " FAIL: cannot initialise persistent MIDI client\n"); + return 1; + } jack_client_t *client; jack_status_t status; client = jack_client_open("test_bind", JackNoStartServer, &status); @@ -649,6 +671,7 @@ static int test_bind_channel(void) { safe_usleep(2000000); jack_deactivate(client); jack_client_close(client); + cleanup_persistent_midi_client(); kill(pid, SIGTERM); waitpid(pid, NULL, 0); int got_bursts = bursts; @@ -666,6 +689,11 @@ static int test_bind_unbind(void) { printf("Test: bind to channel 5, unbind, then toggle default (channel 0)\n"); pid_t pid = start_looper(); if (pid < 0) return 1; + if (init_persistent_midi_client() != 0) { + kill(pid, SIGTERM); waitpid(pid, NULL, 0); + fprintf(stderr, " FAIL: cannot initialise persistent MIDI client\n"); + return 1; + } jack_client_t *client; jack_status_t status; client = jack_client_open("test_unbind", JackNoStartServer, &status); @@ -777,6 +805,7 @@ static int test_bind_unbind(void) { safe_usleep(2000000); jack_deactivate(client); jack_client_close(client); + cleanup_persistent_midi_client(); kill(pid, SIGTERM); waitpid(pid, NULL, 0); int got_bursts = bursts; @@ -794,6 +823,11 @@ static int test_remove_channel(void) { printf("Test: dynamic channel removal via MIDI command\n"); pid_t pid = start_looper(); if (pid < 0) return 1; + if (init_persistent_midi_client() != 0) { + kill(pid, SIGTERM); waitpid(pid, NULL, 0); + fprintf(stderr, " FAIL: cannot initialise persistent MIDI client\n"); + return 1; + } jack_client_t *client; jack_status_t status; client = jack_client_open("test_remove", JackNoStartServer, &status); @@ -854,6 +888,7 @@ static int test_remove_channel(void) { if (!still_found) break; } jack_client_close(client); + cleanup_persistent_midi_client(); kill(pid, SIGTERM); waitpid(pid, NULL, 0); if (still_found) { @@ -870,6 +905,11 @@ static int test_fifo_stop_bind_unbind(void) { printf("Test: FIFO stop, bind, unbind\n"); pid_t pid = start_looper(); if (pid < 0) return 1; + if (init_persistent_midi_client() != 0) { + kill(pid, SIGTERM); waitpid(pid, NULL, 0); + fprintf(stderr, " FAIL: cannot initialise persistent MIDI client\n"); + return 1; + } jack_client_t *client; jack_status_t status; @@ -947,6 +987,7 @@ static int test_fifo_stop_bind_unbind(void) { int bursts_after = bursts; jack_deactivate(client); jack_client_close(client); + cleanup_persistent_midi_client(); kill(pid, SIGTERM); waitpid(pid, NULL, 0); if (bursts_after < 1) { @@ -1085,6 +1126,11 @@ static int test_stop_midi(void) { printf("Test: MIDI stop (note 65 under control key)\n"); pid_t pid = start_looper(); if (pid < 0) return 1; + if (init_persistent_midi_client() != 0) { + kill(pid, SIGTERM); waitpid(pid, NULL, 0); + fprintf(stderr, " FAIL: cannot initialise persistent MIDI client\n"); + return 1; + } jack_client_t *client; jack_status_t status; client = jack_client_open("test_stop", JackNoStartServer, &status); @@ -1177,6 +1223,7 @@ static int test_stop_midi(void) { int bursts_after = bursts; jack_deactivate(client); jack_client_close(client); + cleanup_persistent_midi_client(); kill(pid, SIGTERM); waitpid(pid, NULL, 0); if (bursts_after > bursts_before + 5) { @@ -1193,6 +1240,11 @@ static int test_record_loop_stop(void) { printf("Test: full record‑loop‑stop (≥5 repetitions)\n"); pid_t pid = start_looper(); if (pid < 0) return 1; + if (init_persistent_midi_client() != 0) { + kill(pid, SIGTERM); waitpid(pid, NULL, 0); + fprintf(stderr, " FAIL: cannot initialise persistent MIDI client\n"); + return 1; + } jack_client_t *client; jack_status_t status; client = jack_client_open("test_full", JackNoStartServer, &status); @@ -1278,6 +1330,7 @@ static int test_record_loop_stop(void) { int total_bursts = bursts; jack_deactivate(client); jack_client_close(client); + cleanup_persistent_midi_client(); kill(pid, SIGTERM); waitpid(pid, NULL, 0); if (total_bursts < 5) { @@ -1368,7 +1421,6 @@ int main(void) { failures++; } - cleanup_persistent_midi_client(); if (failures > 0) { fprintf(stderr, "%d test(s) FAILED\n", failures); return 1;