feat: add MIDI stop command and FIFO pipe integration test
Co-authored-by: aider (deepseek/deepseek-reasoner) <aider@aider.chat>
This commit is contained in:
@@ -63,6 +63,11 @@ void midi_handle_events(void *port_buffer, jack_nframes_t nframes) {
|
||||
command_t cmd = { .type = CMD_UNBIND, .channel = -1, .data = 0 };
|
||||
queue_push(&cmd_queue, cmd);
|
||||
} break;
|
||||
case 65:
|
||||
{
|
||||
command_t cmd = { .type = CMD_STOP, .channel = -1, .data = 0 };
|
||||
queue_push(&cmd_queue, cmd);
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -836,6 +836,87 @@ static int test_remove_channel(void) {
|
||||
}
|
||||
|
||||
|
||||
/* test FIFO pipe */
|
||||
static int test_fifo_pipe(void) {
|
||||
printf("Test: FIFO pipe add/remove\n");
|
||||
pid_t pid = start_looper();
|
||||
if (pid < 0) return 1;
|
||||
|
||||
jack_client_t *client;
|
||||
jack_status_t status;
|
||||
client = jack_client_open("test_fifo", JackNoStartServer, &status);
|
||||
if (!client) {
|
||||
kill(pid, SIGTERM); waitpid(pid, NULL, 0);
|
||||
fprintf(stderr, " SKIP: no JACK\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* write "add\n" to the FIFO */
|
||||
int fd = open("/tmp/looper_cmd", O_WRONLY);
|
||||
if (fd < 0) {
|
||||
perror("open fifo");
|
||||
jack_client_close(client);
|
||||
kill(pid, SIGTERM); waitpid(pid, NULL, 0);
|
||||
return 1;
|
||||
}
|
||||
write(fd, "add\n", 4);
|
||||
close(fd);
|
||||
|
||||
safe_usleep(1500000); /* give main loop time to process */
|
||||
|
||||
const char **ports = jack_get_ports(client, NULL, JACK_DEFAULT_AUDIO_TYPE, 0);
|
||||
int found = 0;
|
||||
if (ports) {
|
||||
for (int i = 0; ports[i]; i++) {
|
||||
if (strstr(ports[i], "looper:channel1_input")) {
|
||||
found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
jack_free(ports);
|
||||
}
|
||||
|
||||
/* Write "remove\n" to the FIFO */
|
||||
fd = open("/tmp/looper_cmd", O_WRONLY);
|
||||
if (fd < 0) {
|
||||
perror("open fifo");
|
||||
jack_client_close(client);
|
||||
kill(pid, SIGTERM); waitpid(pid, NULL, 0);
|
||||
return 1;
|
||||
}
|
||||
write(fd, "remove\n", 7);
|
||||
close(fd);
|
||||
|
||||
safe_usleep(1500000);
|
||||
|
||||
ports = jack_get_ports(client, NULL, JACK_DEFAULT_AUDIO_TYPE, 0);
|
||||
int still_found = 0;
|
||||
if (ports) {
|
||||
for (int i = 0; ports[i]; i++) {
|
||||
if (strstr(ports[i], "looper:channel1_input")) {
|
||||
still_found = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
jack_free(ports);
|
||||
}
|
||||
|
||||
jack_client_close(client);
|
||||
kill(pid, SIGTERM);
|
||||
waitpid(pid, NULL, 0);
|
||||
|
||||
if (!found) {
|
||||
fprintf(stderr, " FAIL: channel not added via FIFO\n");
|
||||
return 1;
|
||||
}
|
||||
if (still_found) {
|
||||
fprintf(stderr, " FAIL: channel not removed via FIFO\n");
|
||||
return 1;
|
||||
}
|
||||
printf(" PASS (FIFO add/remove works)\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
/* 1. binary must exist */
|
||||
if (system("test -x ./looper") != 0) {
|
||||
@@ -886,6 +967,12 @@ int main(void) {
|
||||
failures++;
|
||||
}
|
||||
|
||||
/* 10. Test FIFO pipe */
|
||||
if (test_fifo_pipe() != 0) {
|
||||
fprintf(stderr, " FAILED\n");
|
||||
failures++;
|
||||
}
|
||||
|
||||
if (failures > 0) {
|
||||
fprintf(stderr, "%d test(s) FAILED\n", failures);
|
||||
return 1;
|
||||
|
||||
Reference in New Issue
Block a user