refactor(cmake): simplify ImGui test engine integration and feature flags

- Updated CMake configuration to always include the ImGui Test Engine when tests are enabled, removing conditional checks for UI tests.
- Simplified feature flag management by enabling JSON and gRPC by default, with a minimal build option to disable only the most expensive features.
- Enhanced status messages to provide clearer feedback on build configurations and feature availability.

Benefits:
- Streamlined integration of the ImGui Test Engine for testing purposes.
- Improved clarity in feature flag settings, making it easier to manage build configurations.
This commit is contained in:
scawful
2025-10-11 21:44:01 -04:00
parent 4358603874
commit d91dddfbe0
8 changed files with 33 additions and 72 deletions

View File

@@ -55,25 +55,24 @@ set(YAZE_INSTALL_LIB OFF)
# Testing and CI Configuration # Testing and CI Configuration
option(YAZE_ENABLE_ROM_TESTS "Enable tests that require ROM files" OFF) option(YAZE_ENABLE_ROM_TESTS "Enable tests that require ROM files" OFF)
option(YAZE_ENABLE_EXPERIMENTAL_TESTS "Enable experimental/unstable tests" ON) option(YAZE_ENABLE_EXPERIMENTAL_TESTS "Enable experimental/unstable tests" ON)
option(YAZE_ENABLE_UI_TESTS "Enable ImGui Test Engine UI testing" ON)
option(YAZE_MINIMAL_BUILD "Minimal build for CI (disable optional features)" OFF) option(YAZE_MINIMAL_BUILD "Minimal build for CI (disable optional features)" OFF)
option(YAZE_USE_MODULAR_BUILD "Use modularized library build system for faster builds" ON) option(YAZE_USE_MODULAR_BUILD "Use modularized library build system for faster builds" ON)
option(YAZE_UNITY_BUILD "Enable Unity (Jumbo) builds" OFF) option(YAZE_UNITY_BUILD "Enable Unity (Jumbo) builds" OFF)
# Feature Flags # Feature Flags - Simplified: Always enabled by default (use wrapper classes to hide complexity)
# JSON is header-only with minimal overhead
# gRPC is only used in agent/cli tools, not in core editor runtime
set(YAZE_WITH_JSON ON)
set(YAZE_WITH_GRPC ON)
set(Z3ED_AI ON)
# Minimal build override - disable only the most expensive features
if(YAZE_MINIMAL_BUILD) if(YAZE_MINIMAL_BUILD)
# Minimal build for CI: disable features that are slow to build or not essential
set(Z3ED_AI OFF)
set(YAZE_WITH_JSON ON) # JSON is header-only, low impact
set(YAZE_WITH_GRPC OFF) set(YAZE_WITH_GRPC OFF)
set(YAZE_ENABLE_UI_TESTS OFF) set(Z3ED_AI OFF)
message(STATUS "✓ Minimal build enabled for CI") message(STATUS "✓ Minimal build: gRPC and AI disabled")
else() else()
# Full build for development/release message(STATUS "✓ Full build: All features enabled (JSON, gRPC, AI)")
set(Z3ED_AI ON)
set(YAZE_WITH_JSON ON)
set(YAZE_WITH_GRPC ON)
message(STATUS "✓ All features enabled: JSON, gRPC, AI Agent")
endif() endif()
# Define preprocessor macros for feature flags (so #ifdef works in source code) # Define preprocessor macros for feature flags (so #ifdef works in source code)

View File

