Skip to content

Commit 0ed0fc1

Browse files
bors[bot]malbarbo
andcommitted
Merge #171
171: Improve android test support r=Dylan-DPC a=malbarbo With this changes it is possible to run libstd tests and most of cargo tests (qemu segfault in some). Co-authored-by: Marco A L Barbosa <[email protected]>
2 parents a73c4f9 + ee149e2 commit 0ed0fc1

File tree

7 files changed

+91
-68
lines changed

7 files changed

+91
-68
lines changed

docker/aarch64-linux-android/Dockerfile

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,35 @@ RUN apt-get update && \
1212
COPY xargo.sh /
1313
RUN bash /xargo.sh
1414

15-
COPY qemu.sh /
16-
RUN bash /qemu.sh aarch64 android
17-
1815
COPY android-ndk.sh /
1916
RUN bash /android-ndk.sh arm64 21
2017
ENV PATH=$PATH:/android-ndk/bin
2118

19+
COPY android-system.sh /
20+
RUN bash /android-system.sh arm64
21+
22+
COPY qemu.sh /
23+
RUN bash /qemu.sh aarch64 android
24+
2225
COPY openssl.sh /
2326
RUN bash /openssl.sh linux-generic64 aarch64-linux-android- -mandroid -fomit-frame-pointer
2427

25-
COPY android-system.sh /
26-
RUN bash /android-system.sh arm64
28+
RUN cp /android-ndk/sysroot/usr/lib/libz.so /system/lib/
2729

2830
# Libz is distributed in the android ndk, but for some unknown reason it is not
2931
# found in the build process of some crates, so we explicit set the DEP_Z_ROOT
3032
ENV CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=aarch64-linux-android-gcc \
3133
CARGO_TARGET_AARCH64_LINUX_ANDROID_RUNNER=qemu-aarch64 \
3234
CC_aarch64_linux_android=aarch64-linux-android-gcc \
3335
CXX_aarch64_linux_android=aarch64-linux-android-g++ \
34-
DEP_Z_ROOT=/android-ndk/sysroot/usr/ \
36+
DEP_Z_INCLUDE=/android-ndk/sysroot/usr/include/ \
3537
OPENSSL_STATIC=1 \
3638
OPENSSL_DIR=/openssl \
3739
OPENSSL_INCLUDE_DIR=/openssl/include \
3840
OPENSSL_LIB_DIR=/openssl/lib \
3941
RUST_TEST_THREADS=1 \
4042
HOME=/tmp/ \
4143
TMPDIR=/tmp/ \
42-
ANDROID_ROOT=/system \
43-
ANDROID_DATA=/
44+
ANDROID_DATA=/ \
45+
ANDROID_DNS_MODE=local \
46+
ANDROID_ROOT=/system

docker/android-system.sh

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,18 @@ EOF
5252
# this is the minimum set of modules that are need to build bionic
5353
# this was created by trial and error
5454
./repo init -u https://android.googlesource.com/platform/manifest -b android-5.0.0_r1
55-
./repo sync bionic
56-
./repo sync build
57-
./repo sync external/compiler-rt
58-
./repo sync external/jemalloc
59-
./repo sync external/libcxx
60-
./repo sync external/libcxxabi
61-
./repo sync external/stlport
62-
./repo sync prebuilts/clang/linux-x86/host/3.5
63-
./repo sync system/core
55+
./repo sync -c bionic
56+
./repo sync -c build
57+
./repo sync -c external/compiler-rt
58+
./repo sync -c external/jemalloc
59+
./repo sync -c external/libcxx
60+
./repo sync -c external/libcxxabi
61+
./repo sync -c external/libselinux
62+
./repo sync -c external/mksh
63+
./repo sync -c external/openssl
64+
./repo sync -c external/stlport
65+
./repo sync -c prebuilts/clang/linux-x86/host/3.5
66+
./repo sync -c system/core
6467
case $arch in
6568
arm)
6669
./repo sync prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.8
@@ -78,18 +81,36 @@ EOF
7881
esac
7982

8083
# avoid build tests
81-
rm bionic/linker/tests/Android.mk bionic/tests/Android.mk
84+
rm bionic/linker/tests/Android.mk bionic/tests/Android.mk bionic/benchmarks/Android.mk
85+
86+
# patch the linker to avoid the error
87+
# FATAL: kernel did not supply AT_SECURE
88+
sed -i -e 's/if (!kernel_supplied_AT_SECURE)/if (false)/g' bionic/linker/linker_environ.cpp
8289

