tap2pcap_test.py 1.1 KB

12345678910111213141516171819202122232425262728
  1. """Tests for tap2pcap."""
  2. from __future__ import print_function
  3. import os
  4. import subprocess as sp
  5. import sys
  6. import tap2pcap
  7. # Validate that the tapped trace when run through tap2cap | tshark matches
  8. # a golden output file for the tshark dump. Since we run tap2pcap in a
  9. # subshell with a limited environment, the inferred time zone should be UTC.
  10. if __name__ == '__main__':
  11. srcdir = os.path.join(os.getenv('TEST_SRCDIR'), 'envoy_api')
  12. tap_path = os.path.join(srcdir, 'tools/data/tap2pcap_h2_ipv4.pb_text')
  13. expected_path = os.path.join(srcdir, 'tools/data/tap2pcap_h2_ipv4.txt')
  14. pcap_path = os.path.join(os.getenv('TEST_TMPDIR'), 'generated.pcap')
  15. tap2pcap.tap2pcap(tap_path, pcap_path)
  16. actual_output = sp.check_output(
  17. ['tshark', '-r', pcap_path, '-d', 'tcp.port==10000,http2', '-P'])
  18. with open(expected_path, 'rb') as f:
  19. expected_output = f.read()
  20. if actual_output != expected_output:
  21. print('Mismatch')
  22. print('Expected: %s' % expected_output)
  23. print('Actual: %s' % actual_output)
  24. sys.exit(1)