refactor: rewrite stress_test.c to use dispatcher API with Action structs
Co-authored-by: aider (deepseek/deepseek-coder) <aider@aider.chat>
This commit is contained in:
113
stress_test.c
113
stress_test.c
@@ -46,6 +46,58 @@ static void teardown_dispatcher(DispatchFn dispatch) {
|
|||||||
dispatcher_stop();
|
dispatcher_stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helper to build an Action
|
||||||
|
static Action make_action(ActionType type, int int_arg, jack_nframes_t nframes_arg) {
|
||||||
|
Action action;
|
||||||
|
memset(&action, 0, sizeof(action));
|
||||||
|
action.type = type;
|
||||||
|
// Set the appropriate union member based on type
|
||||||
|
switch (type) {
|
||||||
|
case ACTION_TRIGGER_CLIP:
|
||||||
|
action.data.trigger_clip.clip_index = int_arg;
|
||||||
|
break;
|
||||||
|
case ACTION_TRIGGER_SCENE:
|
||||||
|
action.data.trigger_scene.scene_index = int_arg;
|
||||||
|
break;
|
||||||
|
case ACTION_RESET_CLIP:
|
||||||
|
action.data.reset_clip.clip_index = int_arg;
|
||||||
|
break;
|
||||||
|
case ACTION_SET_QUANTIZE_MODE:
|
||||||
|
action.data.set_quantize_mode.mode = (QuantizeMode)int_arg;
|
||||||
|
break;
|
||||||
|
case ACTION_SET_QUANTIZE_THRESHOLD:
|
||||||
|
action.data.set_quantize_threshold.threshold = nframes_arg;
|
||||||
|
break;
|
||||||
|
case ACTION_SET_CLOCK_SOURCE:
|
||||||
|
action.data.set_clock_source.source = (ClockSource)int_arg;
|
||||||
|
break;
|
||||||
|
case ACTION_SET_BPM:
|
||||||
|
action.data.set_bpm.bpm = (double)int_arg;
|
||||||
|
break;
|
||||||
|
case ACTION_SAVE_CLIP:
|
||||||
|
action.data.save_clip.clip_index = int_arg;
|
||||||
|
break;
|
||||||
|
case ACTION_LOAD_CLIP:
|
||||||
|
action.data.load_clip.clip_index = int_arg;
|
||||||
|
break;
|
||||||
|
case ACTION_MIDI_NOTE_ON:
|
||||||
|
action.data.midi_note_on.note = int_arg;
|
||||||
|
action.data.midi_note_on.time = nframes_arg;
|
||||||
|
break;
|
||||||
|
case ACTION_MIDI_SCENE_LAUNCH:
|
||||||
|
action.data.midi_scene_launch.scene_index = int_arg;
|
||||||
|
action.data.midi_scene_launch.time = nframes_arg;
|
||||||
|
break;
|
||||||
|
case ACTION_PROCESS_AUDIO:
|
||||||
|
action.data.process_audio.nframes = nframes_arg;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// For actions with no data (TRANSPORT_PLAY, etc.), nothing to set
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
|
||||||
// Stress test 1: Rapid clip triggers via dispatch
|
// Stress test 1: Rapid clip triggers via dispatch
|
||||||
static void stress_rapid_triggers(void) {
|
static void stress_rapid_triggers(void) {
|
||||||
printf("Stress test 1: Rapid clip triggers...\n");
|
printf("Stress test 1: Rapid clip triggers...\n");
|
||||||
@@ -55,7 +107,8 @@ static void stress_rapid_triggers(void) {
|
|||||||
int num_ops = 10000;
|
int num_ops = 10000;
|
||||||
for (int i = 0; i < num_ops; i++) {
|
for (int i = 0; i < num_ops; i++) {
|
||||||
int clip_idx = i % MAX_CLIPS;
|
int clip_idx = i % MAX_CLIPS;
|
||||||
dispatch(ACTION_TRIGGER_CLIP, clip_idx, 0);
|
Action action = make_action(ACTION_TRIGGER_CLIP, clip_idx, 0);
|
||||||
|
dispatch(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Give dispatcher time to process
|
// Give dispatcher time to process
|
||||||
@@ -83,10 +136,12 @@ static void stress_mixed_triggers(void) {
|
|||||||
for (int i = 0; i < num_ops; i++) {
|
for (int i = 0; i < num_ops; i++) {
|
||||||
if (i % 3 == 0) {
|
if (i % 3 == 0) {
|
||||||
int scene_idx = (i / 3) % MAX_SCENES;
|
int scene_idx = (i / 3) % MAX_SCENES;
|
||||||
dispatch(ACTION_TRIGGER_SCENE, scene_idx, 0);
|
Action action = make_action(ACTION_TRIGGER_SCENE, scene_idx, 0);
|
||||||
|
dispatch(action);
|
||||||
} else {
|
} else {
|
||||||
int clip_idx = i % MAX_CLIPS;
|
int clip_idx = i % MAX_CLIPS;
|
||||||
dispatch(ACTION_TRIGGER_CLIP, clip_idx, 0);
|
Action action = make_action(ACTION_TRIGGER_CLIP, clip_idx, 0);
|
||||||
|
dispatch(action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,7 +160,8 @@ static void stress_queue_overflow(void) {
|
|||||||
// Submit more than queue capacity (256)
|
// Submit more than queue capacity (256)
|
||||||
int num_ops = 500;
|
int num_ops = 500;
|
||||||
for (int i = 0; i < num_ops; i++) {
|
for (int i = 0; i < num_ops; i++) {
|
||||||
dispatch(ACTION_TRIGGER_CLIP, i % MAX_CLIPS, 0);
|
Action action = make_action(ACTION_TRIGGER_CLIP, i % MAX_CLIPS, 0);
|
||||||
|
dispatch(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
usleep(100000);
|
usleep(100000);
|
||||||
@@ -123,19 +179,22 @@ static void stress_undo_redo(void) {
|
|||||||
int num_ops = 1000;
|
int num_ops = 1000;
|
||||||
for (int i = 0; i < num_ops; i++) {
|
for (int i = 0; i < num_ops; i++) {
|
||||||
int clip_idx = i % MAX_CLIPS;
|
int clip_idx = i % MAX_CLIPS;
|
||||||
dispatch(ACTION_TRIGGER_CLIP, clip_idx, 0);
|
Action action = make_action(ACTION_TRIGGER_CLIP, clip_idx, 0);
|
||||||
|
dispatch(action);
|
||||||
usleep(1000);
|
usleep(1000);
|
||||||
|
|
||||||
// Undo every other operation
|
// Undo every other operation
|
||||||
if (i % 2 == 0) {
|
if (i % 2 == 0) {
|
||||||
dispatch(ACTION_UNDO, 0, 0);
|
Action undo_action = make_action(ACTION_UNDO, 0, 0);
|
||||||
|
dispatch(undo_action);
|
||||||
usleep(1000);
|
usleep(1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Redo some
|
// Redo some
|
||||||
for (int i = 0; i < 100; i++) {
|
for (int i = 0; i < 100; i++) {
|
||||||
dispatch(ACTION_REDO, 0, 0);
|
Action redo_action = make_action(ACTION_REDO, 0, 0);
|
||||||
|
dispatch(redo_action);
|
||||||
usleep(1000);
|
usleep(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,23 +212,27 @@ static void stress_transport(void) {
|
|||||||
|
|
||||||
int num_ops = 5000;
|
int num_ops = 5000;
|
||||||
for (int i = 0; i < num_ops; i++) {
|
for (int i = 0; i < num_ops; i++) {
|
||||||
|
Action action;
|
||||||
|
memset(&action, 0, sizeof(action));
|
||||||
switch (i % 5) {
|
switch (i % 5) {
|
||||||
case 0:
|
case 0:
|
||||||
dispatch(ACTION_TRANSPORT_PLAY, 0, 0);
|
action.type = ACTION_TRANSPORT_PLAY;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
dispatch(ACTION_TRANSPORT_PAUSE, 0, 0);
|
action.type = ACTION_TRANSPORT_PAUSE;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
dispatch(ACTION_TRANSPORT_STOP, 0, 0);
|
action.type = ACTION_TRANSPORT_STOP;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
dispatch(ACTION_TRANSPORT_TOGGLE_PLAY, 0, 0);
|
action.type = ACTION_TRANSPORT_TOGGLE_PLAY;
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
dispatch(ACTION_SET_CLOCK_SOURCE, (int)CLOCK_SOURCE_MIDI, 0);
|
action.type = ACTION_SET_CLOCK_SOURCE;
|
||||||
|
action.data.set_clock_source.source = CLOCK_SOURCE_MIDI;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
dispatch(action);
|
||||||
usleep(100);
|
usleep(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,8 +251,10 @@ static void stress_quantize(void) {
|
|||||||
int num_ops = 5000;
|
int num_ops = 5000;
|
||||||
for (int i = 0; i < num_ops; i++) {
|
for (int i = 0; i < num_ops; i++) {
|
||||||
QuantizeMode mode = (QuantizeMode)(i % 3);
|
QuantizeMode mode = (QuantizeMode)(i % 3);
|
||||||
dispatch(ACTION_SET_QUANTIZE_MODE, (int)mode, 0);
|
Action mode_action = make_action(ACTION_SET_QUANTIZE_MODE, (int)mode, 0);
|
||||||
dispatch(ACTION_SET_QUANTIZE_THRESHOLD, 0, (jack_nframes_t)(i * 100));
|
dispatch(mode_action);
|
||||||
|
Action thresh_action = make_action(ACTION_SET_QUANTIZE_THRESHOLD, 0, (jack_nframes_t)(i * 100));
|
||||||
|
dispatch(thresh_action);
|
||||||
usleep(100);
|
usleep(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,11 +273,13 @@ static void stress_reset_while_triggering(void) {
|
|||||||
int num_ops = 2000;
|
int num_ops = 2000;
|
||||||
for (int i = 0; i < num_ops; i++) {
|
for (int i = 0; i < num_ops; i++) {
|
||||||
int clip_idx = i % MAX_CLIPS;
|
int clip_idx = i % MAX_CLIPS;
|
||||||
dispatch(ACTION_TRIGGER_CLIP, clip_idx, 0);
|
Action trigger_action = make_action(ACTION_TRIGGER_CLIP, clip_idx, 0);
|
||||||
|
dispatch(trigger_action);
|
||||||
usleep(500);
|
usleep(500);
|
||||||
|
|
||||||
if (i % 10 == 0) {
|
if (i % 10 == 0) {
|
||||||
dispatch(ACTION_RESET_CLIP, clip_idx, 0);
|
Action reset_action = make_action(ACTION_RESET_CLIP, clip_idx, 0);
|
||||||
|
dispatch(reset_action);
|
||||||
usleep(500);
|
usleep(500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -234,7 +301,8 @@ static void* thread_worker(void *arg) {
|
|||||||
ThreadArg *targ = (ThreadArg *)arg;
|
ThreadArg *targ = (ThreadArg *)arg;
|
||||||
for (int i = 0; i < targ->num_ops; i++) {
|
for (int i = 0; i < targ->num_ops; i++) {
|
||||||
int clip_idx = (targ->thread_id * 1000 + i) % MAX_CLIPS;
|
int clip_idx = (targ->thread_id * 1000 + i) % MAX_CLIPS;
|
||||||
targ->dispatch(ACTION_TRIGGER_CLIP, clip_idx, 0);
|
Action action = make_action(ACTION_TRIGGER_CLIP, clip_idx, 0);
|
||||||
|
targ->dispatch(action);
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -276,9 +344,14 @@ static void stress_create_destroy(void) {
|
|||||||
|
|
||||||
// Do some operations
|
// Do some operations
|
||||||
for (int j = 0; j < 10; j++) {
|
for (int j = 0; j < 10; j++) {
|
||||||
dispatch(ACTION_TRIGGER_CLIP, j % MAX_CLIPS, 0);
|
Action trigger_action = make_action(ACTION_TRIGGER_CLIP, j % MAX_CLIPS, 0);
|
||||||
dispatch(ACTION_TRANSPORT_TOGGLE_PLAY, 0, 0);
|
dispatch(trigger_action);
|
||||||
dispatch(ACTION_SET_QUANTIZE_MODE, j % 3, 0);
|
Action toggle_action;
|
||||||
|
memset(&toggle_action, 0, sizeof(toggle_action));
|
||||||
|
toggle_action.type = ACTION_TRANSPORT_TOGGLE_PLAY;
|
||||||
|
dispatch(toggle_action);
|
||||||
|
Action mode_action = make_action(ACTION_SET_QUANTIZE_MODE, j % 3, 0);
|
||||||
|
dispatch(mode_action);
|
||||||
}
|
}
|
||||||
|
|
||||||
usleep(1000);
|
usleep(1000);
|
||||||
|
|||||||
Reference in New Issue
Block a user