示例#1
0
 def test_AndroidDevice_take_logcat_with_user_param(
         self, check_proc_mock, stop_proc_mock, start_proc_mock,
         creat_dir_mock, FastbootProxy, MockAdbProxy):
     """Verifies the steps of collecting adb logcat on an AndroidDevice
     object, including various function calls and the expected behaviors of
     the calls.
     """
     ad = android_device.AndroidDevice(serial=MOCK_SERIAL)
     ad.adb_logcat_param = "-b radio"
     expected_msg = ("Android device .* does not have an ongoing adb logcat"
                     " collection.")
     # Expect error if stop is called before start.
     with self.assertRaisesRegex(android_device.AndroidDeviceError,
                                 expected_msg):
         ad.stop_adb_logcat()
     ad.start_adb_logcat()
     # Verify start did the correct operations.
     self.assertTrue(ad.adb_logcat_process)
     expected_log_path = os.path.join(logging.log_path,
                                      "AndroidDevice%s" % ad.serial,
                                      "adblog,fakemodel,%s.txt" % ad.serial)
     creat_dir_mock.assert_called_with(os.path.dirname(expected_log_path))
     adb_cmd = 'adb -s %s logcat -T 1 -v year -b radio >> %s'
     start_proc_mock.assert_called_with(adb_cmd %
                                        (ad.serial, expected_log_path))
     self.assertEqual(ad.adb_logcat_file_path, expected_log_path)
示例#2
0
 def test_AndroidDevice_build_info_nyc(self, MockFastboot, MockAdbProxy):
     """Verifies the AndroidDevice object's build id is set correctly for
     NYC releases.
     """
     ad = android_device.AndroidDevice(serial=1)
     build_info = ad.build_info
     self.assertEqual(build_info["build_id"], MOCK_NYC_BUILD_ID)
 def test_AndroidDevice_cat_adb_log(self, check_proc_mock,
                                    mock_timestamp_getter, stop_proc_mock,
                                    start_proc_mock, FastbootProxy,
                                    MockAdbProxy):
     """Verifies that AndroidDevice.cat_adb_log loads the correct adb log
     file, locates the correct adb log lines within the given time range,
     and writes the lines to the correct output file.
     """
     mock_serial = 1
     ad = android_device.AndroidDevice(serial=mock_serial)
     # Expect error if attempted to cat adb log before starting adb logcat.
     expected_msg = ("Attempting to cat adb log when none has been "
                     "collected on Android device .*")
     with self.assertRaisesRegex(android_device.AndroidDeviceError,
                                 expected_msg):
         ad.cat_adb_log("some_test", MOCK_ADB_LOGCAT_BEGIN_TIME)
     ad.start_adb_logcat()
     # Direct the log path of the ad to a temp dir to avoid racing.
     ad.log_path = os.path.join(self.tmp_dir, ad.log_path)
     mock_adb_log_path = os.path.join(
         ad.log_path, "adblog,%s,%s.txt" % (ad.model, ad.serial))
     with open(mock_adb_log_path, 'w') as f:
         f.write(MOCK_ADB_LOGCAT)
     ad.cat_adb_log("some_test", MOCK_ADB_LOGCAT_BEGIN_TIME)
     cat_file_path = os.path.join(
         ad.log_path, "AdbLogExcerpts",
         ("some_test,02-29 14:02:20.123,%s,%s.txt") % (ad.model, ad.serial))
     with open(cat_file_path, 'r') as f:
         actual_cat = f.read()
     self.assertEqual(actual_cat, ''.join(MOCK_ADB_LOGCAT_CAT_RESULT))
     # Stops adb logcat.
     ad.stop_adb_logcat()
示例#4
0
 def test_AndroidDevice_build_info_dev(self, MockFastboot, MockAdbProxy):
     """Verifies the AndroidDevice object's basic attributes are correctly
     set after instantiation.
     """
     ad = android_device.AndroidDevice(serial=1)
     build_info = ad.build_info
     self.assertEqual(build_info["build_id"], "123456789")
     self.assertEqual(build_info["build_type"], "userdebug")
示例#5
0
    def test_push_system_file_returns_false_on_error(self, adb_proxy):
        ad = android_device.AndroidDevice(serial=MOCK_SERIAL)
        ad.ensure_verity_disabled = mock.MagicMock()
        ad.adb.remount = mock.MagicMock()
        ad.adb.push = mock.MagicMock(return_value='error')

        ret = ad.push_system_file('asdf', 'jkl')
        self.assertFalse(ret)
