Skip to content

Commit 5668e6a

Browse files
committed
tests(runtime,engine,io,core): move large test fixtures off stack
1 parent 130d9f9 commit 5668e6a

4 files changed

Lines changed: 223 additions & 133 deletions

File tree

tests/core/test_core_audio_group_gate.c

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,17 @@ int
4141
main(void) {
4242
int rc = 0;
4343

44-
dsd_opts opts;
45-
memset(&opts, 0, sizeof(opts));
44+
// dsd_opts is sizeable enough to keep off the function stack in tests.
45+
dsd_opts* opts = (dsd_opts*)calloc(1, sizeof(*opts));
46+
if (!opts) {
47+
fprintf(stderr, "alloc-failed: dsd_opts\n");
48+
return 1;
49+
}
4650

4751
dsd_state* st = (dsd_state*)calloc(1, sizeof(*st));
4852
if (!st) {
4953
fprintf(stderr, "alloc-failed: dsd_state\n");
54+
free(opts);
5055
return 1;
5156
}
5257

@@ -56,45 +61,45 @@ main(void) {
5661
set_group(st, 1, 200UL, "B", "BLOCK");
5762
{
5863
int outL = -1, outR = -1;
59-
rc |= expect_eq("case1-ret", dsd_audio_group_gate_dual(&opts, st, 100UL, 200UL, 0, 0, &outL, &outR), 0);
64+
rc |= expect_eq("case1-ret", dsd_audio_group_gate_dual(opts, st, 100UL, 200UL, 0, 0, &outL, &outR), 0);
6065
rc |= expect_eq("case1-outL", outL, 0);
6166
rc |= expect_eq("case1-outR", outR, 1);
6267
}
6368

6469
// Case 2: Allow-list mode defaults unknown TGs to blocked.
65-
memset(&opts, 0, sizeof(opts));
70+
memset(opts, 0, sizeof(*opts));
6671
memset(st, 0, sizeof(*st));
67-
opts.trunk_use_allow_list = 1;
72+
opts->trunk_use_allow_list = 1;
6873
st->group_tally = 1;
6974
set_group(st, 0, 300UL, "A", "ONLY");
7075
{
7176
int outL = -1, outR = -1;
72-
rc |= expect_eq("case2-ret", dsd_audio_group_gate_dual(&opts, st, 300UL, 301UL, 0, 0, &outL, &outR), 0);
77+
rc |= expect_eq("case2-ret", dsd_audio_group_gate_dual(opts, st, 300UL, 301UL, 0, 0, &outL, &outR), 0);
7378
rc |= expect_eq("case2-outL", outL, 0);
7479
rc |= expect_eq("case2-outR", outR, 1);
7580
}
7681

7782
// Case 2b: "DE" lockout mode should be treated as blocked by audio gate.
78-
memset(&opts, 0, sizeof(opts));
83+
memset(opts, 0, sizeof(*opts));
7984
memset(st, 0, sizeof(*st));
8085
st->group_tally = 1;
8186
set_group(st, 0, 310UL, "DE", "ENC-LOCKOUT");
8287
{
8388
int outL = -1;
84-
rc |= expect_eq("case2b-ret", dsd_audio_group_gate_mono(&opts, st, 310UL, 0, &outL), 0);
89+
rc |= expect_eq("case2b-ret", dsd_audio_group_gate_mono(opts, st, 310UL, 0, &outL), 0);
8590
rc |= expect_eq("case2b-outL", outL, 1);
8691
}
8792

8893
// Case 3: TG hold mutes non-matching slot and force-unmutes matching slot.
89-
memset(&opts, 0, sizeof(opts));
94+
memset(opts, 0, sizeof(*opts));
9095
memset(st, 0, sizeof(*st));
9196
st->group_tally = 2;
9297
set_group(st, 0, 400UL, "A", "LEFT");
9398
set_group(st, 1, 401UL, "B", "RIGHT-BLOCKED");
9499
st->tg_hold = 401U;
95100
{
96101
int outL = -1, outR = -1;
97-
rc |= expect_eq("case3-ret", dsd_audio_group_gate_dual(&opts, st, 400UL, 401UL, 0, 0, &outL, &outR), 0);
102+
rc |= expect_eq("case3-ret", dsd_audio_group_gate_dual(opts, st, 400UL, 401UL, 0, 0, &outL, &outR), 0);
98103
rc |= expect_eq("case3-outL", outL, 1);
99104
rc |= expect_eq("case3-outR", outR, 0);
100105
}
@@ -103,27 +108,27 @@ main(void) {
103108
{
104109
int out = 0;
105110
rc |= expect_eq("null-mono", dsd_audio_group_gate_mono(NULL, st, 0UL, 0, &out), -1);
106-
rc |= expect_eq("null-dual", dsd_audio_group_gate_dual(&opts, st, 0UL, 0UL, 0, 0, NULL, &out), -1);
107-
rc |= expect_eq("null-record-mono", dsd_audio_record_gate_mono(&opts, NULL, &out), -1);
111+
rc |= expect_eq("null-dual", dsd_audio_group_gate_dual(opts, st, 0UL, 0UL, 0, 0, NULL, &out), -1);
112+
rc |= expect_eq("null-record-mono", dsd_audio_record_gate_mono(opts, NULL, &out), -1);
108113
}
109114

110115
// Case 4: Mono per-call recording gate respects block mode.
111-
memset(&opts, 0, sizeof(opts));
116+
memset(opts, 0, sizeof(*opts));
112117
memset(st, 0, sizeof(*st));
113118
st->group_tally = 1;
114119
st->lasttg = 500UL;
115120
st->dmr_encL = 0;
116121
set_group(st, 0, 500UL, "B", "REC-BLOCK");
117122
{
118123
int allow = -1;
119-
rc |= expect_eq("case4-rec-ret", dsd_audio_record_gate_mono(&opts, st, &allow), 0);
124+
rc |= expect_eq("case4-rec-ret", dsd_audio_record_gate_mono(opts, st, &allow), 0);
120125
rc |= expect_eq("case4-rec-allow", allow, 0);
121126
}
122127

123128
// Case 5: Mono per-call recording gate uses slot-specific TG/encryption state.
124-
memset(&opts, 0, sizeof(opts));
129+
memset(opts, 0, sizeof(*opts));
125130
memset(st, 0, sizeof(*st));
126-
opts.trunk_use_allow_list = 1;
131+
opts->trunk_use_allow_list = 1;
127132
st->currentslot = 1;
128133
st->group_tally = 1;
129134
st->lasttg = 600UL;
@@ -133,26 +138,27 @@ main(void) {
133138
set_group(st, 0, 601UL, "A", "RIGHT-ONLY");
134139
{
135140
int allow = -1;
136-
rc |= expect_eq("case5-rec-ret", dsd_audio_record_gate_mono(&opts, st, &allow), 0);
141+
rc |= expect_eq("case5-rec-ret", dsd_audio_record_gate_mono(opts, st, &allow), 0);
137142
rc |= expect_eq("case5-rec-allow", allow, 1);
138143
}
139144

140145
// Case 6: P25 Phase 2 recording gate follows the per-slot audio-allowed flag.
141-
memset(&opts, 0, sizeof(opts));
146+
memset(opts, 0, sizeof(*opts));
142147
memset(st, 0, sizeof(*st));
143148
st->synctype = DSD_SYNC_P25P2_POS;
144149
st->currentslot = 1;
145150
st->p25_p2_audio_allowed[0] = 0;
146151
st->p25_p2_audio_allowed[1] = 1;
147152
{
148153
int allow = -1;
149-
rc |= expect_eq("case6-rec-ret", dsd_audio_record_gate_mono(&opts, st, &allow), 0);
154+
rc |= expect_eq("case6-rec-ret", dsd_audio_record_gate_mono(opts, st, &allow), 0);
150155
rc |= expect_eq("case6-rec-allow", allow, 1);
151156
}
152157

153158
if (rc == 0) {
154159
printf("CORE_AUDIO_GROUP_GATE: OK\n");
155160
}
161+
free(opts);
156162
free(st);
157163
return rc;
158164
}

tests/engine/test_engine_no_carrier_reset.c

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "dsd-neo/core/state_fwd.h"
2020

2121
#include <stdio.h>
22-
#include <string.h>
22+
#include <stdlib.h>
2323

2424
static int
2525
expect_true(const char* tag, int cond) {
@@ -40,56 +40,83 @@ ui_start(dsd_opts* opts, dsd_state* state) {
4040
void
4141
ui_stop(void) {}
4242

43+
static int
44+
init_test_runtime(dsd_opts** opts_out, dsd_state** state_out) {
45+
// dsd_state is multi-megabyte; keep it off the function stack.
46+
dsd_opts* opts = (dsd_opts*)calloc(1, sizeof(*opts));
47+
dsd_state* state = (dsd_state*)calloc(1, sizeof(*state));
48+
if (opts == NULL || state == NULL) {
49+
fprintf(stderr, "alloc-failed: runtime\n");
50+
free(opts);
51+
free(state);
52+
return 1;
53+
}
54+
55+
initOpts(opts);
56+
initState(state);
57+
58+
*opts_out = opts;
59+
*state_out = state;
60+
return 0;
61+
}
62+
63+
static void
64+
free_test_runtime(dsd_opts* opts, dsd_state* state) {
65+
if (state != NULL) {
66+
freeState(state);
67+
}
68+
free(state);
69+
free(opts);
70+
}
71+
4372
int
4473
main(void) {
4574
int rc = 0;
75+
dsd_opts* opts = NULL;
76+
dsd_state* state = NULL;
4677

47-
dsd_opts opts;
48-
dsd_state state;
49-
memset(&opts, 0, sizeof(opts));
50-
memset(&state, 0, sizeof(state));
51-
52-
initOpts(&opts);
53-
initState(&state);
78+
if (init_test_runtime(&opts, &state) != 0) {
79+
return 1;
80+
}
5481

5582
for (int i = 0; i < 200; i++) {
56-
state.dmr_payload_buf[i] = 0x7F7F7F7F;
57-
if (state.dmr_reliab_buf != NULL) {
58-
state.dmr_reliab_buf[i] = 0xA5U;
83+
state->dmr_payload_buf[i] = 0x7F7F7F7F;
84+
if (state->dmr_reliab_buf != NULL) {
85+
state->dmr_reliab_buf[i] = 0xA5U;
5986
}
6087
}
6188

62-
state.dmr_payload_p = state.dibit_buf + 321;
63-
if (state.dmr_reliab_buf != NULL) {
64-
state.dmr_reliab_p = state.dmr_reliab_buf + 321;
89+
state->dmr_payload_p = state->dibit_buf + 321;
90+
if (state->dmr_reliab_buf != NULL) {
91+
state->dmr_reliab_p = state->dmr_reliab_buf + 321;
6592
}
6693

67-
noCarrier(&opts, &state);
94+
noCarrier(opts, state);
6895

69-
rc |= expect_true("dmr-payload-pointer-buffer", state.dmr_payload_p == state.dmr_payload_buf + 200);
70-
rc |= expect_true("dmr-payload-pointer-not-dibit", state.dmr_payload_p != state.dibit_buf + 200);
71-
rc |= expect_true("dibit-pointer-reset", state.dibit_buf_p == state.dibit_buf + 200);
96+
rc |= expect_true("dmr-payload-pointer-buffer", state->dmr_payload_p == state->dmr_payload_buf + 200);
97+
rc |= expect_true("dmr-payload-pointer-not-dibit", state->dmr_payload_p != state->dibit_buf + 200);
98+
rc |= expect_true("dibit-pointer-reset", state->dibit_buf_p == state->dibit_buf + 200);
7299

73100
for (int i = 0; i < 200; i++) {
74-
if (state.dmr_payload_buf[i] != 0) {
75-
fprintf(stderr, "dmr payload buf[%d] not reset: %d\n", i, state.dmr_payload_buf[i]);
101+
if (state->dmr_payload_buf[i] != 0) {
102+
fprintf(stderr, "dmr payload buf[%d] not reset: %d\n", i, state->dmr_payload_buf[i]);
76103
rc = 1;
77104
break;
78105
}
79106
}
80107

81-
if (state.dmr_reliab_buf != NULL) {
82-
rc |= expect_true("dmr-reliab-pointer-buffer", state.dmr_reliab_p == state.dmr_reliab_buf + 200);
108+
if (state->dmr_reliab_buf != NULL) {
109+
rc |= expect_true("dmr-reliab-pointer-buffer", state->dmr_reliab_p == state->dmr_reliab_buf + 200);
83110
for (int i = 0; i < 200; i++) {
84-
if (state.dmr_reliab_buf[i] != 0U) {
85-
fprintf(stderr, "dmr reliab buf[%d] not reset: %u\n", i, (unsigned)state.dmr_reliab_buf[i]);
111+
if (state->dmr_reliab_buf[i] != 0U) {
112+
fprintf(stderr, "dmr reliab buf[%d] not reset: %u\n", i, (unsigned)state->dmr_reliab_buf[i]);
86113
rc = 1;
87114
break;
88115
}
89116
}
90117
}
91118

92-
freeState(&state);
119+
free_test_runtime(opts, state);
93120

94121
if (rc == 0) {
95122
printf("ENGINE_NO_CARRIER_RESET: OK\n");

0 commit comments

Comments
 (0)