Ian Zerny | 1648f4b | 2021-11-17 09:03:49 +0100 | [diff] [blame^] | 1 | // |
| 2 | // Copyright (C) 2021 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 | // Integration test for the R8 retracing tool. |
| 17 | |
| 18 | // The retracing tool is a developer tool and part of the build tools. |
| 19 | // The following tests are structured so that the app and retrace tool |
| 20 | // are invoked exactly as a normal build would. The check that they |
| 21 | // produce the correct result is then postponed to a test so that a |
| 22 | // retrace tool failure will not result in a build failure. |
| 23 | |
| 24 | // Rule to dexdump the content of a sample app. |
| 25 | // The dexdump is used to simulate a raw stack trace from the app. |
| 26 | genrule { |
| 27 | name: "r8retrace-dexdump-sample-app", |
| 28 | out: ["dexdump.txt"], |
| 29 | srcs: [":HelloActivityWithR8"], |
| 30 | tools: ["dexdump", "extractmarker"], |
| 31 | cmd: "$(location extractmarker) $(in) > $(out)" |
| 32 | + " && $(location dexdump) -d $(in) >> $(out)", |
| 33 | } |
| 34 | |
| 35 | // Tool and rule to create the raw stack trace from a dexdump. |
| 36 | java_binary_host { |
| 37 | name: "r8retrace-create-stacktrace-tool", |
| 38 | main_class: "com.android.tools.r8.CreateStacktraceFromDexDumpTool", |
| 39 | srcs: ["src/com/android/tools/r8/CreateStacktraceFromDexDumpTool.java"], |
| 40 | } |
| 41 | |
| 42 | genrule { |
| 43 | name: "r8retrace-create-stacktrace", |
| 44 | out: ["stacktrace.txt"], |
| 45 | srcs: [":r8retrace-dexdump-sample-app"], |
| 46 | tools: ["r8retrace-create-stacktrace-tool"], |
| 47 | cmd: "$(location r8retrace-create-stacktrace-tool) $(in) $(out)", |
| 48 | } |
| 49 | |
| 50 | // Run retrace on the stack trace to produce a retraced stack trace. |
| 51 | genrule { |
| 52 | name: "r8retrace-run-retrace", |
| 53 | out: ["retraced-stacktrace.txt"], |
| 54 | srcs: [":r8retrace-create-stacktrace", ":HelloActivityWithR8{.proguard_map}"], |
| 55 | tools: ["retrace"], |
| 56 | cmd: "$(location retrace)" |
| 57 | + " --map-search-path $(location :HelloActivityWithR8{.proguard_map})" |
| 58 | + " $(location :r8retrace-create-stacktrace)" |
| 59 | + " > $(out)", |
| 60 | } |
| 61 | |
| 62 | // Test checks that the raw and retraced stack traces are as expected. |
| 63 | // All the output files are added as resources here so that, in case of failure, their content |
| 64 | // can be included in the error message. |
| 65 | java_test_host { |
| 66 | name: "r8retrace-check-retraced-stacktrace", |
| 67 | test_suites: ["general-tests"], |
| 68 | srcs: ["src/com/android/tools/r8/CheckRetracedStacktraceTest.java"], |
| 69 | static_libs: ["junit"], |
| 70 | java_resources: [ |
| 71 | ":r8retrace-dexdump-sample-app", |
| 72 | ":HelloActivityWithR8{.proguard_map}", |
| 73 | ":r8retrace-create-stacktrace", |
| 74 | ":r8retrace-run-retrace", |
| 75 | ], |
| 76 | } |