xref: /aosp_15_r20/frameworks/layoutlib/bridge/tests/run_tests.sh (revision fc3927be90a325f95c74a9043993a80ef388dc46)
1*fc3927beSAndroid Build Coastguard Worker#!/bin/bash
2*fc3927beSAndroid Build Coastguard Workerset -u
3*fc3927beSAndroid Build Coastguard Worker
4*fc3927beSAndroid Build Coastguard Workerreadonly OUT_DIR="$1"
5*fc3927beSAndroid Build Coastguard Workerreadonly DIST_DIR="$2"
6*fc3927beSAndroid Build Coastguard Workerreadonly SCRIPT_DIR="$(dirname "$0")"
7*fc3927beSAndroid Build Coastguard Workerreadonly BASE_DIR=`readlink -m ${SCRIPT_DIR}/../../../../`
8*fc3927beSAndroid Build Coastguard Workerecho "BASE_DIR: $BASE_DIR"
9*fc3927beSAndroid Build Coastguard Workerreadonly FAILURE_DIR=layoutlib-test-failures
10*fc3927beSAndroid Build Coastguard Workerreadonly FAILURE_ZIP=layoutlib-test-failures.zip
11*fc3927beSAndroid Build Coastguard Worker
12*fc3927beSAndroid Build Coastguard Workerreadonly CLEAN_TMP_FILES=1
13*fc3927beSAndroid Build Coastguard Workerreadonly USE_SOONG=1
14*fc3927beSAndroid Build Coastguard Worker
15*fc3927beSAndroid Build Coastguard Workerreadonly APP_NAME="regression"
16*fc3927beSAndroid Build Coastguard Worker#readonly APP_NAME="test_HelloActivity"
17*fc3927beSAndroid Build Coastguard Worker
18*fc3927beSAndroid Build Coastguard WorkerSTUDIO_JDK="${BASE_DIR}/prebuilts/jdk/jdk21/linux-x86"
19*fc3927beSAndroid Build Coastguard WorkerNATIVE_LIBRARIES="${BASE_DIR}/out/host/linux-x86/lib64/"
20*fc3927beSAndroid Build Coastguard WorkerJAVA_LIBRARIES="${BASE_DIR}/out/host/common/obj/JAVA_LIBRARIES/"
21*fc3927beSAndroid Build Coastguard WorkerHOST_LIBRARIES="${BASE_DIR}/out/host/linux-x86"
22*fc3927beSAndroid Build Coastguard WorkerSDK="${BASE_DIR}/out/host/linux-x86/sdk/sdk*/android-sdk*"
23*fc3927beSAndroid Build Coastguard WorkerSDK_REPO="${BASE_DIR}/out/host/linux-x86/sdk-repo"
24*fc3927beSAndroid Build Coastguard WorkerFONT_DIR="${BASE_DIR}/out/host/common/obj/PACKAGING/fonts_intermediates"
25*fc3927beSAndroid Build Coastguard WorkerHYPHEN_DATA_DIR="${BASE_DIR}/out/host/common/obj/PACKAGING/hyphen_intermediates"
26*fc3927beSAndroid Build Coastguard WorkerKEYBOARD_DIR="${BASE_DIR}/out/host/common/obj/PACKAGING/keyboards_intermediates"
27*fc3927beSAndroid Build Coastguard WorkerICU_DATA_PATH="${BASE_DIR}/out/host/linux-x86/com.android.i18n/etc/icu/icudt75l.dat"
28*fc3927beSAndroid Build Coastguard WorkerTMP_DIR=${OUT_DIR}"/layoutlib_tmp"
29*fc3927beSAndroid Build Coastguard Worker
30*fc3927beSAndroid Build Coastguard WorkerPLATFORM=${TMP_DIR}/"android"
31*fc3927beSAndroid Build Coastguard Worker
32*fc3927beSAndroid Build Coastguard Workerif [ ! -d $TMP_DIR ]; then
33*fc3927beSAndroid Build Coastguard Worker    # Copy resources to a temp directory
34*fc3927beSAndroid Build Coastguard Worker    mkdir -p ${TMP_DIR} ${PLATFORM} ${TMP_DIR}/build-tools ${TMP_DIR}/compiled ${TMP_DIR}/manifest
35*fc3927beSAndroid Build Coastguard Worker
36*fc3927beSAndroid Build Coastguard Worker    cp -r ${SDK}/platforms/android*/** ${PLATFORM}
37*fc3927beSAndroid Build Coastguard Worker
38*fc3927beSAndroid Build Coastguard Worker    # Unzip build-tools to access aapt2
39*fc3927beSAndroid Build Coastguard Worker    unzip -q ${SDK_REPO}/sdk-repo-linux-build-tools.zip -d ${TMP_DIR}/build-tools
40*fc3927beSAndroid Build Coastguard Worker
41*fc3927beSAndroid Build Coastguard Worker    # Compile 9-patch files
42*fc3927beSAndroid Build Coastguard Worker    echo \
43*fc3927beSAndroid Build Coastguard Worker'<?xml version="1.0" encoding="utf-8"?>
44*fc3927beSAndroid Build Coastguard Worker<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.google.android.layoutlib" />' \
45*fc3927beSAndroid Build Coastguard Worker> ${TMP_DIR}/manifest/AndroidManifest.xml
46*fc3927beSAndroid Build Coastguard Worker    find ${SDK}/platforms/android*/data/res -name "*.9.png" -print0 | xargs -0 ${TMP_DIR}/build-tools/android-*/aapt2 compile -o ${TMP_DIR}/compiled/
47*fc3927beSAndroid Build Coastguard Worker    find ${TMP_DIR}/compiled -name "*.flat" -print0 | xargs -0 -s 1000000 ${TMP_DIR}/build-tools/android-*/aapt2 link -o ${TMP_DIR}/compiled.apk --manifest ${TMP_DIR}/manifest/AndroidManifest.xml -R
48*fc3927beSAndroid Build Coastguard Worker    unzip -q ${TMP_DIR}/compiled.apk -d ${TMP_DIR}
49*fc3927beSAndroid Build Coastguard Worker    for f in ${TMP_DIR}/res/*; do mv "$f" "${f/-v4/}";done
50*fc3927beSAndroid Build Coastguard Worker    cp -RL ${TMP_DIR}/res ${PLATFORM}/data
51*fc3927beSAndroid Build Coastguard Workerfi
52*fc3927beSAndroid Build Coastguard Worker
53*fc3927beSAndroid Build Coastguard Worker
54*fc3927beSAndroid Build Coastguard WorkerTEST_JARS="${HOST_LIBRARIES}/framework/layoutlib-tests.jar"
55*fc3927beSAndroid Build Coastguard WorkerGRADLE_RES="-Dtest_res.dir=${SCRIPT_DIR}/res"
56*fc3927beSAndroid Build Coastguard Worker
57*fc3927beSAndroid Build Coastguard Worker# Run layoutlib tests
58*fc3927beSAndroid Build Coastguard Worker#DEBUGGER=' -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8000 '
59*fc3927beSAndroid Build Coastguard WorkerDEBUGGER=' '
60*fc3927beSAndroid Build Coastguard Worker
61*fc3927beSAndroid Build Coastguard Workerset -x
62*fc3927beSAndroid Build Coastguard Worker${STUDIO_JDK}/bin/java -ea $DEBUGGER \
63*fc3927beSAndroid Build Coastguard Worker    -Dnative.lib.path=${NATIVE_LIBRARIES} \
64*fc3927beSAndroid Build Coastguard Worker    -Dfont.dir=${FONT_DIR} \
65*fc3927beSAndroid Build Coastguard Worker    -Dicu.data.path=${ICU_DATA_PATH} \
66*fc3927beSAndroid Build Coastguard Worker    -Dhyphen.data.dir=${HYPHEN_DATA_DIR} \
67*fc3927beSAndroid Build Coastguard Worker    -Dkeyboard.dir=${KEYBOARD_DIR} \
68*fc3927beSAndroid Build Coastguard Worker    -Dplatform.dir=${PLATFORM} \
69*fc3927beSAndroid Build Coastguard Worker    -Dtest_failure.dir=${OUT_DIR}/${FAILURE_DIR} \
70*fc3927beSAndroid Build Coastguard Worker    ${GRADLE_RES} \
71*fc3927beSAndroid Build Coastguard Worker    -cp ${TEST_JARS} \
72*fc3927beSAndroid Build Coastguard Worker    org.junit.runner.JUnitCore \
73*fc3927beSAndroid Build Coastguard Worker    com.android.layoutlib.bridge.intensive.Main
74*fc3927beSAndroid Build Coastguard Workertest_exit_code=$?
75*fc3927beSAndroid Build Coastguard Workerset +x
76*fc3927beSAndroid Build Coastguard Worker
77*fc3927beSAndroid Build Coastguard Worker
78*fc3927beSAndroid Build Coastguard Worker# Create zip of all failure screenshots
79*fc3927beSAndroid Build Coastguard Workerrm -f ${OUT_DIR}/${FAILURE_ZIP}
80*fc3927beSAndroid Build Coastguard Workerif [[ -d "${OUT_DIR}/${FAILURE_DIR}" ]]; then
81*fc3927beSAndroid Build Coastguard Worker    zip -q -j -r ${OUT_DIR}/${FAILURE_ZIP} ${OUT_DIR}/${FAILURE_DIR}
82*fc3927beSAndroid Build Coastguard Workerfi
83*fc3927beSAndroid Build Coastguard Worker
84*fc3927beSAndroid Build Coastguard Worker# Move failure zip to dist directory if specified
85*fc3927beSAndroid Build Coastguard Workerif [[ -d "${DIST_DIR}" ]] && [[ -e "${OUT_DIR}/${FAILURE_ZIP}" ]]; then
86*fc3927beSAndroid Build Coastguard Worker    mv ${OUT_DIR}/${FAILURE_ZIP} ${DIST_DIR}
87*fc3927beSAndroid Build Coastguard Workerfi
88*fc3927beSAndroid Build Coastguard Worker
89*fc3927beSAndroid Build Coastguard Worker# Clean
90*fc3927beSAndroid Build Coastguard Workerif [[ $CLEAN_TMP_FILES -eq 1 ]]; then
91*fc3927beSAndroid Build Coastguard Worker  rm -rf ${TMP_DIR}
92*fc3927beSAndroid Build Coastguard Worker  rm -rf ${OUT_DIR}/${FAILURE_DIR}
93*fc3927beSAndroid Build Coastguard Workerfi
94*fc3927beSAndroid Build Coastguard Worker
95*fc3927beSAndroid Build Coastguard Workerexit ${test_exit_code}
96