1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
#
# -*- coding: utf-8 -*-
# Wireshark tests
# By Gerald Combs <gerald@wireshark.org>
#
# Ported from a set of Bash scripts which were copyright 2005 Ulf Lamping
#
# SPDX-License-Identifier: GPL-2.0-or-later
#
'''File format conversion tests'''
import config
import io
import os.path
import subprocesstest
import sys
import unittest
# XXX Currently unused. It would be nice to be able to use this below.
time_output_args = ('-Tfields', '-e', 'frame.number', '-e', 'frame.time_epoch', '-e', 'frame.time_delta')
# Microsecond pcap, direct read was used to generate the baseline:
# tshark -Tfields -e frame.number -e frame.time_epoch -e frame.time_delta \
# -r captures/dhcp.pcap > baseline/ff-ts-usec-pcap-direct.txt
baseline_file = 'ff-ts-usec-pcap-direct.txt'
baseline_fd = io.open(os.path.join(config.baseline_dir, baseline_file), 'r', encoding='UTF-8', errors='replace')
baseline_str = baseline_fd.read()
baseline_fd.close()
class case_fileformat_pcap(subprocesstest.SubprocessTestCase):
def test_pcap_usec_stdin(self):
'''Microsecond pcap direct vs microsecond pcap stdin'''
capture_file = os.path.join(config.capture_dir, 'dhcp.pcap')
capture_proc = self.runProcess(subprocesstest.capture_command(config.cmd_tshark,
'-r', '-',
'-Tfields',
'-e', 'frame.number', '-e', 'frame.time_epoch', '-e', 'frame.time_delta',
'<', capture_file
, shell=True),
shell=True)
self.assertTrue(self.diffOutput(capture_proc.stdout_str, baseline_str, 'tshark', baseline_file))
def test_pcap_nsec_stdin(self):
'''Microsecond pcap direct vs nanosecond pcap stdin'''
capture_file = os.path.join(config.capture_dir, 'dhcp-nanosecond.pcap')
capture_proc = self.runProcess(subprocesstest.capture_command(config.cmd_tshark,
'-r', '-',
'-Tfields',
'-e', 'frame.number', '-e', 'frame.time_epoch', '-e', 'frame.time_delta',
'<', capture_file
, shell=True),
shell=True)
self.assertTrue(self.diffOutput(capture_proc.stdout_str, baseline_str, 'tshark', baseline_file))
def test_pcap_nsec_direct(self):
'''Microsecond pcap direct vs nanosecond pcap direct'''
capture_file = os.path.join(config.capture_dir, 'dhcp-nanosecond.pcap')
capture_proc = self.runProcess(subprocesstest.capture_command(config.cmd_tshark,
'-r', capture_file,
'-Tfields',
'-e', 'frame.number', '-e', 'frame.time_epoch', '-e', 'frame.time_delta',
),
)
self.assertTrue(self.diffOutput(capture_proc.stdout_str, baseline_str, 'tshark', baseline_file))
class case_fileformat_pcapng(subprocesstest.SubprocessTestCase):
def test_pcapng_usec_stdin(self):
'''Microsecond pcap direct vs microsecond pcapng stdin'''
capture_file = os.path.join(config.capture_dir, 'dhcp.pcapng')
capture_proc = self.runProcess(subprocesstest.capture_command(config.cmd_tshark,
'-r', '-',
'-Tfields',
'-e', 'frame.number', '-e', 'frame.time_epoch', '-e', 'frame.time_delta'
'<', capture_file
, shell=True),
shell=True)
self.assertTrue(self.diffOutput(capture_proc.stdout_str, baseline_str, 'tshark', baseline_file))
def test_pcapng_usec_direct(self):
'''Microsecond pcap direct vs microsecond pcapng direct'''
capture_file = os.path.join(config.capture_dir, 'dhcp.pcapng')
capture_proc = self.runProcess(subprocesstest.capture_command(config.cmd_tshark,
'-r', capture_file,
'-Tfields',
'-e', 'frame.number', '-e', 'frame.time_epoch', '-e', 'frame.time_delta',
),
)
self.assertTrue(self.diffOutput(capture_proc.stdout_str, baseline_str, 'tshark', baseline_file))
def test_pcapng_nsec_stdin(self):
'''Microsecond pcap direct vs nanosecond pcapng stdin'''
capture_file = os.path.join(config.capture_dir, 'dhcp-nanosecond.pcapng')
capture_proc = self.runProcess(subprocesstest.capture_command(config.cmd_tshark,
'-r', '-',
'-Tfields',
'-e', 'frame.number', '-e', 'frame.time_epoch', '-e', 'frame.time_delta'
'<', capture_file
, shell=True),
shell=True)
self.assertTrue(self.diffOutput(capture_proc.stdout_str, baseline_str, 'tshark', baseline_file))
def test_pcapng_nsec_direct(self):
'''Microsecond pcap direct vs nanosecond pcapng direct'''
capture_file = os.path.join(config.capture_dir, 'dhcp-nanosecond.pcapng')
capture_proc = self.runProcess(subprocesstest.capture_command(config.cmd_tshark,
'-r', capture_file,
'-Tfields',
'-e', 'frame.number', '-e', 'frame.time_epoch', '-e', 'frame.time_delta',
),
)
self.assertTrue(self.diffOutput(capture_proc.stdout_str, baseline_str, 'tshark', baseline_file))
|