8000 Add android testing CI job by afranchuk · Pull Request #115 · rust-minidump/minidump-writer · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .cargo/android-runner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh -e

BINARY=$1
shift

# Make sure to run the following to copy the test helper binary over.
# cargo run --target x86_64-linux-android --bin test
adb push "$BINARY" "/data/local/$BINARY"
adb shell "chmod 777 /data/local/$BINARY && env TEST_HELPER=/data/local/target/x86_64-linux-android/debug/test /data/local/$BINARY" "$@"
3 changes: 3 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@
# "-C",
# "link-arg=-Wl,--build-id=sha1",
# ]
[target.x86_64-linux-android]
linker = "x86_64-linux-android30-clang"
runner = [".cargo/android-runner.sh"]
35 changes: 35 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,41 @@ jobs:
# /tmp/cross test --target ${{ matrix.job.target }}
# /tmp/cross test --target ${{ matrix.job.target }} -- ignored

# The cargo x86-64-linux-android target configuration in .cargo/config.toml
# interacts with this job.
test-android:
name: Test android
runs-on: ubuntu-latest
env:
ANDROID_HOME: /usr/local/lib/android/sdk
steps:
- uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
target: x86_64-linux-android
- 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
# Add the (eventual) NDK toolchain bin directory to PATH so the linker is
# available to cargo
- run: echo "$ANDROID_HOME/ndk/26.2.11394342/toolchains/llvm/prebuilt/linux-x86_64/bin" >> $GITHUB_PATH
- name: Build/run tests in android emulator
uses: reactivecircus/android-emulator-runner@v2
with:
arch: x86_64
api-level: 30
ndk: 26.2.11394342
script: |
# run adb as root so we can create remote directories
adb root
# Copy test helper binary over as a side-effect of running it.
cargo run --target x86_64-linux-android --bin test -- nop
# Build and run tests
cargo test --target x86_64-linux-android

deny-check:
runs-on: ubuntu-22.04
steps:
Expand Down
1 change: 1 addition & 0 deletions src/bin/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ mod linux {
pub(super) fn real_main(args: Vec<String>) -> Result<()> {
match args.len() {
1 => match args[0].as_ref() {
"nop" => Ok(()),
"file_id" => test_file_id(),
"setup" => test_setup(),
"thread_list" => test_thread_list(),
Expand Down
23 changes: 14 additions & 9 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,21 @@ type Error = Box<dyn error::Error + std::marker::Send + std::marker::Sync>;
pub type Result<T> = result::Result<T, Error>;

fn build_command() -> Command {
let mut cmd = Command::new("cargo");

cmd.env("RUST_BACKTRACE", "1")
.args(["run", "-q", "--bin", "test"]);
let mut cmd;
if let Some(binary) = std::env::var_os("TEST_HELPER") {
cmd = Command::new(binary);
} else {
cmd = Command::new("cargo");
cmd.args(["run", "-q", "--bin", "test"]);

// In normal cases where the host and target are the same this won't matter,
// but tests will fail if you are eg running in a cross container which will
// likely be x86_64 but may be targetting aarch64 or i686, which will result
// in tests failing, or at the least not testing what you think
cmd.args(["--target", current_platform::CURRENT_PLATFORM, "--"]);
}

// In normal cases where the host and target are the same this won't matter,
// but tests will fail if you are eg running in a cross container which will
// likely be x86_64 but may be targetting aarch64 or i686, which will result
// in tests failing, or at the least not testing what you think
cmd.args(["--target", current_platform::CURRENT_PLATFORM, "--"]);
cmd.env("RUST_BACKTRACE", "1");

cmd
}
Expand Down
6 changes: 5 additions & 1 deletion tests/linux_minidump_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,11 @@ fn with_deleted_binary() {
.unwrap();
let binary_copy = binary_copy_dir.as_ref().join("binary_copy");

let path: &'static str = std::env!("CARGO_BIN_EXE_test");
let path: String = if let Ok(p) = std::env::var("TEST_HELPER") {
p
} else {
std::env!("CARGO_BIN_EXE_test").into()
};

std::fs::copy(path, &binary_copy).expect("Failed to copy binary");
let mem_slice = std::fs::read(&binary_copy).expect("Failed to read binary");
Expand Down
10 changes: 7 additions & 3 deletions tests/ptrace_dumper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,12 @@ fn test_merged_mappings() {
let page_size = std::num::NonZeroUsize::new(page_size.unwrap() as usize).unwrap();
let map_size = std::num::NonZeroUsize::new(3 * page_size.get()).unwrap();

let path: &'static str = std::env!("CARGO_BIN_EXE_test");
let file = std::fs::File::open(path).unwrap();
let path: String = if let Ok(p) = std::env::var("TEST_HELPER") {
p
} else {
std::env!("CARGO_BIN_EXE_test").into()
};
let file = std::fs::File::open(&path).unwrap();

// mmap two segments out of the helper binary, one
// enclosed in the other, but with different protections.
Expand Down Expand Up @@ -153,7 +157,7 @@ fn test_merged_mappings() {

spawn_child(
"merged_mappings",
&[path, &format!("{mapped}"), &format!("{map_size}")],
&[&path, &format!("{mapped}"), &format!("{map_size}")],
);
}

Expand Down
0