示例#6
0
    def test_push_system_file(self, adb_proxy):
        ad = android_device.AndroidDevice(serial=MOCK_SERIAL)
        ad.ensure_verity_disabled = mock.MagicMock()
        ad.adb.remount = mock.MagicMock()
        ad.adb.push = mock.MagicMock()

        ret = ad.push_system_file('asdf', 'jkl')
        self.assertTrue(ret)
示例#7
0
 def test_AndroidDevice_take_bug_report_fail(self, mock_log_path, *_):
     """Verifies AndroidDevice.take_bug_report writes out the correct message
     when taking bugreport fails.
     """
     ad = android_device.AndroidDevice(serial=MOCK_SERIAL)
     mock_log_path.return_value = os.path.join(
         logging.log_path, "AndroidDevice%s" % ad.serial)
     expected_msg = "Failed to take bugreport on 1: OMG I died!"
     with self.assertRaisesRegex(errors.AndroidDeviceError, expected_msg):
         ad.take_bug_report("test_something", 4346343.23)
示例#8
0
def get_mock_android_device(serial='', ssh_connection=None):
    """Returns a mocked AndroidDevice with a mocked adb/fastboot."""
    with mock.patch('acts.controllers.adb.AdbProxy') as adb_proxy, (
            mock.patch('acts.controllers.fastboot.FastbootProxy')) as fb_proxy:
        fb_proxy.return_value.devices.return_value = ""
        ret = mock.Mock(
            android_device.AndroidDevice(serial=serial,
                                         ssh_connection=ssh_connection))
        fb_proxy.reset_mock()
        return ret
示例#9
0
 def test_AndroidDevice_take_bug_report(self, exe_mock, create_dir_mock,
                                        FastbootProxy, MockAdbProxy):
     """Verifies AndroidDevice.take_bug_report calls the correct adb command
     and writes the bugreport file to the correct path.
     """
     ad = android_device.AndroidDevice(serial=MOCK_SERIAL)
     ad.take_bug_report("test_something", 234325.32)
     expected_path = os.path.join(logging.log_path,
                                  "AndroidDevice%s" % ad.serial,
                                  "test_something")
     create_dir_mock.assert_called_with(expected_path)
示例#10
0
 def test_AndroidDevice_take_bug_report(self, mock_log_path, exe_mock,
                                        mock_makedirs, FastbootProxy,
                                        MockAdbProxy):
     """Verifies AndroidDevice.take_bug_report calls the correct adb command
     and writes the bugreport file to the correct path.
     """
     ad = android_device.AndroidDevice(serial=MOCK_SERIAL)
     mock_log_path.return_value = os.path.join(
         logging.log_path, "AndroidDevice%s" % ad.serial)
     ad.take_bug_report("test_something", 234325.32)
     mock_makedirs.assert_called_with(mock_log_path(), exist_ok=True)
示例#11
0
 def test_AndroidDevice_take_bug_report_fail(self, exe_mock,
                                             create_dir_mock, FastbootProxy,
                                             MockAdbProxy):
     """Verifies AndroidDevice.take_bug_report writes out the correct message
     when taking bugreport fails.
     """
     ad = android_device.AndroidDevice(serial=MOCK_SERIAL)
     expected_msg = "Failed to take bugreport on 1: OMG I died!"
     with self.assertRaisesRegex(android_device.AndroidDeviceError,
                                 expected_msg):
         ad.take_bug_report("test_something", 4346343.23)
示例#12
0
 def test_AndroidDevice_instantiation(self, MockFastboot, MockAdbProxy):
     """Verifies the AndroidDevice object's basic attributes are correctly
     set after instantiation.
     """
     ad = android_device.AndroidDevice(serial=MOCK_SERIAL)
     self.assertEqual(ad.serial, 1)
     self.assertEqual(ad.model, "fakemodel")
     self.assertIsNone(ad.adb_logcat_process)
     expected_lp = os.path.join(logging.log_path,
                                "AndroidDevice%s" % MOCK_SERIAL)
     self.assertEqual(ad.log_path, expected_lp)
