Files
AutoFilm-ESP32/tests/host/test_process.c

215 lines
8.7 KiB
C

#include "app_process.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
static int g_failures;
static void fail(const char *msg)
{
fprintf(stderr, "FAIL: %s\n", msg);
g_failures++;
}
static void expect_ptr_null(const void *p, const char *msg)
{
if (p != NULL) {
fail(msg);
}
}
static void expect_ptr_nonnull(const void *p, const char *msg)
{
if (p == NULL) {
fail(msg);
}
}
static void expect_str(const char *got, const char *want, const char *msg)
{
if (got == NULL || want == NULL || strcmp(got, want) != 0) {
fprintf(stderr, "FAIL: %s got=\"%s\" want=\"%s\"\n",
msg, got ? got : "(null)", want ? want : "(null)");
g_failures++;
}
}
static void expect_u8(uint8_t got, uint8_t want, const char *msg)
{
if (got != want) {
fprintf(stderr, "FAIL: %s got=%u want=%u\n", msg, got, want);
g_failures++;
}
}
static void expect_u16(uint16_t got, uint16_t want, const char *msg)
{
if (got != want) {
fprintf(stderr, "FAIL: %s got=%u want=%u\n", msg, got, want);
g_failures++;
}
}
static void expect_f(float got, float want, const char *msg)
{
if (fabsf(got - want) >= 1e-4f) {
fprintf(stderr, "FAIL: %s got=%f want=%f\n", msg, (double)got, (double)want);
g_failures++;
}
}
static void expect_err(esp_err_t got, esp_err_t want, const char *msg)
{
if (got != want) {
fprintf(stderr, "FAIL: %s got=%d want=%d\n", msg, got, want);
g_failures++;
}
}
static void check_step(const process_def_t *p, uint8_t i,
const char *name, uint16_t t,
float cw, float ccw,
float tmin, float tpref, float tmax)
{
char buf[96];
snprintf(buf, sizeof(buf), "%s[%u].name", p->name, i);
expect_str(p->steps[i].name, name, buf);
snprintf(buf, sizeof(buf), "%s[%u].time_s", p->name, i);
expect_u16(p->steps[i].time_s, t, buf);
snprintf(buf, sizeof(buf), "%s[%u].cw", p->name, i);
expect_f(p->steps[i].cw_revs, cw, buf);
snprintf(buf, sizeof(buf), "%s[%u].ccw", p->name, i);
expect_f(p->steps[i].ccw_revs, ccw, buf);
snprintf(buf, sizeof(buf), "%s[%u].min", p->name, i);
expect_f(p->steps[i].temp_min_c, tmin, buf);
snprintf(buf, sizeof(buf), "%s[%u].pref", p->name, i);
expect_f(p->steps[i].temp_pref_c, tpref, buf);
snprintf(buf, sizeof(buf), "%s[%u].max", p->name, i);
expect_f(p->steps[i].temp_max_c, tmax, buf);
}
int test_process_run(void)
{
app_process_init();
expect_ptr_null(app_process_get(6), "get(6)");
expect_ptr_null(app_process_find_name("nope"), "find_name nope");
expect_ptr_null(app_process_find_name(NULL), "find_name NULL");
const process_def_t *c41 = app_process_get(PROC_C41);
const process_def_t *e6 = app_process_get(PROC_E6);
const process_def_t *ecn = app_process_get(PROC_ECN2);
const process_def_t *bw = app_process_get(PROC_BW);
const process_def_t *custom = app_process_get(PROC_CUSTOM);
const process_def_t *bwrev = app_process_get(PROC_BWREV);
expect_ptr_nonnull(c41, "C41 get");
expect_ptr_nonnull(e6, "E6 get");
expect_ptr_nonnull(ecn, "ECN-2 get");
expect_ptr_nonnull(bw, "B&W get");
expect_ptr_nonnull(custom, "Custom get");
expect_ptr_nonnull(bwrev, "B&WREV get");
expect_str(c41->name, "C41", "C41 name");
expect_u8(c41->step_count, 7, "C41 count");
check_step(c41, 0, "Prewarm", 180, 1.f, 1.f, 37.8f, 38.f, 38.2f);
check_step(c41, 1, "Developer", 195, 5.5f, 5.f, 37.8f, 38.f, 38.2f);
check_step(c41, 2, "Bleach", 45, 5.5f, 5.f, 32.f, 38.f, 38.2f);
check_step(c41, 3, "Fix", 180, 5.5f, 5.f, 32.f, 38.f, 38.2f);
check_step(c41, 4, "Rinse 1", 60, 3.5f, 3.f, 32.f, 38.f, 38.2f);
check_step(c41, 5, "Rinse 2", 60, 3.5f, 3.f, 32.f, 38.f, 38.2f);
check_step(c41, 6, "Fin Rinse", 30, 1.f, 1.f, 32.f, 38.f, 38.2f);
expect_str(e6->name, "E6", "E6 name");
expect_u8(e6->step_count, 12, "E6 count");
check_step(e6, 0, "Preheat", 180, 1.f, 1.f, 37.5f, 38.f, 38.5f);
check_step(e6, 1, "FirstDev", 360, 5.5f, 5.f, 37.7f, 38.f, 38.3f);
check_step(e6, 2, "Wash 1", 120, 3.5f, 3.f, 33.0f, 38.f, 38.0f);
check_step(e6, 3, "Reversal", 120, 5.f, 5.5f, 37.7f, 38.f, 38.3f);
check_step(e6, 4, "ColorDev", 360, 5.5f, 5.f, 37.0f, 38.f, 39.0f);
check_step(e6, 5, "PreBleach", 120, 5.5f, 5.5f, 37.f, 38.f, 38.f);
check_step(e6, 6, "Bleach", 360, 5.5f, 5.5f, 37.5f, 38.f, 38.5f);
check_step(e6, 7, "Fixer", 240, 5.5f, 5.5f, 37.5f, 38.f, 38.5f);
check_step(e6, 8, "Wash 2", 120, 3.5f, 3.f, 33.0f, 38.f, 38.5f);
check_step(e6, 9, "Wash 3", 120, 3.5f, 3.f, 33.0f, 38.f, 38.5f);
check_step(e6, 10, "Wash 4", 120, 3.5f, 3.f, 33.0f, 38.f, 38.5f);
check_step(e6, 11, "Fin Rinse", 30, 3.5f, 3.f, 19.0f, 20.f, 21.0f);
expect_str(ecn->name, "ECN-2", "ECN-2 name");
expect_u8(ecn->step_count, 9, "ECN-2 count");
check_step(ecn, 0, "Prebath", 180, 1.f, 1.f, 27.f, 38.f, 38.f);
check_step(ecn, 1, "RemJet", 0, 0.f, 0.f, 0.f, 0.f, 0.f);
check_step(ecn, 2, "Developer", 210, 5.5f, 5.f, 40.8f, 41.f, 41.2f);
check_step(ecn, 3, "Stop Bath", 60, 3.5f, 3.f, 27.f, 38.f, 38.f);
check_step(ecn, 4, "Wash", 180, 3.5f, 3.f, 27.f, 38.f, 38.f);
check_step(ecn, 5, "Bleach", 150, 5.5f, 5.f, 27.f, 38.f, 38.f);
check_step(ecn, 6, "Fixer", 120, 5.5f, 5.f, 27.f, 38.f, 38.f);
check_step(ecn, 7, "Wash 2", 300, 3.5f, 3.f, 27.f, 38.f, 38.f);
check_step(ecn, 8, "Fin Rinse", 120, 1.f, 1.f, 27.f, 38.f, 38.f);
expect_str(bw->name, "B&W", "B&W name");
expect_u8(bw->step_count, 7, "B&W count");
check_step(bw, 0, "Developer", 510, 5.5f, 5.f, 19.f, 20.f, 21.f);
check_step(bw, 1, "Stop", 30, 3.5f, 3.f, 19.f, 20.f, 21.f);
check_step(bw, 2, "Fix", 300, 3.5f, 3.f, 19.f, 20.f, 21.f);
check_step(bw, 3, "Rinse 1", 60, 3.5f, 3.f, 19.f, 20.f, 21.f);
check_step(bw, 4, "Rinse 2", 90, 3.5f, 3.f, 19.f, 20.f, 21.f);
check_step(bw, 5, "Rinse 3", 120, 3.5f, 3.f, 19.f, 20.f, 21.f);
check_step(bw, 6, "Fin Rinse", 30, 1.f, 1.f, 19.f, 20.f, 21.f);
expect_str(custom->name, "Custom", "Custom name");
expect_u8(custom->step_count, 4, "Custom count");
check_step(custom, 0, "Developer", 10, 5.5f, 5.f, 19.f, 20.f, 21.f);
check_step(custom, 1, "Stop", 10, 3.5f, 3.f, 19.f, 20.f, 21.f);
check_step(custom, 2, "Fix", 10, 3.5f, 3.f, 19.f, 20.f, 21.f);
check_step(custom, 3, "Rinse", 10, 3.5f, 3.f, 19.f, 20.f, 21.f);
expect_str(bwrev->name, "B&WREV", "B&WREV name");
expect_u8(bwrev->step_count, 12, "B&WREV count");
check_step(bwrev, 0, "FirstDev", 720, 5.5f, 5.f, 19.5f, 20.f, 20.5f);
check_step(bwrev, 1, "Wash 1", 300, 3.5f, 3.f, 15.5f, 20.f, 22.5f);
check_step(bwrev, 2, "Bleach", 300, 5.5f, 5.f, 19.5f, 20.f, 22.5f);
check_step(bwrev, 3, "Wash 2", 60, 3.5f, 3.f, 15.5f, 20.f, 22.5f);
check_step(bwrev, 4, "Clearing", 120, 5.5f, 5.f, 19.5f, 20.f, 22.5f);
check_step(bwrev, 5, "Wash 3", 60, 3.5f, 3.f, 15.5f, 20.f, 22.5f);
check_step(bwrev, 6, "Reversal", 120, 5.5f, 5.f, 19.5f, 20.f, 22.5f);
check_step(bwrev, 7, "SecondDev", 360, 5.5f, 5.f, 19.5f, 20.f, 22.5f);
check_step(bwrev, 8, "Wash 4", 60, 3.5f, 3.f, 15.5f, 20.f, 22.5f);
check_step(bwrev, 9, "Fix", 300, 5.5f, 5.f, 19.5f, 20.f, 22.5f);
check_step(bwrev, 10, "Wash 5", 60, 3.5f, 3.f, 15.5f, 20.f, 22.5f);
check_step(bwrev, 11, "Fin Rinse", 60, 3.5f, 3.f, 15.5f, 20.f, 22.5f);
/* Fix broken overlay default check: compare via id, not pointer arithmetic */
expect_u16(app_process_time_s(PROC_C41, 0), 180, "C41[0] time default");
expect_u16(app_process_time_s(PROC_C41, 1), 195, "C41[1] time default");
static const uint8_t ids[PROCESS_COUNT] = {
PROC_C41, PROC_E6, PROC_ECN2, PROC_BW, PROC_CUSTOM, PROC_BWREV
};
for (int i = 0; i < PROCESS_COUNT; i++) {
const process_def_t *p = app_process_get(ids[i]);
const process_def_t *by_name = app_process_find_name(p->name);
if (by_name != p) {
fprintf(stderr, "FAIL: find_name(%s) != get(%u)\n", p->name, ids[i]);
g_failures++;
}
}
expect_err(app_process_adjust_time(PROC_C41, 1, 5), ESP_OK, "adjust C41 step1 +5");
expect_u16(app_process_time_s(PROC_C41, 1), 200, "C41[1] after +5");
expect_u16(c41->steps[1].time_s, 195, "const C41[1].time_s unchanged");
app_process_reset_session(PROC_C41);
expect_u16(app_process_time_s(PROC_C41, 1), 195, "C41[1] after reset");
expect_err(app_process_adjust_time(6, 0, 1), ESP_ERR_INVALID_ARG, "bad id");
expect_err(app_process_adjust_time(PROC_C41, 7, 1), ESP_ERR_INVALID_ARG, "bad step");
if (g_failures == 0) {
printf("test_process: all assertions passed\n");
return 0;
}
fprintf(stderr, "test_process: %d failure(s)\n", g_failures);
return 1;
}