suite-fileformats.sh 4.64 KB
Newer Older
1 2 3 4 5 6 7 8
#!/bin/bash
#
# Test file format conversions of the Wireshark tools
#
# Wireshark - Network traffic analyzer
# By Gerald Combs <gerald@wireshark.org>
# Copyright 2005 Ulf Lamping
#
9
# SPDX-License-Identifier: GPL-2.0-or-later
10 11 12 13 14 15 16 17
#


# common exit status values
EXIT_OK=0
EXIT_COMMAND_LINE=1
EXIT_ERROR=2

18
TS_FF_ARGS="-Tfields -e frame.number -e frame.time_epoch -e frame.time_delta"
19 20 21 22 23 24

FF_BASELINE=./ff-ts-usec-pcap-direct.txt
DIFF_OUT=./diff-output.txt

# Microsecond pcap / stdin
ff_step_usec_pcap_stdin() {
25
	$TSHARK $TS_FF_ARGS -r - < "${CAPTURE_DIR}dhcp.pcap" > ./ff-ts-usec-pcap-stdin.txt 2> /dev/null
26 27 28 29 30 31 32 33 34 35 36 37
	diff -u $FF_BASELINE ./ff-ts-usec-pcap-stdin.txt > $DIFF_OUT 2>&1
	RETURNVALUE=$?
	if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
		test_step_failed "Output of microsecond pcap direct read vs microsecond pcap via stdin differ"
		cat $DIFF_OUT
		return
	fi
	test_step_ok
}

# Nanosecond pcap / stdin
ff_step_nsec_pcap_stdin() {
38
	$TSHARK $TS_FF_ARGS -r - < "${CAPTURE_DIR}dhcp-nanosecond.pcap" > ./ff-ts-nsec-pcap-stdin.txt 2> /dev/null
39 40 41 42 43 44 45 46 47 48 49 50
	diff -u $FF_BASELINE ./ff-ts-nsec-pcap-stdin.txt > $DIFF_OUT 2>&1
	RETURNVALUE=$?
	if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
		test_step_failed "Output of microsecond pcap direct read vs nanosecond pcap via stdin differ"
		cat $DIFF_OUT
		return
	fi
	test_step_ok
}

# Nanosecond pcap / direct
ff_step_nsec_pcap_direct() {
51
	$TSHARK $TS_FF_ARGS -r "${CAPTURE_DIR}dhcp-nanosecond.pcap" > ./ff-ts-nsec-pcap-direct.txt 2> /dev/null
52 53 54 55 56 57 58 59 60 61
	diff -u $FF_BASELINE ./ff-ts-nsec-pcap-direct.txt > $DIFF_OUT 2>&1
	RETURNVALUE=$?
	if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
		test_step_failed "Output of microsecond pcap direct read vs nanosecond pcap direct read differ"
		cat $DIFF_OUT
		return
	fi
	test_step_ok
}

62
# Microsecond pcapng / stdin
63
ff_step_usec_pcapng_stdin() {
64
	$TSHARK $TS_FF_ARGS -r - < "${CAPTURE_DIR}dhcp.pcapng" > ./ff-ts-usec-pcapng-stdin.txt 2> /dev/null
65 66 67
	diff -u $FF_BASELINE ./ff-ts-usec-pcapng-stdin.txt > $DIFF_OUT 2>&1
	RETURNVALUE=$?
	if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
68
		test_step_failed "Output of microsecond pcap direct read vs microsecond pcapng via stdin differ"
69 70 71 72 73 74
		cat $DIFF_OUT
		return
	fi
	test_step_ok
}

75
# Microsecond pcapng / direct
76
ff_step_usec_pcapng_direct() {
77
	$TSHARK $TS_FF_ARGS -r "${CAPTURE_DIR}dhcp.pcapng" > ./ff-ts-usec-pcapng-direct.txt 2> /dev/null
78 79 80
	diff -u $FF_BASELINE ./ff-ts-usec-pcapng-direct.txt > $DIFF_OUT 2>&1
	RETURNVALUE=$?
	if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
81
		test_step_failed "Output of microsecond pcap direct read vs microsecond pcapng direct read differ"
82 83 84 85 86 87
		cat $DIFF_OUT
		return
	fi
	test_step_ok
}

88
# Nanosecond pcapng / stdin
89
ff_step_nsec_pcapng_stdin() {
90
	$TSHARK $TS_FF_ARGS -r - < "${CAPTURE_DIR}dhcp-nanosecond.pcapng" > ./ff-ts-nsec-pcapng-stdin.txt 2> /dev/null
91 92 93
	diff -u $FF_BASELINE ./ff-ts-nsec-pcapng-stdin.txt > $DIFF_OUT 2>&1
	RETURNVALUE=$?
	if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
94
		test_step_failed "Output of microsecond pcap direct read vs nanosecond pcapng via stdin differ"
95 96 97 98 99 100
		cat $DIFF_OUT
		return
	fi
	test_step_ok
}

101
# Nanosecond pcapng / direct
102
ff_step_nsec_pcapng_direct() {
103
	$TSHARK $TS_FF_ARGS -r "${CAPTURE_DIR}dhcp-nanosecond.pcapng" > ./ff-ts-nsec-pcapng-direct.txt 2> /dev/null
104 105 106
	diff -u $FF_BASELINE ./ff-ts-nsec-pcapng-direct.txt > $DIFF_OUT 2>&1
	RETURNVALUE=$?
	if [ ! $RETURNVALUE -eq $EXIT_OK ]; then
107
		test_step_failed "Output of microsecond pcap direct read vs nanosecond pcapng direct read differ"
108 109 110 111 112 113 114 115 116 117 118
		cat $DIFF_OUT
		return
	fi
	test_step_ok
}

tshark_ff_suite() {
	# Microsecond pcap direct read is used as the baseline.
	test_step_add "Microsecond pcap via stdin" ff_step_usec_pcap_stdin
	test_step_add "Nanosecond pcap via stdin" ff_step_nsec_pcap_stdin
	test_step_add "Nanosecond pcap direct read" ff_step_nsec_pcap_direct
119 120 121 122
	test_step_add "Microsecond pcapng via stdin" ff_step_usec_pcapng_stdin
	test_step_add "Microsecond pcapng direct read" ff_step_usec_pcapng_direct
	test_step_add "Nanosecond pcapng via stdin" ff_step_nsec_pcapng_stdin
	test_step_add "Nanosecond pcapng direct read" ff_step_nsec_pcapng_direct
123 124 125 126 127 128 129 130 131
}

ff_cleanup_step() {
	rm -f ./ff-ts-*.txt
	rm -f $DIFF_OUT
}

ff_prep_step() {
	ff_cleanup_step
132
	$TSHARK $TS_FF_ARGS -r "${CAPTURE_DIR}dhcp.pcap" > $FF_BASELINE 2> /dev/null
133 134 135 136 137 138 139 140 141
}

fileformats_suite() {
	test_step_set_pre ff_prep_step
	test_step_set_post ff_cleanup_step
	test_suite_add "TShark file format conversion" tshark_ff_suite
	#test_suite_add "Wireshark file format" wireshark_ff_suite
	#test_suite_add "Editcap file format" editcap_ff_suite
}
142
#
143 144 145
# Editor modelines  -  http://www.wireshark.org/tools/modelines.html
#
# Local variables:
146
# sh-basic-offset: 8
147 148 149 150
# tab-width: 8
# indent-tabs-mode: t
# End:
#
151
# vi: set shiftwidth=8 tabstop=8 noexpandtab:
152
# :indentSize=8:tabSize=8:noTabs=false:
153
#