From d0cec297a8cbb08767b2675631692fb4010eafec Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 23 Feb 2024 11:39:33 +1100 Subject: [PATCH] AP_JSON: made test pass/fail --- libraries/AP_JSON/examples/XPlane/XPlane.cpp | 21 +++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/libraries/AP_JSON/examples/XPlane/XPlane.cpp b/libraries/AP_JSON/examples/XPlane/XPlane.cpp index d7af16a4f5..197876434a 100644 --- a/libraries/AP_JSON/examples/XPlane/XPlane.cpp +++ b/libraries/AP_JSON/examples/XPlane/XPlane.cpp @@ -12,12 +12,16 @@ void loop(); const AP_HAL::HAL& hal = AP_HAL::get_HAL(); -static void test_xplane(void) +static uint32_t test_count; +static uint32_t label_count; + +static bool test_xplane(void) { const uint32_t m1 = hal.util->available_memory(); auto *obj = AP_JSON::load_json("@ROMFS/models/xplane_plane.json"); if (obj == nullptr) { - ::printf("Failed to parse json\n"); + ::printf("Failed to load or parse json\n"); + return false; } const uint32_t m2 = hal.util->available_memory(); ::printf("Used %u bytes\n", unsigned(m1-m2)); @@ -28,8 +32,10 @@ static void test_xplane(void) ++i) { const char *label = i->first.c_str(); ::printf("Label: %s\n", label); + label_count++; } delete obj; + return label_count > 10; } /* @@ -43,7 +49,16 @@ void setup(void) void loop(void) { ::printf("Memory: %u\n", (unsigned)hal.util->available_memory()); - test_xplane(); + if (test_xplane()) { + test_count++; + } else { + ::printf("Test FAILED\n"); + exit(1); + } + if (test_count > 10) { + ::printf("Test PASSED\n"); + exit(0); + } } AP_HAL_MAIN();