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

Commit 60b722a0 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "[view_compiler] Add end-to-end DexBuilder tests"

parents 777235c4 d683f9fa
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -62,3 +62,22 @@ cc_test_host {
    ],
    test_suites: ["general-tests"],
}

cc_binary_host {
    name: "dex_testcase_generator",
    defaults: ["viewcompiler_defaults"],
    srcs: ["dex_testcase_generator.cc"],
    static_libs: [
        "libviewcompiler",
    ],
}

genrule {
    name: "generate_dex_testcases",
    tools: [":dex_testcase_generator"],
    cmd: "$(location :dex_testcase_generator) $(genDir)",
    out: [
        "simple.dex",
        "trivial.dex",
    ],
}
+28 −0
Original line number Diff line number Diff line
@@ -23,3 +23,31 @@ This tool is still in its early stages and has a number of limitations.
  application.
* This only works for apps that do not use a custom layout inflater.
* Other limitations yet to be discovered.

## DexBuilder Tests

The DexBuilder has several low-level end to end tests to verify generated DEX
code validates, runs, and has the correct behavior. There are, unfortunately, a
number of pieces that must be added to generate new tests. Here are the
components:

* `dex_testcase_generator` - Written in C++ using `DexBuilder`. This runs as a
  build step produce the DEX files that will be tested on device. See the
  `genrule` named `generate_dex_testcases` in `Android.bp`. These files are then
  copied over to the device by TradeFed when running tests.
* `DexBuilderTest` - This is a Java Language test harness that loads the
  generated DEX files and exercises methods in the file.

To add a new DEX file test, follow these steps:
1. Modify `dex_testcase_generator` to produce the DEX file.
2. Add the filename to the `out` list of the `generate_dex_testcases` rule in
   `Android.bp`.
3. Add a new `push` option to `AndroidTest.xml` to copy the DEX file to the
   device.
4. Modify `DexBuilderTest.java` to load and exercise the new test.

In each case, you should be able to cargo-cult the existing test cases.

In general, you can probably get by without adding a new generated DEX file, and
instead add more methods to the files that are already generated. In this case,
you can skip all of steps 2 and 3 above, and simplify steps 1 and 4.
+7 −0
Original line number Diff line number Diff line
{
  "presubmit": [
    {
      "name": "dex-builder-test"
    }
  ]
}
+29 −0
Original line number Diff line number Diff line
//
// Copyright (C) 2018 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.
//

android_test {
    name: "dex-builder-test",
    srcs: ["src/android/startop/test/DexBuilderTest.java"],
    sdk_version: "current",
    data: [":generate_dex_testcases"],
    static_libs: [
        "android-support-test",
        "guava",
    ],
    manifest: "AndroidManifest.xml",
    test_config: "AndroidTest.xml",
    test_suites: ["general-tests"],
}
+29 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2018 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.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="android.startop.test" >

    <uses-sdk android:minSdkVersion="28" android:targetSdkVersion="28" />

    <application>
        <uses-library android:name="android.test.runner" />
    </application>

    <instrumentation android:name="android.support.test.runner.AndroidJUnitRunner"
                     android:targetPackage="android.startop.test"
                     android:label="DexBuilder Tests"/>

</manifest>
Loading