From 982dd4dc02a249da9af78fca7fbf030b583b2b32 Mon Sep 17 00:00:00 2001 From: Loic Coenen Date: Sat, 9 May 2026 13:20:36 +0000 Subject: [PATCH] refactor: replace usleep with safe_usleep in integration tests --- tests/integration.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/tests/integration.c b/tests/integration.c index 07f144b..0119b0e 100644 --- a/tests/integration.c +++ b/tests/integration.c @@ -168,7 +168,7 @@ static int test_audio_pass_through(void) { waitpid(pid, NULL, 0); return 1; } - usleep(200000); + safe_usleep(200000); const char *looper_input = "looper:input"; const char *looper_output = "looper:output"; char my_output[64], my_input[64]; @@ -262,7 +262,7 @@ static int send_jack_note_on(const char *target_port, unsigned char note, unsign } /* wait for the process callback to clear the flag (event delivered) */ for (int attempts = 0; attempts < 50; attempts++) { /* ~50 * 10ms = 500ms */ - usleep(10000); + safe_usleep(10000); if (!midi_inject_pending) break; } jack_deactivate(midi_inject_client); @@ -306,7 +306,7 @@ static int test_looper_looping(void) { kill(pid, SIGTERM); waitpid(pid, NULL, 0); return 1; } - usleep(200000); /* wait for ports to appear */ + safe_usleep(200000); /* wait for ports to appear */ /* connect test:out -> looper:input, looper:output -> test:in */ char my_out[64], my_in[64]; snprintf(my_out, sizeof(my_out), "test_looping:out"); @@ -451,7 +451,7 @@ static int test_control_key_modifier(void) { kill(pid, SIGTERM); waitpid(pid, NULL, 0); return 1; } - usleep(200000); + safe_usleep(200000); char my_out[64], my_in[64]; snprintf(my_out, sizeof(my_out), "test_ctrl_key:out"); snprintf(my_in, sizeof(my_in), "test_ctrl_key:in"); @@ -468,7 +468,7 @@ static int test_control_key_modifier(void) { fprintf(stderr, " FAIL: send note 64 failed\n"); return 1; } - usleep(200000); + safe_usleep(200000); /* Now send note 62 (toggle channel 0) */ if (send_jack_note_on("looper:control", 62, 127) != 0) { jack_client_close(client); @@ -496,7 +496,7 @@ static int test_control_key_modifier(void) { kill(pid, SIGTERM); waitpid(pid, NULL, 0); return 1; } - usleep(200000); /* allow beep */ + safe_usleep(200000); /* allow beep */ /* send note 62 again under control key to move RECORD->LOOPING */ if (send_jack_note_on("looper:control", 64, 127) != 0) { jack_client_close(client); @@ -504,7 +504,7 @@ static int test_control_key_modifier(void) { fprintf(stderr, " FAIL: control key re‑send\n"); return 1; } - usleep(200000); + safe_usleep(200000); if (send_jack_note_on("looper:control", 62, 127) != 0) { jack_client_close(client); kill(pid, SIGTERM); waitpid(pid, NULL, 0); @@ -550,7 +550,7 @@ static int test_bind_channel(void) { kill(pid, SIGTERM); waitpid(pid, NULL, 0); return 1; } - usleep(200000); + safe_usleep(200000); char my_out[64], my_in[64]; snprintf(my_out, sizeof(my_out), "test_bind:out"); snprintf(my_in, sizeof(my_in), "test_bind:in"); @@ -567,14 +567,14 @@ static int test_bind_channel(void) { fprintf(stderr, " FAIL: send control key failed\n"); return 1; } - usleep(200000); + safe_usleep(200000); if (send_jack_note_on("looper:control", 0, 127) != 0) { jack_client_close(client); kill(pid, SIGTERM); waitpid(pid, NULL, 0); fprintf(stderr, " FAIL: send bind note 0 failed\n"); return 1; } - usleep(200000); + safe_usleep(200000); /* Now toggle using control+note62 – should toggle channel 0 */ if (send_jack_note_on("looper:control", 64, 127) != 0) { jack_client_close(client); @@ -582,7 +582,7 @@ static int test_bind_channel(void) { fprintf(stderr, " FAIL: send control key again failed\n"); return 1; } - usleep(200000); + safe_usleep(200000); if (send_jack_note_on("looper:control", 62, 127) != 0) { jack_client_close(client); kill(pid, SIGTERM); waitpid(pid, NULL, 0); @@ -609,7 +609,7 @@ static int test_bind_channel(void) { kill(pid, SIGTERM); waitpid(pid, NULL, 0); return 1; } - usleep(200000); /* allow beep */ + safe_usleep(200000); /* allow beep */ /* send control+note62 again to move RECORD->LOOPING */ if (send_jack_note_on("looper:control", 64, 127) != 0) { jack_client_close(client); @@ -617,7 +617,7 @@ static int test_bind_channel(void) { fprintf(stderr, " FAIL: control key for loop\n"); return 1; } - usleep(200000); + safe_usleep(200000); if (send_jack_note_on("looper:control", 62, 127) != 0) { jack_client_close(client); kill(pid, SIGTERM); waitpid(pid, NULL, 0); @@ -663,7 +663,7 @@ static int test_bind_unbind(void) { kill(pid, SIGTERM); waitpid(pid, NULL, 0); return 1; } - usleep(200000); + safe_usleep(200000); char my_out[64], my_in[64]; snprintf(my_out, sizeof(my_out), "test_unbind:out"); snprintf(my_in, sizeof(my_in), "test_unbind:in"); @@ -680,14 +680,14 @@ static int test_bind_unbind(void) { fprintf(stderr, " FAIL: send control key failed\n"); return 1; } - usleep(200000); + safe_usleep(200000); if (send_jack_note_on("looper:control", 5, 127) != 0) { jack_client_close(client); kill(pid, SIGTERM); waitpid(pid, NULL, 0); fprintf(stderr, " FAIL: bind to 5 failed\n"); return 1; } - usleep(200000); + safe_usleep(200000); /* Unbind (reset to 0) */ if (send_jack_note_on("looper:control", 64, 127) != 0) { jack_client_close(client); @@ -695,14 +695,14 @@ static int test_bind_unbind(void) { fprintf(stderr, " FAIL: control key for unbind\n"); return 1; } - usleep(200000); + safe_usleep(200000); if (send_jack_note_on("looper:control", 63, 127) != 0) { jack_client_close(client); kill(pid, SIGTERM); waitpid(pid, NULL, 0); fprintf(stderr, " FAIL: send unbind note 63 failed\n"); return 1; } - usleep(200000); + safe_usleep(200000); /* Now toggle with control+62 – should affect channel 0 */ if (send_jack_note_on("looper:control", 64, 127) != 0) { jack_client_close(client); @@ -710,7 +710,7 @@ static int test_bind_unbind(void) { fprintf(stderr, " FAIL: control key for toggle\n"); return 1; } - usleep(200000); + safe_usleep(200000); if (send_jack_note_on("looper:control", 62, 127) != 0) { jack_client_close(client); kill(pid, SIGTERM); waitpid(pid, NULL, 0); @@ -737,7 +737,7 @@ static int test_bind_unbind(void) { kill(pid, SIGTERM); waitpid(pid, NULL, 0); return 1; } - usleep(200000); /* allow beep */ + safe_usleep(200000); /* allow beep */ /* second control+62 -> loop */ if (send_jack_note_on("looper:control", 64, 127) != 0) { jack_client_close(client); @@ -745,7 +745,7 @@ static int test_bind_unbind(void) { fprintf(stderr, " FAIL: control key for loop\n"); return 1; } - usleep(200000); + safe_usleep(200000); if (send_jack_note_on("looper:control", 62, 127) != 0) { jack_client_close(client); kill(pid, SIGTERM); waitpid(pid, NULL, 0);