示例#13
0
 def test_AndroidDevice_start_adb_logcat_with_user_param(
         self, create_proc_mock, FastbootProxy, MockAdbProxy):
     """Verifies that start_adb_logcat generates the correct adb logcat
     command if adb_logcat_param is specified.
     """
     ad = android_device.AndroidDevice(serial=MOCK_SERIAL)
     ad.adb_logcat_param = "-b radio"
     ad.start_adb_logcat()
     # Verify that create_logcat_keepalive_process is called with the
     # correct command.
     log_dir = "AndroidDevice%s" % ad.serial
     create_proc_mock.assert_called_with(ad.serial, log_dir, '-b radio')
示例#14
0
 def test_AndroidDevice_take_bug_report_fallback(self, mock_log_path,
                                                 exe_mock, mock_makedirs,
                                                 FastbootProxy,
                                                 MockAdbProxy):
     """Verifies AndroidDevice.take_bug_report falls back to traditional
     bugreport on builds that do not have bugreportz.
     """
     ad = android_device.AndroidDevice(serial=MOCK_SERIAL)
     mock_log_path.return_value = os.path.join(
         logging.log_path, "AndroidDevice%s" % ad.serial)
     ad.take_bug_report("test_something", MOCK_ADB_EPOCH_BEGIN_TIME)
     mock_makedirs.assert_called_with(mock_log_path(), exist_ok=True)
示例#15
0
 def test_AndroidDevice_take_bug_report_fallback(self, exe_mock,
                                                 create_dir_mock,
                                                 FastbootProxy,
                                                 MockAdbProxy):
     """Verifies AndroidDevice.take_bug_report falls back to traditional
     bugreport on builds that do not have bugreportz.
     """
     ad = android_device.AndroidDevice(serial=MOCK_SERIAL)
     ad.take_bug_report("test_something", MOCK_ADB_EPOCH_BEGIN_TIME)
     expected_path = os.path.join(logging.log_path,
                                  "AndroidDevice%s" % ad.serial,
                                  "test_something")
     create_dir_mock.assert_called_with(expected_path)
 def test_AndroidDevice_take_bug_report(self, exe_mock, create_dir_mock,
                                        MockAdbProxy):
     """Verifies AndroidDevice.take_bug_report calls the correct adb command
     and writes the bugreport file to the correct path.
     """
     mock_serial = 1
     ml = get_mock_logger()
     ad = android_device.AndroidDevice(serial=mock_serial, logger=ml)
     ad.take_bug_report("test_something", "sometime")
     expected_path = os.path.join(MOCK_LOG_PATH,
                                  "AndroidDevice%s" % ad.serial,
                                  "BugReports")
     create_dir_mock.assert_called_with(expected_path)
 def test_AndroidDevice_instantiation(self, MockAdbProxy):
     """Verifies the AndroidDevice object's basic attributes are correctly
     set after instantiation.
     """
     mock_serial = 1
     ml = get_mock_logger()
     ad = android_device.AndroidDevice(serial=mock_serial, logger=ml)
     self.assertEqual(ad.serial, 1)
     self.assertEqual(ad.model, "fakemodel")
     self.assertIsNone(ad.adb_logcat_process)
     self.assertIsNone(ad.adb_logcat_file_path)
     expected_lp = os.path.join(ml.log_path,
                                "AndroidDevice%s" % mock_serial)
     self.assertEqual(ad.log_path, expected_lp)
示例#18
0
 def test_AndroidDevice_take_bug_report_fallback(self, exe_mock,
                                                 create_dir_mock,
                                                 FastbootProxy,
                                                 MockAdbProxy):
     """Verifies AndroidDevice.take_bug_report falls back to traditional
     bugreport on builds that do not have bugreportz.
     """
     mock_serial = 1
     ad = android_device.AndroidDevice(serial=mock_serial)
     ad.take_bug_report("test_something", "sometime")
     expected_path = os.path.join(logging.log_path,
                                  "AndroidDevice%s" % ad.serial,
                                  "BugReports")
     create_dir_mock.assert_called_with(expected_path)
示例#19
0
    def test_ensure_verity_enabled_both_enabled_at_start(self, adb_proxy):
        ad = android_device.AndroidDevice(serial=MOCK_SERIAL)
        root_user_id = '0'

        ad.adb.get_user_id = mock.MagicMock()
        ad.adb.get_user_id.return_value = root_user_id

        ad.adb.getprop = mock.MagicMock(side_effect=[
            '2',  # system.verified
            '2'
        ])  # vendor.verified
        ad.adb.ensure_user = mock.MagicMock()
        ad.reboot = mock.MagicMock()
        ad.ensure_verity_enabled()

        assert not ad.reboot.called
