fix: reduce main loop sleep to 1ms and add polling in tests
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
This commit is contained in:
@@ -51,9 +51,9 @@ int main(int argc, char *argv[]) {
|
|||||||
while (1) {
|
while (1) {
|
||||||
looper_process_commands(client);
|
looper_process_commands(client);
|
||||||
{
|
{
|
||||||
struct timespec ts = {.tv_sec = 0, .tv_nsec = 50000000};
|
struct timespec ts = {.tv_sec = 0, .tv_nsec = 1000000};
|
||||||
nanosleep(&ts, NULL);
|
nanosleep(&ts, NULL);
|
||||||
} /* check commands every 50 ms */
|
} /* check commands every 1 ms */
|
||||||
}
|
}
|
||||||
|
|
||||||
jack_client_close(client);
|
jack_client_close(client);
|
||||||
|
|||||||
@@ -396,21 +396,24 @@ static int test_multiple_channels(void) {
|
|||||||
fprintf(stderr, " FAIL: send note 60 failed\n");
|
fprintf(stderr, " FAIL: send note 60 failed\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
/* wait long enough for the looper's main loop to process the add command
|
/* Poll until the port appears (up to 3 seconds) */
|
||||||
(it sleeps for 1 second between checks, so 1.5 s is safe) */
|
|
||||||
safe_usleep(1500000);
|
|
||||||
|
|
||||||
int found = 0;
|
int found = 0;
|
||||||
const char **ports = jack_get_ports(client, NULL, JACK_DEFAULT_AUDIO_TYPE, 0);
|
for (int retries = 0; retries < 30; retries++) {
|
||||||
if (ports) {
|
safe_usleep(100000);
|
||||||
for (int i = 0; ports[i]; i++) {
|
const char **ports = jack_get_ports(client, NULL, JACK_DEFAULT_AUDIO_TYPE, 0);
|
||||||
if (strstr(ports[i], "looper:channel1_input")) {
|
if (ports) {
|
||||||
found = 1;
|
for (int i = 0; ports[i]; i++) {
|
||||||
break;
|
if (strstr(ports[i], "looper:channel1_input")) {
|
||||||
|
found = 1;
|
||||||
|
jack_free(ports);
|
||||||
|
goto port_found;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
jack_free(ports);
|
||||||
}
|
}
|
||||||
jack_free(ports);
|
|
||||||
}
|
}
|
||||||
|
port_found:
|
||||||
|
;
|
||||||
jack_client_close(client);
|
jack_client_close(client);
|
||||||
kill(pid, SIGTERM);
|
kill(pid, SIGTERM);
|
||||||
waitpid(pid, NULL, 0);
|
waitpid(pid, NULL, 0);
|
||||||
@@ -811,18 +814,22 @@ static int test_remove_channel(void) {
|
|||||||
fprintf(stderr, " FAIL: send note 61 failed\n");
|
fprintf(stderr, " FAIL: send note 61 failed\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
safe_usleep(1500000);
|
/* Poll until the port disappears (up to 3 seconds) */
|
||||||
/* verify channel1_input has disappeared */
|
int still_found = 1;
|
||||||
ports = jack_get_ports(client, NULL, JACK_DEFAULT_AUDIO_TYPE, 0);
|
for (int retries = 0; retries < 30; retries++) {
|
||||||
int still_found = 0;
|
safe_usleep(100000);
|
||||||
if (ports) {
|
ports = jack_get_ports(client, NULL, JACK_DEFAULT_AUDIO_TYPE, 0);
|
||||||
for (int i = 0; ports[i]; i++) {
|
still_found = 0;
|
||||||
if (strstr(ports[i], "looper:channel1_input")) {
|
if (ports) {
|
||||||
still_found = 1;
|
for (int i = 0; ports[i]; i++) {
|
||||||
break;
|
if (strstr(ports[i], "looper:channel1_input")) {
|
||||||
|
still_found = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
jack_free(ports);
|
||||||
}
|
}
|
||||||
jack_free(ports);
|
if (!still_found) break;
|
||||||
}
|
}
|
||||||
jack_client_close(client);
|
jack_client_close(client);
|
||||||
kill(pid, SIGTERM);
|
kill(pid, SIGTERM);
|
||||||
|
|||||||
Reference in New Issue
Block a user