2 # -*- coding: utf-8 -*-
4 # By Gerald Combs <gerald@wireshark.org>
6 # Ported from a set of Bash scripts which were copyright 2005 Ulf Lamping
8 # SPDX-License-Identifier: GPL-2.0-or-later
10 '''File format conversion tests'''
19 # XXX Currently unused. It would be nice to be able to use this below.
20 time_output_args = ('-Tfields', '-e', 'frame.number', '-e', 'frame.time_epoch', '-e', 'frame.time_delta')
22 # Microsecond pcap, direct read was used to generate the baseline:
23 # tshark -Tfields -e frame.number -e frame.time_epoch -e frame.time_delta \
24 # -r captures/dhcp.pcap > baseline/ff-ts-usec-pcap-direct.txt
25 baseline_file = 'ff-ts-usec-pcap-direct.txt'
26 baseline_fd = io.open(os.path.join(config.baseline_dir, baseline_file), 'r', encoding='UTF-8', errors='replace')
27 baseline_str = baseline_fd.read()
30 class case_fileformat_pcap(subprocesstest.SubprocessTestCase):
31 def test_pcap_usec_stdin(self):
32 '''Microsecond pcap direct vs microsecond pcap stdin'''
33 capture_file = os.path.join(config.capture_dir, 'dhcp.pcap')
34 capture_proc = self.runProcess(subprocesstest.capture_command(config.cmd_tshark,
37 '-e', 'frame.number', '-e', 'frame.time_epoch', '-e', 'frame.time_delta',
41 self.assertTrue(self.diffOutput(capture_proc.stdout_str, baseline_str, 'tshark', baseline_file))
43 def test_pcap_nsec_stdin(self):
44 '''Microsecond pcap direct vs nanosecond pcap stdin'''
45 capture_file = os.path.join(config.capture_dir, 'dhcp-nanosecond.pcap')
46 capture_proc = self.runProcess(subprocesstest.capture_command(config.cmd_tshark,
49 '-e', 'frame.number', '-e', 'frame.time_epoch', '-e', 'frame.time_delta',
53 self.assertTrue(self.diffOutput(capture_proc.stdout_str, baseline_str, 'tshark', baseline_file))
55 def test_pcap_nsec_direct(self):
56 '''Microsecond pcap direct vs nanosecond pcap direct'''
57 capture_file = os.path.join(config.capture_dir, 'dhcp-nanosecond.pcap')
58 capture_proc = self.runProcess(subprocesstest.capture_command(config.cmd_tshark,
61 '-e', 'frame.number', '-e', 'frame.time_epoch', '-e', 'frame.time_delta',
64 self.assertTrue(self.diffOutput(capture_proc.stdout_str, baseline_str, 'tshark', baseline_file))
66 class case_fileformat_pcapng(subprocesstest.SubprocessTestCase):
67 def test_pcapng_usec_stdin(self):
68 '''Microsecond pcap direct vs microsecond pcapng stdin'''
69 capture_file = os.path.join(config.capture_dir, 'dhcp.pcapng')
70 capture_proc = self.runProcess(subprocesstest.capture_command(config.cmd_tshark,
73 '-e', 'frame.number', '-e', 'frame.time_epoch', '-e', 'frame.time_delta'
77 self.assertTrue(self.diffOutput(capture_proc.stdout_str, baseline_str, 'tshark', baseline_file))
79 def test_pcapng_usec_direct(self):
80 '''Microsecond pcap direct vs microsecond pcapng direct'''
81 capture_file = os.path.join(config.capture_dir, 'dhcp.pcapng')
82 capture_proc = self.runProcess(subprocesstest.capture_command(config.cmd_tshark,
85 '-e', 'frame.number', '-e', 'frame.time_epoch', '-e', 'frame.time_delta',
88 self.assertTrue(self.diffOutput(capture_proc.stdout_str, baseline_str, 'tshark', baseline_file))
90 def test_pcapng_nsec_stdin(self):
91 '''Microsecond pcap direct vs nanosecond pcapng stdin'''
92 capture_file = os.path.join(config.capture_dir, 'dhcp-nanosecond.pcapng')
93 capture_proc = self.runProcess(subprocesstest.capture_command(config.cmd_tshark,
96 '-e', 'frame.number', '-e', 'frame.time_epoch', '-e', 'frame.time_delta'
100 self.assertTrue(self.diffOutput(capture_proc.stdout_str, baseline_str, 'tshark', baseline_file))
102 def test_pcapng_nsec_direct(self):
103 '''Microsecond pcap direct vs nanosecond pcapng direct'''
104 capture_file = os.path.join(config.capture_dir, 'dhcp-nanosecond.pcapng')
105 capture_proc = self.runProcess(subprocesstest.capture_command(config.cmd_tshark,
108 '-e', 'frame.number', '-e', 'frame.time_epoch', '-e', 'frame.time_delta',
111 self.assertTrue(self.diffOutput(capture_proc.stdout_str, baseline_str, 'tshark', baseline_file))