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

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

Merge "Fix + add a golden file test for "ravenhelper PTA"" into main

parents 25499523 8f272b4e
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -75,8 +75,8 @@ run_pta() {
        --output-script $OUT_SCRIPT \
        --annotation-allowed-classes-file $AAC \
        $(with_flag --policy-override-file $POLICIES) \
        $(with_flag --src $SOURCES) \
        $extra_args
        $extra_args \
        $SOURCES

    if ! [[ -f $OUT_SCRIPT ]] ; then
        echo "No files need updating."
+34 −0
Original line number Diff line number Diff line
@@ -189,6 +189,39 @@ java_genrule_host {
    ],
}

// Generate "PTA" script for tiny-framework.
// The output contains files in the fullpaths, so we use the next
// build rule "hoststubgen-test-tiny-framework-pta-output-normalized" to
// remove the unnecessary prefixes.
genrule {
    name: "hoststubgen-test-tiny-framework-pta-output-orig",
    tools: ["ravenhelper"],
    cmd: "$(location ravenhelper) pta " +
        "--output-script $(out) " +
        "--annotation-allowed-classes-file $(location annotation-allowed-classes-tiny-framework-for-pta-test.txt) " +
        "--policy-override-file $(location policy-override-tiny-framework.txt) " +
        "$(locations tiny-framework/src/**/*.java) ",
    srcs: [
        "policy-override-tiny-framework.txt",
        "annotation-allowed-classes-tiny-framework-for-pta-test.txt",
        "tiny-framework/src/**/*.java",
    ],
    out: [
        "pta-output-orig.sed.txt",
    ],
}

genrule {
    name: "hoststubgen-test-tiny-framework-pta-output-normalized",
    cmd: "sed -e 's!^apply .*/test-tiny-framework/!apply \"!' $(in) > $(out)",
    srcs: [
        ":hoststubgen-test-tiny-framework-pta-output-orig",
    ],
    out: [
        "pta-output.sed.txt",
    ],
}

