Bug 1548555 - For android gtest, push support files to device; r=bc

Differential Revision: https://phabricator.services.mozilla.com/D29837

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Geoff Brown 2019-05-03 17:45:21 +00:00
parent e669c78390
commit 51f5d3a884
5 changed files with 37 additions and 13 deletions

View File

@ -652,12 +652,17 @@ class GTestCommands(MachCommandBase):
self._run_make(directory='browser/app', target='repackage',
ensure_exit_code=True)
cwd = os.path.join(self.topobjdir, '_tests', 'gtest')
if not os.path.isdir(cwd):
os.makedirs(cwd)
if conditions.is_android(self):
if jobs != 1:
print("--jobs is not supported on Android and will be ignored")
if debug or debugger or debugger_args:
print("--debug options are not supported on Android and will be ignored")
return self.android_gtest(shuffle, gtest_filter,
return self.android_gtest(cwd, shuffle, gtest_filter,
package, adb_path, device_serial, remote_test_root, libxul_path)
if package or adb_path or device_serial or remote_test_root or libxul_path:
@ -673,11 +678,6 @@ class GTestCommands(MachCommandBase):
if debug or debugger or debugger_args:
args = self.prepend_debugger_args(args, debugger, debugger_args)
cwd = os.path.join(self.topobjdir, '_tests', 'gtest')
if not os.path.isdir(cwd):
os.makedirs(cwd)
# Use GTest environment variable to control test execution
# For details see:
# https://code.google.com/p/googletest/wiki/AdvancedGuide#Running_Test_Programs:_Advanced_Options
@ -739,7 +739,7 @@ class GTestCommands(MachCommandBase):
return exit_code
def android_gtest(self, shuffle, gtest_filter,
def android_gtest(self, test_dir, shuffle, gtest_filter,
package, adb_path, device_serial, remote_test_root, libxul_path):
# setup logging for mozrunner
from mozlog.commandline import setup_logging
@ -764,8 +764,9 @@ class GTestCommands(MachCommandBase):
('.py', 'r', imp.PY_SOURCE))
import remotegtests
tester = remotegtests.RemoteGTests()
tester.run_gtest(shuffle, gtest_filter, package, adb_path, device_serial,
tester.run_gtest(test_dir, shuffle, gtest_filter, package, adb_path, device_serial,
remote_test_root, libxul_path, None)
tester.cleanup()
return 0

View File

@ -114,6 +114,17 @@ int RunGTestFunc(int* argc, char** argv) {
#ifdef XP_WIN
mozilla::ipc::windows::InitUIThread();
#endif
#ifdef ANDROID
// On Android, gtest is running in an application, which uses a
// current working directory of '/' by default. Desktop tests
// sometimes assume that support files are in the current
// working directory. For compatibility with desktop, the Android
// harness pushes test support files to the device at the location
// specified by MOZ_GTEST_CWD and gtest changes the cwd to that
// location.
char* path = PR_GetEnv("MOZ_GTEST_CWD");
chdir(path);
#endif
nsCOMPtr<nsICrashReporter> crashreporter;
char* crashreporterStr = PR_GetEnv("MOZ_CRASHREPORTER");

View File

@ -9,6 +9,7 @@ from __future__ import with_statement
from optparse import OptionParser
import datetime
import glob
import os
import posixpath
import shutil
@ -43,6 +44,7 @@ class RemoteGTests(object):
# custom output parser is mandatory on Android
env["MOZ_TBPL_PARSER"] = "1"
env["MOZ_GTEST_LOG_PATH"] = self.remote_log
env["MOZ_GTEST_CWD"] = self.remote_profile
env["MOZ_GTEST_MINIDUMPS_PATH"] = self.remote_minidumps
env["MOZ_IN_AUTOMATION"] = "1"
if shuffle:
@ -52,7 +54,7 @@ class RemoteGTests(object):
return env
def run_gtest(self, shuffle, test_filter, package, adb_path, device_serial,
def run_gtest(self, test_dir, shuffle, test_filter, package, adb_path, device_serial,
remote_test_root, libxul_path, symbols_path):
"""
Launch the test app, run gtest, collect test results and wait for completion.
@ -83,6 +85,12 @@ class RemoteGTests(object):
remote = "/data/app/%s-1/lib/x86_64/" % self.package
self.device.push(libxul_path, remote)
# Push support files to device. Avoid sub-directories so that libxul.so
# is not included.
for f in glob.glob(os.path.join(test_dir, "*")):
if not os.path.isdir(f):
self.device.push(f, self.remote_profile)
env = self.build_environment(shuffle, test_filter)
args = ["-unittest", "--gtest_death_test_style=threadsafe",
"-profile %s" % self.remote_profile]
@ -334,6 +342,9 @@ class remoteGtestOptions(OptionParser):
action="store_true",
default=False,
help="Randomize the execution order of tests.")
self.add_option("--tests-path",
default=None,
help="Path to gtest directory containing test support files.")
def update_mozinfo():
@ -364,7 +375,8 @@ def main():
result = False
try:
device_exception = False
result = tester.run_gtest(options.shuffle, test_filter, options.package,
result = tester.run_gtest(options.tests_path,
options.shuffle, test_filter, options.package,
options.adb_path, options.device_serial,
options.remote_test_root, options.libxul_path,
options.symbols_path)

View File

@ -333,7 +333,8 @@ config = {
"install": True,
"options": [
"--symbols-path=%(symbols_path)s",
"--libxul=%(gtest_dir)s/libxul.so",
"--tests-path=%(gtest_dir)s",
"--libxul=%(gtest_dir)s/gtest_bin/gtest/libxul.so",
"--package=%(app)s",
"--deviceSerial=%(device_serial)s",
],

View File

@ -247,8 +247,7 @@ class AndroidEmulatorTest(TestingMixin, BaseScript, MozbaseMixin, CodeCoverageMi
dirs['abs_marionette_tests_dir'],
self.config.get('marionette_test_manifest', '')
),
'gtest_dir': os.path.join(dirs['abs_test_install_dir'], 'gtest',
'gtest_bin', 'gtest'),
'gtest_dir': os.path.join(dirs['abs_test_install_dir'], 'gtest'),
}
user_paths = self._get_mozharness_test_paths(self.test_suite)