I know that the compiler can run directly on arm-linux-androideabi
, but the Android emulator (I mean emulation of ARM on x86/amd64) is slow,
so I don't want to use cargo
and rustc
on the emulator, I only want to run tests on it.
I want to cross-compile tests on my PC (cargo test --target=arm-linux-androideabi --no-run
?), and then upload and run them on emulator,
hoping to catch bugs like this.
How can I run cargo test
without running cargo test
? Is it as simple as running all binaries that were built with cargo test --no-run
?
There are two kinds of tests supported by cargo test
, one is the normal tests (#[test] fn
s and files inside tests/
), the other is the doc tests.
The normal tests are as simple as running all binaries. The test is considered successful if it exits with error code 0.
Doc tests cannot be cross-tested. Doc tests are compiled and executed directly by rustdoc
using the compiler libraries, so the compiler must be installed on the ARM machine to run the doc tests. In fact, running cargo test --doc
when HOST ≠ TARGET will do nothing.
So, the answer to your last question is yes as long as you don't rely on doc-tests for coverage.
Starting from Rust 1.19, cargo
supports target specific runners, which allows you to specify a script to upload and execute the test program on the ARM machine.
#!/bin/sh
set -e
adb push "$1" "/sdcard/somewhere/$1"
adb shell "chmod 755 /sdcard/somewhere/$1 && /sdcard/somewhere/$1"
# ^ note: may need to change this line, see https://stackoverflow.com/q/9379400
Put this to your .cargo/config
:
[target.arm-linux-androideabi]
runner = ["/path/to/your/run/script.sh"]
then cargo test --target=arm-linux-androideabi
should Just Work™.
If your project is hosted on GitHub and uses Travis CI, you may also want to check out trust
. It provides a pre-packaged solution for testing on many architectures including ARMv7 Linux on the CI (no Android unfortunately).