Files
ninlight-w600/test/test_console_cmd.c
T
Michael Sauer 4f270ad79b fix: Watchdog wirksam machen, Factory-Reset im App-Task, Resetzähler-Retry
- vApplicationIdleHook() füttert den Watchdog nicht mehr (sdk/Platform/Sys/wm_main.c,
  dokumentiert als Patch 4 in sdk/PATCHES.md). Bisher fütterte der Idle-Task den
  Watchdog bei jedem Leerlauf, auch wenn ein Task deadlockt (z.B. nl_app_lock() hält
  und nie freigibt) - der Watchdog konnte so nie greifen.
- Neues Konsolenkommando `wdtest` (Parser in nl_console_cmd.c/.h, Ausführung in
  nl_console.c, Host-Test in test_console_cmd.c): hält nl_app_lock() für immer, damit
  light_task und app_task blockieren und nur der Watchdog-Reset den Chip retten kann.
- nl_app_request_factory_reset() (nl_app.h) setzt nur ein volatile Flag; app_task
  prüft es in der Hauptschleife und ruft nl_app_factory_reset() selbst auf, da nur der
  App-Task die Flash-Stores besitzt. Das Konsolenkommando `factory` ruft jetzt diese
  Funktion statt nl_app_factory_reset() direkt aufzurufen, um die Race mit
  nl_state_log_append()/nl_resetcnt_clear() im App-Task zu vermeiden. Der Bootpfad
  (Bootzähler >= 5) ruft weiterhin direkt nl_app_factory_reset() auf.
- nl_resetcnt_clear() wird nur noch als erledigt markiert, wenn es 0 zurückgibt, damit
  ein fehlgeschlagener Clear in der nächsten Schleifeniteration erneut versucht wird.
2026-09-11 20:53:25 +02:00

101 lines
3.5 KiB
C

#include "unity.h"
#include "sys/nl_console_cmd.h"
void setUp(void) {}
void tearDown(void) {}
static void test_empty_and_unknown(void)
{
TEST_ASSERT_EQUAL(NL_CMD_NONE, nl_console_parse("").type);
TEST_ASSERT_EQUAL(NL_CMD_NONE, nl_console_parse(" \r\n").type);
TEST_ASSERT_EQUAL(NL_CMD_ERROR, nl_console_parse("dance").type);
}
static void test_on_off(void)
{
nl_cmd_t c = nl_console_parse("on");
TEST_ASSERT_EQUAL(NL_CMD_ON, c.type);
TEST_ASSERT_EQUAL_UINT8(0, c.argc);
c = nl_console_parse("off 1500\r");
TEST_ASSERT_EQUAL(NL_CMD_OFF, c.type);
TEST_ASSERT_EQUAL_UINT8(1, c.argc);
TEST_ASSERT_EQUAL_INT32(1500, c.arg[0]);
TEST_ASSERT_EQUAL(NL_CMD_ERROR, nl_console_parse("on 60001").type);
TEST_ASSERT_EQUAL(NL_CMD_ERROR, nl_console_parse("on abc").type);
}
static void test_bri(void)
{
nl_cmd_t c = nl_console_parse("bri 50 200");
TEST_ASSERT_EQUAL(NL_CMD_BRI, c.type);
TEST_ASSERT_EQUAL_UINT8(2, c.argc);
TEST_ASSERT_EQUAL_INT32(50, c.arg[0]);
TEST_ASSERT_EQUAL_INT32(200, c.arg[1]);
TEST_ASSERT_EQUAL(NL_CMD_ERROR, nl_console_parse("bri 0").type);
TEST_ASSERT_EQUAL(NL_CMD_ERROR, nl_console_parse("bri").type);
}
static void test_rgb(void)
{
nl_cmd_t c = nl_console_parse("rgb 255 0 128 1000");
TEST_ASSERT_EQUAL(NL_CMD_RGB, c.type);
TEST_ASSERT_EQUAL_UINT8(4, c.argc);
TEST_ASSERT_EQUAL_INT32(128, c.arg[2]);
TEST_ASSERT_EQUAL(NL_CMD_ERROR, nl_console_parse("rgb 255 0").type);
TEST_ASSERT_EQUAL(NL_CMD_ERROR, nl_console_parse("rgb 256 0 0").type);
}
static void test_ct(void)
{
nl_cmd_t c = nl_console_parse("ct 2700");
TEST_ASSERT_EQUAL(NL_CMD_CT, c.type);
TEST_ASSERT_EQUAL_INT32(2700, c.arg[0]);
TEST_ASSERT_EQUAL(NL_CMD_ERROR, nl_console_parse("ct 500").type);
}
static void test_pob_fade_blink_pulse(void)
{
TEST_ASSERT_EQUAL_INT32(0, nl_console_parse("pob last").arg[0]);
TEST_ASSERT_EQUAL_INT32(1, nl_console_parse("pob on").arg[0]);
TEST_ASSERT_EQUAL_INT32(2, nl_console_parse("pob off").arg[0]);
TEST_ASSERT_EQUAL(NL_CMD_ERROR, nl_console_parse("pob maybe").type);
nl_cmd_t c = nl_console_parse("fade 300 800");
TEST_ASSERT_EQUAL(NL_CMD_FADE, c.type);
TEST_ASSERT_EQUAL_INT32(800, c.arg[1]);
TEST_ASSERT_EQUAL(NL_CMD_ERROR, nl_console_parse("fade 300").type);
TEST_ASSERT_EQUAL(NL_CMD_ERROR, nl_console_parse("fade 300 10001").type);
c = nl_console_parse("blink");
TEST_ASSERT_EQUAL(NL_CMD_BLINK, c.type);
TEST_ASSERT_EQUAL_INT32(3, c.arg[0]);
TEST_ASSERT_EQUAL_INT32(5, nl_console_parse("blink 5").arg[0]);
TEST_ASSERT_EQUAL_INT32(1, nl_console_parse("pulse on").arg[0]);
TEST_ASSERT_EQUAL_INT32(0, nl_console_parse("pulse off").arg[0]);
}
static void test_simple_commands(void)
{
TEST_ASSERT_EQUAL(NL_CMD_STATE, nl_console_parse("state").type);
TEST_ASSERT_EQUAL(NL_CMD_FACTORY, nl_console_parse("factory").type);
TEST_ASSERT_EQUAL(NL_CMD_REBOOT, nl_console_parse("reboot").type);
TEST_ASSERT_EQUAL(NL_CMD_HELP, nl_console_parse("help").type);
TEST_ASSERT_EQUAL(NL_CMD_WDTEST, nl_console_parse("wdtest").type);
TEST_ASSERT_EQUAL(NL_CMD_ERROR, nl_console_parse("state now").type);
TEST_ASSERT_EQUAL(NL_CMD_ERROR, nl_console_parse("wdtest now").type);
}
int main(void)
{
UNITY_BEGIN();
RUN_TEST(test_empty_and_unknown);
RUN_TEST(test_on_off);
RUN_TEST(test_bri);
RUN_TEST(test_rgb);
RUN_TEST(test_ct);
RUN_TEST(test_pob_fade_blink_pulse);
RUN_TEST(test_simple_commands);
return UNITY_END();
}