Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _update_log_path(self):
"""Updates the logging values with the current timestamp."""
self._start_time = logger.get_log_file_timestamp()
self._root_output_path = os.path.join(self._log_dir,
self._testbed_name,
self._start_time)
def start_capture(self,
override_configs=None,
additional_args=None,
duration=None,
packet_count=None):
"""See base class documentation
"""
if self._process is not None:
raise sniffer.InvalidOperationError(
"Trying to start a sniff while another is still running!")
capture_dir = os.path.join(self._logger.log_path,
"Sniffer-{}".format(self._interface))
os.makedirs(capture_dir, exist_ok=True)
self._capture_file_path = os.path.join(
capture_dir,
"capture_{}.pcap".format(logger.get_log_file_timestamp()))
self._pre_capture_config(override_configs)
_, self._temp_capture_file_path = tempfile.mkstemp(suffix=".pcap")
cmd = self._get_command_line(additional_args=additional_args,
duration=duration,
packet_count=packet_count)
self._process = utils.start_standing_subprocess(cmd)
return sniffer.ActiveCaptureContext(self, duration)
If you want to take a bug report, call this function with a list of
android_device objects in on_fail. But reports will be taken on all the
devices in the list concurrently. Bug report takes a relative long
time to take, so use this cautiously.
Args:
ads: A list of AndroidDevice instances.
test_name: Name of the test method that triggered this bug report.
If None, the default name "bugreport" will be used.
begin_time: timestamp taken when the test started, can be either
string or int. If None, the current time will be used.
destination: string, path to the directory where the bugreport
should be saved.
"""
if begin_time is None:
begin_time = mobly_logger.get_log_file_timestamp()
else:
begin_time = mobly_logger.sanitize_filename(str(begin_time))
def take_br(test_name, begin_time, ad, destination):
ad.take_bug_report(test_name=test_name,
begin_time=begin_time,
destination=destination)
args = [(test_name, begin_time, ad, destination) for ad in ads]
utils.concurrent_exec(take_br, args)
added if specified by user.
Args:
file_type: string, type of this file, like "logcat" etc.
time_identifier: string or RuntimeTestInfo. If a `RuntimeTestInfo`
is passed in, the `signature` of the test case will be used. If
a string is passed in, the string itself will be used.
Otherwise the current timestamp will be used.
extension_name: string, the extension name of the file.
Returns:
String, the filename generated.
"""
time_str = time_identifier
if time_identifier is None:
time_str = mobly_logger.get_log_file_timestamp()
elif isinstance(time_identifier, runtime_test_info.RuntimeTestInfo):
time_str = time_identifier.signature
filename_tokens = [file_type]
if self.debug_tag != self.serial:
filename_tokens.append(self.debug_tag)
filename_tokens.extend([self.serial, self.model, time_str])
filename_str = ','.join(filename_tokens)
if extension_name is not None:
filename_str = '%s.%s' % (filename_str, extension_name)
filename_str = mobly_logger.sanitize_filename(filename_str)
self.log.debug('Generated filename: %s', filename_str)
return filename_str
test_name: Name of the test method that triggered this bug report.
begin_time: Timestamp of when the test started. If not set, then
this will default to the current time.
timeout: float, the number of seconds to wait for bugreport to
complete, default is 5min.
destination: string, path to the directory where the bugreport
should be saved.
Returns:
A string that is the absolute path to the bug report on the host.
"""
prefix = DEFAULT_BUG_REPORT_NAME
if test_name:
prefix = '%s,%s' % (DEFAULT_BUG_REPORT_NAME, test_name)
if begin_time is None:
begin_time = mobly_logger.get_log_file_timestamp()
new_br = True
try:
stdout = self.adb.shell('bugreportz -v').decode('utf-8')
# This check is necessary for builds before N, where adb shell's ret
# code and stderr are not propagated properly.
if 'not found' in stdout:
new_br = False
except adb.AdbError:
new_br = False
if destination is None:
destination = os.path.join(self.log_path, 'BugReports')
br_path = utils.abs_path(destination)
utils.create_dir(br_path)
filename = self.generate_filename(prefix, str(begin_time), 'txt')