Skip to content

Commit

Permalink
Support using the customized fastboot binary
Browse files Browse the repository at this point in the history
This CL aims to allow users to use their customized fastboot binary,
like ADB.
  • Loading branch information
tsunghant committed Feb 4, 2025
1 parent ac65869 commit 2e76622
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
7 changes: 5 additions & 2 deletions mobly/controllers/android_device_lib/fastboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)))
Expand Down
22 changes: 22 additions & 0 deletions tests/mobly/controllers/android_device_lib/fastboot_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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()

0 comments on commit 2e76622

Please sign in to comment.