8390
source build/envsetup.sh
8491
lunch aosp_$arch-user
8592
mmma bionic/
93+
mmma external/mksh/
94+
mmma system/core/toolbox/
8695

8796
if [ $arch = "arm" ]; then
8897
mv out/target/product/generic/system/ /
8998
else
9099
mv out/target/product/generic_$arch/system/ /
91100
fi
92101

102+
# list from https://elinux.org/Android_toolbox
103+
for tool in cat chmod chown cmp cp ctrlaltdel date dd df dmesg du getevent \
104+
getprop grep hd id ifconfig iftop insmod ioctl ionice kill ln log ls \
105+
lsmod lsof lsusb md5 mkdir mount mv nandread netstat newfs_msdos notify \
106+
printenv ps reboot renice rm rmdir rmmod route schedtop sendevent \
107+
setconsole setprop sleep smd start stop sync top touch umount \
108+
uptime vmstat watchprops wipe; do
109+
ln -s /system/bin/toolbox /system/bin/$tool
110+
done
111+
112+
echo "127.0.0.1 localhost" > /system/etc/hosts
113+
93114
# clean up
94115
apt-get purge --auto-remove -y ${purge_list[@]}
95116

docker/arm-linux-androideabi/Dockerfile

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,35 @@ RUN apt-get update && \
1212
COPY xargo.sh /
1313
RUN bash /xargo.sh
1414

15-
COPY qemu.sh /
16-
RUN bash /qemu.sh arm android
17-
1815
COPY android-ndk.sh /
1916
RUN bash /android-ndk.sh arm 21
2017
ENV PATH=$PATH:/android-ndk/bin
2118

19+
COPY android-system.sh /
20+
RUN bash /android-system.sh arm
21+
22+
COPY qemu.sh /
23+
RUN bash /qemu.sh arm android
24+
2225
COPY openssl.sh /
2326
RUN bash /openssl.sh android arm-linux-androideabi-
2427

25-
COPY android-system.sh /
26-
RUN bash /android-system.sh arm
28+
RUN cp /android-ndk/sysroot/usr/lib/libz.so /system/lib/
2729

2830
# Libz is distributed in the android ndk, but for some unknown reason it is not
2931
# found in the build process of some crates, so we explicit set the DEP_Z_ROOT
3032
ENV CARGO_TARGET_ARM_LINUX_ANDROIDEABI_LINKER=arm-linux-androideabi-gcc \
3133
CARGO_TARGET_ARM_LINUX_ANDROIDEABI_RUNNER=qemu-arm \
3234
CC_arm_linux_androideabi=arm-linux-androideabi-gcc \
3335
CXX_arm_linux_androideabi=arm-linux-androideabi-g++ \
34-
DEP_Z_ROOT=/android-ndk/sysroot/usr/ \
36+
DEP_Z_INCLUDE=/android-ndk/sysroot/usr/include/ \
3537
OPENSSL_STATIC=1 \
3638
OPENSSL_DIR=/openssl \
3739
OPENSSL_INCLUDE_DIR=/openssl/include \
3840
OPENSSL_LIB_DIR=/openssl/lib \
3941
RUST_TEST_THREADS=1 \
4042
HOME=/tmp/ \
4143
TMPDIR=/tmp/ \
42-
ANDROID_ROOT=/system \
43-
ANDROID_DATA=/
44+
ANDROID_DATA=/ \
45+
ANDROID_DNS_MODE=local \
46+
ANDROID_ROOT=/system

docker/armv7-linux-androideabi/Dockerfile

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,35 @@ RUN apt-get update && \
1212
COPY xargo.sh /
1313
RUN bash /xargo.sh
1414

15-
COPY qemu.sh /
16-
RUN bash /qemu.sh arm android
17-
1815
COPY android-ndk.sh /
1916
RUN bash /android-ndk.sh arm 21
2017
ENV PATH=$PATH:/android-ndk/bin
2118

19+
COPY android-system.sh /
20+
RUN bash /android-system.sh arm
21+
22+
COPY qemu.sh /
23+
RUN bash /qemu.sh arm android
24+
2225
COPY openssl.sh /
2326
RUN bash /openssl.sh android-armv7 arm-linux-androideabi-
2427

