Exemplo n.º 1
0
def check_capture_stdin(self, cmd=None):
    # Similar to suite_io.check_io_4_packets.
    if cmd == config.cmd_wireshark and not config.canDisplay():
        self.skipTest('Test requires a display.')
    self.assertIsNotNone(cmd)
    capture_file = os.path.join(config.capture_dir, 'dhcp.pcap')
    testout_file = self.filename_from_id(testout_pcap)
    slow_dhcp_cmd = subprocesstest.cat_dhcp_command('slow')
    capture_cmd = subprocesstest.capture_command(
        cmd,
        '-i',
        '-',
        '-w',
        testout_file,
        '-a',
        'duration:{}'.format(capture_duration),
        shell=True)
    if cmd == config.cmd_wireshark:
        capture_cmd += ' -o console.log.level:127'
    pipe_proc = self.runProcess(slow_dhcp_cmd + ' | ' + capture_cmd,
                                shell=True)
    pipe_returncode = pipe_proc.returncode
    self.assertEqual(pipe_returncode, 0)
    if cmd == config.cmd_wireshark:
        self.assertTrue(self.grepOutput('Wireshark is up and ready to go'),
                        'No startup message.')
        self.assertTrue(self.grepOutput('Capture started'),
                        'No capture start message.')
        self.assertTrue(self.grepOutput('Capture stopped'),
                        'No capture stop message.')
    self.assertTrue(os.path.isfile(testout_file))
    if (pipe_returncode == 0):
        self.checkPacketCount(8)
Exemplo n.º 2
0
    def check_dumpcap_autostop_stdin_real(self, packets=None, filesize=None):
        # Similar to check_capture_stdin.
        testout_file = self.filename_from_id(testout_pcap)
        cat100_dhcp_cmd = subprocesstest.cat_dhcp_command('cat100')
        condition = 'oops:invalid'

        self.assertTrue(packets is not None or filesize is not None,
                        'Need one of packets or filesize')
        self.assertFalse(packets is not None and filesize is not None,
                         'Need one of packets or filesize')

        if packets is not None:
            condition = 'packets:{}'.format(packets)
        elif filesize is not None:
            condition = 'filesize:{}'.format(filesize)

        capture_cmd = ' '.join((
            cmd_dumpcap,
            '-i',
            '-',
            '-w',
            testout_file,
            '-a',
            condition,
        ))
        pipe_proc = self.assertRun(cat100_dhcp_cmd + ' | ' + capture_cmd,
                                   shell=True)
        self.assertTrue(os.path.isfile(testout_file))

        if packets is not None:
            self.checkPacketCount(packets)
        elif filesize is not None:
            capturekb = os.path.getsize(testout_file) / 1000
            self.assertGreaterEqual(capturekb, filesize)
Exemplo n.º 3
0
 def check_capture_fifo_real(self, cmd=None):
     self.assertIsNotNone(cmd)
     testout_file = self.filename_from_id(testout_pcap)
     fifo_file = self.filename_from_id('testout.fifo')
     try:
         # If a previous test left its fifo laying around, e.g. from a failure, remove it.
         os.unlink(fifo_file)
     except:
         pass
     os.mkfifo(fifo_file)
     slow_dhcp_cmd = subprocesstest.cat_dhcp_command('slow')
     fifo_proc = self.startProcess(
         ('{0} > {1}'.format(slow_dhcp_cmd, fifo_file)),
         shell=True)
     capture_proc = self.runProcess(capture_command(cmd,
         '-i', fifo_file,
         '-p',
         '-w', testout_file,
         '-a', 'duration:{}'.format(capture_duration),
     ))
     fifo_proc.kill()
     self.assertTrue(os.path.isfile(testout_file))
     capture_returncode = capture_proc.returncode
     self.assertEqual(capture_returncode, 0)
     if (capture_returncode == 0):
         self.checkPacketCount(8)
