Files
fn_registry/cpp/tests/CMakeLists.txt
T
egutierrez 02b4141cc1 perf(viz): graph_renderer Tier 1 (RGBA8 + orphan + frustum cull) + force_layout auto-pause helper
Issue 0049c. Tres optimizaciones internas en graph_renderer.cpp + un
helper puro en graph_force_layout para detectar convergencia. API publica
intacta — solo cambian el layout interno de los buffers, el shader y
los costes por frame.

1. RGBA8 color packing
   - El instance buffer de nodos pasa de (x,y,size,r,g,b,a) 28B a
     (x,y,size,color_u32) 16B (-43%). Aristas: 24B → 12B/vertex (-50%).
   - Shaders desempaquetan con bit shifts (compatible GL 3.30+, no
     necesita unpackUnorm4x8 que es 4.20+).
   - Helpers expuestos: pack_rgba8 / unpack_rgba8 / modulate_alpha_rgba8
     en graph_renderer.h. Los GraphNode.color y la paleta ya tenian el
     layout correcto (R en LSB), asi que CPU ahora pasa el uint32 directo
     sin convertir a 4 floats por nodo y por frame.

2. Capacity-tracked streaming buffers
   - Sustituye el doble glBufferData de antes por:
       glBufferData(NULL, capacity, STREAM_DRAW)   // orphan + reserva
       glBufferSubData(0, used_bytes, data)        // solo lo usado
   - capacity crece x2 cuando hace falta (inicial 4096 nodos /
     8192 vertices de aristas) → reallocaciones en O(log N).
   - Staging CPU (NodeInstance* / EdgeVertex*) reusado entre frames con
     realloc, no malloc/free per frame.

3. Frustum cull (CPU-side)
   - AABB del viewport en world coords con margen 10%.
   - Aristas: skip si AABB del segmento no intersecta el viewport.
   - Nodos: solo los visibles entran al instance buffer; visible_count
     es el N que pasa a glDrawArraysInstanced. Pop-in de borde mitigado
     por el margen.

4. graph_force_layout_should_pause(low_frames, min_consecutive)
   - Helper puro: el caller mantiene el contador, la funcion solo
     decide si parar. Reemplaza la rama inline en demos_graph.cpp.
   - Test Catch2 con secuencias artificiales.

Tests: test_graph_pack_rgba8 (16401 asserts, 4 cases — roundtrip exhaustivo
+ alpha modulation + clamp). test_graph_should_pause (3 cases, 14 asserts).
Los 29 tests del cpp/tests/ siguen verdes (incluido test_visual con goldens).

Bump versiones:
- graph_renderer 1.1.0 → 1.2.0
- graph_force_layout 1.0.0 → 1.1.0  (tested: true via should_pause test)
2026-04-29 22:17:13 +02:00

87 lines
4.2 KiB
CMake

# cpp/tests — Catch2 unit tests for primitives.
#
# Catch2 amalgamated is compiled once as a STATIC LIB. Each test binary is
# its own executable so we can mix tests that use ImGui-context and tests
# that are pure logic without polluting symbols.
add_library(catch2 STATIC
${CMAKE_CURRENT_SOURCE_DIR}/../vendor/catch2/catch_amalgamated.cpp)
target_include_directories(catch2 PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/../vendor/catch2)
target_compile_features(catch2 PUBLIC cxx_std_17)
# Helper: register a test executable.
# add_fn_test(<name> <sources...>)
# By default links Catch2 + the cpp/functions include path. Tests that need
# real symbols (linking against fn_framework etc.) can call
# target_link_libraries(${name} PRIVATE fn_framework imgui ...) afterwards.
function(add_fn_test name)
add_executable(${name} ${ARGN})
target_link_libraries(${name} PRIVATE catch2)
target_include_directories(${name} PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../functions
${CMAKE_CURRENT_SOURCE_DIR}/../framework)
add_test(NAME ${name} COMMAND ${name})
endfunction()
# --- Tests reales (logica pura, no necesitan ImGui context) ----------------
add_fn_test(test_tween_curves test_tween_curves.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../functions/core/tween_curves.cpp)
add_fn_test(test_pie_chart_math test_pie_chart_math.cpp)
add_fn_test(test_kpi_card_math test_kpi_card_math.cpp)
add_fn_test(test_bar_chart_math test_bar_chart_math.cpp)
# Issue 0045 — tests de la logica pura extraida.
add_fn_test(test_sql_parse test_sql_parse.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../functions/core/sql_parse.cpp)
add_fn_test(test_process_state_machine test_process_state_machine.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../functions/core/process_state_machine.cpp)
add_fn_test(test_file_poll_diff test_file_poll_diff.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../functions/core/file_poll_diff.cpp)
# --- Placeholders para primitivos UI (logica visual cubierta en 0048) ------
add_fn_test(test_tokens test_tokens.cpp)
add_fn_test(test_button test_button.cpp)
add_fn_test(test_select test_select.cpp)
add_fn_test(test_text_input test_text_input.cpp)
add_fn_test(test_badge test_badge.cpp)
add_fn_test(test_kpi_card test_kpi_card.cpp)
add_fn_test(test_pie_chart test_pie_chart.cpp)
add_fn_test(test_bar_chart test_bar_chart.cpp)
add_fn_test(test_tree_view test_tree_view.cpp)
add_fn_test(test_modal_dialog test_modal_dialog.cpp)
add_fn_test(test_toolbar test_toolbar.cpp)
add_fn_test(test_toast test_toast.cpp)
add_fn_test(test_empty_state test_empty_state.cpp)
add_fn_test(test_page_header test_page_header.cpp)
add_fn_test(test_dashboard_panel test_dashboard_panel.cpp)
add_fn_test(test_dashboard_grid test_dashboard_grid.cpp)
add_fn_test(test_sparkline test_sparkline.cpp)
add_fn_test(test_table_view test_table_view.cpp)
add_fn_test(test_icon_button test_icon_button.cpp)
# --- Issue 0049c — graph renderer Tier 1 (RGBA8 + auto-pause helper) -------
add_fn_test(test_graph_pack_rgba8 test_graph_pack_rgba8.cpp)
add_fn_test(test_graph_should_pause test_graph_should_pause.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../functions/viz/graph_force_layout.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../functions/viz/graph_types.cpp)
# --- Visual golden-image diff (issue 0048) ---------------------------------
# El binario primitives_gallery se compila con --capture; el test compara los
# PNGs generados con los goldens en cpp/tests/golden/. Si no hay goldens o el
# entorno no tiene GL, el test SKIPea.
add_fn_test(test_visual
test_visual.cpp
png_diff.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../vendor/stb/stb_image_impl.cpp)
target_include_directories(test_visual PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/../vendor/stb)
target_compile_definitions(test_visual PRIVATE
"FN_TEST_GOLDEN_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}/golden\""
"FN_TEST_GALLERY_BIN=\"$<TARGET_FILE:primitives_gallery>\""
"FN_TEST_TMP_DIR=\"${CMAKE_BINARY_DIR}/tests/visual_actual\""
# CMAKE_SOURCE_DIR aqui es cpp/, queremos la raiz del repo (un nivel arriba).
"FN_TEST_REPO_ROOT=\"${CMAKE_SOURCE_DIR}/..\"")
# Asegura que primitives_gallery existe antes de correr el test.
add_dependencies(test_visual primitives_gallery)