0

Reland "base/android: Remove linker tests support."

This reverts commit 8e6f857273.

Reason for reland: The dependency which broke was removed in
https://chromium-review.googlesource.com/c/chromium/src/+/2093606

Original change's description:
> base/android: Remove linker tests support.
>
> The linker tests don't run on bots (and likely not locally either) and
> do not support the latest library loading patterns. This is the first
> step to remove them, as they add non-trivial complexity in the codebase.
>
> Bug: 1059707
> Change-Id: Ia14693419792f57dc4f65b2fc7f999e833aec42e
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2095059
> Reviewed-by: Yaron Friedman <yfriedman@chromium.org>
> Reviewed-by: Egor Pasko <pasko@chromium.org>
> Commit-Queue: Benoit L <lizeb@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#748365}

Bug: 1059707
Change-Id: I3ad7347fdf4868d83ebf1895bee1bd85940ea324
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2098785
Reviewed-by: Egor Pasko <pasko@chromium.org>
Reviewed-by: Yaron Friedman <yfriedman@chromium.org>
Reviewed-by: Benoit L <lizeb@chromium.org>
Commit-Queue: Benoit L <lizeb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#750278}
This commit is contained in:
Benoit L
2020-03-13 19:58:06 +00:00
committed by Commit Bot
parent d9d2e9ee9b
commit 4e43a44afa
5 changed files with 5 additions and 167 deletions
base/android/java/src/org/chromium/base/library_loader
content/public/android/java/src/org/chromium/content

