Files
MobileGL/tools/trace_replay/CMakeLists.txt
T
swung0x48andClaude Opus 5 ea9fc7fa71 [MG_Remote] (P6/cp): a real trace retraces across two processes, pixel-for-pixel
OpenRA.DirectGLES.SPAWN is green: ssim=1.000000, mismatchPixels=0, zero
Fatal{ lines, against a server in a process the client started by name. The
inproc SPLIT arm stays beside it as the control, so "did the transport break
it" and "did the phase break it" remain separately answerable.

Five defects stood between the handshake and that picture. Each one was
silent in its own way, and none of them looked like what it was.

1. THE DOORBELL COULD NOT WAKE ITSELF. SocketDoorbell's one-fd form sends on
   the end it polls, so a write is delivered to the PEER - correct for waking
   the other process, useless for waking a thread in this one. The server's
   control pump posts into the apply thread's mailbox and must ring the bell
   that thread parks on. Symptom: every eglInitialize crossed, landed in the
   mailbox, and timed out at 5 s. The two-fd form (park on [0], notify on [1])
   is restored here, and the bell handover goes from two descriptors to THREE
   - the client needs the same split for the same reason. Seven offers now.

2. InitCapabilities HAD NO WIRE KIND. CONTRACT-P6 §2 predicted this exactly
   ("the request has a live client caller and the codec refuses to encode
   it"). SurfaceOpKind gains 11, append-only; the decode range's upper bound
   moves with it, or the new tag reads as out-of-range and surfaces as
   Fatal{ProtocolCorruption} rather than the missing row it is. The op's name
   loses its InprocOnly suffix, which stopped being true here.

3. THE CHILD LOADED NO CONFIG AT ALL. mobilegl_server_main calls
   InitServerRoleForSpawn directly, and MG_ConfigLoader::Init is a step of
   MobileGL::Initialize - so every MG_Config value in the server was its
   static default. MOBILEGL_BACKEND_TYPE survives the launcher's scrub on
   purpose and was read by nobody: a DirectVulkan session would have brought
   up a DirectGLES server and then disagreed with its client about which
   backend the capability mask describes.

4. AND THEREFORE Transport READ AS Monolith, which CONTRACT-P6 §3.1 (D1)
   forbids in as many words. a6 measured the cost: 226 live lines test
   `Transport != Monolith` to select the SERVER arm, 148 in MG_Backend.
   Monolith flips all of them to frontend glue in the one process with no
   frontend. Observed precisely as predicted - UnitTexturesByHandle() answered
   false, Clear took the legacy arm that dereferences borrowed FRONTEND slot
   pointers, and the apply thread took a SIGSEGV inside SyncNeccessaryTextures
   on the first Clear record of the trace. It is pinned in-process rather than
   through the environment because the environment is where it must NOT be:
   LooksLikeAClientEnvironment exits 65 on a surviving MOBILEGL_TRANSPORT, and
   that check is anti-recursion catch (b). Dial, not Transport, is that axis.

5. THE LOG WAS CORRUPT, NOT MERELY INTERLEAVED. Two processes opened the same
   MOBILEGL_LOG_FILE_PATH with "w" and each carried its OWN file offset, so
   they overwrote each other's bytes - half-lines like `ote client: CapsMirror
   generation 1 adopted`, and the server's whole startup block vanishing under
   the client's later writes. This cost real diagnosis time twice, because a
   missing line read as a code path not taken. O_APPEND now; the client still
   truncates once so a fresh run is not a pile of old ones, and the server
   never does - it would delete the very startup lines a failed session needs.
   run_trace_case.cmake's Fatal{ census reads exactly this file, so it was
   also reading a lie.

The retrace runner's split assertions become transport-aware: one row per
transport it admits, and a transport with no row is a FATAL rather than a
fall-through, because the fall-through is the accident the block exists to
prevent. The spawn row carries a SECOND sentence and it is the stronger half
- ConfigLoader's marker proves the value RESOLVED, while `spawn ARMED - the
server role runs in pid N` is written only after the launch, the connect and
the handshake all succeeded, and carries a pid that is not this process's.
inproc resolves its own marker while running the server role on a thread
here; nothing on that path can write this one.

G14: one test name added (TheEleventhFramedOpIsInitCapabilitiesAndItCrosses-
TheWire), none removed. The ten-op table keeps its name and its scope rather
than being renamed to eleven.

Two unit failures predate this change and are environmental in this tree:
PipeCatalogue.FrontendNeverTakesAnApplierAddress (the frontend source root
resolves empty) and SessionHandshakeTest.TheAbiFingerprintChangesWhenAnyOf-
ItsInputsDoes (GIT_COMMIT_HASH_SHORT is empty here, which a6 already recorded
as red in this configuration).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-21 12:23:41 -04:00

495 lines
23 KiB
CMake

cmake_minimum_required(VERSION 3.22.1)
if(NOT UNIX OR ANDROID)
message(STATUS "MobileGL trace replay runner is only enabled on desktop Unix")
return()
endif()
set(MOBILEGL_TRACE_ROOT "${CMAKE_CURRENT_LIST_DIR}")
set(MOBILEGL_TRACE_SHARED_CPP_DIR "${CMAKE_SOURCE_DIR}/android-plugin/app/src/trace/cpp")
set(APITRACE_ROOT "${CMAKE_SOURCE_DIR}/3rdparty/apitrace")
set(APITRACE_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/apitrace")
set(APITRACE_VERSION "mobilegl-trace")
set(MOBILEGL_TRACE_REPLAY_MOBILEGL_LIBRARY "" CACHE FILEPATH "Existing libMobileGL.so to use for trace replay tests")
find_package(Python3 REQUIRED)
find_package(Threads REQUIRED)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include("${APITRACE_ROOT}/cmake/ConvenienceLibrary.cmake")
function(target_optimize TARGET)
target_compile_definitions(${TARGET} PRIVATE -DNDEBUG)
target_compile_options(${TARGET} PRIVATE -O3)
endfunction()
function(include_with_scope)
include(${ARGV})
endfunction()
set(BUILD_TESTING OFF CACHE BOOL "" FORCE)
set(ENABLE_STATIC_SNAPPY ON CACHE BOOL "" FORCE)
set(DOC_INSTALL_DIR "doc" CACHE PATH "" FORCE)
set(HAVE_X86 OFF CACHE BOOL "" FORCE)
set(ZLIB_FOUND OFF CACHE BOOL "" FORCE)
set(PNG_FOUND OFF CACHE BOOL "" FORCE)
set(Snappy_FOUND OFF CACHE BOOL "" FORCE)
set(BROTLIDEC_FOUND OFF CACHE BOOL "" FORCE)
set(BROTLIENC_FOUND OFF CACHE BOOL "" FORCE)
set(ZSTD_FOUND OFF CACHE BOOL "" FORCE)
if(NOT TARGET check)
add_custom_target(check)
endif()
add_subdirectory("${APITRACE_ROOT}/thirdparty" "${APITRACE_BINARY_DIR}/thirdparty")
set(APITRACE_GENERATED_DIR "${APITRACE_BINARY_DIR}/generated")
file(MAKE_DIRECTORY "${APITRACE_GENERATED_DIR}")
configure_file("${APITRACE_ROOT}/version.h.in" "${APITRACE_GENERATED_DIR}/version.h" @ONLY)
add_custom_command(
OUTPUT
"${APITRACE_GENERATED_DIR}/glproc.hpp"
"${APITRACE_GENERATED_DIR}/glproc.cpp"
COMMAND ${Python3_EXECUTABLE}
"${APITRACE_ROOT}/dispatch/glproc.py"
"${APITRACE_GENERATED_DIR}/glproc.hpp"
"${APITRACE_GENERATED_DIR}/glproc.cpp"
DEPENDS
"${APITRACE_ROOT}/dispatch/glproc.py"
"${APITRACE_ROOT}/dispatch/dispatch.py"
"${APITRACE_ROOT}/specs/wglapi.py"
"${APITRACE_ROOT}/specs/glxapi.py"
"${APITRACE_ROOT}/specs/cglapi.py"
"${APITRACE_ROOT}/specs/eglapi.py"
"${APITRACE_ROOT}/specs/glapi.py"
"${APITRACE_ROOT}/specs/gltypes.py"
"${APITRACE_ROOT}/specs/stdapi.py")
add_library(mobilegl_trace_apitrace_os STATIC
"${APITRACE_ROOT}/lib/os/os_backtrace.cpp"
"${APITRACE_ROOT}/lib/os/os_crtdbg.cpp"
"${APITRACE_ROOT}/lib/os/os_posix.cpp")
target_include_directories(mobilegl_trace_apitrace_os PUBLIC
"${APITRACE_ROOT}/compat"
"${APITRACE_ROOT}/thirdparty"
"${APITRACE_ROOT}/lib/os"
"${APITRACE_ROOT}/lib/trace")
target_link_libraries(mobilegl_trace_apitrace_os PUBLIC Threads::Threads)
add_library(mobilegl_trace_highlight STATIC "${APITRACE_ROOT}/lib/highlight/highlight.cpp")
target_include_directories(mobilegl_trace_highlight PUBLIC "${APITRACE_ROOT}/lib/highlight")
add_library(mobilegl_trace_guids STATIC "${APITRACE_ROOT}/lib/guids/guids.cpp")
target_include_directories(mobilegl_trace_guids PUBLIC
"${APITRACE_ROOT}/lib/guids"
"${APITRACE_ROOT}/lib/os")
add_library(mobilegl_trace_image STATIC
"${APITRACE_ROOT}/lib/image/image_bmp.cpp"
"${APITRACE_ROOT}/lib/image/image_png.cpp"
"${APITRACE_ROOT}/lib/image/image_pnm.cpp"
"${APITRACE_ROOT}/lib/image/image_raw.cpp"
"${APITRACE_ROOT}/lib/image/image_md5.cpp")
target_include_directories(mobilegl_trace_image PUBLIC "${APITRACE_ROOT}/lib/image")
target_link_libraries(mobilegl_trace_image PUBLIC md5 PNG::PNG)
add_library(mobilegl_trace_common STATIC
"${APITRACE_ROOT}/lib/trace/trace_callset.cpp"
"${APITRACE_ROOT}/lib/trace/trace_dump.cpp"
"${APITRACE_ROOT}/lib/trace/trace_fast_callset.cpp"
"${APITRACE_ROOT}/lib/trace/trace_file.cpp"
"${APITRACE_ROOT}/lib/trace/trace_file_read.cpp"
"${APITRACE_ROOT}/lib/trace/trace_file_zlib.cpp"
"${APITRACE_ROOT}/lib/trace/trace_file_brotli.cpp"
"${APITRACE_ROOT}/lib/trace/trace_file_snappy.cpp"
"${APITRACE_ROOT}/lib/trace/trace_file_zstd.cpp"
"${APITRACE_ROOT}/lib/trace/trace_file_zstd_seekable.cpp"
"${APITRACE_ROOT}/lib/trace/trace_model.cpp"
"${APITRACE_ROOT}/lib/trace/trace_option.cpp"
"${APITRACE_ROOT}/lib/trace/trace_ostream_snappy.cpp"
"${APITRACE_ROOT}/lib/trace/trace_ostream_zlib.cpp"
"${APITRACE_ROOT}/lib/trace/trace_ostream_zstd.cpp"
"${APITRACE_ROOT}/lib/trace/trace_parser.cpp"
"${APITRACE_ROOT}/lib/trace/trace_parser_flags.cpp"
"${APITRACE_ROOT}/lib/trace/trace_parser_loop.cpp"
"${APITRACE_ROOT}/lib/trace/trace_profiler.cpp"
"${APITRACE_ROOT}/lib/trace/trace_writer.cpp"
"${APITRACE_ROOT}/lib/trace/trace_writer_local.cpp"
"${APITRACE_ROOT}/lib/trace/trace_writer_model.cpp")
target_include_directories(mobilegl_trace_common PUBLIC
"${APITRACE_ROOT}/compat"
"${APITRACE_ROOT}/thirdparty"
"${APITRACE_ROOT}/lib/guids"
"${APITRACE_ROOT}/lib/highlight"
"${APITRACE_ROOT}/lib/os"
"${APITRACE_ROOT}/lib/trace"
"${APITRACE_ROOT}/lib/ubjson")
target_link_libraries(mobilegl_trace_common PUBLIC
mobilegl_trace_guids
mobilegl_trace_highlight
mobilegl_trace_apitrace_os
Snappy::snappy
ZLIB::ZLIB
PkgConfig::BROTLIDEC
PkgConfig::ZSTD
zstd_seekable)
add_library(mobilegl_trace_glproc STATIC
"${APITRACE_GENERATED_DIR}/glproc.cpp"
"${MOBILEGL_TRACE_ROOT}/apitrace_glproc_mobilegl.cpp")
if(APPLE)
target_compile_definitions(mobilegl_trace_glproc PRIVATE GL_SILENCE_DEPRECATION)
endif()
target_include_directories(mobilegl_trace_glproc PUBLIC
"${CMAKE_SOURCE_DIR}/include"
"${APITRACE_GENERATED_DIR}"
"${APITRACE_ROOT}/dispatch"
"${APITRACE_ROOT}/lib/os"
"${APITRACE_ROOT}/thirdparty/khronos")
target_link_libraries(mobilegl_trace_glproc PUBLIC mobilegl_trace_apitrace_os ${CMAKE_DL_LIBS})
execute_process(
COMMAND ${Python3_EXECUTABLE} "${APITRACE_ROOT}/retrace/glretrace.py"
OUTPUT_FILE "${APITRACE_GENERATED_DIR}/glretrace_gl.cpp"
COMMAND_ERROR_IS_FATAL ANY)
execute_process(
COMMAND ${Python3_EXECUTABLE} "${APITRACE_ROOT}/retrace/glstate_params.py"
OUTPUT_FILE "${APITRACE_GENERATED_DIR}/glstate_params.cpp"
COMMAND_ERROR_IS_FATAL ANY)
add_library(mobilegl_trace_glhelpers STATIC
"${APITRACE_ROOT}/helpers/glfeatures.cpp"
"${APITRACE_ROOT}/helpers/eglsize.cpp")
target_include_directories(mobilegl_trace_glhelpers PUBLIC
"${APITRACE_GENERATED_DIR}"
"${APITRACE_ROOT}/dispatch"
"${APITRACE_ROOT}/helpers"
"${APITRACE_ROOT}/lib/os"
"${APITRACE_ROOT}/thirdparty/khronos")
target_link_libraries(mobilegl_trace_glhelpers PUBLIC mobilegl_trace_glproc mobilegl_trace_apitrace_os)
add_library(mobilegl_trace_retrace_common STATIC
"${APITRACE_ROOT}/retrace/json.cpp"
"${APITRACE_ROOT}/retrace/process_name.cpp"
"${APITRACE_ROOT}/retrace/retrace.cpp"
"${APITRACE_ROOT}/retrace/retrace_main.cpp"
"${APITRACE_ROOT}/retrace/retrace_stdc.cpp"
"${APITRACE_ROOT}/retrace/retrace_swizzle.cpp"
"${APITRACE_ROOT}/retrace/state_writer.cpp"
"${APITRACE_ROOT}/retrace/state_writer_json.cpp"
"${APITRACE_ROOT}/retrace/state_writer_ubjson.cpp"
"${APITRACE_ROOT}/retrace/ws.cpp")
target_compile_definitions(mobilegl_trace_retrace_common PUBLIC RETRACE)
target_compile_definitions(mobilegl_trace_retrace_common PRIVATE
exit=mobilegl_apitrace_exit
main=mobilegl_apitrace_main)
target_compile_options(mobilegl_trace_retrace_common PRIVATE "-include${MOBILEGL_TRACE_SHARED_CPP_DIR}/apitrace_exit.hpp")
target_include_directories(mobilegl_trace_retrace_common PUBLIC
"${APITRACE_GENERATED_DIR}"
"${APITRACE_ROOT}/compat"
"${APITRACE_ROOT}/dispatch"
"${APITRACE_ROOT}/helpers"
"${APITRACE_ROOT}/lib/highlight"
"${APITRACE_ROOT}/lib/image"
"${APITRACE_ROOT}/lib/os"
"${APITRACE_ROOT}/lib/trace"
"${APITRACE_ROOT}/lib/ubjson"
"${APITRACE_ROOT}/retrace"
"${APITRACE_ROOT}/thirdparty"
"${APITRACE_ROOT}/thirdparty/khronos")
target_link_libraries(mobilegl_trace_retrace_common PUBLIC mobilegl_trace_image mobilegl_trace_common)
add_library(mobilegl_trace_glretrace_common STATIC
"${APITRACE_GENERATED_DIR}/glretrace_gl.cpp"
"${APITRACE_GENERATED_DIR}/glstate_params.cpp"
"${APITRACE_ROOT}/retrace/glretrace_cgl.cpp"
"${APITRACE_ROOT}/retrace/glretrace_egl.cpp"
"${APITRACE_ROOT}/retrace/glretrace_glx.cpp"
"${APITRACE_ROOT}/retrace/glretrace_main.cpp"
"${APITRACE_ROOT}/retrace/glretrace_wgl.cpp"
"${APITRACE_ROOT}/retrace/glretrace_wgl_font_bitmaps.cpp"
"${APITRACE_ROOT}/retrace/glretrace_wgl_font_outlines.cpp"
"${APITRACE_ROOT}/retrace/glretrace_ws.cpp"
"${APITRACE_ROOT}/retrace/glstate.cpp"
"${APITRACE_ROOT}/retrace/glstate_formats.cpp"
"${APITRACE_ROOT}/retrace/glstate_images.cpp"
"${APITRACE_ROOT}/retrace/glstate_shaders.cpp"
"${APITRACE_ROOT}/retrace/glws.cpp"
"${APITRACE_ROOT}/retrace/metric_backend_amd_perfmon.cpp"
"${APITRACE_ROOT}/retrace/metric_backend_intel_perfquery.cpp"
"${APITRACE_ROOT}/retrace/metric_backend_opengl.cpp"
"${APITRACE_ROOT}/retrace/metric_helper.cpp"
"${APITRACE_ROOT}/retrace/metric_writer.cpp"
"${MOBILEGL_TRACE_ROOT}/apitrace_fbo_dump.cpp"
"${MOBILEGL_TRACE_ROOT}/apitrace_glws_egl.cpp"
"${MOBILEGL_TRACE_SHARED_CPP_DIR}/trace_benchmark.cpp")
if(APPLE)
set(MOBILEGL_TRACE_APPLE_FRAMEWORKS
"-framework Cocoa"
"-framework QuartzCore"
"-framework Foundation")
target_sources(mobilegl_trace_glretrace_common PRIVATE
"${MOBILEGL_TRACE_ROOT}/macos_cgs_surface_bounds.cpp")
target_compile_definitions(mobilegl_trace_glretrace_common PRIVATE GL_SILENCE_DEPRECATION)
endif()
target_include_directories(mobilegl_trace_glretrace_common PUBLIC
"${APITRACE_GENERATED_DIR}"
"${APITRACE_ROOT}/dispatch"
"${APITRACE_ROOT}/helpers"
"${APITRACE_ROOT}/retrace"
"${MOBILEGL_TRACE_SHARED_CPP_DIR}")
target_compile_definitions(mobilegl_trace_glretrace_common PRIVATE
exit=mobilegl_apitrace_exit
main=mobilegl_apitrace_main)
target_compile_options(mobilegl_trace_glretrace_common PRIVATE "-include${MOBILEGL_TRACE_SHARED_CPP_DIR}/apitrace_exit.hpp")
target_link_libraries(mobilegl_trace_glretrace_common PUBLIC
mobilegl_trace_retrace_common
mobilegl_trace_glhelpers
mobilegl_trace_glproc)
add_executable(mobilegl_trace_replay
"${MOBILEGL_TRACE_SHARED_CPP_DIR}/trace_replay_core.cpp"
"${MOBILEGL_TRACE_ROOT}/trace_replay_cli.cpp")
target_compile_features(mobilegl_trace_replay PRIVATE cxx_std_17)
target_compile_definitions(mobilegl_trace_replay PRIVATE
MOBILEGL_APITRACE_RETRACE_MAIN=mobilegl_apitrace_main)
target_include_directories(mobilegl_trace_replay PRIVATE
"${MOBILEGL_TRACE_SHARED_CPP_DIR}"
"${APITRACE_ROOT}/lib/image")
set(MOBILEGL_TRACE_REPLAY_LINK_LIBRARIES
mobilegl_trace_glretrace_common
mobilegl_trace_retrace_common
mobilegl_trace_image
mobilegl_trace_common
mobilegl_trace_glhelpers
mobilegl_trace_glproc
mobilegl_trace_apitrace_os
${CMAKE_DL_LIBS})
if(APPLE)
target_link_libraries(mobilegl_trace_replay PRIVATE
${MOBILEGL_TRACE_REPLAY_LINK_LIBRARIES}
${MOBILEGL_TRACE_APPLE_FRAMEWORKS})
else()
target_link_libraries(mobilegl_trace_replay PRIVATE
"-Wl,--start-group"
${MOBILEGL_TRACE_REPLAY_LINK_LIBRARIES}
"-Wl,--end-group")
endif()
# The `K=V;K=V` environment passthrough is the only hand-rolled parse between a CI flag
# and setenv(), and the lane that exercises it end to end is an on-device retrace, which
# would report a splitting bug as "the knob had no effect". This pins it instead, in the
# cheapest place that no configuration can skip: the check is built and RUN at build time,
# and mobilegl_trace_replay depends on it, so `cmake --build ... --target
# mobilegl_trace_replay` - the exact command of test.yml's "Build trace replay" - runs it
# even though that job never invokes ctest.
if(NOT CMAKE_CROSSCOMPILING)
add_executable(mobilegl_trace_env_overrides_test
"${MOBILEGL_TRACE_ROOT}/trace_env_overrides_test.cpp")
target_compile_features(mobilegl_trace_env_overrides_test PRIVATE cxx_std_17)
target_include_directories(mobilegl_trace_env_overrides_test PRIVATE
"${MOBILEGL_TRACE_SHARED_CPP_DIR}")
add_custom_command(TARGET mobilegl_trace_env_overrides_test POST_BUILD
COMMAND mobilegl_trace_env_overrides_test
COMMENT "Checking the retrace env passthrough parser")
add_dependencies(mobilegl_trace_replay mobilegl_trace_env_overrides_test)
add_executable(mobilegl_trace_replay_lease_test
"${MOBILEGL_TRACE_ROOT}/trace_replay_lease_test.cpp")
target_compile_features(mobilegl_trace_replay_lease_test PRIVATE cxx_std_17)
target_include_directories(mobilegl_trace_replay_lease_test PRIVATE
"${MOBILEGL_TRACE_SHARED_CPP_DIR}")
target_link_libraries(mobilegl_trace_replay_lease_test PRIVATE Threads::Threads)
add_custom_command(TARGET mobilegl_trace_replay_lease_test POST_BUILD
COMMAND mobilegl_trace_replay_lease_test
COMMENT "Checking process ownership of native trace replay")
add_dependencies(mobilegl_trace_replay mobilegl_trace_replay_lease_test)
endif()
if(MOBILEGL_TRACE_REPLAY_MOBILEGL_LIBRARY)
set(mobilegl_trace_replay_mobilegl_library "${MOBILEGL_TRACE_REPLAY_MOBILEGL_LIBRARY}")
else()
set(mobilegl_trace_replay_mobilegl_library "$<TARGET_FILE:MobileGL>")
add_dependencies(mobilegl_trace_replay MobileGL)
endif()
enable_testing()
function(add_trace_replay_test CASE_NAME BACKEND)
set(oneValueArgs
TRACE_ARCHIVE
TRACE_FILE
GOLDEN
ALTERNATE_GOLDEN
TARGET_CALL
WIDTH
HEIGHT
SSIM_THRESHOLD
CROP_X
CROP_Y
CROP_WIDTH
CROP_HEIGHT
COHERENT_AS_FLUSH
# P5. VARIANT is a NAME SUFFIX and TRANSPORT is what the variant runs with; passing
# TRANSPORT without VARIANT is a configure error below, because add_test with a
# duplicate NAME is a hard CMake error and the collision is with the very case this
# entry is a second arm of.
VARIANT
TRANSPORT
IPC_SERVER_PATH)
cmake_parse_arguments(TRACE_CASE "" "${oneValueArgs}" "" ${ARGN})
foreach(required TRACE_ARCHIVE GOLDEN TARGET_CALL WIDTH HEIGHT)
if(NOT TRACE_CASE_${required})
message(FATAL_ERROR "${required} is required for ${CASE_NAME}")
endif()
endforeach()
if(NOT TRACE_CASE_TRACE_FILE)
set(TRACE_CASE_TRACE_FILE trace.trace)
endif()
if(NOT TRACE_CASE_SSIM_THRESHOLD)
set(TRACE_CASE_SSIM_THRESHOLD 0.99)
endif()
if(NOT TRACE_CASE_CROP_X)
set(TRACE_CASE_CROP_X 0)
endif()
if(NOT TRACE_CASE_CROP_Y)
set(TRACE_CASE_CROP_Y 0)
endif()
if(NOT TRACE_CASE_CROP_WIDTH)
set(TRACE_CASE_CROP_WIDTH 0)
endif()
if(NOT TRACE_CASE_CROP_HEIGHT)
set(TRACE_CASE_CROP_HEIGHT 0)
endif()
# --- P5: the variant suffix, and why the OUTPUT DIRECTORIES have to carry it too ----------
#
# ARCHITECTURE.md:584 asks for the SPLIT suffix because without it the entry collides with
# the same case+backend and add_test with a duplicate NAME is a hard CMake error.
#
# THE DIRECTORIES ARE THE HALF THAT IS EASY TO FORGET AND EXPENSIVE TO GET WRONG. Both arms
# of a case write output/mobilegl.log, and run_trace_case.cmake deletes TRACE_OUTPUT_DIR
# before every run - so two arms sharing one directory means the second arm's run erases the
# first arm's log while `ctest -j` may still be reading it, and, worse, the SPLIT arm's
# refusal census is then a census of whichever arm happened to finish last. That log is the
# ONLY valid census: the console sink is compiled out of these configurations, so a `ctest -V`
# transcript reports a FALSE ZERO for Fatal{ lines. P4a shipped exactly that defect once
# already, in a different place. Same argument for TRACE_ARTIFACT_DIR, which is what CI
# uploads.
set(trace_case_suffix "")
set(trace_case_output_tag "${BACKEND}")
set(trace_case_artifact_tag "actual-images")
if(TRACE_CASE_VARIANT)
set(trace_case_suffix ".${TRACE_CASE_VARIANT}")
set(trace_case_output_tag "${BACKEND}-${TRACE_CASE_VARIANT}")
set(trace_case_artifact_tag "actual-images-${TRACE_CASE_VARIANT}")
elseif(TRACE_CASE_TRANSPORT)
message(FATAL_ERROR
"add_trace_replay_test(${CASE_NAME} ${BACKEND} TRANSPORT ${TRACE_CASE_TRANSPORT}) with no "
"VARIANT: the entry would collide with the monolith arm of the same case and backend, and "
"a duplicate add_test NAME is a hard error")
endif()
set(trace_case_name "MobileGLTraceReplay.${CASE_NAME}.${BACKEND}${trace_case_suffix}")
add_test(
NAME ${trace_case_name}
COMMAND "${CMAKE_COMMAND}"
-DTRACE_REPLAY_EXE=$<TARGET_FILE:mobilegl_trace_replay>
-DMOBILEGL_LIBRARY=${mobilegl_trace_replay_mobilegl_library}
-DTRACE_CASE_NAME=${CASE_NAME}
-DTRACE_ARCHIVE=${TRACE_CASE_TRACE_ARCHIVE}
-DTRACE_FILE=${TRACE_CASE_TRACE_FILE}
-DTRACE_GOLDEN=${TRACE_CASE_GOLDEN}
-DTRACE_ALTERNATE_GOLDEN=${TRACE_CASE_ALTERNATE_GOLDEN}
-DTRACE_BACKEND=${BACKEND}
-DTRACE_TARGET_CALL=${TRACE_CASE_TARGET_CALL}
-DTRACE_WIDTH=${TRACE_CASE_WIDTH}
-DTRACE_HEIGHT=${TRACE_CASE_HEIGHT}
-DTRACE_SSIM_THRESHOLD=${TRACE_CASE_SSIM_THRESHOLD}
-DTRACE_CROP_X=${TRACE_CASE_CROP_X}
-DTRACE_CROP_Y=${TRACE_CASE_CROP_Y}
-DTRACE_CROP_WIDTH=${TRACE_CASE_CROP_WIDTH}
-DTRACE_CROP_HEIGHT=${TRACE_CASE_CROP_HEIGHT}
-DTRACE_COHERENT_AS_FLUSH=${TRACE_CASE_COHERENT_AS_FLUSH}
-DTRACE_TRANSPORT=${TRACE_CASE_TRANSPORT}
-DTRACE_IPC_SERVER_PATH=${TRACE_CASE_IPC_SERVER_PATH}
-DTRACE_OUTPUT_DIR=${CMAKE_CURRENT_BINARY_DIR}/${CASE_NAME}/${trace_case_output_tag}
-DTRACE_ARTIFACT_DIR=${CMAKE_CURRENT_BINARY_DIR}/${CASE_NAME}/${trace_case_artifact_tag}
-P ${MOBILEGL_TRACE_ROOT}/run_trace_case.cmake)
# The label list gains `retrace-split` on a variant arm, for the same reason
# integration-split exists: a private second label is what lets `ctest -L retrace-split
# --no-tests=error` go RED in a build that never registered the arm, instead of greenly
# running nothing. `retrace` stays so the existing whole-label selections keep describing the
# whole set. A `;` inside a property value has to be escaped.
set(trace_case_labels retrace)
if(TRACE_CASE_VARIANT)
set(trace_case_labels "retrace\;retrace-${TRACE_CASE_VARIANT}")
string(TOLOWER "${trace_case_labels}" trace_case_labels)
endif()
if(BACKEND STREQUAL "DirectGLES")
set_tests_properties(${trace_case_name} PROPERTIES
ENVIRONMENT "EGL_PLATFORM=surfaceless;LIBGL_ALWAYS_SOFTWARE=1;MESA_GL_VERSION_OVERRIDE=3.3;MESA_GLSL_VERSION_OVERRIDE=330"
LABELS "${trace_case_labels}")
else()
set_tests_properties(${trace_case_name} PROPERTIES
ENVIRONMENT "LIBGL_ALWAYS_SOFTWARE=1;MESA_GL_VERSION_OVERRIDE=3.3;MESA_GLSL_VERSION_OVERRIDE=330"
LABELS "${trace_case_labels}")
endif()
endfunction()
function(add_trace_replay_test_for_backends CASE_NAME)
add_trace_replay_test(${CASE_NAME} DirectGLES ${ARGN})
add_trace_replay_test(${CASE_NAME} DirectVulkan ${ARGN})
endfunction()
# --- P5: the SPLIT arm of the retrace matrix -------------------------------------------------
#
# One variant entry per case that trace_cases.json marks `split: true` - today that is OpenRA
# alone, which is the only target the phase gate names and (measurably) the only fixture hydrated
# locally. DirectGLES only: the split shape's first backend is Espryt, and a DirectVulkan arm
# would be measuring a server nobody has written yet.
#
# REGISTERED ONLY UNDER MOBILEGL_BUILD_DISAGGREGATED, because the arm is a statement about a
# library that compiled MG_Remote. A build without the option accepts MOBILEGL_TRANSPORT=inproc
# and silently ignores it (CONTRACT-P5 5), so an unconditional registration would be an entry
# that passes by running monolith - and run_trace_case.cmake's split block would then be the only
# thing standing between that and a green, which is one guard too few for a name that says SPLIT.
function(add_trace_replay_split_test CASE_NAME)
if(NOT MOBILEGL_BUILD_DISAGGREGATED)
return()
endif()
add_trace_replay_test(${CASE_NAME} DirectGLES VARIANT SPLIT TRANSPORT inproc
IPC_SERVER_PATH "${CMAKE_BINARY_DIR}/libMobileGLServer.so" ${ARGN})
# --- P6: the SPAWN arm, beside the inproc one rather than instead of it ------------------
#
# TWO ARMS, NOT ONE RENAMED. The inproc arm is the CONTROL: it is the same
# library, the same codec, the same applier and the same picture, with the
# only difference being which process the server role runs in. A spawn arm
# that had replaced it would have left "did the transport break it?" and
# "did the phase break it?" answerable only together.
#
# G14 is satisfied by construction - a name is added, none is removed - and
# the VARIANT gives it its own output and artifact directories, which is the
# half the comment above says is easy to forget: both arms write
# output/mobilegl.log, and that log is the ONLY valid refusal census because
# the console sink is compiled out of these configurations.
add_trace_replay_test(${CASE_NAME} DirectGLES VARIANT SPAWN TRANSPORT spawn
IPC_SERVER_PATH "${CMAKE_BINARY_DIR}/libMobileGLServer.so" ${ARGN})
endfunction()
set(MOBILEGL_TRACE_CASES_CMAKE "${CMAKE_CURRENT_BINARY_DIR}/trace_cases.cmake")
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${MOBILEGL_TRACE_ROOT}/trace_cases.json")
execute_process(
COMMAND ${Python3_EXECUTABLE} "${MOBILEGL_TRACE_ROOT}/trace_cases.py"
--format cmake
--fixture-root "${MOBILEGL_TRACE_ROOT}/fixtures"
OUTPUT_FILE "${MOBILEGL_TRACE_CASES_CMAKE}"
COMMAND_ERROR_IS_FATAL ANY)
include("${MOBILEGL_TRACE_CASES_CMAKE}")