示例#20
0
    def test_ensure_verity_disabled_system_already_disabled(self, adb_proxy):
        ad = android_device.AndroidDevice(serial=MOCK_SERIAL)
        root_user_id = '0'

        ad.adb.get_user_id = mock.MagicMock()
        ad.adb.get_user_id.return_value = root_user_id

        ad.adb.getprop = mock.MagicMock(side_effect=[
            '2',  # system.verified
            ''
        ])  # vendor.verified
        ad.adb.ensure_user = mock.MagicMock()
        ad.reboot = mock.MagicMock()
        ad.ensure_verity_disabled()

        ad.reboot.assert_called_once()
示例#21
0
    def test_AndroidDevice_stop_adb_logcat(self, proc_mock, FastbootProxy,
                                           MockAdbProxy):
        """Verifies the AndroidDevice method stop_adb_logcat. Checks that the
        underlying logcat process is stopped properly and correct warning msgs
        are generated.
        """
        ad = android_device.AndroidDevice(serial=MOCK_SERIAL)
        ad.adb_logcat_process = proc_mock
        # Expect warning msg if stop is called before start.
        expected_msg = (
            "Android device .* does not have an ongoing adb logcat")
        proc_mock.is_running.return_value = False
        with self.assertLogs(level='WARNING') as log:
            ad.stop_adb_logcat()
            self.assertRegex(log.output[0], expected_msg)

        # Verify the underlying process is stopped.
        proc_mock.is_running.return_value = True
        ad.stop_adb_logcat()
        proc_mock.stop.assert_called_with()
示例#22
0
    def __init__(self, serial_number):
        """Initializes the ACTS library components.

        @param serial_number Serial number of the android device to be tested,
               None if there is only one device connected to the host.

        """
        if not serial_number:
            ads = android_device.get_all_instances()
            if not ads:
                msg = "No android device found, abort!"
                logging.error(msg)
                raise XmlRpcServerError(msg)
            self.ad = ads[0]
        elif serial_number in android_device.list_adb_devices():
            self.ad = android_device.AndroidDevice(serial_number)
        else:
            msg = ("Specified Android device %s can't be found, abort!"
                   ) % serial_number
            logging.error(msg)
            raise XmlRpcServerError(msg)
示例#23
0
 def test_AndroidDevice_start_adb_logcat(self, proc_mock, FastbootProxy,
                                         MockAdbProxy):
     """Verifies the AndroidDevice method start_adb_logcat. Checks that the
     underlying logcat process is started properly and correct warning msgs
     are generated.
     """
     with mock.patch(('acts.controllers.android_lib.logcat.'
                      'create_logcat_keepalive_process'),
                     return_value=proc_mock) as create_proc_mock:
         ad = android_device.AndroidDevice(serial=MOCK_SERIAL)
         ad.start_adb_logcat()
         # Verify start did the correct operations.
         self.assertTrue(ad.adb_logcat_process)
         log_dir = "AndroidDevice%s" % ad.serial
         create_proc_mock.assert_called_with(ad.serial, log_dir, '-b all')
         proc_mock.start.assert_called_with()
         # Expect warning msg if start is called back to back.
         expected_msg = "Android device .* already has a running adb logcat"
         proc_mock.is_running.return_value = True
         with self.assertLogs(level='WARNING') as log:
             ad.start_adb_logcat()
             self.assertRegex(log.output[0], expected_msg)
 def test_AndroidDevice_take_logcat(self, check_proc_mock, stop_proc_mock,
                                    start_proc_mock, creat_dir_mock,
                                    FastbootProxy, MockAdbProxy):
     """Verifies the steps of collecting adb logcat on an AndroidDevice
     object, including various function calls and the expected behaviors of
     the calls.
     """
     mock_serial = 1
     ad = android_device.AndroidDevice(serial=mock_serial)
     expected_msg = ("Android device .* does not have an ongoing adb logcat"
                     " collection.")
     # Expect error if stop is called before start.
     with self.assertRaisesRegex(android_device.AndroidDeviceError,
                                 expected_msg):
         ad.stop_adb_logcat()
     ad.start_adb_logcat()
     # Verify start did the correct operations.
     self.assertTrue(ad.adb_logcat_process)
     expected_log_path = os.path.join(logging.log_path,
                                      "AndroidDevice%s" % ad.serial,
                                      "adblog,fakemodel,%s.txt" % ad.serial)
     creat_dir_mock.assert_called_with(os.path.dirname(expected_log_path))
     adb_cmd = 'adb -s %s logcat -v threadtime -b all >> %s'
     start_proc_mock.assert_called_with(adb_cmd %
                                        (ad.serial, expected_log_path))
     self.assertEqual(ad.adb_logcat_file_path, expected_log_path)
     expected_msg = ("Android device .* already has an adb logcat thread "
                     "going on. Cannot start another one.")
     # Expect error if start is called back to back.
     with self.assertRaisesRegex(android_device.AndroidDeviceError,
                                 expected_msg):
         ad.start_adb_logcat()
     # Verify stop did the correct operations.
     ad.stop_adb_logcat()
     stop_proc_mock.assert_called_with("process")
     self.assertIsNone(ad.adb_logcat_process)
     self.assertEqual(ad.adb_logcat_file_path, expected_log_path)
