Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6fdd28a9 authored by Makoto Onuki's avatar Makoto Onuki Committed by Android (Google) Code Review
Browse files

Merge "Initial commit of "HostStubGen" (Ravenwood)" into main

parents 5e661b59 8558e9a9
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -163,6 +163,12 @@ java_library {
        //same purpose.
        "//external/robolectric:__subpackages__",
        "//frameworks/layoutlib:__subpackages__",

        // This is for the same purpose as robolectric -- to build "framework.jar" for host-side
        // testing.
        // TODO: Once Ravenwood is stable, move the host side jar targets to this directory,
        // and remove this line.
        "//frameworks/base/tools/hoststubgen:__subpackages__",
    ],
}

@@ -405,6 +411,7 @@ java_defaults {
        "audiopolicy-aidl-java",
        "sounddose-aidl-java",
        "modules-utils-expresslog",
        "hoststubgen-annotations",
    ],
}

+3 −0
Original line number Diff line number Diff line
out/
*-out/
*.log
+76 −0
Original line number Diff line number Diff line
# HostStubGen

## Overview

This directory contains tools / sample code / investigation for host side test support.


## Directories and files

- `hoststubgen/`
  Contains source code of the "hoststubgen" tool and relevant code

  - `framework-policy-override.txt`
    This file contains "policy overrides", which allows to control what goes to stub/impl without
    having to touch the target java files. This allows quicker iteration, because you can skip
    having to rebuild framework.jar.

  - `src/`

    HostStubGen tool source code.

  - `annotations-src/` See `Android.bp`.
  - `helper-framework-buildtime-src/` See `Android.bp`.
  - `helper-framework-runtime-src/` See `Android.bp`.
  - `helper-runtime-src/` See `Android.bp`.

  - `test-tiny-framework/` See `README.md` in it.

  - `test-framework` See `README.md` in it.

- `scripts`
  - `run-host-test.sh`

    Run a host side test. Use it instead of `atest` for now. (`atest` works "mostly" but it has
    problems.)

  - `dump-jar.sh`

    A script to dump the content of `*.class` and `*.jar` files.

  - `run-all-tests.sh`

    Run all tests. Many tests may fail, but at least this should run til the end.
    (It should print `run-all-tests.sh finished` at the end)

## Build and run

### Building `HostStubGen` binary

```
m hoststubgen
```

### Run the tests

- Run all relevant tests and test scripts. Some of thests are still expected to fail,
  but this should print "finished, with no unexpected failures" at the end.

  However, because some of the script it executes depend on internal file paths to Soong's
  intermediate directory, some of it might fail when something changes in the build system.

  We need proper build system integration to fix them.
```
$ ./scripts/run-all-tests.sh
```

- See also `README.md` in `test-*` directories.

## TODOs, etc

 - Make sure the parent's visibility is not smaller than the member's.

- @HostSideTestNativeSubstitutionClass should automatically add class-keep to the substitute class.
  (or at least check it.)

 - The `HostStubGenTest-framework-test-host-test-lib` jar somehow contain all ASM classes? Figure out where the dependency is coming from.
+6 −0
Original line number Diff line number Diff line
{
    // TODO: Change to presubmit.
    "postsubmit": [
        { "name": "tiny-framework-dump-test" }
    ]
}
+116 −0
Original line number Diff line number Diff line
# Copyright (C) 2023 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -e # Exit at failure
shopt -s globstar # Enable double-star wildcards (**)

cd "${0%/*}" # Move to the script dir

fail() {
  echo "Error: $*" 1>&2
  exit 1
}

# Print the arguments and then execute.
run() {
  echo "Running: $*" 1>&2
  "$@"
}

# Concatenate the second and subsequent args with the first arg as a separator.
# e.g. `join : a b c` -> prints `a:b:c`
join() {
  local IFS="$1"
  shift
  echo "$*"
}

abspath() {
  for name in "${@}"; do
    readlink -f $name
  done
}

m() {
  if (( $SKIP_BUILD )) ; then
    echo "Skipping build: $*" 1>&2
    return 0
  fi
  run ${ANDROID_BUILD_TOP}/build/soong/soong_ui.bash --make-mode "$@"
}

# Extract given jar files
extract() {
  for f in "${@}"; do
    local out=$f.ext
    run rm -fr $out
    run mkdir -p $out

    # It's too noisy, so only show the first few lines.
    {
      # Hmm unzipping kotlin jar files may produce a warning? Let's just add `|| true`...
      run unzip $f -d $out || true
    } |& sed -e '5,$d'
    echo '  (omitting remaining output)'

  done
}

# Find all *.java files in $1, and print them as Java class names.
# For example, if there's a file `src/com/android/test/Test.java`, and you run
# `list_all_classes_under_dir src`, then it'll print `com.android.test.Test`.
list_all_classes_under_dir() {
  local dir="$1"
  ( # Use a subshell, so we won't change the current directory on the caller side.
    cd "$dir"

    # List the java files, but replace the slashes with dots, and remove the `.java` suffix.
    ls **/*.java | sed -e 's!/!.!g' -e 's!.java$!!'
  )
}

checkenv() {
  # Make sure $ANDROID_BUILD_TOP is set.
  : ${ANDROID_BUILD_TOP:?}

  # Make sure ANDROID_BUILD_TOP doesn't contain whitespace.
  set ${ANDROID_BUILD_TOP}
  if [[ $# != 1 ]] ; then
    fail "\$ANDROID_BUILD_TOP cannot contain whitespace."
  fi
}

checkenv

JAVAC=${JAVAC:-javac}
JAVA=${JAVA:-java}
JAR=${JAR:-jar}

JAVAC_OPTS=${JAVAC_OPTS:--Xmaxerrs 99999 -Xlint:none}

SOONG_INT=$ANDROID_BUILD_TOP/out/soong/.intermediates

JUNIT_TEST_MAIN_CLASS=com.android.hoststubgen.hosthelper.HostTestSuite

run_junit_test_jar() {
  local jar="$1"
  echo "Starting test: $jar ..."
  run cd "${jar%/*}"

  run $JAVA $JAVA_OPTS \
      -cp $jar \
      org.junit.runner.JUnitCore \
      $main_class || return 1
  return 0
}
Loading