Skip to content

Commit 5392031

Browse files
committed
Updates for test suite
1 parent 026ffbc commit 5392031

2 files changed

Lines changed: 38 additions & 20 deletions

File tree

test/test_map_timed.c

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,28 @@ double expected = 0;
3737
"y = a++;" \
3838
"next = now + period;"
3939

40-
/* schedule next periodic event (explicit start time) */
41-
#define NOW_W_START \
42-
"period = %g;" \
43-
"start = 10;" \
44-
"y = 1;" \
45-
"next = (floor((now - start) / period) + 1) * period + start;"
40+
/* schedule next periodic event from current time (explicit phase)
41+
* we "round up" when calculating num periods since start if closer than 0.999 */
42+
#define NOW_W_START \
43+
"period = %g;" \
44+
"start = 10;" \
45+
"y = 1;" \
46+
"next = (floor((now - start + 0.001) / period) + 1) * period + start;"
4647

47-
/* schedule next periodic event (implicit start time) */
48+
/* better to schedule by incrementing the `next` timestamp for drift-free timing */
49+
/* schedule next periodic event (implicit phase) */
4850
#define NEXT \
4951
"period = %g;" \
5052
"y = 1;" \
5153
"next += period;"
5254

53-
/* better to schedule by incrementing the `next` timestamp for drift-free timing */
55+
/* schedule next periodic event (explicit phase)
56+
* we "round up" when calculating num periods since start if closer than 0.999 */
5457
#define NEXT_W_START \
5558
"period = %g;" \
5659
"start = 10;" \
5760
"y = _x;" \
58-
"next = (floor((next - start) / period) + 1) * period + start;"
61+
"next = (floor((next - start + 0.001) / period) + 1) * period + start;"
5962

6063
/* if we track num_periods it is much cheaper to calculate `(n++)*period+start`
6164
* also have access to beat number which could be useful
@@ -112,6 +115,9 @@ double expected = 0;
112115
"y = period;" \
113116
"next += period;"
114117

118+
#define RANDOM \
119+
"p = %g; r = uniform(p) + p * 0.5; y = r; next += r;"
120+
115121
//"new{-1}=0; period = ema(new?0.1:(t_x')
116122

117123
/* TODO: need unmodified t_x to estimate timebase offset
@@ -167,10 +173,12 @@ test_config test_configs[] = {
167173
{ 24, DOWNSAMPLE, MPR_LOC_DST, 1.95, 2.05 },
168174
{ 25, QUANTIZE, MPR_LOC_SRC, 1.65, 1.90 },
169175
{ 26, QUANTIZE, MPR_LOC_DST, 1.65, 1.90 },
170-
// { 21, SYNC_LOCAL, MPR_LOC_SRC, 2.0, 2.0 },
171-
// { 22, SYNC_LOCAL, MPR_LOC_DST, 2.0, 2.0 },
172-
// { 23, SYNC_REMOTE, MPR_LOC_SRC, 2.0, 2.0 },
173-
// { 24, SYNC_REMOTE, MPR_LOC_DST, 2.0, 2.0 },
176+
{ 27, RANDOM, MPR_LOC_SRC, 0.75, 1.25 },
177+
{ 28, RANDOM, MPR_LOC_DST, 0.75, 1.25 },
178+
// { 29, SYNC_LOCAL, MPR_LOC_SRC, 2.0, 2.0 },
179+
// { 30, SYNC_LOCAL, MPR_LOC_DST, 2.0, 2.0 },
180+
// { 31, SYNC_REMOTE, MPR_LOC_SRC, 2.0, 2.0 },
181+
// { 32, SYNC_REMOTE, MPR_LOC_DST, 2.0, 2.0 },
174182

175183
};
176184
const int NUM_TESTS = sizeof(test_configs)/sizeof(test_configs[0]);

test/testmaplocation.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ int set_map_location(mpr_loc loc)
129129
{
130130
int len;
131131
mpr_type type;
132-
const void *val;
132+
mpr_map *map_src;
133+
const void *proc_loc_src, *proc_loc_dst;
133134

134135
if (shared_graph) {
135136
eprintf("skipping location switch since map endpoints share a graph.\n");
@@ -147,13 +148,22 @@ int set_map_location(mpr_loc loc)
147148
}
148149
mpr_obj_push((mpr_obj)map);
149150

150-
/* wait until change has taken effect */
151-
do {
151+
map_src = mpr_dev_get_maps(src, MPR_DIR_ANY);
152+
if (!map_src)
153+
return 1;
154+
155+
/* wait until change has taken effect – check both endpoints before proceeding */
156+
while (!done) {
152157
mpr_dev_poll(src, 10);
153158
mpr_dev_poll(dst, 10);
154-
mpr_obj_get_prop_by_idx(map, MPR_PROP_PROCESS_LOC, NULL, &len, &type, &val, 0);
159+
mpr_obj_get_prop_by_idx(map, MPR_PROP_PROCESS_LOC, NULL, &len, &type, &proc_loc_dst, 0);
160+
if (1 != len || MPR_INT32 != type || *(int*)proc_loc_dst != loc)
161+
continue;
162+
mpr_obj_get_prop_by_idx(*map_src, MPR_PROP_PROCESS_LOC, NULL, &len, &type, &proc_loc_src, 0);
163+
if (1 != len || MPR_INT32 != type || *(int*)proc_loc_src != loc)
164+
continue;
165+
break;
155166
}
156-
while (!done && (1 != len || MPR_INT32 != type || *(int*)val != loc));
157167

158168
return done;
159169
}
@@ -290,15 +300,15 @@ int main(int argc, char **argv)
290300
result = 1;
291301
goto done;
292302
}
293-
eprintf("PROCESS_LOC: DST\n");
303+
eprintf("PROCESS_LOC: SRC\n");
294304
loop();
295305

296306
if (set_map_location(MPR_LOC_DST)) {
297307
eprintf("Error setting map process location. (2)\n");
298308
result = 1;
299309
goto done;
300310
}
301-
eprintf("PROCESS_LOC: SRC\n");
311+
eprintf("PROCESS_LOC: DST\n");
302312
loop();
303313
} while (!terminate && !done);
304314

0 commit comments

Comments
 (0)