Exemplo n.º 4
0
 def check_capture_stdin_real(self, cmd=None):
     # Similar to suite_io.check_io_4_packets.
     self.assertIsNotNone(cmd)
     testout_file = self.filename_from_id(testout_pcap)
     slow_dhcp_cmd = subprocesstest.cat_dhcp_command('slow')
     capture_cmd = capture_command(cmd,
                                   '-i',
                                   '-',
                                   '-w',
                                   testout_file,
                                   '-a',
                                   'duration:{}'.format(capture_duration),
                                   shell=True)
     is_gui = type(cmd) != str and '-k' in cmd[0]
     if is_gui:
         capture_cmd += ' -o console.log.level:127'
     pipe_proc = self.assertRun(slow_dhcp_cmd + ' | ' + capture_cmd,
                                shell=True)
     if is_gui:
         self.assertTrue(self.grepOutput('Wireshark is up and ready to go'),
                         'No startup message.')
         self.assertTrue(self.grepOutput('Capture started'),
                         'No capture start message.')
         self.assertTrue(self.grepOutput('Capture stopped'),
                         'No capture stop message.')
     self.assertTrue(os.path.isfile(testout_file))
     self.checkPacketCount(8)
Exemplo n.º 5
0
    def check_dumpcap_autostop_stdin_real(self, packets=None, filesize=None):
        # Similar to check_capture_stdin.
        testout_file = self.filename_from_id(testout_pcap)
        cat100_dhcp_cmd = subprocesstest.cat_dhcp_command('cat100')
        condition='oops:invalid'

        self.assertTrue(packets is not None or filesize is not None, 'Need one of packets or filesize')
        self.assertFalse(packets is not None and filesize is not None, 'Need one of packets or filesize')

        if packets is not None:
            condition = 'packets:{}'.format(packets)
        elif filesize is not None:
            condition = 'filesize:{}'.format(filesize)

        capture_cmd = ' '.join((cmd_dumpcap,
            '-i', '-',
            '-w', testout_file,
            '-a', condition,
        ))
        pipe_proc = self.runProcess(cat100_dhcp_cmd + ' | ' + capture_cmd, shell=True)
        pipe_returncode = pipe_proc.returncode
        self.assertEqual(pipe_returncode, 0)
        self.assertTrue(os.path.isfile(testout_file))
        if (pipe_returncode != 0):
            return

        if packets is not None:
            self.checkPacketCount(packets)
        elif filesize is not None:
            capturekb = os.path.getsize(testout_file) / 1000
            self.assertGreaterEqual(capturekb, filesize)
Exemplo n.º 6
0
def check_capture_fifo(self, cmd=None):
    if not config.canMkfifo():
        self.skipTest('Test requires OS fifo support.')
    if cmd == config.cmd_wireshark and not config.canDisplay():
        self.skipTest('Test requires a display.')
    self.assertIsNotNone(cmd)
    capture_file = os.path.join(config.capture_dir, 'dhcp.pcap')
    testout_file = self.filename_from_id(testout_pcap)
    fifo_file = self.filename_from_id('testout.fifo')
    try:
        # If a previous test left its fifo laying around, e.g. from a failure, remove it.
        os.unlink(fifo_file)
    except:
        pass
    os.mkfifo(fifo_file)
    slow_dhcp_cmd = subprocesstest.cat_dhcp_command('slow')
    fifo_proc = self.startProcess(
        ('{0} > {1}'.format(slow_dhcp_cmd, fifo_file)), shell=True)
    capture_proc = self.runProcess(
        subprocesstest.capture_command(
            cmd,
            '-i',
            fifo_file,
            '-p',
            '-w',
            testout_file,
            '-a',
            'duration:{}'.format(capture_duration),
        ))
    fifo_proc.kill()
    self.assertTrue(os.path.isfile(testout_file))
    capture_returncode = capture_proc.returncode
    self.assertEqual(capture_returncode, 0)
    if (capture_returncode == 0):
        self.checkPacketCount(8)
