Skip to content

Commit 7d85cf6

Browse files
committed
test(nav3): Verify serial name mappers under R8
1 parent f7b850a commit 7d85cf6

11 files changed

Lines changed: 744 additions & 1 deletion

File tree

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
name: Nav3 BackStackEntryMapper R8 Check
2+
3+
# Verifies behavior of BackStackEntryMapper.SerialName and SerialNameAndProperties
4+
# from sentry-android-navigation3 in R8-minified builds on an emulator (full and compat mode,
5+
# with the compile floor + latest versions of kotlinx.serialization). See
6+
# sentry-android-integration-tests/nav3-backstack-entry-mapper-r8-check/README.md.
7+
8+
on:
9+
push:
10+
branches:
11+
- main
12+
paths:
13+
- "sentry-android-navigation3/**"
14+
- "sentry-android-integration-tests/nav3-backstack-entry-mapper-r8-check/**"
15+
- "sentry-android-integration-tests/*.gradle.kts"
16+
- "scripts/test-nav3-backstack-entry-mapper-r8.sh"
17+
- "scripts/update-nav3-kotlinx-serialization.sh"
18+
- "gradle/libs.versions.toml"
19+
- "gradle/nav3.versions.toml"
20+
- ".github/workflows/integration-tests-nav3-r8.yml"
21+
# Omit PRs that only change gradle/libs.versions.toml so we don't trigger R8 tests on unrelated
22+
# dependency bumps. (Those changes are checked once they reach main.) The kotlinx.serialization
23+
# floor lives in gradle/nav3.versions.toml so that PRs changing it are still checked.
24+
pull_request:
25+
paths:
26+
- "sentry-android-navigation3/**"
27+
- "sentry-android-integration-tests/nav3-backstack-entry-mapper-r8-check/**"
28+
- "sentry-android-integration-tests/*.gradle.kts"
29+
- "scripts/test-nav3-backstack-entry-mapper-r8.sh"
30+
- "scripts/update-nav3-kotlinx-serialization.sh"
31+
- "gradle/nav3.versions.toml"
32+
- ".github/workflows/integration-tests-nav3-r8.yml"
33+
34+
concurrency:
35+
group: ${{ github.workflow }}-${{ github.ref }}
36+
cancel-in-progress: true
37+
38+
env:
39+
APK_DIR: "nav3-r8-check-apks"
40+
APK_ARTIFACT_NAME: "nav3-r8-check-apks"
41+
42+
jobs:
43+
build:
44+
name: Build
45+
runs-on: ubuntu-latest
46+
47+
steps:
48+
- name: Checkout code
49+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
50+
51+
- name: Set up Java
52+
uses: actions/setup-java@b843ebf9b913146b38da2eaa7aeddf76074ae1ad # v6.1.0
53+
with:
54+
distribution: 'temurin'
55+
java-version: '21'
56+
57+
- name: Setup Gradle
58+
uses: gradle/actions/setup-gradle@8da46b539cd8fe6ab27ca75128919a18d757604c # v6.4.1
59+
60+
# Apps may ship a newer kotlinx.serialization than sentry-android-navigation3 compiles
61+
# against, and the properties encoder relies on its experimental AbstractEncoder.
62+
- name: Run unit tests against the latest kotlinx.serialization
63+
run: |
64+
tag="$(./scripts/update-nav3-kotlinx-serialization.sh get-version)"
65+
version="${tag#v}"
66+
./gradlew :sentry-android-navigation3:testReleaseUnitTest -Pnav3TestKotlinxVersion="$version"
67+
68+
- name: Build APKs
69+
run: ./scripts/test-nav3-backstack-entry-mapper-r8.sh build "${{ env.APK_DIR }}"
70+
71+
- name: Upload APK artifact
72+
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7
73+
with:
74+
name: ${{ env.APK_ARTIFACT_NAME }}
75+
path: ${{ env.APK_DIR }}
76+
retention-days: 1
77+
78+
run:
79+
name: Run on API Level ${{ matrix.api-level }}
80+
needs: build
81+
runs-on: ubuntu-latest
82+
strategy:
83+
fail-fast: false
84+
matrix:
85+
# Tests against API 37.0 on every run. Also tests against API 23 (Nav3's minSdkVersion) when changes reach main.
86+
# The latter lets us catch issues present on the oldest Nav3 app runtime without slowing down PRs.
87+
api-level: ${{ fromJSON(github.event_name == 'push' && '[23, "37.0"]' || '["37.0"]') }}
88+
steps:
89+
- name: Checkout code
90+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
91+
92+
- name: Enable KVM
93+
run: |
94+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
95+
sudo udevadm control --reload-rules
96+
sudo udevadm trigger --name-match=kvm
97+
98+
- name: Download APK artifact
99+
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8
100+
with:
101+
name: ${{ env.APK_ARTIFACT_NAME }}
102+
path: ${{ env.APK_DIR }}
103+
104+
# The runner ships an outdated avdmanager that writes target=android-0 into the
105+
# AVD config for minor-versioned packages (android-37.x), so the emulator clamps
106+
# to API 3 and boots misconfigured. Update cmdline-tools so avdmanager parses it.
107+
# See https://github.com/ReactiveCircus/android-emulator-runner/issues/482
108+
- name: Update SDK cmdline-tools
109+
if: matrix.api-level == '37.0'
110+
run: |
111+
SDK="${ANDROID_HOME:-${ANDROID_SDK_ROOT:-/usr/local/lib/android/sdk}}"
112+
yes | "$SDK/cmdline-tools/latest/bin/sdkmanager" --install "cmdline-tools;latest" > /dev/null
113+
# sdkmanager won't overwrite the preinstalled dir, so it installs to latest-2.
114+
if [ -d "$SDK/cmdline-tools/latest-2" ]; then
115+
rm -rf "$SDK/cmdline-tools/latest"
116+
mv "$SDK/cmdline-tools/latest-2" "$SDK/cmdline-tools/latest"
117+
fi
118+
119+
- name: Run check
120+
uses: reactivecircus/android-emulator-runner@a421e43855164a8197daf9d8d40fe71c6996bb0d # pin@v2.38.0
121+
with:
122+
api-level: ${{ matrix.api-level }}
123+
# API 37 has no plain google_apis image.
124+
target: ${{ matrix.api-level == 23 && 'google_apis' || 'google_apis_ps16k' }}
125+
# Use canary for API 37, matching the critical UI tests.
126+
channel: ${{ matrix.api-level == 23 && 'stable' || 'canary' }}
127+
arch: x86_64
128+
disable-animations: true
129+
disable-spellchecker: true
130+
emulator-options: -memory 4096 -no-window -gpu auto -noaudio -no-boot-anim -camera-back none -no-snapshot-save
131+
script: ./scripts/test-nav3-backstack-entry-mapper-r8.sh run "${{ env.APK_DIR }}"

