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