Exemplo n.º 7
0
def check_io_4_packets(self, cmd=None, from_stdin=False, to_stdout=False):
    # Test direct->direct, stdin->direct, and direct->stdout file I/O.
    # Similar to suite_capture.check_capture_10_packets and
    # suite_capture.check_capture_stdin.
    if cmd == config.cmd_wireshark and not config.canDisplay():
        self.skipTest('Test requires a display.')
    self.assertIsNotNone(cmd)
    capture_file = os.path.join(config.capture_dir, 'dhcp.pcap')
    testout_file = self.filename_from_id(testout_pcap)
    if from_stdin and to_stdout:
        # XXX If we support this, should we bother with separate stdin->direct
        # and direct->stdout tests?
        self.fail('Stdin and stdout not supported in the same test.')
    elif from_stdin:
        # cat -B "${CAPTURE_DIR}dhcp.pcap" | $DUT -r - -w ./testout.pcap 2>./testout.txt
        cat_dhcp_cmd = subprocesstest.cat_dhcp_command('cat')
        stdin_cmd = '{0} | "{1}" -r - -w "{2}"'.format(cat_dhcp_cmd, cmd, testout_file)
        io_proc = self.runProcess(stdin_cmd, shell=True)
    elif to_stdout:
        # $DUT -r "${CAPTURE_DIR}dhcp.pcap" -w - > ./testout.pcap 2>./testout.txt
        stdout_cmd = '"{0}" -r "{1}" -w - > "{2}"'.format(cmd, capture_file, testout_file)
        io_proc = self.runProcess(stdout_cmd, shell=True)
    else: # direct->direct
        # $DUT -r "${CAPTURE_DIR}dhcp.pcap" -w ./testout.pcap > ./testout.txt 2>&1
        capture_file = os.path.join(config.capture_dir, 'dhcp.pcap')
        io_proc = self.runProcess(subprocesstest.capture_command(cmd,
            '-r', capture_file,
            '-w', testout_file,
        ))
    io_returncode = io_proc.returncode
    self.assertEqual(io_returncode, 0)
    self.assertTrue(os.path.isfile(testout_file))
    if (io_returncode == 0):
        self.checkPacketCount(4)
Exemplo n.º 8
0
def check_io_4_packets(self, capture_file, cmd=None, from_stdin=False, to_stdout=False):
    # Test direct->direct, stdin->direct, and direct->stdout file I/O.
    # Similar to suite_capture.check_capture_10_packets and
    # suite_capture.check_capture_stdin.
    self.assertIsNotNone(cmd)
    testout_file = self.filename_from_id(testout_pcap)
    if from_stdin and to_stdout:
        # XXX If we support this, should we bother with separate stdin->direct
        # and direct->stdout tests?
        self.fail('Stdin and stdout not supported in the same test.')
    elif from_stdin:
        # cat -B "${CAPTURE_DIR}dhcp.pcap" | $DUT -r - -w ./testout.pcap 2>./testout.txt
        cat_dhcp_cmd = subprocesstest.cat_dhcp_command('cat')
        stdin_cmd = '{0} | "{1}" -r - -w "{2}"'.format(cat_dhcp_cmd, cmd, testout_file)
        io_proc = self.assertRun(stdin_cmd, shell=True)
    elif to_stdout:
        # $DUT -r "${CAPTURE_DIR}dhcp.pcap" -w - > ./testout.pcap 2>./testout.txt
        stdout_cmd = '"{0}" -r "{1}" -w - > "{2}"'.format(cmd, capture_file('dhcp.pcap'), testout_file)
        io_proc = self.assertRun(stdout_cmd, shell=True)
    else: # direct->direct
        # $DUT -r "${CAPTURE_DIR}dhcp.pcap" -w ./testout.pcap > ./testout.txt 2>&1
        io_proc = self.assertRun((cmd,
            '-r', capture_file('dhcp.pcap'),
            '-w', testout_file,
        ))
    self.assertTrue(os.path.isfile(testout_file))
    self.checkPacketCount(4)
Exemplo n.º 9
0
def check_capture_fifo(self, cmd=None):
    if not config.canMkfifo():
        self.skipTest('Test requires OS fifo support.')
    if cmd == config.cmd_wireshark and not config.canDisplay():
        self.skipTest('Test requires a display.')
    self.assertIsNotNone(cmd)
    capture_file = os.path.join(config.capture_dir, 'dhcp.pcap')
    testout_file = self.filename_from_id(testout_pcap)
    fifo_file = self.filename_from_id('testout.fifo')
    try:
        # If a previous test left its fifo laying around, e.g. from a failure, remove it.
        os.unlink(fifo_file)
    except:
        pass
    os.mkfifo(fifo_file)
    slow_dhcp_cmd = subprocesstest.cat_dhcp_command('slow')
    fifo_proc = self.startProcess(
        ('{0} > {1}'.format(slow_dhcp_cmd, fifo_file)),
        shell=True)
    capture_proc = self.runProcess(subprocesstest.capture_command(cmd,
        '-i', fifo_file,
        '-p',
        '-w', testout_file,
        '-a', 'duration:{}'.format(capture_duration),
    ),
    env=capture_env
    )
    fifo_proc.kill()
    self.assertTrue(os.path.isfile(testout_file))
    capture_returncode = capture_proc.returncode
    self.assertEqual(capture_returncode, 0)
    if (capture_returncode == 0):
        self.checkPacketCount(8)
