blob: 10ce37df1d133bc9c18e0a184a5e4b21ac661394 [file] [log] [blame]
// Copyright (c) 2019, the R8 project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
package com.android.tools.r8.naming.b139991218;
import static com.android.tools.r8.ToolHelper.getMostRecentKotlinAnnotationJar;
import static com.android.tools.r8.utils.codeinspector.Matchers.isPresent;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import com.android.tools.r8.CompilationFailedException;
import com.android.tools.r8.TestBase;
import com.android.tools.r8.TestParameters;
import com.android.tools.r8.TestParametersCollection;
import com.android.tools.r8.ToolHelper;
import com.android.tools.r8.ir.optimize.Inliner.Reason;
import com.android.tools.r8.utils.FileUtils;
import com.google.common.collect.ImmutableSet;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.concurrent.ExecutionException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
/**
* This is a reproduction of b/139991218 where a defined annotation can no longer be found because
* the hash has changed from when it was cached, due to the GenericSignatureRewriter.
*
* <p>It requires that the hash is pre-computed and that seem to happen only in the lambda merger,
* which is why the ASMified code is generated from kotlin.
*/
@RunWith(Parameterized.class)
public class TestRunner extends TestBase {
private final TestParameters parameters;
@Parameters(name = "{0}")
public static TestParametersCollection data() {
return getTestParameters().withDexRuntimes().withAllApiLevels().build();
}
public TestRunner(TestParameters parameters) {
this.parameters = parameters;
}
@Test
public void testSignatureRewriteHash()
throws ExecutionException, CompilationFailedException, IOException {
testForR8(parameters.getBackend())
.addProgramClassFileData(Lambda1.dump(), Lambda2.dump(), Main.dump(), Alpha.dump())
.addProgramFiles(
Paths.get(
ToolHelper.TESTS_BUILD_DIR,
"kotlinR8TestResources",
"JAVA_8",
"lambdas_kstyle_generics" + FileUtils.JAR_EXTENSION),
getMostRecentKotlinAnnotationJar())
.addKeepMainRule(Main.class)
.addKeepAllAttributes()
.addOptionsModification(
options -> {
options.testing.validInliningReasons = ImmutableSet.of(Reason.FORCE);
options.enableClassInlining = false;
// TODO(b/179019716): Add support for merging in presence of annotations.
options.horizontalClassMergerOptions()
.skipNoClassesOrMembersWithAnnotationsPolicyForTesting =
true;
})
.addHorizontallyMergedClassesInspector(
inspector ->
inspector.assertIsCompleteMergeGroup(
"com.android.tools.r8.naming.b139991218.Lambda1",
"com.android.tools.r8.naming.b139991218.Lambda2"))
.allowDiagnosticWarningMessages()
.setMinApi(parameters.getApiLevel())
.compile()
.assertAllWarningMessagesMatch(equalTo("Resource 'META-INF/MANIFEST.MF' already exists."))
.run(parameters.getRuntime(), Main.class)
.assertSuccessWithOutputLines("11", "12")
.inspect(
inspector ->
assertThat(
inspector.clazz("com.android.tools.r8.naming.b139991218.Lambda1"),
isPresent()));
}
}