Beispiel #1
0
    def start_packet_capture(self, band, log_path, pcap_fname):
        """Start packet capture for band.

        band = 2G starts tcpdump on 'mon0' interface.
        band = 5G starts tcpdump on 'mon1' interface.

        Args:
            band: '2g' or '2G' and '5g' or '5G'.
            log_path: test log path to save the pcap file.
            pcap_fname: name of the pcap file.

        Returns:
            pcap_proc: Process object of the tcpdump.
        """
        band = band.upper()
        if band not in BAND_IFACE.keys() or band in self.pcap_properties:
            self.log.error("Invalid band or packet capture already running")
            return None

        pcap_name = '%s_%s.pcap' % (pcap_fname, band)
        pcap_fname = os.path.join(log_path, pcap_name)
        pcap_file = open(pcap_fname, 'w+b')

        tcpdump_cmd = 'tcpdump -i %s -w - -U 2>/dev/null' % (BAND_IFACE[band])
        cmd = formatter.SshFormatter().format_command(
            tcpdump_cmd, None, self.ssh_settings, extra_flags={'-q': None})
        pcap_proc = Process(cmd)
        pcap_proc.set_on_output_callback(
            lambda msg: pcap_file.write(msg), binary=True)
        pcap_proc.start()

        self.pcap_properties[band] = PcapProperties(pcap_proc, pcap_fname,
                                                    pcap_file)
        return pcap_proc
Beispiel #2
0
    def test_redirect_output_feeds_all_lines_to_on_output_callback(self):
        """Tests that _redirect_output loops until all lines are parsed."""
        received_list = []

        def appender(line):
            received_list.append(line)

        process = Process('cmd')
        process.set_on_output_callback(appender)
        process._process = mock.Mock()
        process._process.stdout.readline.side_effect = [b'a\n', b'b\n', b'']

        process._redirect_output()

        self.assertEqual(received_list[0], 'a')
        self.assertEqual(received_list[1], 'b')
        self.assertEqual(len(received_list), 2)
Beispiel #3
0
def create_logcat_keepalive_process(serial, logcat_dir, extra_params=''):
    """Creates a Logcat Process that automatically attempts to reconnect.

    Args:
        serial: The serial of the device to read the logcat of.
        logcat_dir: The directory used for logcat file output.
        extra_params: Any additional params to be added to the logcat cmdline.

    Returns:
        A acts.libs.proc.process.Process object.
    """
    logger = log_stream.create_logger(
        'adblog_%s' % serial, log_name=serial, subcontext=logcat_dir,
        log_styles=(LogStyles.LOG_DEBUG | LogStyles.TESTCASE_LOG))
    process = Process('adb -s %s logcat -T 1 -v year %s' %
                      (serial, extra_params))
    timestamp_tracker = TimestampTracker()
    process.set_on_output_callback(_log_line_func(logger, timestamp_tracker))
    process.set_on_terminate_callback(
        _on_retry(serial, extra_params, timestamp_tracker))
    return process