Exemplo n.º 10
0
def check_capture_stdin(self, cmd=None):
    # Similar to suite_io.check_io_4_packets.
    if cmd == config.cmd_wireshark and not config.canDisplay():
        self.skipTest('Test requires a display.')
    self.assertIsNotNone(cmd)
    capture_file = os.path.join(config.capture_dir, 'dhcp.pcap')
    testout_file = self.filename_from_id(testout_pcap)
    slow_dhcp_cmd = subprocesstest.cat_dhcp_command('slow')
    capture_cmd = subprocesstest.capture_command(cmd,
        '-i', '-',
        '-w', testout_file,
        '-a', 'duration:{}'.format(capture_duration),
        shell=True
    )
    if cmd == config.cmd_wireshark:
        capture_cmd += ' -o console.log.level:127'
    pipe_proc = self.runProcess(slow_dhcp_cmd + ' | ' + capture_cmd, env=capture_env, shell=True)
    pipe_returncode = pipe_proc.returncode
    self.assertEqual(pipe_returncode, 0)
    if cmd == config.cmd_wireshark:
        self.assertTrue(self.grepOutput('Wireshark is up and ready to go'), 'No startup message.')
        self.assertTrue(self.grepOutput('Capture started'), 'No capture start message.')
        self.assertTrue(self.grepOutput('Capture stopped'), 'No capture stop message.')
    self.assertTrue(os.path.isfile(testout_file))
    if (pipe_returncode == 0):
        self.checkPacketCount(8)
Exemplo n.º 11
0
 def check_capture_fifo_real(self, cmd=None):
     self.assertIsNotNone(cmd)
     testout_file = self.filename_from_id(testout_pcap)
     fifo_file = self.filename_from_id('testout.fifo')
     try:
         # If a previous test left its fifo laying around, e.g. from a failure, remove it.
         os.unlink(fifo_file)
     except Exception:
         pass
     os.mkfifo(fifo_file)
     slow_dhcp_cmd = subprocesstest.cat_dhcp_command('slow')
     fifo_proc = self.startProcess(
         ('{0} > {1}'.format(slow_dhcp_cmd, fifo_file)), shell=True)
     capture_proc = self.assertRun(
         capture_command(
             cmd,
             '-i',
             fifo_file,
             '-p',
             '-w',
             testout_file,
             '-a',
             'duration:{}'.format(capture_duration),
         ))
     fifo_proc.kill()
     self.assertTrue(os.path.isfile(testout_file))
     self.checkPacketCount(8)
Exemplo n.º 12
0
 def test_rawshark_io_stdin(self, cmd_rawshark, capture_file, io_baseline_str):
     '''Read from stdin using Rawshark'''
     # tail -c +25 "${CAPTURE_DIR}dhcp.pcap" | $RAWSHARK -dencap:1 -R "udp.port==68" -nr - > $IO_RAWSHARK_DHCP_PCAP_TESTOUT 2> /dev/null
     # diff -u --strip-trailing-cr $IO_RAWSHARK_DHCP_PCAP_BASELINE $IO_RAWSHARK_DHCP_PCAP_TESTOUT > $DIFF_OUT 2>&1
     capture_file = capture_file('dhcp.pcap')
     testout_file = self.filename_from_id(testout_pcap)
     raw_dhcp_cmd = subprocesstest.cat_dhcp_command('raw')
     rawshark_cmd = '{0} | "{1}" -r - -n -dencap:1 -R "udp.port==68"'.format(raw_dhcp_cmd, cmd_rawshark)
     rawshark_proc = self.assertRun(rawshark_cmd, shell=True)
     self.assertTrue(self.diffOutput(rawshark_proc.stdout_str, io_baseline_str, 'rawshark', baseline_file))
