Commit 1ea229b3 authored by Mike Wittman's avatar Mike Wittman Committed by Commit Bot

Update device directories to allow gtests to run on R

The external storage root path is currently used as the location to
write test runner output, but this path is no longer writable by apps
on Android R. Update to use DeviceUtils' GetAppWritablePath() instead
of GetExternalStoragePath() to support test execution on this version.

Bug: 1094062
Change-Id: Ie90c46d4ed0c3e421d83c8d0ae8edee047f2dcac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2242845Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Reviewed-by: default avatarJohn Budorick <jbudorick@chromium.org>
Commit-Queue: Mike Wittman <wittman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#780836}
parent 7246220d
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
package org.chromium.base.test.util; package org.chromium.base.test.util;
import android.os.Bundle;
import org.junit.Assert; import org.junit.Assert;
import org.chromium.base.PathUtils; import org.chromium.base.PathUtils;
...@@ -16,7 +18,19 @@ import org.chromium.base.annotations.MainDex; ...@@ -16,7 +18,19 @@ import org.chromium.base.annotations.MainDex;
*/ */
@MainDex @MainDex
public class UrlUtils { public class UrlUtils {
public static final String EXTRA_ROOT_DIRECTORY =
"org.chromium.base.test.util.UrlUtils.RootDirectory";
private static final String DATA_DIR = "/chrome/test/data/"; private static final String DATA_DIR = "/chrome/test/data/";
private static String sRootDirectory = PathUtils.getExternalStorageDirectory();
/**
* Sets the root directory from state in the bundle.
* @param bundle Bundle containing the intent extras.
*/
public static void setPathsFromBundle(Bundle bundle) {
String rootDirectory = bundle.getString(EXTRA_ROOT_DIRECTORY);
if (rootDirectory != null) sRootDirectory = rootDirectory;
}
/** /**
* Construct the full path of a test data file. * Construct the full path of a test data file.
...@@ -43,7 +57,7 @@ public class UrlUtils { ...@@ -43,7 +57,7 @@ public class UrlUtils {
@CalledByNative @CalledByNative
public static String getIsolatedTestRoot() { public static String getIsolatedTestRoot() {
try (StrictModeContext ignored = StrictModeContext.allowDiskReads()) { try (StrictModeContext ignored = StrictModeContext.allowDiskReads()) {
return PathUtils.getExternalStorageDirectory() + "/chromium_tests_root"; return sRootDirectory + "/chromium_tests_root";
} }
} }
......
...@@ -40,6 +40,7 @@ _EXTRA_COMMAND_LINE_FLAGS = ( ...@@ -40,6 +40,7 @@ _EXTRA_COMMAND_LINE_FLAGS = (
'org.chromium.native_test.NativeTest.CommandLineFlags') 'org.chromium.native_test.NativeTest.CommandLineFlags')
_EXTRA_COVERAGE_DEVICE_FILE = ( _EXTRA_COVERAGE_DEVICE_FILE = (
'org.chromium.native_test.NativeTest.CoverageDeviceFile') 'org.chromium.native_test.NativeTest.CoverageDeviceFile')
_EXTRA_ROOT_DIRECTORY = 'org.chromium.base.test.util.UrlUtils.RootDirectory'
_EXTRA_STDOUT_FILE = ( _EXTRA_STDOUT_FILE = (
'org.chromium.native_test.NativeTestInstrumentationTestRunner' 'org.chromium.native_test.NativeTestInstrumentationTestRunner'
'.StdoutFile') '.StdoutFile')
...@@ -136,7 +137,7 @@ def _GetDeviceCoverageDir(device): ...@@ -136,7 +137,7 @@ def _GetDeviceCoverageDir(device):
Returns: Returns:
The directory path on the device. The directory path on the device.
""" """
return posixpath.join(device.GetExternalStoragePath(), 'chrome', 'test', return posixpath.join(device.GetAppWritablePath(), 'chrome', 'test',
'coverage', 'profraw') 'coverage', 'profraw')
...@@ -179,8 +180,7 @@ class _ApkDelegate(object): ...@@ -179,8 +180,7 @@ class _ApkDelegate(object):
def GetTestDataRoot(self, device): def GetTestDataRoot(self, device):
# pylint: disable=no-self-use # pylint: disable=no-self-use
return posixpath.join(device.GetExternalStoragePath(), return posixpath.join(device.GetAppWritablePath(), 'chromium_tests_root')
'chromium_tests_root')
def Install(self, device): def Install(self, device):
if self._test_apk_incremental_install_json: if self._test_apk_incremental_install_json:
...@@ -200,6 +200,8 @@ class _ApkDelegate(object): ...@@ -200,6 +200,8 @@ class _ApkDelegate(object):
extras = dict(self._extras) extras = dict(self._extras)
device_api = device.build_version_sdk device_api = device.build_version_sdk
extras[_EXTRA_ROOT_DIRECTORY] = device.GetAppWritablePath()
if self._coverage_dir and device_api >= version_codes.LOLLIPOP: if self._coverage_dir and device_api >= version_codes.LOLLIPOP:
device_coverage_dir = _GetDeviceCoverageDir(device) device_coverage_dir = _GetDeviceCoverageDir(device)
extras[_EXTRA_COVERAGE_DEVICE_FILE] = _GetLLVMProfilePath( extras[_EXTRA_COVERAGE_DEVICE_FILE] = _GetLLVMProfilePath(
...@@ -236,7 +238,7 @@ class _ApkDelegate(object): ...@@ -236,7 +238,7 @@ class _ApkDelegate(object):
# pylint: enable=redefined-variable-type # pylint: enable=redefined-variable-type
stdout_file = device_temp_file.DeviceTempFile( stdout_file = device_temp_file.DeviceTempFile(
device.adb, dir=device.GetExternalStoragePath(), suffix='.gtest_out') device.adb, dir=device.GetAppWritablePath(), suffix='.gtest_out')
extras[_EXTRA_STDOUT_FILE] = stdout_file.name extras[_EXTRA_STDOUT_FILE] = stdout_file.name
if self._wait_for_java_debugger: if self._wait_for_java_debugger:
...@@ -344,8 +346,7 @@ class _ExeDelegate(object): ...@@ -344,8 +346,7 @@ class _ExeDelegate(object):
try: try:
gcov_strip_depth = os.environ['NATIVE_COVERAGE_DEPTH_STRIP'] gcov_strip_depth = os.environ['NATIVE_COVERAGE_DEPTH_STRIP']
external = device.GetExternalStoragePath() env['GCOV_PREFIX'] = '%s/gcov' % device.GetAppWritablePath()
env['GCOV_PREFIX'] = '%s/gcov' % external
env['GCOV_PREFIX_STRIP'] = gcov_strip_depth env['GCOV_PREFIX_STRIP'] = gcov_strip_depth
except (device_errors.CommandFailedError, KeyError): except (device_errors.CommandFailedError, KeyError):
pass pass
......
...@@ -18,6 +18,7 @@ import android.os.Process; ...@@ -18,6 +18,7 @@ import android.os.Process;
import android.util.SparseArray; import android.util.SparseArray;
import org.chromium.base.Log; import org.chromium.base.Log;
import org.chromium.base.test.util.UrlUtils;
import org.chromium.test.reporter.TestStatusReceiver; import org.chromium.test.reporter.TestStatusReceiver;
import java.io.BufferedReader; import java.io.BufferedReader;
...@@ -74,6 +75,8 @@ public class NativeTestInstrumentationTestRunner extends Instrumentation { ...@@ -74,6 +75,8 @@ public class NativeTestInstrumentationTestRunner extends Instrumentation {
if (mNativeTestActivity == null) mNativeTestActivity = DEFAULT_NATIVE_TEST_ACTIVITY; if (mNativeTestActivity == null) mNativeTestActivity = DEFAULT_NATIVE_TEST_ACTIVITY;
mTransparentArguments.remove(EXTRA_NATIVE_TEST_ACTIVITY); mTransparentArguments.remove(EXTRA_NATIVE_TEST_ACTIVITY);
UrlUtils.setPathsFromBundle(arguments);
String shardNanoTimeout = arguments.getString(EXTRA_SHARD_NANO_TIMEOUT); String shardNanoTimeout = arguments.getString(EXTRA_SHARD_NANO_TIMEOUT);
if (shardNanoTimeout != null) mShardNanoTimeout = Long.parseLong(shardNanoTimeout); if (shardNanoTimeout != null) mShardNanoTimeout = Long.parseLong(shardNanoTimeout);
mTransparentArguments.remove(EXTRA_SHARD_NANO_TIMEOUT); mTransparentArguments.remove(EXTRA_SHARD_NANO_TIMEOUT);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment