diff --git a/main/mqtt_tool.c b/main/mqtt_tool.c index 6cfc717..8fb4d42 100644 --- a/main/mqtt_tool.c +++ b/main/mqtt_tool.c @@ -1637,12 +1637,12 @@ void mqtt_tool_show(lv_obj_t *parent, bool wifi_connected, bool sd_available, lv_obj_t *credentials = row(parent, 78); username_area = lv_textarea_create(credentials); - lv_obj_set_size(username_area, 312, 64); + lv_obj_set_size(username_area, 312, 72); lv_textarea_set_one_line(username_area, true); lv_textarea_set_max_length(username_area, MQTT_CREDENTIAL_MAX + 1); lv_textarea_set_placeholder_text(username_area, "Username"); password_area = lv_textarea_create(credentials); - lv_obj_set_size(password_area, 312, 64); + lv_obj_set_size(password_area, 312, 72); lv_textarea_set_one_line(password_area, true); lv_textarea_set_password_mode(password_area, true); lv_textarea_set_max_length(password_area, MQTT_CREDENTIAL_MAX + 1); @@ -1729,7 +1729,9 @@ void mqtt_tool_show(lv_obj_t *parent, bool wifi_connected, bool sd_available, lv_textarea_set_placeholder_text(history_area, "No messages"); /* One-line textareas derive their height from the font; apply the touch - * height after enabling one-line mode so LVGL does not shrink them. */ + * height after enabling one-line mode so LVGL does not shrink them. + * Leave room for the 30 px font line, 32 px padding and theme border; a + * shorter viewport repeatedly scrolls between the top and bottom of it. */ lv_obj_t *fields[] = {uri_area, username_area, password_area, topic_area, payload_area, history_area}; for (size_t i = 0; i < sizeof(fields) / sizeof(fields[0]); i++) { lv_obj_set_style_text_font(fields[i], &lv_font_montserrat_28, 0); @@ -1737,10 +1739,10 @@ void mqtt_tool_show(lv_obj_t *parent, bool wifi_connected, bool sd_available, lv_obj_set_style_radius(fields[i], 12, 0); } lv_obj_set_style_text_color(history_area, lv_color_hex(0x475569), LV_PART_TEXTAREA_PLACEHOLDER); - lv_obj_set_size(uri_area, 640, 64); - lv_obj_set_size(username_area, 312, 64); - lv_obj_set_size(password_area, 312, 64); - lv_obj_set_size(topic_area, 640, 64); + lv_obj_set_size(uri_area, 640, 72); + lv_obj_set_size(username_area, 312, 72); + lv_obj_set_size(password_area, 312, 72); + lv_obj_set_size(topic_area, 640, 72); keyboard = lv_keyboard_create(parent); lv_obj_set_size(keyboard, 640, 360); diff --git a/tests/device_network/device_test.c b/tests/device_network/device_test.c index 09bdd28..8856fb7 100644 --- a/tests/device_network/device_test.c +++ b/tests/device_network/device_test.c @@ -67,6 +67,7 @@ static void expect(const char *text) static void click(const char *text) { lv_obj_t *label = find_text(content, text, true); + if (!label) { fprintf(stderr, "Missing button: %s\n", text); dump_text(content); } assert(label); lv_obj_t *button = lv_obj_get_parent(label); assert(!lv_obj_has_state(button, LV_STATE_DISABLED)); @@ -102,7 +103,12 @@ static void check_bounds(lv_obj_t *o) /* Textarea internal labels intentionally scroll inside their field. */ if (lv_obj_check_type(o, &lv_textarea_class) || lv_obj_check_type(o, &lv_keyboard_class) || lv_obj_check_type(o, &lv_button_class) || lv_obj_get_parent(o) == content) { - if (a.x1 < 28 || a.x2 > 691 || a.y1 < 128 || a.y2 > 1251) { + /* Larger controls and the keyboard extend the vertically scrollable + * app. Keep horizontal bounds strict and require vertical reachability. */ + lv_area_t viewport; lv_obj_get_content_coords(content, &viewport); + int32_t top = viewport.y1 - LV_MAX(0, lv_obj_get_scroll_top(content)); + int32_t bottom = viewport.y2 + LV_MAX(0, lv_obj_get_scroll_bottom(content)); + if (a.x1 < viewport.x1 || a.x2 > viewport.x2 || a.y1 < top || a.y2 > bottom) { fprintf(stderr, "Object overflow: (%ld,%ld)-(%ld,%ld)\n", (long)a.x1, (long)a.y1, (long)a.x2, (long)a.y2); assert(0); } @@ -260,7 +266,7 @@ static void ntp_case(const char *scenario, const char *port) for (size_t i = 0; i < sizeof(bad_hosts) / sizeof(bad_hosts[0]); i++) { input(0, bad_hosts[i]); assert(!strcmp(lv_textarea_get_text(nth(&lv_textarea_class, 0)), bad_hosts[i])); - click("SAMPLE 4"); expect("full decimal IPv4"); + click("Sample 4"); expect("full decimal IPv4"); assert(host_sockets_opened == 0 && host_tasks_started == 0 && !busy()); } input(0, "127.0.0.1"); @@ -268,41 +274,41 @@ static void ntp_case(const char *scenario, const char *port) for (size_t i = 0; i < sizeof(bad_ports) / sizeof(bad_ports[0]); i++) { input(1, bad_ports[i]); assert(!strcmp(lv_textarea_get_text(nth(&lv_textarea_class, 1)), bad_ports[i])); - click("SAMPLE 4"); expect("1 to 65535"); + click("Sample 4"); expect("1 to 65535"); assert(host_sockets_opened == 0 && host_tasks_started == 0); } clean_app(); open_app(); assert(!strcmp(lv_textarea_get_text(nth(&lv_textarea_class, 1)), "000001")); - click("SAMPLE 4"); expect("1 to 65535"); + click("Sample 4"); expect("1 to 65535"); char unicode[65]; for (unsigned i = 0; i < 16; i++) memcpy(unicode + 4 * i, "\xf0\x9f\x94\xa5", 4); unicode[64] = 0; input(0, unicode); clean_app(); open_app(); assert(!strcmp(lv_textarea_get_text(nth(&lv_textarea_class, 0)), unicode)); - click("SAMPLE 4"); expect("full decimal IPv4"); + click("Sample 4"); expect("full decimal IPv4"); input(0, "127.0.0.1"); unicode[24] = 0; input(1, unicode); clean_app(); open_app(); assert(!strcmp(lv_textarea_get_text(nth(&lv_textarea_class, 1)), unicode)); - click("SAMPLE 4"); expect("1 to 65535"); + click("Sample 4"); expect("1 to 65535"); assert(host_sockets_opened == 0 && host_tasks_started == 0 && !busy()); return; } if (!strcmp(scenario, "ntp-gates")) { - InterlockedExchange(&host_online, 0); click("SAMPLE 4"); expect("Connect to Wi-Fi"); + InterlockedExchange(&host_online, 0); click("Sample 4"); expect("Connect to Wi-Fi"); assert(host_sockets_opened == 0); InterlockedExchange(&host_online, 1); struct timeval time; host_gettimeofday(&time, NULL); InterlockedExchange64(&host_wall_offset_us, -(int64_t)time.tv_sec * 1000000); - click("SAMPLE 4"); expect("Tablet clock is not set"); assert(host_sockets_opened == 0); + click("Sample 4"); expect("Tablet clock is not set"); assert(host_sockets_opened == 0); InterlockedExchange64(&host_wall_offset_us, 0); - input(0, "999.0.0.1"); click("SAMPLE 4"); expect("full decimal IPv4"); - input(0, "127.0.0.1"); input(1, "0"); click("SAMPLE 4"); expect("1 to 65535"); + input(0, "999.0.0.1"); click("Sample 4"); expect("full decimal IPv4"); + input(0, "127.0.0.1"); input(1, "0"); click("Sample 4"); expect("1 to 65535"); assert(host_sockets_opened == 0); return; } if (!strcmp(scenario, "ntp-repeated")) { DWORD before = 0, after = 0; lv_mem_monitor_t memory_before, memory_after; for (unsigned i = 0; i < 25; i++) { - click("SAMPLE 4"); pump_for(200); expect("1 valid"); + click("Sample 4"); pump_for(200); expect("1 valid"); clean_app(); finish(); if (i == 0) { GetProcessHandleCount(GetCurrentProcess(), &before); lv_mem_monitor(&memory_before); } open_app(); expect("Cancelled; UDP socket closed."); @@ -313,15 +319,15 @@ static void ntp_case(const char *scenario, const char *port) open_app(); return; } int64_t started = esp_timer_get_time(); - click("SAMPLE 4"); + click("Sample 4"); if (!strcmp(scenario, "ntp-stop") || !strcmp(scenario, "ntp-home")) { pump_for(250); assert(busy()); int64_t cancel_at = esp_timer_get_time(); - if (!strcmp(scenario, "ntp-stop")) click("STOP"); else clean_app(); + if (!strcmp(scenario, "ntp-stop")) click("Stop"); else clean_app(); finish(); assert(esp_timer_get_time() - cancel_at < 1200000); if (!strcmp(scenario, "ntp-home")) open_app(); expect("Cancelled; UDP socket closed."); printf("cancel_ms=%lld ", (long long)((esp_timer_get_time() - cancel_at) / 1000)); - click("SAMPLE 4"); finish(); expect("KoD RATE"); + click("Sample 4"); finish(); expect("KoD RATE"); } else if (!strcmp(scenario, "ntp-clockstep") || !strcmp(scenario, "ntp-clockgap")) { pump_for(200); if (!strcmp(scenario, "ntp-clockgap")) expect("1 valid"); @@ -616,13 +622,13 @@ static void queued_check(bool condition, const char *message) } static void launch_job(void) { - if (ntp) click("SAMPLE 4"); + if (ntp) click("Sample 4"); else if (udp) start_udp(); else start_wol(); } static void force_launch(void) { - lv_obj_t *label = find_text(content, ntp ? "SAMPLE 4" : "SEND", true); + lv_obj_t *label = find_text(content, ntp ? "Sample 4" : "SEND", true); assert(label); lv_obj_send_event(lv_obj_get_parent(label), LV_EVENT_CLICKED, NULL); } @@ -704,7 +710,7 @@ static void queued_case(const char *scenario, const char *port) bool home = strstr(scenario, "-home") != NULL; LONG sockets = host_sockets_opened; hold_job(); - if (cancel) click(ntp ? "STOP" : "CANCEL"); + if (cancel) click(ntp ? "Stop" : "CANCEL"); if (home) { clean_app(); open_app(); assert(busy()); diff --git a/tests/mqtt_ui/ui_test.c b/tests/mqtt_ui/ui_test.c index f2904ab..58c1b73 100644 --- a/tests/mqtt_ui/ui_test.c +++ b/tests/mqtt_ui/ui_test.c @@ -5,6 +5,7 @@ #include "payload_clipboard.h" #include "byte_tool.h" #include "src/display/lv_display_private.h" +#include "src/core/lv_global.h" #include "src/stdlib/builtin/lv_tlsf.h" #include #include @@ -146,21 +147,65 @@ static void wait_action(bool with_ui) } } } +static unsigned transient_animations(bool diagnostic) +{ + unsigned count = 0; + lv_anim_t *animation; + LV_LL_READ(&LV_GLOBAL_DEFAULT()->anim_state.anim_ll, animation) { + if (animation->repeat_cnt == LV_ANIM_REPEAT_INFINITE) continue; + count++; + if (diagnostic) + fprintf(stderr, "Pending animation: duration=%ld elapsed=%ld repeats=%lu\n", + (long)animation->duration, (long)animation->act_time, (unsigned long)animation->repeat_cnt); + } + return count; +} static void settle_ui(void) { lv_obj_update_layout(content); - uint16_t animations = lv_anim_count_running(); - int64_t stable_since = esp_timer_get_time(), until = stable_since + 1500000; - /* Theme transitions include a delay; wait for their allocation count to - * settle across the 400 ms maximum scroll duration. Cursor blinking remains - * active. Do not delete animations to make a memory comparison pass. */ + int64_t stable_since = esp_timer_get_time(), until = stable_since + 3000000; + /* Wait for finite theme/scroll animations to finish, then remain idle for + * 500 ms. Infinite cursor blinking stays active; no animations are deleted + * to make a memory comparison pass. */ while (esp_timer_get_time() - stable_since < 500000) { + if (esp_timer_get_time() >= until) transient_animations(true); assert(esp_timer_get_time() < until); pump(); - uint16_t current = lv_anim_count_running(); - if (current != animations) { animations = current; stable_since = esp_timer_get_time(); } + if (transient_animations(false) || lv_obj_is_scrolling(area(5)) || lv_obj_is_scrolling(content)) + stable_since = esp_timer_get_time(); } assert(!lv_obj_is_scrolling(area(5)) && !lv_obj_is_scrolling(content)); } +typedef struct { + size_t block_bytes; + uint32_t count, capacity; +} display_memory_t; + +static display_memory_t display_memory(void) +{ + lv_array_t *events = &lv_display_get_default()->event_list.array; + size_t requested = (size_t)events->capacity * events->element_size; + size_t block_bytes = lv_tlsf_block_size(events->data); + /* After Home only the two permanent display callbacks remain. TLSF can + * absorb an unsplittable tail in this resized array without a new leak. */ + assert(requested == 16 && block_bytes >= requested && block_bytes - requested <= 32); + assert(lv_mem_test() == LV_RESULT_OK); + return (display_memory_t){block_bytes, events->size, events->capacity}; +} + +static void assert_home_memory(const lv_mem_monitor_t *before, const lv_mem_monitor_t *after, + display_memory_t display_before) +{ + display_memory_t display_after = display_memory(); + printf("Home memory: free=%zu -> %zu, allocations=%zu -> %zu, display_array=%zu -> %zu\n", + before->free_size, after->free_size, before->used_cnt, after->used_cnt, + display_before.block_bytes, display_after.block_bytes); fflush(stdout); + assert(display_before.count == display_after.count && display_before.capacity == display_after.capacity); + /* Account for the measured array block only; every other byte and live + * allocation must match. A blanket heap tolerance would hide real leaks. */ + assert(before->free_size + display_before.block_bytes == after->free_size + display_after.block_bytes); + assert(before->used_cnt == after->used_cnt); +} + static void wait_logging(LONG entries, bool with_ui) { int64_t until = esp_timer_get_time() + 1000000; @@ -233,6 +278,12 @@ static void setup(void) } static void geometry(void) { + for (unsigned i = 0; i < 4; i++) { + lv_obj_t *field = area(i); + const lv_font_t *font = lv_obj_get_style_text_font(field, LV_PART_MAIN); + assert(lv_textarea_get_one_line(field)); + assert(lv_obj_get_content_height(field) >= lv_font_get_line_height(font)); + } const char *controls[] = {"CONNECT", "SUBSCRIBE", "PUBLISH", "SAVE PROFILE", "DELETE PROFILE", "CLEAR", "COPY RX", "PAYLOAD: TEXT", "PASTE BYTES"}; for (unsigned i = 0; i < sizeof(controls) / sizeof(controls[0]); i++) { @@ -453,6 +504,7 @@ static bool run_profile_case(void) /* Warm-up and measured cycles end after Save/Home; ending warm-up after * Load/Home leaves a different small LVGL allocator tail in the parent. */ lv_mem_monitor_t before, after; lv_mem_monitor(&before); + display_memory_t display_before = display_memory(); DWORD handles_before, handles_after; assert(GetProcessHandleCount(GetCurrentProcess(), &handles_before)); LONG tasks = host_tasks_started; for (unsigned i = 0; i < 25; i++) { @@ -463,7 +515,7 @@ static bool run_profile_case(void) lv_mem_monitor(&after); assert(GetProcessHandleCount(GetCurrentProcess(), &handles_after)); printf("Profile memory before assertion: free=%zu -> %zu, allocations=%zu -> %zu, animations=%u\n", before.free_size, after.free_size, before.used_cnt, after.used_cnt, lv_anim_count_running()); fflush(stdout); - assert(before.free_size == after.free_size && before.used_cnt == after.used_cnt); + assert_home_memory(&before, &after, display_before); assert(handles_before == handles_after && host_tasks_started == tasks && host_active_tasks == 1); printf("25 profile reload/delete/save cycles: LVGL free=%zu -> %zu, allocations=%zu -> %zu, handles=%lu -> %lu, standby workers=%ld\n", before.free_size, after.free_size, before.used_cnt, after.used_cnt, @@ -475,7 +527,8 @@ static void lifecycle(void) bool logged = !strcmp(mode, "logged-lifecycle"); connect_session(); if (logged) click("SD LOG\nOFF"); click("PUBLISH"); wait_action(false); mqtt_host_receive("fixture/rx", "bounded preview"); close_app(); finish(false); - lv_mem_monitor_t before, after; lv_mem_monitor(&before); DWORD handles_before, handles_after; + lv_mem_monitor_t before, after; lv_mem_monitor(&before); + display_memory_t display_before = display_memory(); DWORD handles_before, handles_after; assert(GetProcessHandleCount(GetCurrentProcess(), &handles_before)); LONG tasks_before = host_tasks_started; for (unsigned i = 0; i < 25; i++) { @@ -486,7 +539,7 @@ static void lifecycle(void) lv_mem_monitor(&after); assert(GetProcessHandleCount(GetCurrentProcess(), &handles_after)); printf("Session memory: free=%zu -> %zu, allocations=%zu -> %zu, animations=%u\n", before.free_size, after.free_size, before.used_cnt, after.used_cnt, lv_anim_count_running()); fflush(stdout); - assert(before.free_size == after.free_size && before.used_cnt == after.used_cnt); + assert_home_memory(&before, &after, display_before); assert(handles_before == handles_after && host_tasks_started == tasks_before); printf("25 sessions: LVGL free=%zu -> %zu, allocations=%zu, handles=%lu -> %lu, standby workers=%ld\n", before.free_size, after.free_size, after.used_cnt, (unsigned long)handles_before, (unsigned long)handles_after, host_active_tasks); @@ -927,10 +980,7 @@ static bool run_paste_case(void) } assert(!strcmp(mode, "paste-soak")); close_app(); finish(false); lv_mem_monitor_t before, after; lv_mem_monitor(&before); - lv_array_t *events = &lv_display_get_default()->event_list.array; - size_t first_display = lv_tlsf_block_size(events->data); - uint32_t event_count = events->size, event_capacity = events->capacity; - assert((size_t)event_capacity * events->element_size == 16); + display_memory_t display_before = display_memory(); DWORD before_handles, after_handles; assert(GetProcessHandleCount(GetCurrentProcess(), &before_handles)); LONG tasks = host_tasks_started; for (unsigned i = 0; i < 25; ++i) { @@ -941,13 +991,7 @@ static bool run_paste_case(void) close_app(); finish(false); } lv_mem_monitor(&after); assert(GetProcessHandleCount(GetCurrentProcess(), &after_handles)); - size_t last_display = lv_tlsf_block_size(events->data); - printf("PASTE_MEMORY free=%zu -> %zu used=%zu -> %zu display_array=%zu -> %zu requested=16 handles=%lu -> %lu\n", - before.free_size, after.free_size, before.used_cnt, after.used_cnt, first_display, last_display, - before_handles, after_handles); fflush(stdout); - assert(first_display >= 16 && first_display - 16 <= 32 && last_display >= 16 && last_display - 16 <= 32); - assert(before.free_size + first_display == after.free_size + last_display && before.used_cnt == after.used_cnt); - assert(events->size == event_count && events->capacity == event_capacity && lv_mem_test() == LV_RESULT_OK); + assert_home_memory(&before, &after, display_before); assert(before_handles == after_handles && tasks == host_tasks_started && !mqtt_host_allocations); return true; } @@ -1043,12 +1087,8 @@ static bool run_copy_case(void) } if (!strcmp(mode, "copy-soak")) { click("CLEAR"); settle_ui(); close_app(); finish(false); lv_mem_monitor_t before, after; - lv_mem_monitor(&before); DWORD handles_before, handles_after; - lv_array_t *display_events = &lv_display_get_default()->event_list.array; - size_t before_display_bytes = lv_tlsf_block_size(display_events->data); - uint32_t before_events = display_events->size, before_capacity = display_events->capacity; - assert((size_t)display_events->capacity * display_events->element_size == 16); - assert(before_display_bytes >= 16 && before_display_bytes - 16 <= 32); + lv_mem_monitor(&before); display_memory_t display_before = display_memory(); + DWORD handles_before, handles_after; assert(GetProcessHandleCount(GetCurrentProcess(), &handles_before)); LONG tasks = host_tasks_started; for (unsigned i = 0; i < 25; ++i) { open_app(); connect_session(); event = copy_message(bytes, 128); mqtt_host_data(&event); @@ -1056,15 +1096,7 @@ static bool run_copy_case(void) close_app(); finish(false); } lv_mem_monitor(&after); assert(GetProcessHandleCount(GetCurrentProcess(), &handles_after)); - printf("COPY_MEMORY free=%zu -> %zu used=%zu -> %zu display_array=%zu -> %zu requested=%zu handles=%lu -> %lu\n", - before.free_size, after.free_size, before.used_cnt, after.used_cnt, - before_display_bytes, lv_tlsf_block_size(display_events->data), - (size_t)display_events->capacity * display_events->element_size, handles_before, handles_after); - fflush(stdout); - size_t after_display_bytes = lv_tlsf_block_size(display_events->data); - assert(after_display_bytes >= 16 && after_display_bytes - 16 <= 32); - assert(before.free_size + before_display_bytes == after.free_size + after_display_bytes && before.used_cnt == after.used_cnt); - assert(display_events->size == before_events && display_events->capacity == before_capacity && lv_mem_test() == LV_RESULT_OK); + assert_home_memory(&before, &after, display_before); assert(handles_before == handles_after && host_tasks_started == tasks); printf("25 copied receives: LVGL free=%zu -> %zu, handles=%lu -> %lu\n", before.free_size, after.free_size, handles_before, handles_after); } @@ -1196,6 +1228,7 @@ static bool run_receive_case(void) } click("CLEAR"); settle_ui(); lv_mem_monitor_t live_before, live_after, before, after; lv_mem_monitor(&live_before); close_app(); finish(false); lv_mem_monitor(&before); + display_memory_t display_before = display_memory(); DWORD handles_before, handles_after; assert(GetProcessHandleCount(GetCurrentProcess(), &handles_before)); LONG tasks = host_tasks_started; open_app(); connect_session(); click("SD LOG\nOFF"); for (unsigned i = 0; i < 50; i++) { @@ -1206,7 +1239,7 @@ static bool run_receive_case(void) click("CLEAR"); settle_ui(); lv_mem_monitor(&live_after); assert(live_before.used_cnt == live_after.used_cnt && mqtt_host_allocations == 3); close_app(); finish(false); lv_mem_monitor(&after); assert(GetProcessHandleCount(GetCurrentProcess(), &handles_after)); - assert(before.free_size == after.free_size && before.used_cnt == after.used_cnt); + assert_home_memory(&before, &after, display_before); assert(handles_before == handles_after && host_tasks_started == tasks); printf("50 fragmented receives: LVGL free=%zu -> %zu, handles=%lu -> %lu, standby workers=%ld\n", before.free_size, after.free_size, (unsigned long)handles_before, (unsigned long)handles_after, host_active_tasks); @@ -1558,7 +1591,8 @@ static bool run_action_case(void) click("CLEAR"); settle_ui(); lv_mem_monitor_t before, after, warm_ui, used_ui; lv_mem_monitor(&warm_ui); close_app(); finish(false); - lv_mem_monitor(&before); DWORD handles_before, handles_after; + lv_mem_monitor(&before); display_memory_t display_before = display_memory(); + DWORD handles_before, handles_after; assert(GetProcessHandleCount(GetCurrentProcess(), &handles_before)); LONG tasks = host_tasks_started; open_app(); connect_session(); for (unsigned i = 0; i < 50; i++) { click(i % 2 ? "PUBLISH" : "SUBSCRIBE"); wait_action(true); } @@ -1570,7 +1604,7 @@ static bool run_action_case(void) printf("Action memory after Home: free=%zu -> %zu, allocations=%zu -> %zu; active UI allocations=%zu -> %zu\n", before.free_size, after.free_size, before.used_cnt, after.used_cnt, warm_ui.used_cnt, used_ui.used_cnt); fflush(stdout); - assert(before.free_size == after.free_size && before.used_cnt == after.used_cnt); + assert_home_memory(&before, &after, display_before); assert(handles_before == handles_after && host_tasks_started == tasks && !mqtt_host_allocations); printf("50 actions: LVGL free=%zu -> %zu, handles=%lu -> %lu, standby workers=%ld\n", before.free_size, after.free_size, (unsigned long)handles_before, (unsigned long)handles_after, host_active_tasks);