diff options
author | Aidan Holm <aidanholm+github@gmail.com> | 2022-12-01 04:58:44 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-30 12:58:44 -0800 |
commit | 1b6e611e937bf4b59ffa5b8fe8056d0b7ed205b6 (patch) | |
tree | a2639b00c6d2dab79a0e97a9d769e2422d9bc9c9 | |
parent | a6e5ad247480adb4491560423e90259d697f75b0 (diff) | |
download | mobly-1b6e611e937bf4b59ffa5b8fe8056d0b7ed205b6.tar.gz |
Add debug logging for fastboot commands. (#854)
This is equivalent in functionality to the existing logging for ADB commands.
Co-authored-by: Aidan Holm <alfh@google.com>
-rw-r--r-- | mobly/controllers/android_device_lib/fastboot.py | 6 | ||||
-rw-r--r-- | tests/mobly/controllers/android_device_lib/fastboot_test.py | 43 |
2 files changed, 49 insertions, 0 deletions
diff --git a/mobly/controllers/android_device_lib/fastboot.py b/mobly/controllers/android_device_lib/fastboot.py index 754a039..1ef4969 100644 --- a/mobly/controllers/android_device_lib/fastboot.py +++ b/mobly/controllers/android_device_lib/fastboot.py @@ -12,8 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. +import logging from subprocess import Popen, PIPE +from mobly import utils + def exe_cmd(*cmds): """Executes commands in a new shell. Directing stderr to PIPE. @@ -33,6 +36,9 @@ def exe_cmd(*cmds): cmd = ' '.join(cmds) proc = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True) (out, err) = proc.communicate() + ret = proc.returncode + logging.debug('cmd: %s, stdout: %s, stderr: %s, ret: %s', + utils.cli_cmd_to_string(cmds), out, err, ret) if not err: return out return err diff --git a/tests/mobly/controllers/android_device_lib/fastboot_test.py b/tests/mobly/controllers/android_device_lib/fastboot_test.py new file mode 100644 index 0000000..6e59dea --- /dev/null +++ b/tests/mobly/controllers/android_device_lib/fastboot_test.py @@ -0,0 +1,43 @@ +# Copyright 2022 Google Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest +from unittest import mock + +from mobly.controllers.android_device_lib import fastboot + + +class FastbootTest(unittest.TestCase): + """Unit tests for mobly.controllers.android_device_lib.adb.""" + + @mock.patch('mobly.controllers.android_device_lib.fastboot.Popen') + @mock.patch('logging.debug') + def test_fastboot_commands_and_results_are_logged_to_debug_log( + self, mock_debug_logger, 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.FastbootProxy().fake_command('extra', 'flags') + + mock_debug_logger.assert_called_with( + 'cmd: %s, stdout: %s, stderr: %s, ret: %s', + '\'fastboot fake-command extra flags\'', expected_stdout, + expected_stderr, 123) + + +if __name__ == '__main__': + unittest.main() |