示例#25
0
 def test_get_apk_process_id_bad_return(self, adb_proxy):
     ad = android_device.AndroidDevice(serial=MOCK_SERIAL)
     ad.adb.return_value = "bad return value error"
     self.assertEqual(None, ad.get_package_pid("some_package"))
示例#26
0
 def test_get_apk_process_id_process_exists_second_try(self, adb_proxy):
     ad = android_device.AndroidDevice(serial=MOCK_SERIAL)
     ad.adb.return_multiple = True
     ad.adb.return_value = ["", "system 1 2 3 4  S com.some_package"]
     self.assertEqual(1, ad.get_package_pid("some_package"))
示例#27
0
 def test_get_apk_process_id_process_cannot_find(self, adb_proxy):
     ad = android_device.AndroidDevice(serial=MOCK_SERIAL)
     ad.adb.return_value = "does_not_contain_value"
     self.assertEqual(None, ad.get_package_pid("some_package"))
    def __init__(self, serial_number, log_dir, test_station):
        """Initializes the ACTS library components.

        @test_station string represting teststation's hostname.
        @param serial_number Serial number of the android device to be tested,
               None if there is only one device connected to the host.
        @param log_dir Path to store output logs of this run.

        """
        # Cleanup all existing logs for this device when starting.
        shutil.rmtree(log_dir, ignore_errors=True)
        logger.setup_test_logger(log_path=log_dir, prefix="ANDROID_XMLRPC")
        if not serial_number:
            ads = android_device.get_all_instances()
            if not ads:
                msg = "No android device found, abort!"
                logging.error(msg)
                raise XmlRpcServerError(msg)
            self.ad = ads[0]
        elif serial_number in android_device.list_adb_devices():
            self.ad = android_device.AndroidDevice(serial_number)
        else:
            msg = ("Specified Android device %s can't be found, abort!"
                   ) % serial_number
            logging.error(msg)
            raise XmlRpcServerError(msg)
        # Even if we find one attenuator assume the rig has attenuators for now.
        # With the single IP attenuator, this will be a easy check.
        rig_has_attenuator = False
        count = 0
        for i in range(1, self.NUM_ATTEN + 1):
            atten_addr = test_station + '-attenuator-' + '%d' % i
            if subprocess.Popen(['ping', '-c', '2', atten_addr],
                                stdout=subprocess.PIPE).communicate()[0]:
                rig_has_attenuator = True
                count = count + 1
        if rig_has_attenuator and count == self.NUM_ATTEN:
            atten = attenuator.create([{
                "Address": test_station + '-attenuator-1',
                "Port": 23,
                "Model": "minicircuits",
                "InstrumentCount": 1,
                "Paths": ["Attenuator-1"]
            }, {
                "Address": test_station + '-attenuator-2',
                "Port": 23,
                "Model": "minicircuits",
                "InstrumentCount": 1,
                "Paths": ["Attenuator-2"]
            }, {
                "Address": test_station + '-attenuator-3',
                "Port": 23,
                "Model": "minicircuits",
                "InstrumentCount": 1,
                "Paths": ["Attenuator-3"]
            }, {
                "Address": test_station + '-attenuator-4',
                "Port": 23,
                "Model": "minicircuits",
                "InstrumentCount": 1,
                "Paths": ["Attenuator-4"]
            }])
            device = 0
            # Set attenuation on all attenuators to 0.
            for device in range(len(atten)):
                atten[device].set_atten(0)
            attenuator.destroy(atten)
        elif rig_has_attenuator and count < self.NUM_ATTEN:
            msg = 'One or more attenuators are down.'
            logging.error(msg)
            raise XmlRpcServerError(msg)