Exemplo n.º 13
0
 def test_rawshark_io_stdin(self):
     '''Read from stdin using Rawshark'''
     # tail -c +25 "${CAPTURE_DIR}dhcp.pcap" | $RAWSHARK -dencap:1 -R "udp.port==68" -nr - > $IO_RAWSHARK_DHCP_PCAP_TESTOUT 2> /dev/null
     # diff -u --strip-trailing-cr $IO_RAWSHARK_DHCP_PCAP_BASELINE $IO_RAWSHARK_DHCP_PCAP_TESTOUT > $DIFF_OUT 2>&1
     capture_file = os.path.join(config.capture_dir, 'dhcp.pcap')
     testout_file = self.filename_from_id(testout_pcap)
     raw_dhcp_cmd = subprocesstest.cat_dhcp_command('raw')
     rawshark_cmd = '{0} | "{1}" -r - -n -dencap:1 -R "udp.port==68"'.format(raw_dhcp_cmd, config.cmd_rawshark)
     rawshark_proc = self.runProcess(rawshark_cmd, shell=True)
     rawshark_returncode = rawshark_proc.returncode
     self.assertEqual(rawshark_returncode, 0)
     if (rawshark_returncode == 0):
         self.assertTrue(self.diffOutput(rawshark_proc.stdout_str, baseline_str, 'rawshark', baseline_file))
Exemplo n.º 14
0
def check_dumpcap_ringbuffer_stdin(self, packets=None, filesize=None):
    # Similar to check_capture_stdin.
    cmd = config.cmd_dumpcap
    capture_file = os.path.join(config.capture_dir, 'dhcp.pcap')
    rb_unique = 'dhcp_rb_' + uuid.uuid4().hex[:6]  # Random ID
    testout_file = '{}.{}.pcapng'.format(self.id(), rb_unique)
    testout_glob = '{}.{}_*.pcapng'.format(self.id(), rb_unique)
    cat100_dhcp_cmd = subprocesstest.cat_dhcp_command('cat100')
    condition = 'oops:invalid'

    self.assertTrue(packets is not None or filesize is not None,
                    'Need one of packets or filesize')
    self.assertFalse(packets is not None and filesize is not None,
                     'Need one of packets or filesize')

    if packets is not None:
        condition = 'packets:{}'.format(packets)
    elif filesize is not None:
        condition = 'filesize:{}'.format(filesize)

    capture_cmd = subprocesstest.capture_command(cmd,
                                                 '-i',
                                                 '-',
                                                 '-w',
                                                 testout_file,
                                                 '-a',
                                                 'files:2',
                                                 '-b',
                                                 condition,
                                                 shell=True)
    pipe_proc = self.runProcess(cat100_dhcp_cmd + ' | ' + capture_cmd,
                                shell=True)
    pipe_returncode = pipe_proc.returncode
    self.assertEqual(pipe_returncode, 0)
    if (pipe_returncode != 0):
        return

    rb_files = glob.glob(testout_glob)
    for rbf in rb_files:
        self.cleanup_files.append(rbf)

    self.assertEqual(len(rb_files), 2)

    for rbf in rb_files:
        self.assertTrue(os.path.isfile(rbf))
        if packets is not None:
            self.checkPacketCount(packets, cap_file=rbf)
        elif filesize is not None:
            capturekb = os.path.getsize(rbf) / 1000
            self.assertGreaterEqual(capturekb, filesize)
Exemplo n.º 15
0
 def test_rawshark_io_stdin(self, cmd_rawshark, capture_file,
                            io_baseline_str):
     '''Read from stdin using Rawshark'''
     # tail -c +25 "${CAPTURE_DIR}dhcp.pcap" | $RAWSHARK -dencap:1 -R "udp.port==68" -nr - > $IO_RAWSHARK_DHCP_PCAP_TESTOUT 2> /dev/null
     # diff -u --strip-trailing-cr $IO_RAWSHARK_DHCP_PCAP_BASELINE $IO_RAWSHARK_DHCP_PCAP_TESTOUT > $DIFF_OUT 2>&1
     capture_file = capture_file('dhcp.pcap')
     testout_file = self.filename_from_id(testout_pcap)
     raw_dhcp_cmd = subprocesstest.cat_dhcp_command('raw')
     rawshark_cmd = '{0} | "{1}" -r - -n -dencap:1 -R "udp.port==68"'.format(
         raw_dhcp_cmd, cmd_rawshark)
     rawshark_proc = self.assertRun(rawshark_cmd, shell=True)
     self.assertTrue(
         self.diffOutput(rawshark_proc.stdout_str, io_baseline_str,
                         'rawshark', baseline_file))
