Files
fmini-1/tests/union_test.c
T
Claude 0006fd81ce FMini-1 v1.13.0: retire the SAMPLE, GRAIN and SLICE engines
The three engines and their 126 KB of factory IMA samples are gone, with the
sample slots (80 KiB x 3 in flash), the SLICES page, the sample waveform, the
web editor's sample protocol and the slice store. Their engine numbers stay
(4, 8, 13): a track, a project or a user preset that names one is silent and
is never offered, through a stub like DIGITAL's (ENG_RETIRED, engines.c).

Image 536.6 KB -> 394.9 KB; RAM .data+.bss 65.9 KB -> 60.1 KB. The sample
flash region 0xA0000..0xDBFFF is free for user presets.

Protocol: SMP_BEGIN/WRITE/END/ERASE (11..14) get no reply; SMP_INFO answers 0
slots so the editor hides its Samples tab; backup ids 32..34 are gone. The
PERC conversion (SAMPLE PERC -> DRUM) stays. See web/EDITOR_PROTOCOL.md.

Tests: sample_test, slice_test, fuzz_smp removed; the others follow. Golden
renders of the retired engines removed; target budgets for their functions
removed and the ISR / mix_part costs updated on purpose.

Known, unchanged failures: fm4, union_test, the regress hashes of Felucca's
engines (66 changed at 1.12 too), web mock tables.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QUF6pQ1NkTwmBC8SR8AK94
2026-10-28 14:03:21 -03:00

140 lines
5.2 KiB
C

/* SPDX-License-Identifier: GPL-3.0-only
* Copyright (C) 2026 Leo Kuroshita (@kurogedelic), Hügelton Instruments */
/* Engine switches on a part, hashed (1.5: the engines' per-part state shares one region, engines.c eng_mem).
* build/host/union_test [GOLDEN_FILE] (run_tests.sh builds and runs it against tests/union_golden.txt)
*
* Every pair (and A -> B -> A) of the engines that keep state per part (GRAIN, PHYS, DRUM, FM6, SLICE), with
* ANALOG, SAMPLE and WHEEL (state outside the region) among them, on part 1 while part 3 plays other engines
* alongside, at three presets: a chord and a low note held, released, still ringing at the next switch (the
* fade on the old engine), and once more with the next notes inside the fade (they wait for the switch).
* Each sequence runs in its own fork()ed child from boot state; its mix is one 64-bit FNV-1a hash. The file
* holds the hashes of 1.4 (the engines' own arrays, before the shared region): any difference fails. The 380
* sequences that play SAMPLE's PIANO (SAMPLE presets 0 / 1, GRAIN's FROZEN / SHIMMER) were rewritten in 1.5, when
* PIANO went back to the full piano of 1.1.5; the other 340 are 1.4's.
* env: GOLDEN_UPDATE=1 rewrites GOLDEN_FILE (only with a reason: a switch is to sound as it did). */
#define main hostsim_main
#include "hostsim.c"
#undef main
#include <sys/wait.h>
static uint64_t uh;
static void ublock(void)
{
int32_t o[2 * CTL];
uint32_t i;
mix_block(o, CTL);
for (i = 0; i < 2u * CTL; i++) {
uh ^= (uint32_t)o[i];
uh *= 0x100000001B3ull;
}
}
static void urun(uint32_t ms)
{
uint32_t n = ms * (FS / 1000u) / CTL;
while (n--)
ublock();
}
/* engine e (preset pi) on t: notes base + a chord and base - 24; wait_ms before them (0: inside the fade) */
static void uplay(track_t *t, uint32_t e, uint32_t pi, uint32_t base, uint32_t wait_ms)
{
static const uint8_t CH[4] = {0, 4, 7, 12};
uint32_t i;
if (e == ENGI_DRUM) /* (DRUM had one preset until 1.5.6 (#216): the 1.4 hashes play DRUM KIT */
pi = 0; /* at every pi; the new kits' presets are not engine-memory cases) */
host_preset_req(t, e, pi); /* eng_req: the audio side switches (voice.c engine_block) */
urun(wait_ms);
for (i = 0; i < 4u; i++)
input_on(t, base + CH[i], 100);
urun(400);
input_on(t, base - 24u, 110);
urun(300);
for (i = 0; i < 4u; i++)
input_off(t, base + CH[i]);
input_off(t, base - 24u);
urun(250); /* still ringing at the next switch */
}
static const uint32_t UE[] = {0 /* ANALOG */, 3u /* LOFI */, 7 /* WHEEL */, ENGI_PHYS, ENGI_DRUM, ENGI_FM6, ENGI_FMINI};
#define UNE (sizeof UE / sizeof UE[0])
static uint64_t useq(const uint32_t *e, uint32_t n, uint32_t pi, uint32_t wait_ms)
{
pid_t pid;
int fd[2];
uint64_t h = 0;
if (pipe(fd))
return 0;
if (!(pid = fork())) {
uint32_t k;
host_tracks_init();
uh = 0xcbf29ce484222325ull;
for (k = 0; k < n; k++) {
uplay(&trk[0], e[k], pi + k, 60, wait_ms);
uplay(&trk[2], UE[(k + 3u) % UNE], pi, 55, 10); /* another part busy alongside */
}
urun(1000);
if (write(fd[1], &uh, 8) != 8)
_exit(1);
_exit(0);
}
close(fd[1]);
if (read(fd[0], &h, 8) != 8)
h = 0;
close(fd[0]);
waitpid(pid, 0, 0);
return h;
}
int main(int argc, char **argv)
{
static char got[4096][64];
uint32_t a, b, pi, w, n = 0, bad = 0, i;
const char *gf = argc > 1 ? argv[1] : 0;
FILE *f;
for (w = 0; w < 2u; w++)
for (pi = 0; pi < 3u; pi++)
for (a = 0; a < UNE; a++)
for (b = 0; b < UNE; b++) {
uint32_t s2[2] = {UE[a], UE[b]}, s3[3] = {UE[b], UE[a], UE[b]};
uint32_t wait = w ? 0u : 10u;
snprintf(got[n++], 64, "%u-%u p%u w%u %016llx", UE[a], UE[b], pi, wait,
(unsigned long long)useq(s2, 2, pi, wait));
if (a != b)
snprintf(got[n++], 64, "%u-%u-%u p%u w%u %016llx", UE[b], UE[a], UE[b], pi, wait,
(unsigned long long)useq(s3, 3, pi, wait));
}
if (!gf) {
for (i = 0; i < n; i++)
printf("%s\n", got[i]);
return 0;
}
if (getenv("GOLDEN_UPDATE")) {
if (!(f = fopen(gf, "w")))
return 1;
for (i = 0; i < n; i++)
fprintf(f, "%s\n", got[i]);
fclose(f);
printf("union_test: %u hashes written to %s\n", n, gf);
return 0;
}
if (!(f = fopen(gf, "r"))) {
printf("union_test: no %s\n", gf);
return 1;
}
for (i = 0; i < n; i++) {
char ln[96];
if (!fgets(ln, sizeof ln, f))
ln[0] = 0;
ln[strcspn(ln, "\n")] = 0;
if (strcmp(ln, got[i])) {
if (bad < 20u)
printf("union_test: FAIL %s (expected %s)\n", got[i], ln);
bad++;
}
}
fclose(f);
printf("union_test: %u engine switch sequences, %u differ from 1.4: %s\n", n, bad, bad ? "FAIL" : "ok");
return bad != 0;
}