xref: /aosp_15_r20/art/libnativebridge/tests/runtests.sh (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1#!/bin/bash
2
3set -e
4
5skip_build=
6skip_host=
7skip_target=
8skip_cleanup=
9for arg; do
10  case "$arg" in
11    --skip-build) skip_build=true ;;
12    --skip-host) skip_host=true ;;
13    --skip-target) skip_target=true ;;
14    --skip-cleanup) skip_cleanup=true ;;
15    *) break ;;
16  esac
17  shift
18done
19
20echo_and_run() {
21  echo "$@"
22  eval "$@"
23}
24
25device_test_root=/data/local/tmp/libnativebridge-test
26
27vars="$(build/soong/soong_ui.bash --dumpvars-mode --vars='HOST_OUT PRODUCT_OUT TARGET_ARCH')"
28# Assign to a variable and eval that, since bash ignores any error status
29# from the command substitution if it's directly on the eval line.
30eval $vars
31
32if [ -z "$skip_build" ]; then
33  rm -rf $HOST_OUT/nativetest{,64} $PRODUCT_OUT/data/nativetest{,64}/art/$TARGET_ARCH
34  echo_and_run build/soong/soong_ui.bash --make-mode MODULES-IN-art-libnativebridge-tests
35fi
36
37if [ -z "$skip_host" ]; then
38  for build_dir in $HOST_OUT/nativetest{,64}/ ; do
39    if [ ! -d $build_dir ]; then
40      echo "Skipping missing $build_dir"
41    else
42      for test_path in $build_dir/*/* ; do
43        echo_and_run LD_LIBRARY_PATH=$build_dir $test_path $*
44      done
45    fi
46  done
47fi
48
49if [ -z "$skip_target" ]; then
50  adb root
51  adb wait-for-device
52
53  for build_dir in $PRODUCT_OUT/data/nativetest{,64}/art/$TARGET_ARCH ; do
54    if [ ! -d $build_dir ]; then
55      echo "Skipping missing $build_dir"
56    else
57      test_dir=$device_test_root/$TARGET_ARCH
58
59      echo_and_run adb shell rm -rf $test_dir
60      echo_and_run adb push $build_dir $test_dir
61
62      for test_path in $build_dir/*/* ; do
63        test_rel_path=${test_path#${build_dir}/}
64        echo_and_run adb shell cd $test_dir '\;' LD_LIBRARY_PATH=. $test_rel_path $*
65      done
66    fi
67  done
68
69  if [ -z "$skip_cleanup" ]; then
70    echo_and_run adb shell rm -rf $device_test_root
71  fi
72fi
73
74echo "No errors"
75