Exemplo n.º 16
0
 def test_rawshark_io_stdin(self):
     '''Read from stdin using Rawshark'''
     # tail -c +25 "${CAPTURE_DIR}dhcp.pcap" | $RAWSHARK -dencap:1 -R "udp.port==68" -nr - > $IO_RAWSHARK_DHCP_PCAP_TESTOUT 2> /dev/null
     # diff -u --strip-trailing-cr $IO_RAWSHARK_DHCP_PCAP_BASELINE $IO_RAWSHARK_DHCP_PCAP_TESTOUT > $DIFF_OUT 2>&1
     capture_file = os.path.join(config.capture_dir, 'dhcp.pcap')
     testout_file = self.filename_from_id(testout_pcap)
     raw_dhcp_cmd = subprocesstest.cat_dhcp_command('raw')
     rawshark_cmd = '{0} | "{1}" -r - -n -dencap:1 -R "udp.port==68"'.format(
         raw_dhcp_cmd, config.cmd_rawshark)
     rawshark_proc = self.runProcess(rawshark_cmd, shell=True)
     rawshark_returncode = rawshark_proc.returncode
     self.assertEqual(rawshark_returncode, 0)
     if (rawshark_returncode == 0):
         self.assertTrue(
             self.diffOutput(rawshark_proc.stdout_str, baseline_str,
                             'rawshark', baseline_file))
Exemplo n.º 17
0
    def check_dumpcap_ringbuffer_stdin_real(self, packets=None, filesize=None):
        # Similar to check_capture_stdin.
        rb_unique = 'dhcp_rb_' + uuid.uuid4().hex[:6] # Random ID
        testout_file = '{}.{}.pcapng'.format(self.id(), rb_unique)
        testout_glob = '{}.{}_*.pcapng'.format(self.id(), rb_unique)
        cat100_dhcp_cmd = subprocesstest.cat_dhcp_command('cat100')
        condition='oops:invalid'

        self.assertTrue(packets is not None or filesize is not None, 'Need one of packets or filesize')
        self.assertFalse(packets is not None and filesize is not None, 'Need one of packets or filesize')

        if packets is not None:
            condition = 'packets:{}'.format(packets)
        elif filesize is not None:
            condition = 'filesize:{}'.format(filesize)

        capture_cmd = ' '.join((cmd_dumpcap,
            '-i', '-',
            '-w', testout_file,
            '-a', 'files:2',
            '-b', condition,
        ))
        pipe_proc = self.runProcess(cat100_dhcp_cmd + ' | ' + capture_cmd, shell=True)
        pipe_returncode = pipe_proc.returncode
        self.assertEqual(pipe_returncode, 0)
        if (pipe_returncode != 0):
            return

        rb_files = glob.glob(testout_glob)
        for rbf in rb_files:
            self.cleanup_files.append(rbf)

        self.assertEqual(len(rb_files), 2)

        for rbf in rb_files:
            self.assertTrue(os.path.isfile(rbf))
            if packets is not None:
                self.checkPacketCount(packets, cap_file=rbf)
            elif filesize is not None:
                capturekb = os.path.getsize(rbf) / 1000
                self.assertGreaterEqual(capturekb, filesize)
Exemplo n.º 18
0
 def check_capture_stdin_real(self, cmd=None):
     # Similar to suite_io.check_io_4_packets.
     self.assertIsNotNone(cmd)
     testout_file = self.filename_from_id(testout_pcap)
     slow_dhcp_cmd = subprocesstest.cat_dhcp_command('slow')
     capture_cmd = capture_command(cmd,
         '-i', '-',
         '-w', testout_file,
         '-a', 'duration:{}'.format(capture_duration),
         shell=True
     )
     is_gui = type(cmd) != str and '-k' in cmd[0]
     if is_gui:
         capture_cmd += ' -o console.log.level:127'
     pipe_proc = self.assertRun(slow_dhcp_cmd + ' | ' + capture_cmd, shell=True)
     if is_gui:
         self.assertTrue(self.grepOutput('Wireshark is up and ready to go'), 'No startup message.')
         self.assertTrue(self.grepOutput('Capture started'), 'No capture start message.')
         self.assertTrue(self.grepOutput('Capture stopped'), 'No capture stop message.')
     self.assertTrue(os.path.isfile(testout_file))
     self.checkPacketCount(8)
Exemplo n.º 19
0
def check_io_4_packets(self,
                       capture_file,
                       cmd=None,
                       from_stdin=False,
                       to_stdout=False):
    # Test direct->direct, stdin->direct, and direct->stdout file I/O.
    # Similar to suite_capture.check_capture_10_packets and
    # suite_capture.check_capture_stdin.
    self.assertIsNotNone(cmd)
    testout_file = self.filename_from_id(testout_pcap)
    if from_stdin and to_stdout:
        # XXX If we support this, should we bother with separate stdin->direct
        # and direct->stdout tests?
        self.fail('Stdin and stdout not supported in the same test.')
    elif from_stdin:
        # cat -B "${CAPTURE_DIR}dhcp.pcap" | $DUT -r - -w ./testout.pcap 2>./testout.txt
        cat_dhcp_cmd = subprocesstest.cat_dhcp_command('cat')
        stdin_cmd = '{0} | "{1}" -r - -w "{2}"'.format(cat_dhcp_cmd, cmd,
                                                       testout_file)
        io_proc = self.runProcess(stdin_cmd, shell=True)
    elif to_stdout:
        # $DUT -r "${CAPTURE_DIR}dhcp.pcap" -w - > ./testout.pcap 2>./testout.txt
        stdout_cmd = '"{0}" -r "{1}" -w - > "{2}"'.format(
            cmd, capture_file('dhcp.pcap'), testout_file)
        io_proc = self.runProcess(stdout_cmd, shell=True)
    else:  # direct->direct
        # $DUT -r "${CAPTURE_DIR}dhcp.pcap" -w ./testout.pcap > ./testout.txt 2>&1
        io_proc = self.runProcess(
            subprocesstest.capture_command(
                cmd,
                '-r',
                capture_file('dhcp.pcap'),
                '-w',
                testout_file,
            ))
    io_returncode = io_proc.returncode
    self.assertEqual(io_returncode, 0)
    self.assertTrue(os.path.isfile(testout_file))
    if (io_returncode == 0):
        self.checkPacketCount(4)
Exemplo n.º 20
0
def check_dumpcap_autostop_stdin(self, packets=None, filesize=None):
    # Similar to check_capture_stdin.
    cmd = config.cmd_dumpcap
    capture_file = os.path.join(config.capture_dir, 'dhcp.pcap')
    testout_file = self.filename_from_id(testout_pcap)
    cat100_dhcp_cmd = subprocesstest.cat_dhcp_command('cat100')
    condition = 'oops:invalid'

    self.assertTrue(packets is not None or filesize is not None,
                    'Need one of packets or filesize')
    self.assertFalse(packets is not None and filesize is not None,
                     'Need one of packets or filesize')

    if packets is not None:
        condition = 'packets:{}'.format(packets)
    elif filesize is not None:
        condition = 'filesize:{}'.format(filesize)

    capture_cmd = subprocesstest.capture_command(cmd,
                                                 '-i',
                                                 '-',
                                                 '-w',
                                                 testout_file,
                                                 '-a',
                                                 condition,
                                                 shell=True)
    pipe_proc = self.runProcess(cat100_dhcp_cmd + ' | ' + capture_cmd,
                                shell=True)
    pipe_returncode = pipe_proc.returncode
    self.assertEqual(pipe_returncode, 0)
    self.assertTrue(os.path.isfile(testout_file))
    if (pipe_returncode != 0):
        return

    if packets is not None:
        self.checkPacketCount(packets)
    elif filesize is not None:
        capturekb = os.path.getsize(testout_file) / 1000
        self.assertGreaterEqual(capturekb, filesize)