Skip to content
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

Add limited android test support #132

Merged
merged 7 commits into from
Oct 20, 2017
Merged

Conversation

malbarbo
Copy link
Contributor

We could provide android test support by launching an android emulator and running tests in the emulator (like how it is done in libc and rust), but there is licenses issues in redistributing the sdk (see 3.4 of https://developer.android.com/studio/terms.html). Off course, I maybe be wrong about this.

So we download and build bionic libc from source, which I think allows we to distribute the binaries. Having the android libc allows running native binaries using qemu, which can be enough for projects like, nix, ripgrep, etc.

Related #82

Copy link
Contributor

@japaric japaric left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, @malbarbo.

I think this is a great start towards supporting testing on android targets.

I'm wondering if we can workaround this potential redistribution issue by downloading the SDK on user machine (and cache it somehow) instead of distributing it with our docker images. But that's something we can look into later.

So, I left some questions in the comments. But, other than that this looks good to me. Excellent work as usual. 💯

@@ -29,5 +35,7 @@ ENV CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=aarch64-linux-android-gcc \
OPENSSL_DIR=/openssl \
OPENSSL_INCLUDE_DIR=/openssl/include \
OPENSSL_LIB_DIR=/openssl/lib \
RUST_TEST_THREADS=1 \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentional? Does QEMU have good threading support for android / bionic? Or are all Rust (or bionic?) applications single threaded?

(This comment applies to all the RUST_TEST_THREADS removals)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was unintentional, sorry.

# script ask for it
cat << EOF > /usr/bin/java
#!/bin/bash
echo "java version \"1.7.0\""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an interesting hack. I suppose that all android programs read the java version (e.g. by calling java --version) at runtime or something like that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are right.

rm bionic/linker/tests/Android.mk bionic/tests/Android.mk

source build/envsetup.sh
lunch aosp_$arch-user
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lunch? not launch? (probably intentional)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lunch is a command of the android build system.

@@ -12,22 +12,39 @@ RUN apt-get update && \
COPY xargo.sh /
RUN bash /xargo.sh

# We could supposedly directly run i686 binaries like we do for x86_64, but
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ... interesting. Any idea why this happen? IIRC, this also happens with the i686-musl target. A panicking program cross compiled for this target will fail in a similar way when executed on x86_64. But I never tried running running that binary under qemu-i386. Cross compiling that binary for i686-gnu and running it on x86_64 works fine though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it seams I got this wrong. Using qemu is enough to pass the ci/script.sh testing, but it fails in in the ripgrep tests. I was unable to reproduce the i686-musl failure... Running cross test --target i686-unknown-linux-musl in the ripgrep repository worked as expected. I tested a simple program that panics, and it also worked.

Maybe this is a std issue? How should we proceed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, it seems that unwinding on i686-unknown-linux-musl was fixed a while ago but didn't notice.

i686-unknown-linux-musl is not tested in rust-lang/rust so what you are reporting may indeed be a std bug.

COPY android-ndk.sh /
RUN bash /android-ndk.sh x86 21
ENV PATH=$PATH:/android-ndk/bin

# Build with no-asm to make openssl linked binaries position-independent (PIE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting finding. I wonder if no-asm would fix OpenSSL builds on i686-musl. IIRC, when cross compiling OpenSSL for i686-musl caused some PIC/PIE errors later on in the linking process.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried and it didn't work...

Copy link
Contributor

@japaric japaric Oct 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Doesn't matter; it seems that there may be a solution for that issue in #27 (comment) .

docker/qemu.sh Outdated
# Allow qemu to run android (bionic libc) binaries
if [[ "$target" == "android" ]]; then
patch -p1 <<'EOF'
diff -ur qemu-2.10.0/linux-user/elfload.c qemu-2.10.0.new/linux-user/elfload.c
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this an upstream QEMU commit that was not part of the 2.10.0 release? Or did you come up with this patch yourself? If the latter is there any change you could upstream it. If the former could you include a link to the commit change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote this patch my self some time ago. I updated qemu to 2.10 to keep it up to date. I thought to send it upstream, but I gave up reading https://wiki.qemu.org/Contribute/SubmitAPatch (Later I found https://wiki.qemu.org/Contribute/TrivialPatches but I was already tired...). I will soon ask in the users list why qemu does not support ioctl with RNDGETENTCNT.

docker/qemu.sh Outdated

local arch=$1 \
target=$2 \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this should be named os?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better!

@@ -41,7 +41,7 @@ matrix:

# BSD
- env: TARGET=i686-unknown-freebsd DYLIB=1 STD=1 OPENSSL=0.7.17
- env: TARGET=x86_64-unknown-dragonfly DYLIB=1 OPENSSL=0.5.5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: alignment regression :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a fix, isn't it?

@malbarbo
Copy link
Contributor Author

malbarbo commented Oct 2, 2017

I'm wondering if we can workaround this potential redistribution issue by downloading the SDK on user machine (and cache it somehow) instead of distributing it with our docker images.

An alternative is to build the docker image in the user machine. In a more general away, we can pack all Docker files inside the cross binary and give the user the option of downloading the pre-build docker image or build it locally. We can also let the user specify a Docker file.

@malbarbo
Copy link
Contributor Author

I submitted the qemu patch upstream.

Running ripgrep tests in an i686 android emulator works as expected. So I think std is correct. Anyway, the error seems only to happen when Command is used.

@japaric Anything else? Can we test this?

@japaric
Copy link
Contributor

japaric commented Oct 20, 2017

Sorry for the delay @malbarbo. Could you please add:

  • A note about testing support being limited for these target. Noting that Command doesn't work, for example, would be great.

  • Add the _RUNNER variable to the Dockerfiles so that these targets work without binfmt-misc support (which requires sudo). You can find an example of that variable here.

After that you can r+ this.

@homunkulus delegate+

@homunkulus
Copy link
Contributor

✌️ @malbarbo can now approve this pull request

@malbarbo
Copy link
Contributor Author

Thanks @japaric!

@homunkulus +r

@malbarbo
Copy link
Contributor Author

Ops, let's try again.

@homunkulus r+

@homunkulus
Copy link
Contributor

📌 Commit 140aff3 has been approved by malbarbo

japaric pushed a commit that referenced this pull request Oct 20, 2017
Add limited android test support

We could provide android test support by launching an android emulator and running tests in the emulator (like how it is done in libc and rust), but there is licenses issues in redistributing the sdk (see 3.4 of https://developer.android.com/studio/terms.html). Off course, I maybe be wrong about this.

So we download and build bionic libc from source, which I think allows we to distribute the binaries. Having the android libc allows running native binaries using qemu, which can be enough for projects like, nix, ripgrep, etc.

Related #82
@homunkulus
Copy link
Contributor

⌛ Testing commit 140aff3 with merge 3de557c...

@homunkulus
Copy link
Contributor

☀️ Test successful - status-travis
Approved by: malbarbo
Pushing 3de557c to master...

@homunkulus homunkulus merged commit 140aff3 into cross-rs:master Oct 20, 2017
@homunkulus homunkulus mentioned this pull request Oct 20, 2017
@malbarbo malbarbo deleted the android-test branch October 16, 2018 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants