xref: /aosp_15_r20/external/ltp/android/ltp_android_walkthrough.md (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1Building LTP for Android (complete walkthrough)
2===============================================
3This tutorial will walk you through building LTP for Android, starting from scratch.
4
5Install build tools
6-------------------
7Follow the instructions here based on your operating system:
8
9https://source.android.com/docs/setup/start/initializing?hl=en
10
11Install repo
12------------
13```
14sudo apt-get update
15sudo apt-get install repo
16```
17(https://source.android.com/docs/setup/download?hl=en)
18
19Checkout AOSP
20-------------
21**WARNING**: this step downloads ~300GB of files from the AOSP repository.
22
23```
24mkdir aosp-master
25cd aosp-master
26repo init -u https://android.googlesource.com/platform/manifest -b master --partial-clone --clone-filter=blob:limit=10M
27repo sync -c -j8
28```
29(https://source.android.com/docs/setup/download/downloading?hl=en)
30
31Set up environment
32------------------
33This configures the tooling to target cuttlefish arm64:
34```
35source build/envsetup.sh
36lunch aosp_cf_arm64_phone-userdebug
37```
38Alternatively, this will target 32-bit arm:
39```
40source build/envsetup.sh
41lunch aosp_cf_arm_only_phone-userdebug
42```
43If you are targeting something else, you can follow the link below for further instructions on how to adjust the target accordingly:
44
45https://source.android.com/docs/setup/build/building?hl=en#choose-a-target
46
47Build ADB and atest
48-------------------
49```
50m -j adb atest
51adb version
52```
53(https://source.android.com/docs/setup/build/adb?hl=en)
54
55Connect the device
56------------------
57Connect the device to your system and verify that ADB can see it.
58```
59adb devices
60```
61
62Two ways to run LTP:
63--------------------
64### Use atest tool to build and run tests
65https://android.googlesource.com/platform/external/ltp/+/master/android/README.md#running-ltp-through-atest
66```
67atest -a vts_ltp_test_arm     # 32-bit arm tests
68atest -a vts_ltp_test_arm_64  # 64-bit arm tests
69```
70
71### Manually build and run tests
72This is faster to build but requires more manual steps.
73
74Setup temporary directories:
75```
76adb root
77adb shell "mkdir -p /data/local/tmp/ltp/tmp/ltptemp; mkdir -p /data/local/tmp/ltp/tmp/tmpbase; mkdir -p /data/local/tmp/ltp/tmp/tmpdir; restorecon -F -R /data/local/tmp/ltp"
78```
79
80This example builds ltp and runs the `pcrypt_aead01` binary:
81```
82cd external/ltp
83mma
84adb sync data
85adb shell "TMP=/data/local/tmp/ltp/tmp LTPTMP=/data/local/tmp/ltp/tmp/ltptemp LTP_DEV_FS_TYPE=ext4 TMPBASE=/data/local/tmp/ltp/tmp/tmpbase TMPDIR=/data/local/tmp/ltp/tmp/tmpdir LTPROOT=/data/local/tmp/ltp PATH=/data/nativetest64/ltp/testcases/bin:$PATH pcrypt_aead01"
86```
87(https://android.googlesource.com/platform/external/ltp/+/master/android/README.md#running-ltp-directly)
88
89Modify an existing test and rerun it
90------------------------------------
91After making code changes to an existing test, following either of the previous steps will rebuild and run it.
92
93If you are applying a patch file, you may do the following, filling in the patch file and binary:
94```
95cd external/ltp
96git apply <patch filename>.patch
97mma
98adb sync data
99adb shell "TMP=/data/local/tmp/ltp/tmp LTPTMP=/data/local/tmp/ltp/tmp/ltptemp LTP_DEV_FS_TYPE=ext4 TMPBASE=/data/local/tmp/ltp/tmp/tmpbase TMPDIR=/data/local/tmp/ltp/tmp/tmpdir LTPROOT=/data/local/tmp/ltp PATH=/data/nativetest64/ltp/testcases/bin:$PATH <test binary>"
100```
101