From 66862579245d257a27f43b522444249511243658 Mon Sep 17 00:00:00 2001 From: Remi NGUYEN VAN Date: Thu, 31 May 2018 11:23:39 +0900 Subject: [PATCH] Add --no-hidden-api-checks to runtest New test tools are adding --no-hidden-api-checks when tests have hidden-api-checks=false in their AndroidTest.xml, however this is not supported by runtest. As only runtest is available in AOSP, this leaves no option to make tests of internal classes pass. Add an option to disable the check in runtest so we can still run tests in AOSP. Test: runtest frameworks-net still fails Test: runtest --no-hidden-api-checks frameworks-net now passes Change-Id: I9be9674d0bf2588ff509121273379f08d4cb3aea --- testrunner/adb_interface.py | 32 +++++++++++++------- testrunner/runtest.py | 4 +++ testrunner/test_defs/instrumentation_test.py | 16 +++++----- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/testrunner/adb_interface.py b/testrunner/adb_interface.py index 7dd8f4cbd..93b4088d2 100755 --- a/testrunner/adb_interface.py +++ b/testrunner/adb_interface.py @@ -176,7 +176,8 @@ class AdbInterface: def StartInstrumentationForPackage( self, package_name, runner_name, timeout_time=60*10, - no_window_animation=False, instrumentation_args={}, user=None): + no_window_animation=False, instrumentation_args={}, user=None, + no_hidden_api_checks=False): """Run instrumentation test for given package and runner. Equivalent to StartInstrumentation, except instrumentation path is @@ -186,11 +187,13 @@ class AdbInterface: return self.StartInstrumentation(instrumentation_path, timeout_time=timeout_time, no_window_animation=no_window_animation, instrumentation_args=instrumentation_args, - user=user) + user=user, + no_hidden_api_checks=no_hidden_api_checks) def StartInstrumentation( self, instrumentation_path, timeout_time=60*10, no_window_animation=False, - profile=False, instrumentation_args={}, user=None): + profile=False, instrumentation_args={}, user=None, + no_hidden_api_checks=False): """Runs an instrumentation class on the target. @@ -232,7 +235,7 @@ class AdbInterface: instrumentation_path, no_window_animation=no_window_animation, profile=profile, raw_mode=True, instrumentation_args=instrumentation_args, - user=user) + user=user, no_hidden_api_checks=no_hidden_api_checks) logger.Log(command_string) (test_results, inst_finished_bundle) = ( am_instrument_parser.ParseAmInstrumentOutput( @@ -258,7 +261,8 @@ class AdbInterface: def StartInstrumentationNoResults( self, package_name, runner_name, no_window_animation=False, - raw_mode=False, instrumentation_args={}, user=None): + raw_mode=False, instrumentation_args={}, user=None, + no_hidden_api_checks=False): """Runs instrumentation and dumps output to stdout. Equivalent to StartInstrumentation, but will dump instrumentation @@ -268,18 +272,19 @@ class AdbInterface: adb_command_string = self.PreviewInstrumentationCommand( package_name, runner_name, no_window_animation=no_window_animation, raw_mode=raw_mode, instrumentation_args=instrumentation_args, - user=user) + user=user, no_hidden_api_checks=no_hidden_api_checks) logger.Log(adb_command_string) run_command.RunCommand(adb_command_string, return_output=False) def PreviewInstrumentationCommand( self, package_name, runner_name, no_window_animation=False, - raw_mode=False, instrumentation_args={}, user=None): + raw_mode=False, instrumentation_args={}, user=None, + no_hidden_api_checks=False): """Returns a string of adb command that will be executed.""" inst_command_string = self._BuildInstrumentationCommand( package_name, runner_name, no_window_animation=no_window_animation, raw_mode=raw_mode, instrumentation_args=instrumentation_args, - user=user) + user=user, no_hidden_api_checks=no_hidden_api_checks) return self.PreviewShellCommand(inst_command_string) def PreviewShellCommand(self, cmd): @@ -287,18 +292,23 @@ class AdbInterface: def _BuildInstrumentationCommand( self, package, runner_name, no_window_animation=False, profile=False, - raw_mode=True, instrumentation_args={}, user=None): + raw_mode=True, instrumentation_args={}, user=None, + no_hidden_api_checks=False): instrumentation_path = "%s/%s" % (package, runner_name) return self._BuildInstrumentationCommandPath( instrumentation_path, no_window_animation=no_window_animation, profile=profile, raw_mode=raw_mode, - instrumentation_args=instrumentation_args, user=user) + instrumentation_args=instrumentation_args, user=user, + no_hidden_api_checks=no_hidden_api_checks) def _BuildInstrumentationCommandPath( self, instrumentation_path, no_window_animation=False, profile=False, - raw_mode=True, instrumentation_args={}, user=None): + raw_mode=True, instrumentation_args={}, user=None, + no_hidden_api_checks=False): command_string = "am instrument" + if no_hidden_api_checks: + command_string += " --no-hidden-api-checks" if user: command_string += " --user %s" % user if no_window_animation: diff --git a/testrunner/runtest.py b/testrunner/runtest.py index 2a11871df..2072cfe0b 100755 --- a/testrunner/runtest.py +++ b/testrunner/runtest.py @@ -183,6 +183,10 @@ class TestRunner(object): " and will install all packages built. This is" " useful when the test path has a lot of apks but you" " only care about one.") + parser.add_option("--no-hidden-api-checks", dest="no_hidden_api_checks", + default=False, action="store_true", + help="Disable hidden API checks in instrumentation" + " tests.") group = optparse.OptionGroup( parser, "Targets", "Use these options to direct tests to a specific " "Android target") diff --git a/testrunner/test_defs/instrumentation_test.py b/testrunner/test_defs/instrumentation_test.py index 979ba0b60..5651d2ead 100644 --- a/testrunner/test_defs/instrumentation_test.py +++ b/testrunner/test_defs/instrumentation_test.py @@ -155,7 +155,8 @@ class InstrumentationTestSuite(test_suite.AbstractTestSuite): runner_name=self.GetRunnerName(), timeout_time=60*60, instrumentation_args=instrumentation_args, - user=options.user) + user=options.user, + no_hidden_api_checks=options.no_hidden_api_checks) except errors.InstrumentationError, errors.DeviceUnresponsiveError: return self._PrintTestResults(test_results) @@ -172,12 +173,13 @@ class InstrumentationTestSuite(test_suite.AbstractTestSuite): else: self._CheckInstrumentationInstalled(adb) - adb.StartInstrumentationNoResults(package_name=self.GetPackageName(), - runner_name=self.GetRunnerName(), - raw_mode=options.raw_mode, - instrumentation_args= - instrumentation_args, - user=options.user) + adb.StartInstrumentationNoResults( + package_name=self.GetPackageName(), + runner_name=self.GetRunnerName(), + raw_mode=options.raw_mode, + instrumentation_args=instrumentation_args, + user=options.user, + no_hidden_api_checks=options.no_hidden_api_checks) def _CheckInstrumentationInstalled(self, adb): if not adb.IsInstrumentationInstalled(self.GetPackageName(),