From 2e76622e719045a1cf3ca33e352eaac85375b464 Mon Sep 17 00:00:00 2001 From: Johnny Tsai Date: Tue, 4 Feb 2025 07:34:07 +0000 Subject: [PATCH] Support using the customized fastboot binary This CL aims to allow users to use their customized fastboot binary, like ADB. --- .../android_device_lib/fastboot.py | 7 ++++-- .../android_device_lib/fastboot_test.py | 22 +++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/mobly/controllers/android_device_lib/fastboot.py b/mobly/controllers/android_device_lib/fastboot.py index 607470a3..e4aab8e9 100644 --- a/mobly/controllers/android_device_lib/fastboot.py +++ b/mobly/controllers/android_device_lib/fastboot.py @@ -17,6 +17,9 @@ from mobly import utils +# Command to use for running fastboot commands. +FASTBOOT = 'fastboot' + def exe_cmd(*cmds): """Executes commands in a new shell. Directing stderr to PIPE. @@ -63,8 +66,8 @@ def __init__(self, serial=''): def fastboot_str(self): if self.serial: - return 'fastboot -s {}'.format(self.serial) - return 'fastboot' + return '{} -s {}'.format(FASTBOOT, self.serial) + return FASTBOOT def _exec_fastboot_cmd(self, name, arg_str): return exe_cmd(' '.join((self.fastboot_str(), name, arg_str))) diff --git a/tests/mobly/controllers/android_device_lib/fastboot_test.py b/tests/mobly/controllers/android_device_lib/fastboot_test.py index 3bd204fa..10bc9533 100644 --- a/tests/mobly/controllers/android_device_lib/fastboot_test.py +++ b/tests/mobly/controllers/android_device_lib/fastboot_test.py @@ -21,6 +21,9 @@ class FastbootTest(unittest.TestCase): """Unit tests for mobly.controllers.android_device_lib.adb.""" + def setUp(self): + fastboot.FASTBOOT = 'fastboot' + @mock.patch('mobly.controllers.android_device_lib.fastboot.Popen') @mock.patch('logging.debug') def test_fastboot_commands_and_results_are_logged_to_debug_log( @@ -100,6 +103,25 @@ def test_fastboot_update_serial(self, mock_popen): shell=True, ) + @mock.patch('mobly.controllers.android_device_lib.fastboot.Popen') + def test_fastboot_use_customized_fastboot(self, mock_popen): + expected_stdout = 'stdout' + expected_stderr = b'stderr' + mock_popen.return_value.communicate = mock.Mock( + return_value=(expected_stdout, expected_stderr) + ) + mock_popen.return_value.returncode = 123 + fastboot.FASTBOOT = 'my_fastboot' + + fastboot.FastbootProxy('ABC').fake_command('extra', 'flags') + + mock_popen.assert_called_with( + 'my_fastboot -s ABC fake-command extra flags', + stdout=mock.ANY, + stderr=mock.ANY, + shell=True, + ) + if __name__ == '__main__': unittest.main()