@ -36,6 +36,7 @@ class LegacyLinker extends Linker {
void loadLibraryImplLocked(String library, boolean isFixedAddressPermitted) {
ensureInitializedLocked();
assert mState == State.INITIALIZED; // Only one successful call.
assert !NativeLibraries.sEnableLinkerTests;
boolean provideRelro = mInBrowserProcess;
long loadAddress = isFixedAddressPermitted ? mBaseLoadAddress : 0;
@ -50,17 +51,6 @@ class LegacyLinker extends Linker {
}
libInfo.mLibFilePath = libFilePath;
// Print the load address to the logcat when testing the linker. The format
// of the string is expected by the Python test_runner script as one of:
// BROWSER_LIBRARY_ADDRESS: <library-name> <address>
// RENDERER_LIBRARY_ADDRESS: <library-name> <address>
// Where <library-name> is the library name, and <address> is the hexadecimal load
// address.
if (NativeLibraries.sEnableLinkerTests) {
String tag = mInBrowserProcess ? "BROWSER_LIBRARY_ADDRESS" : "RENDERER_LIBRARY_ADDRESS";
Log.i(TAG, "%s: %s %x", tag, libFilePath, libInfo.mLoadAddress);
}
if (provideRelro) {
if (!nativeCreateSharedRelro(sharedRelRoName, mBaseLoadAddress, libInfo)) {
Log.w(TAG, "Could not create shared RELRO for %s at %x", libFilePath,
@ -85,9 +75,6 @@ class LegacyLinker extends Linker {
mLibInfo = null;
mState = State.DONE;
}
// If testing, run tests now that all libraries are loaded and initialized.
if (NativeLibraries.sEnableLinkerTests) runTestRunnerClassForTesting(mInBrowserProcess);
}
/**

@ -256,10 +256,6 @@ public class LibraryLoader {
return mUseModernLinker;
}
public boolean areTestsEnabled() {
return NativeLibraries.sEnableLinkerTests;
}
@RemovableInRelease
public void enableJniChecks() {
if (!BuildConfig.DCHECK_IS_ON) return;
@ -711,7 +707,8 @@ public class LibraryLoader {
}
/**
* Override the library loader (normally with a mock) for testing.
* Overrides the library loader (normally with a mock) for testing.
*
* @param loader the mock library loader.
*/
@VisibleForTesting

@ -129,16 +129,6 @@ public abstract class Linker {
public static final String EXTRA_LINKER_SHARED_RELROS =
"org.chromium.base.android.linker.shared_relros";
// The name of a class that implements TestRunner.
private String mTestRunnerClassName;
// Constants used to indicate a given Linker implementation, for testing.
// LEGACY -> Always uses the LegacyLinker implementation.
// MODERN -> Always uses the ModernLinker implementation.
// NOTE: These names are known and expected by the Linker test scripts.
public static final int LINKER_IMPLEMENTATION_LEGACY = 1;
public static final int LINKER_IMPLEMENTATION_MODERN = 2;
// Singleton.
protected static final Object sLock = new Object();
@ -239,7 +229,7 @@ public abstract class Linker {
// regular library loading. See http://crbug.com/980304 as example.
//
// This is only called if LibraryLoader.useChromiumLinker() returns true, meaning this is
// either Chrome{,Modern}, the linker tests or Trichrome.
// either Chrome{,Modern} or Trichrome.
synchronized (sLock) {
if (sSingleton == null) {
// With incremental install, it's important to fall back to the "normal"
@ -593,128 +583,6 @@ public abstract class Linker {
public int mRelroFd = -1; // shared RELRO file descriptor, or -1
}
/* ---------------------- Testing support methods. ---------------------- */
/**
* Get Linker implementation type.
* For testing.
*
* @return LINKER_IMPLEMENTATION_LEGACY or LINKER_IMPLEMENTATION_MODERN
*/
public final int getImplementationForTesting() {
// Sanity check. This method may only be called during tests.
assert NativeLibraries.sEnableLinkerTests;
synchronized (sLock) {
assert sSingleton == this;
if (sSingleton instanceof ModernLinker) {
return LINKER_IMPLEMENTATION_MODERN;
} else if (sSingleton instanceof LegacyLinker) {
return LINKER_IMPLEMENTATION_LEGACY;
}
throw new AssertionError("Invalid linker: " + sSingleton.getClass().getName());
}
}
/**
* A public interface used to run runtime linker tests after loading
* libraries. Should only be used to implement the linker unit tests,
* which is controlled by the value of NativeLibraries.sEnableLinkerTests
* configured at build time.
*/
public interface TestRunner {
/**
* Run runtime checks and return true if they all pass.
*
* @param inBrowserProcess true iff this is the browser process.
* @return true if all checks pass.
*/
public boolean runChecks(boolean inBrowserProcess);
}
/**
* Call this to retrieve the name of the current TestRunner class name
* if any. This can be useful to pass it from the browser process to
* child ones.
*
* @return null or a String holding the name of the class implementing
* the TestRunner set by calling setTestRunnerClassNameForTesting() previously.
*/
public final String getTestRunnerClassNameForTesting() {
assert NativeLibraries.sEnableLinkerTests;
synchronized (sLock) {
return mTestRunnerClassName;
}
}
/**
* Set up the Linker for a test.
* Convenience function that calls setImplementationForTesting() to force an
* implementation, and then setTestRunnerClassNameForTesting() to set the test
* class name.
*
* On first call, instantiates a Linker of the requested type and sets its test
* runner class name. On subsequent calls, checks that the singleton produced by
* the first call matches the requested type and test runner class name.
*/
public static final void setupForTesting(int type, String testRunnerClassName) {
assert NativeLibraries.sEnableLinkerTests;
assert type == LINKER_IMPLEMENTATION_LEGACY || type == LINKER_IMPLEMENTATION_MODERN;
if (DEBUG) Log.i(TAG, "setupForTesting(%d, %s) called", type, testRunnerClassName);
synchronized (sLock) {
assert sSingleton == null;
if (type == LINKER_IMPLEMENTATION_MODERN) {
sSingleton = new ModernLinker();
} else if (type == LINKER_IMPLEMENTATION_LEGACY) {
sSingleton = new LegacyLinker();
}
Log.i(TAG, "Forced linker: %s", sSingleton.getClass().getName());
Linker.getInstance().mTestRunnerClassName = testRunnerClassName;
}
}
/**
* Instantiate and run the current TestRunner, if any. The TestRunner implementation
* must be instantiated _after_ all libraries are loaded to ensure that its
* native methods are properly registered.
*
* @param inBrowserProcess true if in the browser process
*/
protected final void runTestRunnerClassForTesting(boolean inBrowserProcess) {
assert NativeLibraries.sEnableLinkerTests;
if (DEBUG) Log.i(TAG, "runTestRunnerClassForTesting called");
synchronized (sLock) {
if (mTestRunnerClassName == null) {
Log.wtf(TAG, "Linker runtime tests not set up for this process");
assert false;
}
if (DEBUG) {
Log.i(TAG, "Instantiating " + mTestRunnerClassName);
}
TestRunner testRunner = null;
try {
testRunner = (TestRunner) Class.forName(mTestRunnerClassName)
.getDeclaredConstructor()
.newInstance();
} catch (Exception e) {
Log.wtf(TAG, "Could not instantiate test runner class by name", e);
assert false;
}
if (!testRunner.runChecks(inBrowserProcess)) {
Log.wtf(TAG, "Linker runtime tests failed in this process");
assert false;
}
Log.i(TAG, "All linker tests passed");
}
}
/**
* Return a random address that should be free to be mapped with the given size.
* Maps an area large enough for the largest library we might attempt to load,

@ -163,13 +163,6 @@ public class ContentChildProcessServiceDelegate implements ChildProcessServiceDe
// Return a Linker instance. If testing, the Linker needs special setup.
private Linker getLinker() {
if (LibraryLoader.getInstance().areTestsEnabled()) {
// For testing, set the Linker implementation and the test runner
// class name to match those used by the parent.
assert mLinkerParams != null;
Linker.setupForTesting(mLinkerParams.mLinkerImplementationForTesting,
mLinkerParams.mTestRunnerClassNameForTesting);
}
return Linker.getInstance();
}

@ -640,14 +640,7 @@ public final class ChildProcessLauncherHelperImpl {
// Always wait for the shared RELROs in service processes.
final boolean waitForSharedRelros = true;
if (LibraryLoader.getInstance().areTestsEnabled()) {
Linker linker = Linker.getInstance();
return new ChromiumLinkerParams(sLinkerLoadAddress, waitForSharedRelros,
linker.getTestRunnerClassNameForTesting(),
linker.getImplementationForTesting());
} else {
return new ChromiumLinkerParams(sLinkerLoadAddress, waitForSharedRelros);
}
return new ChromiumLinkerParams(sLinkerLoadAddress, waitForSharedRelros);
}
private static Bundle populateServiceBundle(Bundle bundle) {