Repository navigation
test(nav3): [Part 7] Verify mapping after R8 minification #6708
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
0xadam-brown
wants to merge
1
commit into
feat/nav3-serial-name-mappers-10
Choose a base branch
from
feat/nav3-serial-name-mappers-11
base: feat/nav3-serial-name-mappers-10
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| name: Nav3 BackStackEntryMapper R8 Check | ||
|
|
||
| # Verifies behavior of BackStackEntryMapper.SerialName and SerialNameAndProperties | ||
| # from sentry-android-navigation3 in R8-minified builds on an emulator (full and compat mode, | ||
| # with the compile floor + latest versions of kotlinx.serialization). See | ||
| # sentry-android-integration-tests/nav3-backstack-entry-mapper-r8-check/README.md. | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - "sentry-android-navigation3/**" | ||
| - "sentry-android-integration-tests/nav3-backstack-entry-mapper-r8-check/**" | ||
| - "sentry-android-integration-tests/*.gradle.kts" | ||
| - "scripts/test-nav3-backstack-entry-mapper-r8.sh" | ||
| - "scripts/update-nav3-kotlinx-serialization.sh" | ||
| - "gradle/libs.versions.toml" | ||
| - "gradle/nav3.versions.toml" | ||
| - ".github/workflows/integration-tests-nav3-r8.yml" | ||
| # Omit PRs that only change gradle/libs.versions.toml so we don't trigger R8 tests on unrelated | ||
| # dependency bumps. (Those changes are checked once they reach main.) The kotlinx.serialization | ||
| # floor lives in gradle/nav3.versions.toml so that PRs changing it are still checked. | ||
| pull_request: | ||
| paths: | ||
| - "sentry-android-navigation3/**" | ||
| - "sentry-android-integration-tests/nav3-backstack-entry-mapper-r8-check/**" | ||
| - "sentry-android-integration-tests/*.gradle.kts" | ||
| - "scripts/test-nav3-backstack-entry-mapper-r8.sh" | ||
| - "scripts/update-nav3-kotlinx-serialization.sh" | ||
| - "gradle/nav3.versions.toml" | ||
| - ".github/workflows/integration-tests-nav3-r8.yml" | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| env: | ||
| APK_DIR: "nav3-r8-check-apks" | ||
| APK_ARTIFACT_NAME: "nav3-r8-check-apks" | ||
|
|
||
| jobs: | ||
| build: | ||
| name: Build | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
|
|
||
| - name: Set up Java | ||
| uses: actions/setup-java@b843ebf9b913146b38da2eaa7aeddf76074ae1ad # v6.1.0 | ||
| with: | ||
| distribution: 'temurin' | ||
| java-version: '21' | ||
|
|
||
| - name: Setup Gradle | ||
| uses: gradle/actions/setup-gradle@8da46b539cd8fe6ab27ca75128919a18d757604c # v6.4.1 | ||
|
|
||
| # Apps may ship a newer kotlinx.serialization than sentry-android-navigation3 compiles | ||
| # against, and the properties encoder relies on its experimental AbstractEncoder. | ||
| - name: Run unit tests against the latest kotlinx.serialization | ||
| run: | | ||
| tag="$(./scripts/update-nav3-kotlinx-serialization.sh get-version)" | ||
| version="${tag#v}" | ||
| ./gradlew :sentry-android-navigation3:testReleaseUnitTest -Pnav3TestKotlinxVersion="$version" | ||
|
|
||
| - name: Build APKs | ||
| run: ./scripts/test-nav3-backstack-entry-mapper-r8.sh build "${{ env.APK_DIR }}" | ||
|
|
||
| - name: Upload APK artifact | ||
| uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7 | ||
| with: | ||
| name: ${{ env.APK_ARTIFACT_NAME }} | ||
| path: ${{ env.APK_DIR }} | ||
| retention-days: 1 | ||
|
|
||
| run: | ||
| name: Run on API Level ${{ matrix.api-level }} | ||
| needs: build | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| # Tests against API 37.0 on every run. Also tests against API 23 (Nav3's minSdkVersion) when changes reach main. | ||
| # The latter lets us catch issues present on the oldest Nav3 app runtime without slowing down PRs. | ||
| api-level: ${{ fromJSON(github.event_name == 'push' && '[23, "37.0"]' || '["37.0"]') }} | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | ||
|
|
||
| - name: Enable KVM | ||
| run: | | ||
| echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules | ||
| sudo udevadm control --reload-rules | ||
| sudo udevadm trigger --name-match=kvm | ||
|
|
||
| - name: Download APK artifact | ||
| uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8 | ||
| with: | ||
| name: ${{ env.APK_ARTIFACT_NAME }} | ||
| path: ${{ env.APK_DIR }} | ||
|
|
||
| # The runner ships an outdated avdmanager that writes target=android-0 into the | ||
| # AVD config for minor-versioned packages (android-37.x), so the emulator clamps | ||
| # to API 3 and boots misconfigured. Update cmdline-tools so avdmanager parses it. | ||
| # See https://github.com/ReactiveCircus/android-emulator-runner/issues/482 | ||
| - name: Update SDK cmdline-tools | ||
| if: matrix.api-level == '37.0' | ||
| run: | | ||
| SDK="${ANDROID_HOME:-${ANDROID_SDK_ROOT:-/usr/local/lib/android/sdk}}" | ||
| yes | "$SDK/cmdline-tools/latest/bin/sdkmanager" --install "cmdline-tools;latest" > /dev/null | ||
| # sdkmanager won't overwrite the preinstalled dir, so it installs to latest-2. | ||
| if [ -d "$SDK/cmdline-tools/latest-2" ]; then | ||
| rm -rf "$SDK/cmdline-tools/latest" | ||
| mv "$SDK/cmdline-tools/latest-2" "$SDK/cmdline-tools/latest" | ||
| fi | ||
|
|
||
| - name: Run check | ||
| uses: reactivecircus/android-emulator-runner@a421e43855164a8197daf9d8d40fe71c6996bb0d # pin@v2.38.0 | ||
| with: | ||
| api-level: ${{ matrix.api-level }} | ||
| # API 37 has no plain google_apis image. | ||
| target: ${{ matrix.api-level == 23 && 'google_apis' || 'google_apis_ps16k' }} | ||
| # Use canary for API 37, matching the critical UI tests. | ||
| channel: ${{ matrix.api-level == 23 && 'stable' || 'canary' }} | ||
| arch: x86_64 | ||
| disable-animations: true | ||
| disable-spellchecker: true | ||
| emulator-options: -memory 4096 -no-window -gpu auto -noaudio -no-boot-anim -camera-back none -no-snapshot-save | ||
| script: ./scripts/test-nav3-backstack-entry-mapper-r8.sh run "${{ env.APK_DIR }}" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| #!/usr/bin/env bash | ||
| # Verifies the behavior of BackStackEntryMapper.SerialName and SerialNameAndProperties | ||
| # in R8-minified builds on a booted emulator or device. See | ||
| # sentry-android-integration-tests/nav3-backstack-entry-mapper-r8-check/README.md. | ||
| # | ||
| # The app is built against the kotlinxSerializationFloor in gradle/nav3.versions.toml | ||
| # plus each version in NAV3_EXTRA_KOTLINX_VERSIONS (default: defaultLatestKotlinx below), | ||
| # each in R8 full and compat modes. | ||
| # | ||
| # Usage: | ||
| # test-nav3-backstack-entry-mapper-r8.sh Build all APKs, then run them. | ||
| # test-nav3-backstack-entry-mapper-r8.sh build DIR Build all APKs into DIR. | ||
| # test-nav3-backstack-entry-mapper-r8.sh run DIR Install and run every APK in DIR. | ||
| set -euo pipefail | ||
|
|
||
| module="nav3-backstack-entry-mapper-r8-check" | ||
| moduleDir="sentry-android-integration-tests/nav3-backstack-entry-mapper-r8-check" | ||
| appId="io.sentry.tests.nav3.r8" | ||
| tag="NAV3_R8_CHECK" | ||
|
|
||
| # Newer kotlinx.serialization versions to also build the app against, on top of the | ||
| # kotlinxSerializationFloor. Lets us prevent regressions should host apps ship a newer | ||
| # kotlinx.serialization version than we compile against. Also protects us against changes | ||
| # to the experimental kotlinx.serialization APIs used by the arguments encoder. Override | ||
| # with, e.g., NAV3_EXTRA_KOTLINX_VERSIONS="1.10.0 1.12.0" to test the compile floor, | ||
| # 1.10.0, and 1.12.0. (Provide an empty string to test the floor only.) | ||
| # | ||
| # The latest kotlinx-serialization-core release. Bumped by a weekly PR from | ||
| # scripts/update-nav3-kotlinx-serialization.sh (.github/workflows/update-deps.yml). | ||
| defaultLatestKotlinx="1.13.0" | ||
| extraKotlinxVersions=(${NAV3_EXTRA_KOTLINX_VERSIONS-$defaultLatestKotlinx}) | ||
|
|
||
| copyApk() { | ||
| cp "${moduleDir}/build/outputs/apk/release/nav3-backstack-entry-mapper-r8-check-release.apk" "$1" | ||
| } | ||
|
|
||
| build() { | ||
| local outDir="$1" | ||
| mkdir -p "$outDir" | ||
| for mode in full compat; do | ||
| local fullMode=true | ||
| [[ "$mode" == "compat" ]] && fullMode=false | ||
| echo "Building R8 $mode mode APK (kotlinx floor)..." | ||
| ./gradlew -p sentry-android-integration-tests ":${module}:assembleRelease" "-Pandroid.enableR8.fullMode=${fullMode}" | ||
| copyApk "${outDir}/${mode}.apk" | ||
|
|
||
| # Apps may ship a newer kotlinx than our compile floor, so rebuild against each. | ||
| for version in ${extraKotlinxVersions[@]+"${extraKotlinxVersions[@]}"}; do | ||
| echo "Building R8 $mode mode APK (kotlinx ${version})..." | ||
| ./gradlew -p sentry-android-integration-tests ":${module}:assembleRelease" \ | ||
| "-Pandroid.enableR8.fullMode=${fullMode}" "-Pnav3CheckKotlinxVersion=${version}" | ||
| copyApk "${outDir}/${mode}-kotlinx-${version}.apk" | ||
| done | ||
| done | ||
| } | ||
|
|
||
| run() { | ||
| local apkDir="$1" | ||
| local failed=0 | ||
| shopt -s nullglob | ||
| local apks=("$apkDir"/*.apk) | ||
| if [[ ${#apks[@]} -eq 0 ]]; then | ||
| echo "No APKs found in $apkDir" | ||
| exit 1 | ||
| fi | ||
|
|
||
| for apk in "${apks[@]}"; do | ||
| local name | ||
| name="$(basename "$apk" .apk)" | ||
| echo "=== $name" | ||
| adb uninstall "$appId" > /dev/null 2>&1 || true | ||
| adb install -r -d "$apk" > /dev/null | ||
| # Only read lines logged from this launch on, so a stale RESULT=PASS from the previous APK can't | ||
| # hide this one's failure. Doesn't clear the log, which would also discard unrelated logs on a | ||
| # development device. The timestamp is truncated to the second, so wait a second for it to | ||
| # postdate earlier lines. | ||
| local since | ||
| sleep 1 | ||
| since="$(adb shell "date +'%m-%d %H:%M:%S.000'" | tr -d '\r')" | ||
| adb shell am start -W -n "${appId}/.BackStackEntryMapperActivity" > /dev/null | ||
|
|
||
| local output="" | ||
| for _ in $(seq 1 60); do | ||
| output="$(adb logcat -d -T "$since" -s "${tag}:I" | grep "${tag}" || true)" | ||
| if grep -q "RESULT=" <<< "$output"; then | ||
| break | ||
| fi | ||
| if adb logcat -d -T "$since" -b crash | grep -q "$appId"; then | ||
| break | ||
| fi | ||
| sleep 1 | ||
| done | ||
|
|
||
| if [[ -n "$output" ]]; then | ||
| sed -E "s/^.*${tag}: //" <<< "$output" | ||
| fi | ||
| if ! grep -q "RESULT=PASS" <<< "$output"; then | ||
| echo "FAILED: $name" | ||
| adb logcat -d -T "$since" -b crash | grep -A 20 "$appId" || true | ||
| failed=1 | ||
| fi | ||
| done | ||
|
|
||
| if [[ $failed -ne 0 ]]; then | ||
| echo "Nav3 BackStackEntryMapper R8 check failed." | ||
| exit 1 | ||
| fi | ||
| echo "Nav3 BackStackEntryMapper R8 check passed." | ||
| } | ||
|
|
||
| case "${1:-}" in | ||
| build) build "${2:?Usage: $0 build DIR}" ;; | ||
| run) run "${2:?Usage: $0 run DIR}" ;; | ||
| "") | ||
| apkDir="${moduleDir}/build/r8-check-apks" | ||
| rm -rf "$apkDir" | ||
| build "$apkDir" | ||
| run "$apkDir" | ||
| ;; | ||
| *) | ||
| echo "Usage: $0 [build DIR | run DIR]" | ||
| exit 1 | ||
| ;; | ||
| esac |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| # Script for keeping the Nav3 R8 test up-to-date with new kotlinx.serialization releases. | ||
| # Updates defaultLatestKotlinx in scripts/test-nav3-backstack-entry-mapper-r8.sh, which | ||
| # adds that version to the test matrix alongside the SDK's pinned compile version. | ||
| # | ||
| # Run weekly by update-deps.yml. Does not change kotlinxSerializationFloor in | ||
| # gradle/nav3.versions.toml. | ||
|
|
||
| cd "$(dirname "$0")/../" | ||
| SCRIPT_FILEPATH=scripts/test-nav3-backstack-entry-mapper-r8.sh | ||
|
|
||
| case $1 in | ||
| get-version) | ||
| # Printed as the release's tag (e.g. v1.13.0), which the updater uses as the old ref when it | ||
| # compares upstream changelogs. | ||
| perl -ne 'print "v$1\n" if ( m/^defaultLatestKotlinx="([0-9.]+)"/ )' "$SCRIPT_FILEPATH" | ||
| ;; | ||
| *) | ||
| echo "Unknown argument $1" | ||
| exit 1 | ||
| ;; | ||
| esac |
22 changes: 22 additions & 0 deletions
22
sentry-android-integration-tests/nav3-backstack-entry-mapper-r8-check/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # nav3-backstack-entry-mapper-r8-check | ||
|
|
||
| Verifies that `BackStackEntryMapper.SerialName` and | ||
| `BackStackEntryMapper.SerialNameAndProperties` from `sentry-android-navigation3` return expected Sentry names and arguments despite | ||
| R8 obfuscation. `sentry-android-navigation3` ships no kotlinx.serialization R8 rules, so the check relies on kotlinx.serialization's own | ||
| consumer rules, plus the per-class rules in this app's `proguard-rules.pro` file. | ||
|
|
||
| The tests check serialization names, argument encoding, and sensitive-value filtering. They also verify that R8 actually renamed | ||
| representative classes and fields. | ||
|
|
||
| ## How to run it | ||
|
|
||
| Run the tests against a booted emulator or device: | ||
|
|
||
| ```bash | ||
| ./scripts/test-nav3-backstack-entry-mapper-r8.sh | ||
| ``` | ||
|
|
||
|
|
||
| The script builds and runs four APKs: R8 full and compat modes, each with the pinned and latest kotlinx.serialization versions. Every APK | ||
| must report `RESULT=PASS` in order to pass. Set `NAV3_EXTRA_KOTLINX_VERSIONS` to override the extra versions tested (i.e., the versions | ||
| besides the compile floor, which is always tested). |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.