‎Makefile‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: all clean compile javadocs dryRelease update format checkFormat api assembleUiTestRelease assembleUiTestCriticalRelease runUiTestCritical check preMerge publish
1+
.PHONY: all clean compile javadocs dryRelease update format checkFormat api assembleUiTestRelease assembleUiTestCriticalRelease runUiTestCritical runNav3BackStackEntryMapperR8Test check preMerge publish
22

33
all: stop clean javadocs compile
44
assembleUiTests: assembleUiTestRelease
@@ -53,6 +53,11 @@ assembleUiTestCriticalRelease:
5353
runUiTestCritical:
5454
./scripts/test-ui-critical.sh
5555

56+
# Build and run the R8 check for BackStackEntryMapper.SerialName and
57+
# SerialNameAndProperties on a booted emulator
58+
runNav3BackStackEntryMapperR8Test:
59+
./scripts/test-nav3-backstack-entry-mapper-r8.sh
60+
5661
# Run tests and lint
5762
check:
5863
./gradlew check
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
#!/usr/bin/env bash
2+
# Verifies the behavior of BackStackEntryMapper.SerialName and SerialNameAndProperties
3+
# in R8-minified builds on a booted emulator or device. See
4+
# sentry-android-integration-tests/nav3-backstack-entry-mapper-r8-check/README.md.
5+
#
6+
# The app is built against the kotlinxSerializationFloor in gradle/nav3.versions.toml
7+
# plus each version in NAV3_EXTRA_KOTLINX_VERSIONS (default: defaultLatestKotlinx below),
8+
# each in R8 full and compat modes.
9+
#
10+
# Usage:
11+
# test-nav3-backstack-entry-mapper-r8.sh Build all APKs, then run them.
12+
# test-nav3-backstack-entry-mapper-r8.sh build DIR Build all APKs into DIR.
13+
# test-nav3-backstack-entry-mapper-r8.sh run DIR Install and run every APK in DIR.
14+
set -euo pipefail
15+
16+
module="nav3-backstack-entry-mapper-r8-check"
17+
moduleDir="sentry-android-integration-tests/nav3-backstack-entry-mapper-r8-check"
18+
appId="io.sentry.tests.nav3.r8"
19+
tag="NAV3_R8_CHECK"
20+
21+
# Newer kotlinx.serialization versions to also build the app against, on top of the
22+
# kotlinxSerializationFloor. Lets us prevent regressions should host apps ship a newer
23+
# kotlinx.serialization version than we compile against. Also protects us against changes
24+
# to the experimental kotlinx.serialization APIs used by the arguments encoder. Override
25+
# with, e.g., NAV3_EXTRA_KOTLINX_VERSIONS="1.10.0 1.12.0" to test the compile floor,
26+
# 1.10.0, and 1.12.0. (Provide an empty string to test the floor only.)
27+
#
28+
# The latest kotlinx-serialization-core release. Bumped by a weekly PR from
29+
# scripts/update-nav3-kotlinx-serialization.sh (.github/workflows/update-deps.yml).
30+
defaultLatestKotlinx="1.13.0"
31+
extraKotlinxVersions=(${NAV3_EXTRA_KOTLINX_VERSIONS-$defaultLatestKotlinx})
32+
33+
copyApk() {
34+
cp "${moduleDir}/build/outputs/apk/release/nav3-backstack-entry-mapper-r8-check-release.apk" "$1"
35+
}
36+
37+
build() {
38+
local outDir="$1"
39+
mkdir -p "$outDir"
40+
for mode in full compat; do
41+
local fullMode=true
42+
[[ "$mode" == "compat" ]] && fullMode=false
43+
echo "Building R8 $mode mode APK (kotlinx floor)..."
44+
./gradlew -p sentry-android-integration-tests ":${module}:assembleRelease" "-Pandroid.enableR8.fullMode=${fullMode}"
45+
copyApk "${outDir}/${mode}.apk"
46+
47+
# Apps may ship a newer kotlinx than our compile floor, so rebuild against each.
48+
for version in ${extraKotlinxVersions[@]+"${extraKotlinxVersions[@]}"}; do
49+
echo "Building R8 $mode mode APK (kotlinx ${version})..."
50+
./gradlew -p sentry-android-integration-tests ":${module}:assembleRelease" \
51+
"-Pandroid.enableR8.fullMode=${fullMode}" "-Pnav3CheckKotlinxVersion=${version}"
52+
copyApk "${outDir}/${mode}-kotlinx-${version}.apk"
53+
done
54+
done
55+
}
56+
57+
run() {
58+
local apkDir="$1"
59+
local failed=0
60+
shopt -s nullglob
61+
local apks=("$apkDir"/*.apk)
62+
if [[ ${#apks[@]} -eq 0 ]]; then
63+
echo "No APKs found in $apkDir"
64+
exit 1
65+
fi
66+
67+
for apk in "${apks[@]}"; do
68+
local name
69+
name="$(basename "$apk" .apk)"
70+
echo "=== $name"
71+
adb uninstall "$appId" > /dev/null 2>&1 || true
72+
adb install -r -d "$apk" > /dev/null
73+
# Only read lines logged from this launch on, so a stale RESULT=PASS from the previous APK can't
74+
# hide this one's failure. Doesn't clear the log, which would also discard unrelated logs on a
75+
# development device. The timestamp is truncated to the second, so wait a second for it to
76+
# postdate earlier lines.
77+
local since
78+
sleep 1
79+
since="$(adb shell "date +'%m-%d %H:%M:%S.000'" | tr -d '\r')"
80+
adb shell am start -W -n "${appId}/.BackStackEntryMapperActivity" > /dev/null
81+
82+
local output=""
83+
for _ in $(seq 1 60); do
84+
output="$(adb logcat -d -T "$since" -s "${tag}:I" | grep "${tag}" || true)"
85+
if grep -q "RESULT=" <<< "$output"; then
86+
break
87+
fi
88+
if adb logcat -d -T "$since" -b crash | grep -q "$appId"; then
89+
break
90+
fi
91+
sleep 1
92+
done
93+
94+
if [[ -n "$output" ]]; then
95+
sed -E "s/^.*${tag}: //" <<< "$output"
96+
fi
97+
if ! grep -q "RESULT=PASS" <<< "$output"; then
98+
echo "FAILED: $name"
99+
adb logcat -d -T "$since" -b crash | grep -A 20 "$appId" || true
100+
failed=1
101+
fi
102+
done
103+
104+
if [[ $failed -ne 0 ]]; then
105+
echo "Nav3 BackStackEntryMapper R8 check failed."
106+
exit 1
107+
fi
108+
echo "Nav3 BackStackEntryMapper R8 check passed."
109+
}
110+
111+
case "${1:-}" in
112+
build) build "${2:?Usage: $0 build DIR}" ;;
113+
run) run "${2:?Usage: $0 run DIR}" ;;
114+
"")
115+
apkDir="${moduleDir}/build/r8-check-apks"
116+
rm -rf "$apkDir"
117+
build "$apkDir"
118+
run "$apkDir"
119+
;;
120+
*)
121+
echo "Usage: $0 [build DIR | run DIR]"
122+
exit 1
123+
;;
124+
esac
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Script for keeping the Nav3 R8 test up-to-date with new kotlinx.serialization releases.
5+
# Updates defaultLatestKotlinx in scripts/test-nav3-backstack-entry-mapper-r8.sh, which
6+
# adds that version to the test matrix alongside the SDK's pinned compile version.
7+
#
8+
# Run weekly by update-deps.yml. Does not change kotlinxSerializationFloor in
9+
# gradle/nav3.versions.toml.
10+
11+
cd "$(dirname "$0")/../"
12+
SCRIPT_FILEPATH=scripts/test-nav3-backstack-entry-mapper-r8.sh
13+
14+
case $1 in
15+
get-version)
16+
# Printed as the release's tag (e.g. v1.13.0), which the updater uses as the old ref when it
17+
# compares upstream changelogs.
18+
perl -ne 'print "v$1\n" if ( m/^defaultLatestKotlinx="([0-9.]+)"/ )' "$SCRIPT_FILEPATH"
19+
;;
20+
*)
21+
echo "Unknown argument $1"
22+
exit 1
23+
;;
24+
esac
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# nav3-backstack-entry-mapper-r8-check
2+
3+
Verifies that `BackStackEntryMapper.SerialName` and
4+
`BackStackEntryMapper.SerialNameAndProperties` from `sentry-android-navigation3` return expected Sentry names and arguments despite
5+
R8 obfuscation. `sentry-android-navigation3` ships no kotlinx.serialization R8 rules, so the check relies on kotlinx.serialization's own
6+
consumer rules, plus the per-class rules in this app's `proguard-rules.pro` file.
7+
8+
The tests check serialization names, argument encoding, and sensitive-value filtering. They also verify that R8 actually renamed
9+
representative classes and fields.
10+
11+
## How to run it
12+
13+
Run the tests against a booted emulator or device:
14+
15+
```bash
16+
./scripts/test-nav3-backstack-entry-mapper-r8.sh
17+
```
18+
19+
20+
The script builds and runs four APKs: R8 full and compat modes, each with the pinned and latest kotlinx.serialization versions. Every APK
21+
must report `RESULT=PASS` in order to pass. Set `NAV3_EXTRA_KOTLINX_VERSIONS` to override the extra versions tested (i.e., the versions
22+
besides the compile floor, which is always tested).

0 commit comments

Comments
 (0)