[client] tests: replace test defines with the unified ENABLE_TEST define

This commit is contained in:
Geoffrey McRae
2026-07-31 13:32:53 +10:00
parent 9a3d994204
commit 1a2e92beae
6 changed files with 69 additions and 86 deletions

View File

@@ -262,8 +262,7 @@ jobs:
cmake -S client -B client/build-client-tests \ cmake -S client -B client/build-client-tests \
-DOPTIMIZE_FOR_NATIVE=OFF \ -DOPTIMIZE_FOR_NATIVE=OFF \
-DENABLE_LIBDECOR=OFF \ -DENABLE_LIBDECOR=OFF \
-DENABLE_TEST_TRANSPORT=ON \ -DENABLE_TESTS=ON
-DENABLE_RENDER_TESTS=ON
- name: Build - name: Build
run: cmake --build client/build-client-tests --parallel run: cmake --build client/build-client-tests --parallel

View File

@@ -34,25 +34,14 @@ add_feature_info(ENABLE_OPENGL ENABLE_OPENGL "Legacy OpenGL renderer.")
option(ENABLE_EGL "Enable the EGL renderer" ON) option(ENABLE_EGL "Enable the EGL renderer" ON)
add_feature_info(ENABLE_EGL ENABLE_EGL "EGL renderer.") add_feature_info(ENABLE_EGL ENABLE_EGL "EGL renderer.")
option(ENABLE_TEST_TRANSPORT "Enable the test transport" OFF) option(ENABLE_TESTS "Build all client tests and test support" OFF)
add_feature_info(ENABLE_TEST_TRANSPORT ENABLE_TEST_TRANSPORT add_feature_info(ENABLE_TESTS ENABLE_TESTS
"Synthetic frames for graphics-pipeline validation.") "Client unit and integration tests with synthetic transport support.")
if(ENABLE_TEST_TRANSPORT) if(ENABLE_TESTS)
add_definitions(-D ENABLE_TEST_TRANSPORT) if(NOT ENABLE_EGL)
endif() message(FATAL_ERROR "ENABLE_TESTS requires ENABLE_EGL")
endif()
option(ENABLE_RENDER_TESTS "Build framebuffer rendering integration tests" OFF) add_definitions(-D ENABLE_TESTS)
add_feature_info(ENABLE_RENDER_TESTS ENABLE_RENDER_TESTS
"Pixel-accurate EGL rendering tests using the test transport.")
option(ENABLE_TRANSPORT_TESTS "Build transport integration tests"
${ENABLE_RENDER_TESTS})
add_feature_info(ENABLE_TRANSPORT_TESTS ENABLE_TRANSPORT_TESTS
"Transport lifecycle and protocol integration tests.")
if(ENABLE_RENDER_TESTS AND NOT ENABLE_TEST_TRANSPORT)
message(FATAL_ERROR "ENABLE_RENDER_TESTS requires ENABLE_TEST_TRANSPORT")
endif()
if(ENABLE_RENDER_TESTS AND NOT ENABLE_EGL)
message(FATAL_ERROR "ENABLE_RENDER_TESTS requires ENABLE_EGL")
endif() endif()
option(ENABLE_BACKTRACE "Enable backtrace support on crash" ON) option(ENABLE_BACKTRACE "Enable backtrace support on crash" ON)
@@ -249,7 +238,7 @@ target_link_libraries(looking-glass-client
cimgui cimgui
) )
if(ENABLE_RENDER_TESTS OR ENABLE_TRANSPORT_TESTS) if(ENABLE_TESTS)
include(CTest) include(CTest)
enable_testing() enable_testing()
add_subdirectory(tests) add_subdirectory(tests)

View File

