[Fix] (ci): validate debuggable retrace APKs

This commit is contained in:
2026-06-16 19:31:34 +08:00
parent 19c0ae4e33
commit 4e3679c7b7
5 changed files with 36 additions and 33 deletions
+1 -1
View File
@@ -54,7 +54,7 @@ jobs:
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }} SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
- name: Build retrace APKs - name: Build retrace APKs
run: gradle --no-daemon -p android-plugin :app:assembleEsprytTraceRelease :app:assembleMagmaTraceRelease -Pmobilegl.abis=all --parallel --max-workers "$(nproc)" run: gradle --no-daemon -p android-plugin :app:assembleEsprytTraceRelease :app:assembleMagmaTraceRelease -Pmobilegl.abis=all -Pmobilegl.debuggableRelease=true --parallel --max-workers "$(nproc)"
env: env:
SIGNING_STORE_PASSWORD: ${{ secrets.SIGNING_STORE_PASSWORD }} SIGNING_STORE_PASSWORD: ${{ secrets.SIGNING_STORE_PASSWORD }}
SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }} SIGNING_KEY_ALIAS: ${{ secrets.SIGNING_KEY_ALIAS }}
+2
View File
@@ -17,6 +17,7 @@ def releaseSigningReady = signingStoreFile.exists()
&& signingStorePassword && signingStorePassword
&& signingKeyAlias && signingKeyAlias
&& signingKeyPassword && signingKeyPassword
def debuggableRelease = (findProperty('mobilegl.debuggableRelease') ?: 'false').toString().toBoolean()
def mobileGlAbiFilters = { def mobileGlAbiFilters = {
def abiList = (findProperty('mobilegl.abis') ?: System.getenv('MOBILEGL_ABIS') ?: 'arm64-v8a') as String def abiList = (findProperty('mobilegl.abis') ?: System.getenv('MOBILEGL_ABIS') ?: 'arm64-v8a') as String
if (abiList.equalsIgnoreCase('all')) { if (abiList.equalsIgnoreCase('all')) {
@@ -99,6 +100,7 @@ android {
buildTypes { buildTypes {
release { release {
debuggable debuggableRelease
minifyEnabled false minifyEnabled false
if (releaseSigningReady) { if (releaseSigningReady) {
signingConfig signingConfigs.release signingConfig signingConfigs.release
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> <manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:debuggable="true"> <application>
<activity <activity
android:name=".trace.TraceReplayActivity" android:name=".trace.TraceReplayActivity"
android:exported="true" android:exported="true"
@@ -20,6 +20,11 @@ function(include_with_scope)
include(${ARGV}) include(${ARGV})
endfunction() endfunction()
function(target_redirect_exit TARGET)
target_compile_definitions(${TARGET} PRIVATE exit=mobilegl_apitrace_exit)
target_compile_options(${TARGET} PRIVATE "-include${CMAKE_CURRENT_LIST_DIR}/apitrace_exit.hpp")
endfunction()
set(BUILD_TESTING OFF CACHE BOOL "" FORCE) set(BUILD_TESTING OFF CACHE BOOL "" FORCE)
set(ENABLE_STATIC_SNAPPY ON CACHE BOOL "" FORCE) set(ENABLE_STATIC_SNAPPY ON CACHE BOOL "" FORCE)
set(DOC_INSTALL_DIR "doc" CACHE PATH "" FORCE) set(DOC_INSTALL_DIR "doc" CACHE PATH "" FORCE)
@@ -88,6 +93,7 @@ target_include_directories(apitrace_os PUBLIC
"${APITRACE_ROOT}/lib/os" "${APITRACE_ROOT}/lib/os"
"${APITRACE_ROOT}/lib/trace") "${APITRACE_ROOT}/lib/trace")
target_link_libraries(apitrace_os PUBLIC Threads::Threads) target_link_libraries(apitrace_os PUBLIC Threads::Threads)
target_redirect_exit(apitrace_os)
add_library(highlight STATIC "${APITRACE_ROOT}/lib/highlight/highlight.cpp") add_library(highlight STATIC "${APITRACE_ROOT}/lib/highlight/highlight.cpp")
target_include_directories(highlight PUBLIC "${APITRACE_ROOT}/lib/highlight") target_include_directories(highlight PUBLIC "${APITRACE_ROOT}/lib/highlight")
@@ -146,6 +152,7 @@ target_link_libraries(common PUBLIC
PkgConfig::BROTLIDEC PkgConfig::BROTLIDEC
PkgConfig::ZSTD PkgConfig::ZSTD
zstd_seekable) zstd_seekable)
target_redirect_exit(common)
add_library(glhelpers STATIC add_library(glhelpers STATIC
"${APITRACE_ROOT}/helpers/glfeatures.cpp" "${APITRACE_ROOT}/helpers/glfeatures.cpp"
@@ -171,9 +178,8 @@ add_library(retrace_common STATIC
"${APITRACE_ROOT}/retrace/ws.cpp") "${APITRACE_ROOT}/retrace/ws.cpp")
target_compile_definitions(retrace_common PUBLIC RETRACE) target_compile_definitions(retrace_common PUBLIC RETRACE)
target_compile_definitions(retrace_common PRIVATE target_compile_definitions(retrace_common PRIVATE
exit=mobilegl_apitrace_exit
main=mobilegl_apitrace_main) main=mobilegl_apitrace_main)
target_compile_options(retrace_common PRIVATE "-include${CMAKE_CURRENT_LIST_DIR}/apitrace_exit.hpp") target_redirect_exit(retrace_common)
target_include_directories(retrace_common PUBLIC target_include_directories(retrace_common PUBLIC
"${APITRACE_GENERATED_DIR}" "${APITRACE_GENERATED_DIR}"
"${APITRACE_ROOT}/compat" "${APITRACE_ROOT}/compat"
@@ -219,9 +225,8 @@ target_include_directories(glretrace_common PUBLIC
"${APITRACE_ROOT}/helpers" "${APITRACE_ROOT}/helpers"
"${APITRACE_ROOT}/retrace") "${APITRACE_ROOT}/retrace")
target_compile_definitions(glretrace_common PRIVATE target_compile_definitions(glretrace_common PRIVATE
exit=mobilegl_apitrace_exit
main=mobilegl_apitrace_main) main=mobilegl_apitrace_main)
target_compile_options(glretrace_common PRIVATE "-include${CMAKE_CURRENT_LIST_DIR}/apitrace_exit.hpp") target_redirect_exit(glretrace_common)
target_link_libraries(glretrace_common PUBLIC retrace_common glhelpers glproc) target_link_libraries(glretrace_common PUBLIC retrace_common glhelpers glproc)
add_library(trace_replay_runner SHARED add_library(trace_replay_runner SHARED
+23 -27
View File
@@ -1,6 +1,9 @@
#!/bin/sh #!/bin/sh
set -eu set -eu
ADB="${ADB:-adb}"
PYTHON="${PYTHON:-python3}"
usage() { usage() {
cat <<'EOF' cat <<'EOF'
Usage: Usage:
@@ -120,10 +123,6 @@ test -f "${golden_path}" || die "golden image does not exist: ${golden_path}"
safe_case="$(printf '%s' "${case_name}" | sed 's/[^A-Za-z0-9._-]/_/g')" safe_case="$(printf '%s' "${case_name}" | sed 's/[^A-Za-z0-9._-]/_/g')"
quote_android_path() {
printf '%s' "$1" | sed "s/'/'\\\\''/g"
}
prepare_fixture() { prepare_fixture() {
fixture_dir="${fixture_root}/${safe_case}" fixture_dir="${fixture_root}/${safe_case}"
rm -rf "${fixture_dir}" rm -rf "${fixture_dir}"
@@ -133,22 +132,19 @@ prepare_fixture() {
extracted_trace="${fixture_dir}/${trace_file}" extracted_trace="${fixture_dir}/${trace_file}"
test -f "${extracted_trace}" || die "trace file not found in archive: ${trace_file}" test -f "${extracted_trace}" || die "trace file not found in archive: ${trace_file}"
adb push "${extracted_trace}" "/data/local/tmp/mobilegl-${safe_case}.trace" "${ADB}" push "${extracted_trace}" "/data/local/tmp/mobilegl-${safe_case}.trace"
adb push "${golden_path}" "/data/local/tmp/mobilegl-${safe_case}.golden.png" "${ADB}" push "${golden_path}" "/data/local/tmp/mobilegl-${safe_case}.golden.png"
adb shell chmod 0644 "/data/local/tmp/mobilegl-${safe_case}.trace" "/data/local/tmp/mobilegl-${safe_case}.golden.png" "${ADB}" shell chmod 0644 "/data/local/tmp/mobilegl-${safe_case}.trace" "/data/local/tmp/mobilegl-${safe_case}.golden.png"
} }
copy_fixture_to_app() { copy_fixture_to_app() {
package_name="$1"
trace_tmp="/data/local/tmp/mobilegl-${safe_case}.trace" trace_tmp="/data/local/tmp/mobilegl-${safe_case}.trace"
golden_tmp="/data/local/tmp/mobilegl-${safe_case}.golden.png" golden_tmp="/data/local/tmp/mobilegl-${safe_case}.golden.png"
escaped_trace_tmp="$(quote_android_path "${trace_tmp}")"
escaped_golden_tmp="$(quote_android_path "${golden_tmp}")"
adb shell run-as "${package_name}" rm -rf files/trace-replay "${ADB}" shell run-as "${package_name}" rm -rf files/trace-replay
adb shell run-as "${package_name}" mkdir -p files/trace-replay/input files/trace-replay/output "${ADB}" shell run-as "${package_name}" mkdir -p files/trace-replay/input files/trace-replay/output
adb shell run-as "${package_name}" sh -c "cat '${escaped_trace_tmp}' > files/trace-replay/input/trace.trace" "${ADB}" shell run-as "${package_name}" cp "${trace_tmp}" files/trace-replay/input/trace.trace
adb shell run-as "${package_name}" sh -c "cat '${escaped_golden_tmp}' > files/trace-replay/input/golden.png" "${ADB}" shell run-as "${package_name}" cp "${golden_tmp}" files/trace-replay/input/golden.png
} }
run_retrace() { run_retrace() {
@@ -156,11 +152,11 @@ run_retrace() {
result_dir="${result_root}/${safe_case}-${backend}" result_dir="${result_root}/${safe_case}-${backend}"
mkdir -p "${result_dir}" mkdir -p "${result_dir}"
adb install -r "${apk_file}" "${ADB}" install -r "${apk_file}"
copy_fixture_to_app "${package_name}" copy_fixture_to_app
adb shell am force-stop "${package_name}" "${ADB}" shell am force-stop "${package_name}"
adb logcat -c "${ADB}" logcat -c
adb shell am start -W -a top.mobilegl.plugin.TRACE_REPLAY \ "${ADB}" shell am start -W -a top.mobilegl.plugin.TRACE_REPLAY \
-n "${package_name}/top.mobilegl.plugin.trace.TraceReplayActivity" \ -n "${package_name}/top.mobilegl.plugin.trace.TraceReplayActivity" \
--es trace_path "${app_dir}/input/trace.trace" \ --es trace_path "${app_dir}/input/trace.trace" \
--es golden_path "${app_dir}/input/golden.png" \ --es golden_path "${app_dir}/input/golden.png" \
@@ -178,21 +174,21 @@ run_retrace() {
--ei fuzz_percent "${fuzz_percent}" --ei fuzz_percent "${fuzz_percent}"
for _ in $(seq 1 "${timeout_seconds}"); do for _ in $(seq 1 "${timeout_seconds}"); do
if adb shell run-as "${package_name}" ls files/trace-replay/output/result.json >/dev/null 2>&1; then if "${ADB}" shell run-as "${package_name}" ls files/trace-replay/output/result.json >/dev/null 2>&1; then
break break
fi fi
sleep 1 sleep 1
done done
adb logcat -d -t 1000 > "${result_dir}/logcat.txt" || true "${ADB}" logcat -d -t 1000 > "${result_dir}/logcat.txt" || true
adb shell run-as "${package_name}" ls files/trace-replay/output/result.json "${ADB}" shell run-as "${package_name}" ls files/trace-replay/output/result.json
adb exec-out run-as "${package_name}" cat files/trace-replay/output/result.json > "${result_dir}/result.json" "${ADB}" exec-out run-as "${package_name}" cat files/trace-replay/output/result.json > "${result_dir}/result.json"
cat "${result_dir}/result.json" cat "${result_dir}/result.json"
adb exec-out run-as "${package_name}" cat files/trace-replay/output/actual.png > "${result_dir}/${safe_case}-${backend}-actual.png" "${ADB}" exec-out run-as "${package_name}" cat files/trace-replay/output/actual.png > "${result_dir}/${safe_case}-${backend}-actual.png"
adb exec-out run-as "${package_name}" cat "files/trace-replay/output/${safe_case}-diff.png" > "${result_dir}/${safe_case}-${backend}-diff.png" "${ADB}" exec-out run-as "${package_name}" cat "files/trace-replay/output/${safe_case}-diff.png" > "${result_dir}/${safe_case}-${backend}-diff.png"
adb exec-out run-as "${package_name}" cat files/trace-replay/output/retrace.log > "${result_dir}/retrace.log" || true "${ADB}" exec-out run-as "${package_name}" cat files/trace-replay/output/retrace.log > "${result_dir}/retrace.log" || true
python3 -c 'import json, sys; result = json.load(open(sys.argv[1], encoding="utf-8")); sys.exit(0 if result.get("passed") else f"trace replay failed: {result}")' "${result_dir}/result.json" "${PYTHON}" -c 'import json, sys; result = json.load(open(sys.argv[1], encoding="utf-8")); sys.exit(0 if result.get("passed") else f"trace replay failed: {result}")' "${result_dir}/result.json"
} }
mkdir -p "${fixture_root}" "${result_root}" mkdir -p "${fixture_root}" "${result_root}"