Skip to content

Commit

Permalink
build(ci): added android tests (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
berendsliedrecht authored Feb 27, 2024
1 parent e042b16 commit e7a426d
Show file tree
Hide file tree
Showing 9 changed files with 897 additions and 43 deletions.
19 changes: 11 additions & 8 deletions .github/workflows/android_test.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
#!/bin/bash

set -e

adb uninstall id.animo.example.android || true
adb install -r "$1"
adb logcat -c
adb shell am start -a android.intent.action.MAIN -n "id.animo.example.android/android.app.NativeActivity"

sleep 30
sleep 10

adb logcat RustStdoutStderr:D '*:S' | tee ~/logcat.log
LOG=$(adb logcat -d RustStdoutStderr:D '*:S')
HAS_STARTED=$(echo $LOG | grep 'RustStdoutStderr')
HAS_ERROR=$(echo $LOG | grep 'panicked')

if grep 'RustStdoutStderr' ~/logcat.log;
then
if [ -n "$HAS_STARTED" ]; then
echo "App running"
else
echo "::error:: App not running"
exit 1
fi

MSG=$(grep -e 'panicked' "$HOME"/logcat.log)
if [ -z "${MSG}" ]; then
if [ -n "$HAS_ERROR" ]; then
cat $LOG
echo "::error:: Rust panicked! Tests failed. Logs will be uploaded"
exit 1
else
echo "::success:: All tests passed!"
exit 0
fi

exit 0
32 changes: 31 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- main

env:
RUST_VERSION: "1.69"
RUST_VERSION: "1.74"

jobs:
format:
Expand Down Expand Up @@ -106,3 +106,33 @@ jobs:
cache-on-failure: true

- run: cargo check --target=${{ matrix.target }}


test-android:
name: Test Android

# Using macos runner for hardware acceleration
runs-on: macos-latest

steps:
- uses: actions/checkout@v4

- name: Install Rust Toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ env.RUST_VERSION }}
targets: x86_64-linux-android

- name: Install Cargo APK
run: cargo install cargo-apk

- name: Build Android Application
run: cargo apk build --manifest-path ./examples/android/Cargo.toml --target=x86_64-linux-android

- name: Run Tests
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 31
arch: x86_64
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none -no-snapshot-save
script: ./.github/workflows/android_test.sh examples/android/target/debug/apk/android.apk
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ name = "secure_env"

[target.'cfg(target_os = "ios")'.dependencies]
security-framework = { version = "2.9.2" }
p256 = { version = "0.13.2", features = ["ecdsa-core"] }

[target.'cfg(target_os = "android")'.dependencies]
android-activity = { version = "0.5.0", features = ["native-activity"] }
jni = { version = "0.21.1", features = ["invocation"] }
lazy_static = "1.4.0"
ndk-context = "0.1.1"
paste = "1.0.14"
x509-parser = "0.15.1"

[dependencies]
thiserror = "1.0.50"
p256 = { version = "0.13.2", features = ["ecdsa-core"] }
Loading

0 comments on commit e7a426d

Please sign in to comment.