blob: 616bfb3d1d56987e292c2ebb31a4f7f1507c6cf7 [file]
// Copyright (c) 2025, 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.assistant;
import com.android.tools.r8.TestBase;
import com.android.tools.r8.TestParameters;
import com.android.tools.r8.TestParametersCollection;
import com.android.tools.r8.assistant.JavaLangClassTestClass.Bar;
import com.android.tools.r8.assistant.JavaLangClassTestClass.Foo;
import com.android.tools.r8.assistant.runtime.EmptyReflectiveOperationReceiver;
import com.android.tools.r8.assistant.runtime.ReflectiveOracle.Stack;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Parameterized.class)
public class AtomicUpdaterTest extends TestBase {
@Parameter(0)
public TestParameters parameters;
@Parameters(name = "{0}")
public static TestParametersCollection data() {
return getTestParameters().withNativeMultidexDexRuntimes().withMaximumApiLevel().build();
}
@Test
public void testInstrumentationWithCustomOracle() throws Exception {
testForAssistant()
.addProgramClasses(AtomicUpdaterTestClass.class, Foo.class, Bar.class)
.addInstrumentationClasses(Instrumentation.class)
.setCustomReflectiveOperationReceiver(Instrumentation.class)
.setMinApi(parameters)
.compile()
.run(parameters.getRuntime(), AtomicUpdaterTestClass.class)
.assertSuccessWithOutputLines(
"int com.android.tools.r8.assistant.AtomicUpdaterTestClass#i",
"42",
"long com.android.tools.r8.assistant.AtomicUpdaterTestClass#l",
"42",
"java.lang.Object com.android.tools.r8.assistant.AtomicUpdaterTestClass#o",
"42");
}
public static class Instrumentation extends EmptyReflectiveOperationReceiver {
@Override
public void onAtomicFieldUpdaterNewUpdater(
Stack stack, Class<?> fieldClass, Class<?> clazz, String name) {
System.out.println(fieldClass.getName() + " " + clazz.getName() + "#" + name);
}
}
}