xref: /aosp_15_r20/frameworks/base/ravenwood/tools/hoststubgen/test-tiny-framework/run-test-manually.sh (revision d57664e9bc4670b3ecf6748a746a57c557b6bc9e)
1#!/bin/bash
2# Copyright (C) 2023 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
17source "${0%/*}"/../../common.sh
18
19# This scripts run the "tiny-framework" test, but does most stuff from the command line, using
20# the native java and javac commands.
21
22debug=0
23while getopts "d" opt; do
24case "$opt" in
25    d) debug=1 ;;
26esac
27done
28shift $(($OPTIND - 1))
29
30
31out=out
32
33rm -fr $out
34mkdir -p $out
35
36HOSTSTUBGEN=hoststubgen
37
38# Rebuild the tool and the dependencies. These are the only things we build with the build system.
39run m $HOSTSTUBGEN hoststubgen-annotations hoststubgen-helper-runtime truth junit
40
41
42# Build tiny-framework
43
44tiny_framework_classes=$out/tiny-framework/classes/
45tiny_framework_jar=$out/tiny-framework.jar
46tiny_framework_host_jar=$out/tiny-framework_host.jar
47
48tiny_test_classes=$out/tiny-test/classes/
49tiny_test_jar=$out/tiny-test.jar
50
51framework_compile_classpaths=(
52  $SOONG_INT/frameworks/base/tools/hoststubgen/hoststubgen/hoststubgen-annotations/android_common/javac/hoststubgen-annotations.jar
53)
54
55test_compile_classpaths=(
56  $SOONG_INT/external/junit/junit/android_common/combined/junit.jar
57  $SOONG_INT/external/truth/truth/android_common/combined/truth.jar
58)
59
60test_runtime_classpaths=(
61  $SOONG_INT/frameworks/base/tools/hoststubgen/hoststubgen/hoststubgen-helper-runtime/linux_glibc_common/javac/hoststubgen-helper-runtime.jar
62)
63
64# This suite runs all tests in the JAR.
65test_classes=(com.android.hoststubgen.hosthelper.HostTestSuite)
66
67# Uncomment this to run a specific test.
68# tests=(com.android.hoststubgen.test.tinyframework.TinyFrameworkBenchmark)
69
70
71# Build tiny-framework.jar
72echo "# Building tiny-framework..."
73run $JAVAC \
74    -cp $( \
75        join : \
76        ${framework_compile_classpaths[@]} \
77        ) \
78    -d $tiny_framework_classes \
79    tiny-framework/src/**/*.java
80
81run $JAR cvf $tiny_framework_jar \
82    -C $tiny_framework_classes .
83
84# Build stub/impl jars
85echo "# Generating the stub and impl jars..."
86run $HOSTSTUBGEN \
87    @../hoststubgen-standard-options.txt \
88    --in-jar $tiny_framework_jar \
89    --out-jar $tiny_framework_host_jar \
90    --policy-override-file policy-override-tiny-framework.txt \
91    --gen-keep-all-file out/tiny-framework_keep_all.txt \
92    --gen-input-dump-file out/tiny-framework_dump.txt \
93    --package-redirect com.unsupported:com.supported \
94    --annotation-allowed-classes-file annotation-allowed-classes-tiny-framework.txt \
95    $HOSTSTUBGEN_OPTS
96
97# Extract the jar files, so we can look into them.
98extract $tiny_framework_host_jar
99
100# Build the test
101echo "# Building tiny-test..."
102run $JAVAC \
103    -cp $( \
104        join : \
105        $tiny_framework_jar \
106        "${test_compile_classpaths[@]}" \
107        ) \
108    -d $tiny_test_classes \
109    tiny-test/src/**/*.java
110
111run $JAR cvf $tiny_test_jar \
112    -C $tiny_test_classes .
113
114if (( $debug )) ; then
115  JAVA_OPTS="$JAVA_OPTS -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8700"
116fi
117
118# Run the test
119echo "# Running tiny-test..."
120run $JAVA \
121    $JAVA_OPTS \
122    -cp $( \
123        join : \
124        $tiny_test_jar \
125        $tiny_framework_host_jar \
126        "${test_compile_classpaths[@]}" \
127        "${test_runtime_classpaths[@]}" \
128        ) \
129    org.junit.runner.JUnitCore \
130    ${test_classes[@]}
131