@@ -69,7 +69,7 @@
#include "render_queue.h" #include "render_queue.h"
#include "evdev.h" #include "evdev.h"
#ifdef ENABLE_TEST_TRANSPORT #ifdef ENABLE_TESTS
#include "interface/test_capture.h" #include "interface/test_capture.h"
_Static_assert((int)LG_CAPTURE_RGBA8 == (int)LG_TEST_CAPTURE_RGBA8, _Static_assert((int)LG_CAPTURE_RGBA8 == (int)LG_TEST_CAPTURE_RGBA8,
"capture format mismatch"); "capture format mismatch");
@@ -99,7 +99,7 @@ struct CursorState g_cursor;
// this structure is initialized in config.c // this structure is initialized in config.c
struct AppParams g_params = { 0 }; struct AppParams g_params = { 0 };
#ifdef ENABLE_TEST_TRANSPORT #ifdef ENABLE_TESTS
static struct static struct
{ {
const char * path; const char * path;
@@ -205,7 +205,7 @@ static void preSwapCallback(void * udata)
ringbuffer_push(g_state.renderDuration, ringbuffer_push(g_state.renderDuration,
&(float) {(nanotime() - *renderStart) * 1e-6f}); &(float) {(nanotime() - *renderStart) * 1e-6f});
#ifdef ENABLE_TEST_TRANSPORT #ifdef ENABLE_TESTS
if (!l_testCapture.enabled || l_testCapture.complete) if (!l_testCapture.enabled || l_testCapture.complete)
return; return;
@@ -713,7 +713,7 @@ int main_frameThread(void * unused)
g_state.formatValid = true; g_state.formatValid = true;
formatVersion = format->version; formatVersion = format->version;
#ifdef ENABLE_TEST_TRANSPORT #ifdef ENABLE_TESTS
atomic_store_explicit(&l_testFrameType, format->type, atomic_store_explicit(&l_testFrameType, format->type,
memory_order_release); memory_order_release);
#endif #endif
@@ -803,7 +803,7 @@ int main_frameThread(void * unused)
g_state.lastFrameTimeValid = true; g_state.lastFrameTimeValid = true;
atomic_fetch_add_explicit(&g_state.frameCount, 1, memory_order_relaxed); atomic_fetch_add_explicit(&g_state.frameCount, 1, memory_order_relaxed);
#ifdef ENABLE_TEST_TRANSPORT #ifdef ENABLE_TESTS
atomic_store_explicit(&l_testFrameSerial, frame.serial, atomic_store_explicit(&l_testFrameSerial, frame.serial,
memory_order_release); memory_order_release);
#endif #endif
@@ -1211,7 +1211,7 @@ static int transportSessionProbe(void * opaque)
static int lg_run(void) static int lg_run(void)
{ {
#ifdef ENABLE_TEST_TRANSPORT #ifdef ENABLE_TESTS
memset(&l_testCapture, 0, sizeof(l_testCapture)); memset(&l_testCapture, 0, sizeof(l_testCapture));
atomic_store_explicit(&l_testFrameSerial, 0, memory_order_relaxed); atomic_store_explicit(&l_testFrameSerial, 0, memory_order_relaxed);
atomic_store_explicit(&l_testFrameType, FRAME_TYPE_INVALID, atomic_store_explicit(&l_testFrameType, FRAME_TYPE_INVALID,

View File

@@ -17,64 +17,60 @@ set_tests_properties(font-tests PROPERTIES
TIMEOUT 10 TIMEOUT 10
) )
if(ENABLE_TRANSPORT_TESTS) add_executable(lgmp-transport-tests
add_executable(lgmp-transport-tests
lgmp_transport_test.c lgmp_transport_test.c
) )
target_link_libraries(lgmp-transport-tests target_link_libraries(lgmp-transport-tests
${EXE_FLAGS} ${EXE_FLAGS}
transport_LGMP transport_LGMP
lg_common lg_common
lgmp lgmp
) )
add_test(NAME lgmp-transport-tests add_test(NAME lgmp-transport-tests
COMMAND lgmp-transport-tests COMMAND lgmp-transport-tests
) )
set_tests_properties(lgmp-transport-tests PROPERTIES set_tests_properties(lgmp-transport-tests PROPERTIES
TIMEOUT 10 TIMEOUT 10
) )
find_package(GTest REQUIRED)
find_program(WESTON_EXECUTABLE NAMES weston)
if(NOT WESTON_EXECUTABLE)
message(FATAL_ERROR "weston is required to run framebuffer rendering tests")
endif() endif()
if(ENABLE_RENDER_TESTS) add_executable(render-tests
find_package(GTest REQUIRED)
find_program(WESTON_EXECUTABLE NAMES weston)
if(NOT WESTON_EXECUTABLE)
message(FATAL_ERROR "weston is required to run framebuffer rendering tests")
endif()
add_executable(render-tests
render_test.cpp render_test.cpp
) )
add_dependencies(render-tests looking-glass-client) add_dependencies(render-tests looking-glass-client)
set_target_properties(render-tests PROPERTIES set_target_properties(render-tests PROPERTIES
CXX_STANDARD 17 CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON CXX_STANDARD_REQUIRED ON
) )
target_compile_definitions(render-tests PRIVATE target_compile_definitions(render-tests PRIVATE
LG_CLIENT_PATH="$<TARGET_FILE:looking-glass-client>" LG_CLIENT_PATH="$<TARGET_FILE:looking-glass-client>"
) )
target_include_directories(render-tests PRIVATE target_include_directories(render-tests PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/../include" "${CMAKE_CURRENT_SOURCE_DIR}/../include"
"${PROJECT_TOP}/common/include" "${PROJECT_TOP}/common/include"
) )
if(TARGET GTest::gtest_main) if(TARGET GTest::gtest_main)
target_link_libraries(render-tests GTest::gtest_main) target_link_libraries(render-tests GTest::gtest_main)
else() else()
target_link_libraries(render-tests GTest::Main) target_link_libraries(render-tests GTest::Main)
endif() endif()
add_test(NAME render-tests add_test(NAME render-tests
COMMAND /bin/bash COMMAND /bin/bash
"${CMAKE_CURRENT_SOURCE_DIR}/run-with-weston.sh" "${CMAKE_CURRENT_SOURCE_DIR}/run-with-weston.sh"
"${WESTON_EXECUTABLE}" "${WESTON_EXECUTABLE}"
"$<TARGET_FILE:render-tests>" "$<TARGET_FILE:render-tests>"
) )
set_tests_properties(render-tests PROPERTIES set_tests_properties(render-tests PROPERTIES
TIMEOUT 120 TIMEOUT 120
) )
endif()

View File

@@ -22,14 +22,13 @@ luminance, MaxCLL, and MaxFALL in the client log.
```sh ```sh
cmake -S client -B client/build \ cmake -S client -B client/build \
-DENABLE_TEST_TRANSPORT=ON \ -DENABLE_TESTS=ON
-DENABLE_RENDER_TESTS=ON
cmake --build client/build cmake --build client/build
ctest --test-dir client/build --output-on-failure \ ctest --test-dir client/build --output-on-failure \
-R render-tests -R render-tests
``` ```
GoogleTest and Weston are required when `ENABLE_RENDER_TESTS` is enabled. GoogleTest and Weston are required when `ENABLE_TESTS` is enabled.
Failed cases retain their capture and client log under `/tmp` and print the Failed cases retain their capture and client log under `/tmp` and print the
artifact paths. artifact paths.

View File

@@ -20,7 +20,7 @@ endfunction()
# Add/remove transports here! # Add/remove transports here!
add_transport(LGMP) add_transport(LGMP)
if(ENABLE_TEST_TRANSPORT) if(ENABLE_TESTS)
add_transport(Test) add_transport(Test)
endif() endif()