You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
1.0 KiB
28 lines
1.0 KiB
6 years ago
|
"""Tests for tap2pcap."""
|
||
6 years ago
|
from __future__ import print_function
|
||
7 years ago
|
|
||
|
import os
|
||
|
import subprocess as sp
|
||
|
import sys
|
||
|
|
||
6 years ago
|
import tap2pcap
|
||
7 years ago
|
|
||
6 years ago
|
# Validate that the tapped trace when run through tap2cap | tshark matches
|
||
|
# a golden output file for the tshark dump. Since we run tap2pcap in a
|
||
7 years ago
|
# subshell with a limited environment, the inferred time zone should be UTC.
|
||
|
if __name__ == '__main__':
|
||
|
srcdir = os.path.join(os.getenv('TEST_SRCDIR'), 'envoy_api')
|
||
6 years ago
|
tap_path = os.path.join(srcdir, 'tools/data/tap2pcap_h2_ipv4.pb_text')
|
||
|
expected_path = os.path.join(srcdir, 'tools/data/tap2pcap_h2_ipv4.txt')
|
||
7 years ago
|
pcap_path = os.path.join(os.getenv('TEST_TMPDIR'), 'generated.pcap')
|
||
|
|
||
6 years ago
|
tap2pcap.Tap2Pcap(tap_path, pcap_path)
|
||
6 years ago
|
actual_output = sp.check_output(['tshark', '-r', pcap_path, '-d', 'tcp.port==10000,http2', '-P'])
|
||
7 years ago
|
with open(expected_path, 'r') as f:
|
||
|
expected_output = f.read()
|
||
|
if actual_output != expected_output:
|
||
6 years ago
|
print('Mismatch')
|
||
|
print('Expected: %s' % expected_output)
|
||
|
print('Actual: %s' % actual_output)
|
||
7 years ago
|
sys.exit(1)
|