25-
COPY android-system.sh /
26-
RUN bash /android-system.sh arm
28+
RUN cp /android-ndk/sysroot/usr/lib/libz.so /system/lib/
2729

2830
# Libz is distributed in the android ndk, but for some unknown reason it is not
2931
# found in the build process of some crates, so we explicit set the DEP_Z_ROOT
3032
ENV CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_LINKER=arm-linux-androideabi-gcc \
3133
CARGO_TARGET_ARMV7_LINUX_ANDROIDEABI_RUNNER=qemu-arm \
3234
CC_armv7_linux_androideabi=arm-linux-androideabi-gcc \
3335
CXX_armv7_linux_androideabi=arm-linux-androideabi-g++ \
34-
DEP_Z_ROOT=/android-ndk/sysroot/usr/ \
36+
DEP_Z_INCLUDE=/android-ndk/sysroot/usr/include/ \
3537
OPENSSL_STATIC=1 \
3638
OPENSSL_DIR=/openssl \
3739
OPENSSL_INCLUDE_DIR=/openssl/include \
3840
OPENSSL_LIB_DIR=/openssl/lib \
3941
RUST_TEST_THREADS=1 \
4042
HOME=/tmp/ \
4143
TMPDIR=/tmp/ \
42-
ANDROID_ROOT=/system \
43-
ANDROID_DATA=/
44+
ANDROID_DATA=/ \
45+
ANDROID_DNS_MODE=local \
46+
ANDROID_ROOT=/system

docker/i686-linux-android/Dockerfile

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ RUN apt-get update && \
1212
COPY xargo.sh /
1313
RUN bash /xargo.sh
1414

15+
COPY android-ndk.sh /
16+
RUN bash /android-ndk.sh x86 21
17+
ENV PATH=$PATH:/android-ndk/bin
18+
19+
COPY android-system.sh /
20+
RUN bash /android-system.sh x86
21+
1522
# We could supposedly directly run i686 binaries like we do for x86_64, but
1623
# doing so generates an assertion failure:
1724
# ... assertion failed: signal(libc::SIGPIPE, libc::SIG_IGN) != libc::SIG_ERR
@@ -22,30 +29,27 @@ RUN bash /xargo.sh
2229
COPY qemu.sh /
2330
RUN bash /qemu.sh i386 android
2431

25-
COPY android-ndk.sh /
26-
RUN bash /android-ndk.sh x86 21
27-
ENV PATH=$PATH:/android-ndk/bin
28-
2932
# Build with no-asm to make openssl linked binaries position-independent (PIE)
3033
COPY openssl.sh /
3134
RUN bash /openssl.sh android-x86 i686-linux-android- no-asm
3235

33-
COPY android-system.sh /
34-
RUN bash /android-system.sh x86
36+
RUN cp /android-ndk/sysroot/usr/lib/libz.so /system/lib/
3537

3638
# Libz is distributed in the android ndk, but for some unknown reason it is not
3739
# found in the build process of some crates, so we explicit set the DEP_Z_ROOT
3840
ENV CARGO_TARGET_I686_LINUX_ANDROID_LINKER=i686-linux-android-gcc \
3941
CARGO_TARGET_I686_LINUX_ANDROID_RUNNER="qemu-i386 -cpu n270" \
4042
CC_i686_linux_android=i686-linux-android-gcc \
4143
CXX_i686_linux_android=i686-linux-android-g++ \
42-
DEP_Z_ROOT=/android-ndk/sysroot/usr/ \
44+
DEP_Z_INCLUDE=/android-ndk/sysroot/usr/include/ \
45+
LIBZ_SYS_STATIC=1 \
4346
OPENSSL_STATIC=1 \
4447
OPENSSL_DIR=/openssl \
4548
OPENSSL_INCLUDE_DIR=/openssl/include \
4649
OPENSSL_LIB_DIR=/openssl/lib \
4750
RUST_TEST_THREADS=1 \
4851
HOME=/tmp/ \
4952
TMPDIR=/tmp/ \
50-
ANDROID_ROOT=/system \
51-
ANDROID_DATA=/
53+
ANDROID_DATA=/ \
54+
ANDROID_DNS_MODE=local \
55+
ANDROID_ROOT=/system