@@ -12,31 +12,21 @@ target_include_directories(ImGui PUBLIC ${SDL2_INCLUDE_DIR})
target_compile_definitions(ImGui PUBLIC target_compile_definitions(ImGui PUBLIC
IMGUI_IMPL_OPENGL_LOADER_CUSTOM=<SDL2/SDL_opengl.h> GL_GLEXT_PROTOTYPES=1) IMGUI_IMPL_OPENGL_LOADER_CUSTOM=<SDL2/SDL_opengl.h> GL_GLEXT_PROTOTYPES=1)
# Set up ImGui Test Engine sources and target conditionally # ImGui Test Engine - Always built when tests are enabled for simplified integration
if(YAZE_ENABLE_UI_TESTS) # The test infrastructure is tightly coupled with the editor, so we always include it
if(YAZE_BUILD_TESTS)
set(IMGUI_TEST_ENGINE_PATH ${CMAKE_SOURCE_DIR}/src/lib/imgui_test_engine/imgui_test_engine) set(IMGUI_TEST_ENGINE_PATH ${CMAKE_SOURCE_DIR}/src/lib/imgui_test_engine/imgui_test_engine)
file(GLOB IMGUI_TEST_ENGINE_SOURCES ${IMGUI_TEST_ENGINE_PATH}/*.cpp) file(GLOB IMGUI_TEST_ENGINE_SOURCES ${IMGUI_TEST_ENGINE_PATH}/*.cpp)
add_library("ImGuiTestEngine" STATIC ${IMGUI_TEST_ENGINE_SOURCES}) add_library("ImGuiTestEngine" STATIC ${IMGUI_TEST_ENGINE_SOURCES})
target_include_directories(ImGuiTestEngine PUBLIC ${IMGUI_PATH} ${CMAKE_SOURCE_DIR}/src/lib) target_include_directories(ImGuiTestEngine PUBLIC ${IMGUI_PATH} ${CMAKE_SOURCE_DIR}/src/lib)
target_link_libraries(ImGuiTestEngine PUBLIC ImGui) target_link_libraries(ImGuiTestEngine PUBLIC ImGui)
# Enable test engine definitions only when UI tests are enabled
target_compile_definitions(ImGuiTestEngine PUBLIC target_compile_definitions(ImGuiTestEngine PUBLIC
IMGUI_ENABLE_TEST_ENGINE=1 IMGUI_ENABLE_TEST_ENGINE=1
IMGUI_TEST_ENGINE_ENABLE_COROUTINE_STDTHREAD_IMPL=1) IMGUI_TEST_ENGINE_ENABLE_COROUTINE_STDTHREAD_IMPL=1)
# Also define for targets that link to ImGuiTestEngine message(STATUS "✓ ImGui Test Engine enabled (tests are ON)")
set(IMGUI_TEST_ENGINE_DEFINITIONS
IMGUI_ENABLE_TEST_ENGINE=1
IMGUI_TEST_ENGINE_ENABLE_COROUTINE_STDTHREAD_IMPL=1)
# Make ImGuiTestEngine target available
set(IMGUI_TEST_ENGINE_TARGET ImGuiTestEngine)
else() else()
# Create empty variables when UI tests are disabled message(STATUS "✗ ImGui Test Engine disabled (tests are OFF)")
set(IMGUI_TEST_ENGINE_SOURCES "")
set(IMGUI_TEST_ENGINE_TARGET "")
set(IMGUI_TEST_ENGINE_DEFINITIONS "")
endif() endif()
set( set(

View File

@@ -121,12 +121,11 @@ if(YAZE_WITH_JSON)
target_compile_definitions(yaze_editor PUBLIC YAZE_WITH_JSON) target_compile_definitions(yaze_editor PUBLIC YAZE_WITH_JSON)
endif() endif()
# Conditionally link ImGui Test Engine # Link ImGui Test Engine when tests are enabled
if(YAZE_ENABLE_UI_TESTS AND TARGET ImGuiTestEngine) # The test infrastructure is integrated into the editor for test automation
if(YAZE_BUILD_TESTS AND TARGET ImGuiTestEngine)
target_link_libraries(yaze_editor PUBLIC ImGuiTestEngine) target_link_libraries(yaze_editor PUBLIC ImGuiTestEngine)
target_compile_definitions(yaze_editor PRIVATE YAZE_ENABLE_IMGUI_TEST_ENGINE=1) message(STATUS "✓ yaze_editor linked to ImGuiTestEngine")
else()
target_compile_definitions(yaze_editor PRIVATE YAZE_ENABLE_IMGUI_TEST_ENGINE=0)
endif() endif()
# Conditionally link gRPC if enabled # Conditionally link gRPC if enabled

View File

@@ -34,9 +34,8 @@ if(YAZE_BUILD_EMU AND NOT YAZE_MINIMAL_BUILD)
message(WARNING "yaze_emu needs yaze_test_support but TARGET not found") message(WARNING "yaze_emu needs yaze_test_support but TARGET not found")
endif() endif()
if(YAZE_ENABLE_UI_TESTS) # Test engine is always available when tests are built
target_compile_definitions(yaze_emu PRIVATE YAZE_ENABLE_IMGUI_TEST_ENGINE=1) # No need for conditional definitions
endif()
# Headless Emulator Test Harness # Headless Emulator Test Harness
add_executable(yaze_emu_test emu_test.cc) add_executable(yaze_emu_test emu_test.cc)

View File

@@ -34,10 +34,12 @@ if(YAZE_BUILD_TESTS)
${SDL_TARGETS} ${SDL_TARGETS}
) )
# Link ImGui Test Engine for GUI tests # Link ImGui Test Engine for GUI tests (always available when tests are built)
if(is_gui_test AND YAZE_ENABLE_UI_TESTS) if(is_gui_test AND TARGET ImGuiTestEngine)
target_link_libraries(${suite_name} PRIVATE ${IMGUI_TEST_ENGINE_TARGET}) target_link_libraries(${suite_name} PRIVATE ImGuiTestEngine)
target_compile_definitions(${suite_name} PRIVATE ${IMGUI_TEST_ENGINE_DEFINITIONS}) target_compile_definitions(${suite_name} PRIVATE
IMGUI_ENABLE_TEST_ENGINE=1
IMGUI_TEST_ENGINE_ENABLE_COROUTINE_STDTHREAD_IMPL=1)
endif() endif()
if(WIN32) if(WIN32)

View File

@@ -6,16 +6,12 @@ namespace test {
namespace gui { namespace gui {
void LoadRomInTest(ImGuiTestContext* ctx, const std::string& rom_path) { void LoadRomInTest(ImGuiTestContext* ctx, const std::string& rom_path) {
#ifdef YAZE_ENABLE_IMGUI_TEST_ENGINE
yaze::core::Controller* controller = (yaze::core::Controller*)ctx->Test->UserData; yaze::core::Controller* controller = (yaze::core::Controller*)ctx->Test->UserData;
controller->OnEntry(rom_path); controller->OnEntry(rom_path);
#endif
} }
void OpenEditorInTest(ImGuiTestContext* ctx, const std::string& editor_name) { void OpenEditorInTest(ImGuiTestContext* ctx, const std::string& editor_name) {
#ifdef YAZE_ENABLE_IMGUI_TEST_ENGINE
ctx->MenuClick(absl::StrFormat("Editors/%s", editor_name).c_str()); ctx->MenuClick(absl::StrFormat("Editors/%s", editor_name).c_str());
#endif
} }
} // namespace gui } // namespace gui

View File

@@ -15,11 +15,8 @@
#include <gmock/gmock.h> #include <gmock/gmock.h>
#include "absl/strings/str_format.h" #include "absl/strings/str_format.h"
#include "app/rom.h"
#ifdef YAZE_ENABLE_IMGUI_TEST_ENGINE
#include "imgui_test_engine/imgui_te_context.h" #include "imgui_test_engine/imgui_te_context.h"
#endif #include "app/rom.h"
namespace yaze { namespace yaze {
namespace test { namespace test {
@@ -196,10 +193,8 @@ class RomDependentTest : public ::testing::Test {
namespace gui { namespace gui {
#ifdef YAZE_ENABLE_IMGUI_TEST_ENGINE
void LoadRomInTest(ImGuiTestContext* ctx, const std::string& rom_path); void LoadRomInTest(ImGuiTestContext* ctx, const std::string& rom_path);
void OpenEditorInTest(ImGuiTestContext* ctx, const std::string& editor_name); void OpenEditorInTest(ImGuiTestContext* ctx, const std::string& editor_name);
#endif
} // namespace gui } // namespace gui

View File

@@ -17,18 +17,15 @@
#include "imgui/imgui.h" #include "imgui/imgui.h"
#include "imgui/backends/imgui_impl_sdl2.h" #include "imgui/backends/imgui_impl_sdl2.h"
#include "imgui/backends/imgui_impl_sdlrenderer2.h" #include "imgui/backends/imgui_impl_sdlrenderer2.h"
#include "app/core/window.h"
#include "app/core/controller.h"
#include "app/gfx/backend/sdl2_renderer.h"
#ifdef YAZE_ENABLE_IMGUI_TEST_ENGINE
#include "imgui_test_engine/imgui_te_context.h" #include "imgui_test_engine/imgui_te_context.h"
#include "imgui_test_engine/imgui_te_engine.h" #include "imgui_test_engine/imgui_te_engine.h"
#include "imgui_test_engine/imgui_te_ui.h" #include "imgui_test_engine/imgui_te_ui.h"
#include "app/core/window.h"
#include "app/core/controller.h"
#include "app/gfx/backend/sdl2_renderer.h"
#include "e2e/canvas_selection_test.h" #include "e2e/canvas_selection_test.h"
#include "e2e/framework_smoke_test.h" #include "e2e/framework_smoke_test.h"
#include "e2e/dungeon_editor_smoke_test.h" #include "e2e/dungeon_editor_smoke_test.h"
#endif
// #include "test_editor.h" // Not used in main // #include "test_editor.h" // Not used in main
@@ -58,9 +55,7 @@ struct TestConfig {
bool skip_rom_tests = false; bool skip_rom_tests = false;
bool enable_ui_tests = false; bool enable_ui_tests = false;
bool show_gui = false; bool show_gui = false;
#ifdef YAZE_ENABLE_IMGUI_TEST_ENGINE
ImGuiTestRunSpeed test_speed = ImGuiTestRunSpeed_Fast; ImGuiTestRunSpeed test_speed = ImGuiTestRunSpeed_Fast;
#endif
}; };
// Parse command line arguments for better AI agent testing support // Parse command line arguments for better AI agent testing support
@@ -136,15 +131,11 @@ TestConfig ParseArguments(int argc, char* argv[]) {
} else if (arg == "--show-gui") { } else if (arg == "--show-gui") {
config.show_gui = true; config.show_gui = true;
} else if (arg == "--fast") { } else if (arg == "--fast") {
#ifdef YAZE_ENABLE_IMGUI_TEST_ENGINE
config.test_speed = ImGuiTestRunSpeed_Fast; config.test_speed = ImGuiTestRunSpeed_Fast;
} else if (arg == "--normal") { } else if (arg == "--normal") {
config.test_speed = ImGuiTestRunSpeed_Normal; config.test_speed = ImGuiTestRunSpeed_Normal;
#endif
} else if (arg == "--cinematic") { } else if (arg == "--cinematic") {
#ifdef YAZE_ENABLE_IMGUI_TEST_ENGINE
config.test_speed = ImGuiTestRunSpeed_Cinematic; config.test_speed = ImGuiTestRunSpeed_Cinematic;
#endif
} else if (arg == "--ui") { } else if (arg == "--ui") {
config.enable_ui_tests = true; config.enable_ui_tests = true;
} else if (arg.find("--") != 0) { } else if (arg.find("--") != 0) {
@@ -307,7 +298,6 @@ int main(int argc, char* argv[]) {
yaze::core::Controller controller; yaze::core::Controller controller;
#ifdef YAZE_ENABLE_IMGUI_TEST_ENGINE
// Setup test engine // Setup test engine
ImGuiTestEngine* engine = ImGuiTestEngine_CreateContext(); ImGuiTestEngine* engine = ImGuiTestEngine_CreateContext();
ImGuiTestEngineIO& test_io = ImGuiTestEngine_GetIO(engine); ImGuiTestEngineIO& test_io = ImGuiTestEngine_GetIO(engine);
@@ -320,6 +310,7 @@ int main(int argc, char* argv[]) {
if (config.test_speed == ImGuiTestRunSpeed_Normal) speed_name = "Normal"; if (config.test_speed == ImGuiTestRunSpeed_Normal) speed_name = "Normal";
else if (config.test_speed == ImGuiTestRunSpeed_Cinematic) speed_name = "Cinematic"; else if (config.test_speed == ImGuiTestRunSpeed_Cinematic) speed_name = "Cinematic";
std::cout << "Running tests in " << speed_name << " mode" << std::endl; std::cout << "Running tests in " << speed_name << " mode" << std::endl;
// Register smoke test // Register smoke test
ImGuiTest* smoke_test = IM_REGISTER_TEST(engine, "E2ETest", "FrameworkSmokeTest"); ImGuiTest* smoke_test = IM_REGISTER_TEST(engine, "E2ETest", "FrameworkSmokeTest");
smoke_test->TestFunc = E2ETest_FrameworkSmokeTest; smoke_test->TestFunc = E2ETest_FrameworkSmokeTest;
@@ -333,7 +324,6 @@ int main(int argc, char* argv[]) {
ImGuiTest* dungeon_test = IM_REGISTER_TEST(engine, "E2ETest", "DungeonEditorSmokeTest"); ImGuiTest* dungeon_test = IM_REGISTER_TEST(engine, "E2ETest", "DungeonEditorSmokeTest");
dungeon_test->TestFunc = E2ETest_DungeonEditorV2SmokeTest; dungeon_test->TestFunc = E2ETest_DungeonEditorV2SmokeTest;
dungeon_test->UserData = &controller; dungeon_test->UserData = &controller;
#endif
// Main loop // Main loop
bool done = false; bool done = false;
@@ -355,11 +345,9 @@ int main(int argc, char* argv[]) {
ImGui::NewFrame(); ImGui::NewFrame();
// Render the UI // Render the UI
#ifdef YAZE_ENABLE_IMGUI_TEST_ENGINE
if (config.show_gui) { if (config.show_gui) {
ImGuiTestEngine_ShowTestEngineWindows(engine, &config.show_gui); ImGuiTestEngine_ShowTestEngineWindows(engine, &config.show_gui);
} }
#endif
controller.DoRender(); controller.DoRender();
// End the Dear ImGui frame // End the Dear ImGui frame
@@ -377,13 +365,10 @@ int main(int argc, char* argv[]) {
SDL_GL_MakeCurrent(backup_current_window, backup_current_context); SDL_GL_MakeCurrent(backup_current_window, backup_current_context);
} }
#ifdef YAZE_ENABLE_IMGUI_TEST_ENGINE
// Run test engine // Run test engine
ImGuiTestEngine_PostSwap(engine); ImGuiTestEngine_PostSwap(engine);
#endif
} }
#ifdef YAZE_ENABLE_IMGUI_TEST_ENGINE
// Get test result // Get test result
ImGuiTestEngineResultSummary summary; ImGuiTestEngineResultSummary summary;
ImGuiTestEngine_GetResultSummary(engine, &summary); ImGuiTestEngine_GetResultSummary(engine, &summary);
@@ -392,10 +377,6 @@ int main(int argc, char* argv[]) {
// Cleanup // Cleanup
controller.OnExit(); controller.OnExit();
ImGuiTestEngine_DestroyContext(engine); ImGuiTestEngine_DestroyContext(engine);
#else
int result = 0;
controller.OnExit();
#endif
ImGui_ImplSDLRenderer2_Shutdown(); ImGui_ImplSDLRenderer2_Shutdown();
ImGui_ImplSDL2_Shutdown(); ImGui_ImplSDL2_Shutdown();
ImGui::DestroyContext(); ImGui::DestroyContext();