| 1 | #! /bin/bash |
| 2 | # |
| 3 | |
| 4 | # Copyright (C) 2023 The Android Open Source Project |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except |
| 7 | # in compliance with the License. You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software distributed under the License |
| 12 | # is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 13 | # or implied. See the License for the specific language governing permissions and limitations under |
| 14 | # the License. |
| 15 | |
| 16 | # This script runs the tests for the lockedregioninjectioncode. See |
| 17 | # TestMain.java for the invocation. The script expects that a full build has |
| 18 | # already been done and artifacts are in $TOP/out. |
| 19 | |
| 20 | # Compute the default top of the workspace. The following code copies the |
| 21 | # strategy of croot. (croot cannot be usd directly because it is a function and |
| 22 | # functions are not carried over into subshells.) This gives the correct answer |
| 23 | # if run from inside a workspace. If run from outside a workspace, supply TOP |
| 24 | # on the command line. |
| 25 | TOPFILE=build/make/core/envsetup.mk |
| 26 | TOP=$(dirname $(realpath $0)) |
| 27 | while [[ ! $TOP = / && ! -f $TOP/$TOPFILE ]]; do |
| 28 | TOP=$(dirname $TOP) |
| 29 | done |
| 30 | # TOP is "/" if this script is located outside a workspace. |
| 31 | |
| 32 | # If the user supplied a top directory, use it instead |
| 33 | if [[ -n $1 ]]; then |
| 34 | TOP=$1 |
| 35 | shift |
| 36 | fi |
| 37 | if [[ -z $TOP || $TOP = / ]]; then |
| 38 | echo "usage: $0 <workspace-root>" |
| 39 | exit 1 |
| 40 | elif [[ ! -d $TOP ]]; then |
| 41 | echo "$TOP is not a directory" |
| 42 | exit 1 |
| 43 | elif [[ ! -d $TOP/prebuilts/misc/common ]]; then |
| 44 | echo "$TOP does not look like w workspace" |
| 45 | exit 1 |
| 46 | fi |
| 47 | echo "Using workspace $TOP" |
| 48 | |
| 49 | # Pick up the current java compiler. The lunch target is not very important, |
| 50 | # since most, if not all, will use the same host binaries. |
| 51 | pushd $TOP > /dev/null |
| 52 | . build/envsetup.sh > /dev/null 2>&1 |
| 53 | lunch redfin-userdebug > /dev/null 2>&1 |
| 54 | popd > /dev/null |
| 55 | |
| 56 | # Bail on any error |
| 57 | set -o pipefail |
| 58 | trap 'exit 1' ERR |
| 59 | |
| 60 | # Create the two sources |
| 61 | pushd $TOP > /dev/null |
| 62 | m lockedregioncodeinjection |
| 63 | m lockedregioncodeinjection_input |
| 64 | popd > /dev/null |
| 65 | |
| 66 | # Create a temporary directory outside of the workspace. |
| 67 | OUT=$TOP/out/host/test/lockedregioncodeinjection |
| 68 | echo |
| 69 | |
| 70 | # Clean the directory |
| 71 | if [[ -d $OUT ]]; then rm -r $OUT; fi |
| 72 | mkdir -p $OUT |
| 73 | |
| 74 | ROOT=$TOP/out/host/linux-x86 |
| 75 | EXE=$ROOT/bin/lockedregioncodeinjection |
| 76 | INP=$ROOT/framework/lockedregioncodeinjection_input.jar |
| 77 | |
| 78 | # Run tool on unit tests. |
| 79 | $EXE \ |
| 80 | -i $INP -o $OUT/test_output.jar \ |
| 81 | --targets 'Llockedregioncodeinjection/TestTarget;' \ |
| 82 | --pre 'lockedregioncodeinjection/TestTarget.boost' \ |
| 83 | --post 'lockedregioncodeinjection/TestTarget.unboost' \ |
| 84 | --scoped 'Llockedregioncodeinjection/TestScopedLock;,monitorEnter,monitorExit' |
| 85 | |
| 86 | # Run unit tests. |
| 87 | java -ea -cp $OUT/test_output.jar \ |
| 88 | org.junit.runner.JUnitCore lockedregioncodeinjection.TestMain |
| 89 | |
| 90 | # Extract the class files and decompile them for possible post-analysis. |
| 91 | pushd $OUT > /dev/null |
| 92 | jar -x --file test_output.jar lockedregioncodeinjection |
| 93 | for class in lockedregioncodeinjection/*.class; do |
| 94 | javap -c -v $class > ${class%.class}.asm |
| 95 | done |
| 96 | popd > /dev/null |
| 97 | |
| 98 | echo "artifacts are in $OUT" |