docker/qemu.sh

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,6 @@ main() {
4141
# https://lists.nongnu.org/archive/html/qemu-trivial/2017-10/msg00023.html
4242
if [[ "$os" == "android" ]]; then
4343
patch -p1 <<'EOF'
44-
diff -ur qemu-2.10.0/linux-user/elfload.c qemu-2.10.0.new/linux-user/elfload.c
45-
--- qemu-2.10.0/linux-user/elfload.c 2017-09-27 11:27:13.866595788 -0300
46-
+++ qemu-2.10.0.new/linux-user/elfload.c 2017-09-27 11:58:30.662613425 -0300
47-
@@ -1354,7 +1354,7 @@
48-
~(abi_ulong)(TARGET_ELF_EXEC_PAGESIZE-1))
49-
#define TARGET_ELF_PAGEOFFSET(_v) ((_v) & (TARGET_ELF_EXEC_PAGESIZE-1))
50-
51-
-#define DLINFO_ITEMS 14
52-
+#define DLINFO_ITEMS 15
53-
54-
static inline void memcpy_fromfs(void * to, const void * from, unsigned long n)
55-
{
56-
@@ -1782,6 +1782,7 @@
57-
NEW_AUX_ENT(AT_HWCAP, (abi_ulong) ELF_HWCAP);
58-
NEW_AUX_ENT(AT_CLKTCK, (abi_ulong) sysconf(_SC_CLK_TCK));
59-
NEW_AUX_ENT(AT_RANDOM, (abi_ulong) u_rand_bytes);
60-
+ NEW_AUX_ENT(AT_SECURE, (abi_ulong) (getuid() != geteuid() || getgid() != getegid()));
61-
62-
#ifdef ELF_HWCAP2
63-
NEW_AUX_ENT(AT_HWCAP2, (abi_ulong) ELF_HWCAP2);
6444
diff -ur qemu-2.10.0/linux-user/ioctls.h qemu-2.10.0.new/linux-user/ioctls.h
6545
--- qemu-2.10.0/linux-user/ioctls.h 2017-09-27 11:27:13.858595669 -0300
6646
+++ qemu-2.10.0.new/linux-user/ioctls.h 2017-09-27 11:43:40.613299859 -0300

docker/x86_64-linux-android/Dockerfile

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,32 @@ COPY android-ndk.sh /
1616
RUN bash /android-ndk.sh x86_64 21
1717
ENV PATH=$PATH:/android-ndk/bin
1818

19+
COPY android-system.sh /
20+
RUN bash /android-system.sh x86_64
21+
22+
# Using qemu allows older host cpus (without sse4) to execute the target binaries
23+
COPY qemu.sh /
24+
RUN bash /qemu.sh x86_64 android
25+
1926
COPY openssl.sh /
2027
RUN bash /openssl.sh linux-x86_64 x86_64-linux-android- -mandroid -fomit-frame-pointer
2128

22-
COPY android-system.sh /
23-
RUN bash /android-system.sh x86_64
29+
RUN cp /android-ndk/sysroot/usr/lib/libz.so /system/lib/
2430

2531
# Libz is distributed in the android ndk, but for some unknown reason it is not
2632
# found in the build process of some crates, so we explicit set the DEP_Z_ROOT
2733
ENV CARGO_TARGET_X86_64_LINUX_ANDROID_LINKER=x86_64-linux-android-gcc \
34+
CARGO_TARGET_X86_64_LINUX_ANDROID_RUNNER="qemu-x86_64 -cpu Penryn" \
2835
CC_x86_64_linux_android=x86_64-linux-android-gcc \
2936
CXX_x86_64_linux_android=x86_64-linux-android-g++ \
30-
DEP_Z_ROOT=/android-ndk/sysroot/usr/ \
37+
DEP_Z_INCLUDE=/android-ndk/sysroot/usr/include/ \
3138
OPENSSL_STATIC=1 \
3239
OPENSSL_DIR=/openssl \
3340
OPENSSL_INCLUDE_DIR=/openssl/include \
3441
OPENSSL_LIB_DIR=/openssl/lib \
42+
RUST_TEST_THREADS=1 \
3543
HOME=/tmp/ \
3644
TMPDIR=/tmp/ \
37-
ANDROID_ROOT=/system \
38-
ANDROID_DATA=/
45+
ANDROID_DATA=/ \
46+
ANDROID_DNS_MODE=local \
47+
ANDROID_ROOT=/system

0 commit comments

Comments
 (0)