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. |
Bob Badour | 0bc14d9 | 2022-01-13 11:52:30 -0800 | [diff] [blame] | 26 | package { |
| 27 | // See: http://go/android-license-faq |
| 28 | // A large-scale-change added 'default_applicable_licenses' to import |
| 29 | // all of the 'license_kinds' from "prebuilts_r8_license" |
| 30 | // to get the below license kinds: |
| 31 | // SPDX-license-identifier-Apache-2.0 |
| 32 | default_applicable_licenses: ["prebuilts_r8_license"], |
| 33 | } |
| 34 | |
Ian Zerny | 1648f4b | 2021-11-17 09:03:49 +0100 | [diff] [blame] | 35 | genrule { |
| 36 | name: "r8retrace-dexdump-sample-app", |
| 37 | out: ["dexdump.txt"], |
| 38 | srcs: [":HelloActivityWithR8"], |
| 39 | tools: ["dexdump", "extractmarker"], |
| 40 | cmd: "$(location extractmarker) $(in) > $(out)" |
| 41 | + " && $(location dexdump) -d $(in) >> $(out)", |
| 42 | } |
| 43 | |
| 44 | // Tool and rule to create the raw stack trace from a dexdump. |
| 45 | java_binary_host { |
| 46 | name: "r8retrace-create-stacktrace-tool", |
| 47 | main_class: "com.android.tools.r8.CreateStacktraceFromDexDumpTool", |
| 48 | srcs: ["src/com/android/tools/r8/CreateStacktraceFromDexDumpTool.java"], |
| 49 | } |
| 50 | |
| 51 | genrule { |
| 52 | name: "r8retrace-create-stacktrace", |
| 53 | out: ["stacktrace.txt"], |
| 54 | srcs: [":r8retrace-dexdump-sample-app"], |
| 55 | tools: ["r8retrace-create-stacktrace-tool"], |
| 56 | cmd: "$(location r8retrace-create-stacktrace-tool) $(in) $(out)", |
| 57 | } |
| 58 | |
| 59 | // Run retrace on the stack trace to produce a retraced stack trace. |
| 60 | genrule { |
| 61 | name: "r8retrace-run-retrace", |
| 62 | out: ["retraced-stacktrace.txt"], |
| 63 | srcs: [":r8retrace-create-stacktrace", ":HelloActivityWithR8{.proguard_map}"], |
| 64 | tools: ["retrace"], |
| 65 | cmd: "$(location retrace)" |
| 66 | + " --map-search-path $(location :HelloActivityWithR8{.proguard_map})" |
| 67 | + " $(location :r8retrace-create-stacktrace)" |
| 68 | + " > $(out)", |
| 69 | } |
| 70 | |
| 71 | // Test checks that the raw and retraced stack traces are as expected. |
| 72 | // All the output files are added as resources here so that, in case of failure, their content |
| 73 | // can be included in the error message. |
| 74 | java_test_host { |
| 75 | name: "r8retrace-check-retraced-stacktrace", |
| 76 | test_suites: ["general-tests"], |
| 77 | srcs: ["src/com/android/tools/r8/CheckRetracedStacktraceTest.java"], |
| 78 | static_libs: ["junit"], |
| 79 | java_resources: [ |
| 80 | ":r8retrace-dexdump-sample-app", |
| 81 | ":HelloActivityWithR8{.proguard_map}", |
| 82 | ":r8retrace-create-stacktrace", |
| 83 | ":r8retrace-run-retrace", |
| 84 | ], |
| 85 | } |