// Compare the dump of the jar files to the golden output.
python_test_host {
    name: "tiny-framework-dump-test",
@@ -197,6 +230,7 @@ python_test_host {
    ],
    data: [
        "golden-output/*.txt",
        ":hoststubgen-test-tiny-framework-pta-output-normalized",
    ],
    java_data: [
        "hoststubgen-test-tiny-framework-orig-dump",
+4 −0
Original line number Diff line number Diff line
# Policy file used for "PTA" golden test.

# Just allow this class. Other classes are not allow-listed.
com.android.hoststubgen.test.tinyframework.TinyFrameworkAnnotations
+353 −0
Original line number Diff line number Diff line
#!/bin/bash

set -e # Finish when any command fails.

function apply() {
    local file="$1"

    # The script is given via stdin. Write it to file.
    local sed="/tmp/pta-script.sed.tmp"
    cat > "$sed"

    echo "Running: sed -i -f \"$sed\" \"$file\""

    if ! sed -i -f "$sed" "$file" ; then
        echo 'Failed!' 1>&2
        return 1
    fi
}

#==============================================================================

apply "tiny-framework/src/com/android/hoststubgen/test/tinyframework/TinyFrameworkForTextPolicy.java" <<'__END_OF_SCRIPT__'

# add class annotation to com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPolicy
21i\
@android.ravenwood.annotation.RavenwoodKeepPartialClass

# add class annotation to com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPolicy
21i\
@android.ravenwood.annotation.RavenwoodClassLoadHook("com.android.hoststubgen.test.tinyframework.TinyFrameworkClassLoadHook.onClassLoaded")

# add annotation to method com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPolicy.<init>()V
22i\
    @android.ravenwood.annotation.RavenwoodKeep

# add annotation to field com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPolicy.stub
25i\
    @android.ravenwood.annotation.RavenwoodKeep

# add annotation to method com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPolicy.addOne(I)I
31i\
    @android.ravenwood.annotation.RavenwoodKeep

# add annotation to method com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPolicy.toBeRemoved(Ljava/lang/String;)V
35i\
    @android.ravenwood.annotation.RavenwoodRemove

# add annotation to method com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPolicy.toBeIgnoredObj()Ljava/lang/String;
39i\
    @android.ravenwood.annotation.RavenwoodIgnore

# add annotation to method com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPolicy.toBeIgnoredV()V
43i\
    @android.ravenwood.annotation.RavenwoodIgnore

# add annotation to method com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPolicy.toBeIgnoredZ()Z
47i\
    @android.ravenwood.annotation.RavenwoodIgnore

# add annotation to method com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPolicy.toBeIgnoredB()B
51i\
    @android.ravenwood.annotation.RavenwoodIgnore

# add annotation to method com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPolicy.toBeIgnoredC()C
55i\
    @android.ravenwood.annotation.RavenwoodIgnore

# add annotation to method com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPolicy.toBeIgnoredS()S
59i\
    @android.ravenwood.annotation.RavenwoodIgnore

# add annotation to method com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPolicy.toBeIgnoredI()I
63i\
    @android.ravenwood.annotation.RavenwoodIgnore

# add annotation to method com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPolicy.toBeIgnoredF()F
67i\
    @android.ravenwood.annotation.RavenwoodIgnore

# add annotation to method com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPolicy.toBeIgnoredD()D
71i\
    @android.ravenwood.annotation.RavenwoodIgnore

# add annotation to method com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPolicy.unsupportedMethod()Ljava/lang/String;
89i\
    @android.ravenwood.annotation.RavenwoodThrow
__END_OF_SCRIPT__

#==============================================================================

apply "tiny-framework/src/com/android/hoststubgen/test/tinyframework/TinyFrameworkMethodCallReplace.java" <<'__END_OF_SCRIPT__'

# add class annotation to com.android.hoststubgen.test.tinyframework.TinyFrameworkMethodCallReplace
23i\
@android.ravenwood.annotation.RavenwoodKeepWholeClass
__END_OF_SCRIPT__

#==============================================================================

apply "tiny-framework/src/com/android/hoststubgen/test/tinyframework/packagetest/B.java" <<'__END_OF_SCRIPT__'

# add class annotation to com.android.hoststubgen.test.tinyframework.packagetest.B
18i\
@android.ravenwood.annotation.RavenwoodRemove
__END_OF_SCRIPT__

#==============================================================================

apply "tiny-framework/src/com/android/hoststubgen/test/tinyframework/packagetest/sub/B.java" <<'__END_OF_SCRIPT__'

# add class annotation to com.android.hoststubgen.test.tinyframework.packagetest.sub.B
18i\
@android.ravenwood.annotation.RavenwoodRemove
__END_OF_SCRIPT__

#==============================================================================

apply "tiny-framework/src/com/android/hoststubgen/test/tinyframework/subclasstest/C1.java" <<'__END_OF_SCRIPT__'

# add class annotation to com.android.hoststubgen.test.tinyframework.subclasstest.C1
18i\
@android.ravenwood.annotation.RavenwoodKeepPartialClass
__END_OF_SCRIPT__

#==============================================================================

apply "tiny-framework/src/com/android/hoststubgen/test/tinyframework/subclasstest/C2.java" <<'__END_OF_SCRIPT__'

# add class annotation to com.android.hoststubgen.test.tinyframework.subclasstest.C2
18i\
@android.ravenwood.annotation.RavenwoodKeepPartialClass
__END_OF_SCRIPT__

#==============================================================================

apply "tiny-framework/src/com/android/hoststubgen/test/tinyframework/subclasstest/C3.java" <<'__END_OF_SCRIPT__'

# add class annotation to com.android.hoststubgen.test.tinyframework.subclasstest.C3
18i\
@android.ravenwood.annotation.RavenwoodKeepPartialClass
__END_OF_SCRIPT__

#==============================================================================

apply "tiny-framework/src/com/android/hoststubgen/test/tinyframework/subclasstest/CA.java" <<'__END_OF_SCRIPT__'

# add class annotation to com.android.hoststubgen.test.tinyframework.subclasstest.CA
18i\
@android.ravenwood.annotation.RavenwoodKeepPartialClass
__END_OF_SCRIPT__

#==============================================================================

apply "tiny-framework/src/com/android/hoststubgen/test/tinyframework/subclasstest/CB.java" <<'__END_OF_SCRIPT__'

# add class annotation to com.android.hoststubgen.test.tinyframework.subclasstest.CB
18i\
@android.ravenwood.annotation.RavenwoodKeepPartialClass
__END_OF_SCRIPT__

#==============================================================================

apply "tiny-framework/src/com/android/hoststubgen/test/tinyframework/subclasstest/I1.java" <<'__END_OF_SCRIPT__'

# add class annotation to com.android.hoststubgen.test.tinyframework.subclasstest.I1
18i\
@android.ravenwood.annotation.RavenwoodKeepPartialClass
__END_OF_SCRIPT__

#==============================================================================

apply "tiny-framework/src/com/android/hoststubgen/test/tinyframework/subclasstest/I2.java" <<'__END_OF_SCRIPT__'

# add class annotation to com.android.hoststubgen.test.tinyframework.subclasstest.I2
18i\
@android.ravenwood.annotation.RavenwoodKeepPartialClass
__END_OF_SCRIPT__

#==============================================================================

apply "tiny-framework/src/com/android/hoststubgen/test/tinyframework/subclasstest/I3.java" <<'__END_OF_SCRIPT__'

# add class annotation to com.android.hoststubgen.test.tinyframework.subclasstest.I3
18i\
@android.ravenwood.annotation.RavenwoodKeepPartialClass
__END_OF_SCRIPT__

#==============================================================================

apply "tiny-framework/src/com/android/hoststubgen/test/tinyframework/subclasstest/IA.java" <<'__END_OF_SCRIPT__'

# add class annotation to com.android.hoststubgen.test.tinyframework.subclasstest.IA
18i\
@android.ravenwood.annotation.RavenwoodKeepPartialClass
__END_OF_SCRIPT__

#==============================================================================

apply "tiny-framework/src/com/android/hoststubgen/test/tinyframework/subclasstest/IB.java" <<'__END_OF_SCRIPT__'

# add class annotation to com.android.hoststubgen.test.tinyframework.subclasstest.IB
18i\
@android.ravenwood.annotation.RavenwoodKeepPartialClass
__END_OF_SCRIPT__

#==============================================================================

apply "annotation-allowed-classes-tiny-framework-for-pta-test.txt" <<'__END_OF_SCRIPT__'

# add to annotation allowlist
$a\
com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPolicy

# add to annotation allowlist
$a\
com.android.hoststubgen.test.tinyframework.TinyFrameworkMethodCallReplace

# add to annotation allowlist
$a\
com.android.hoststubgen.test.tinyframework.packagetest.B

# add to annotation allowlist
$a\
com.android.hoststubgen.test.tinyframework.packagetest.sub.B

# add to annotation allowlist
$a\
com.android.hoststubgen.test.tinyframework.subclasstest.C1

# add to annotation allowlist
$a\
com.android.hoststubgen.test.tinyframework.subclasstest.C2

# add to annotation allowlist
$a\
com.android.hoststubgen.test.tinyframework.subclasstest.C3

# add to annotation allowlist
$a\
com.android.hoststubgen.test.tinyframework.subclasstest.CA

# add to annotation allowlist
$a\
com.android.hoststubgen.test.tinyframework.subclasstest.CB

# add to annotation allowlist
$a\
com.android.hoststubgen.test.tinyframework.subclasstest.I1

# add to annotation allowlist
$a\
com.android.hoststubgen.test.tinyframework.subclasstest.I2

# add to annotation allowlist
$a\
com.android.hoststubgen.test.tinyframework.subclasstest.I3

# add to annotation allowlist
$a\
com.android.hoststubgen.test.tinyframework.subclasstest.IA

# add to annotation allowlist
$a\
com.android.hoststubgen.test.tinyframework.subclasstest.IB
__END_OF_SCRIPT__

#==============================================================================

apply "policy-override-tiny-framework.txt" <<'__END_OF_SCRIPT__'

# remove field policy com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPolicy.stub
2s/^/#[PTA]: /

# remove method policy com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPolicy.<init>()V
4s/^/#[PTA]: /

# remove method policy com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPolicy.addOne(I)I
5s/^/#[PTA]: /

# remove method policy com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPolicy.toBeRemoved(Ljava/lang/String;)V
7s/^/#[PTA]: /

# remove method policy com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPolicy.unsupportedMethod()Ljava/lang/String;
12s/^/#[PTA]: /

# remove method policy com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPolicy.toBeIgnoredObj()Ljava/lang/String;
14s/^/#[PTA]: /

# remove method policy com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPolicy.toBeIgnoredV()V
15s/^/#[PTA]: /

# remove method policy com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPolicy.toBeIgnoredZ()Z
16s/^/#[PTA]: /

# remove method policy com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPolicy.toBeIgnoredB()B
17s/^/#[PTA]: /

# remove method policy com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPolicy.toBeIgnoredC()C
18s/^/#[PTA]: /

# remove method policy com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPolicy.toBeIgnoredS()S
19s/^/#[PTA]: /

# remove method policy com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPolicy.toBeIgnoredI()I
20s/^/#[PTA]: /

# remove method policy com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPolicy.toBeIgnoredF()F
22s/^/#[PTA]: /

# remove method policy com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPolicy.toBeIgnoredD()D
23s/^/#[PTA]: /

# remove class load hook policy on com.android.hoststubgen.test.tinyframework.TinyFrameworkForTextPolicy
26s/^/#[PTA]: /

# remove class policy on com.android.hoststubgen.test.tinyframework.subclasstest.C1
35s/^/#[PTA]: /

# remove class policy on com.android.hoststubgen.test.tinyframework.subclasstest.C2
36s/^/#[PTA]: /

# remove class policy on com.android.hoststubgen.test.tinyframework.subclasstest.C3
37s/^/#[PTA]: /

# remove class policy on com.android.hoststubgen.test.tinyframework.subclasstest.CA
38s/^/#[PTA]: /

# remove class policy on com.android.hoststubgen.test.tinyframework.subclasstest.CB
39s/^/#[PTA]: /

# remove class policy on com.android.hoststubgen.test.tinyframework.subclasstest.I1
40s/^/#[PTA]: /

# remove class policy on com.android.hoststubgen.test.tinyframework.subclasstest.I2
41s/^/#[PTA]: /

# remove class policy on com.android.hoststubgen.test.tinyframework.subclasstest.I3
42s/^/#[PTA]: /

# remove class policy on com.android.hoststubgen.test.tinyframework.subclasstest.IA
43s/^/#[PTA]: /

# remove class policy on com.android.hoststubgen.test.tinyframework.subclasstest.IB
44s/^/#[PTA]: /

# remove class policy on com.android.hoststubgen.test.tinyframework.packagetest.B
55s/^/#[PTA]: /

# remove class policy on com.android.hoststubgen.test.tinyframework.packagetest.sub.B
56s/^/#[PTA]: /
__END_OF_SCRIPT__

echo "All files updated successfully!"
+4 −0
Original line number Diff line number Diff line
@@ -44,6 +44,10 @@ class PtaOptions(
    override fun parseOption(option: String, args: ArgIterator): Boolean {
        fun nextArg(): String = args.nextArgRequired(option)

        if (!option.startsWith("-")) {
            sourceFilesOrDirectories.add(option.ensureFileExists())
            return true
        }
        when (option) {
            // TODO: Write help
            "-h", "--help" -> TODO("Help is not implemented yet")
Loading