aboutsummaryrefslogtreecommitdiffstats
path: root/test/suite_sharkd.py
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2018-06-18 11:01:31 -0700
committerAnders Broman <a.broman58@gmail.com>2018-06-21 03:30:30 +0000
commit293be57265da22f18be2d4323a43985908f39e7e (patch)
tree36c1ff162b5c76298607fe6bf09b062e753d2f21 /test/suite_sharkd.py
parent69fc3d8f3a9cdf3cb82b897107da52abda2930d3 (diff)
Test: Add sharkd tests.
Change-Id: I0e5049700ab9285196ce6b4567bd2d034529e763 Reviewed-on: https://code.wireshark.org/review/28327 Reviewed-by: Gerald Combs <gerald@wireshark.org> Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
Diffstat (limited to 'test/suite_sharkd.py')
-rw-r--r--test/suite_sharkd.py72
1 files changed, 72 insertions, 0 deletions
diff --git a/test/suite_sharkd.py b/test/suite_sharkd.py
new file mode 100644
index 0000000000..27eb9d58ce
--- /dev/null
+++ b/test/suite_sharkd.py
@@ -0,0 +1,72 @@
+#
+# -*- coding: utf-8 -*-
+# Wireshark tests
+# By Gerald Combs <gerald@wireshark.org>
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+'''sharkd tests'''
+
+import config
+import json
+import os.path
+import subprocess
+import subprocesstest
+import sys
+import unittest
+
+dhcp_pcap = os.path.join(config.capture_dir, 'dhcp.pcap')
+
+class case_sharkd(subprocesstest.SubprocessTestCase):
+ def test_sharkd_hello_no_pcap(self):
+ '''sharkd hello message, no capture file'''
+ sharkd_proc = self.startProcess((config.cmd_sharkd, '-'),
+ stdin=subprocess.PIPE
+ )
+
+ sharkd_commands = '{"req":"status"}\n'
+ if sys.version_info[0] >= 3:
+ sharkd_commands = sharkd_commands.encode('UTF-8')
+ sharkd_proc.stdin.write(sharkd_commands)
+ self.waitProcess(sharkd_proc)
+
+ self.assertEqual(self.countOutput('Hello in child.', count_stdout=False, count_stderr=True), 1, 'No hello message.')
+
+ try:
+ jdata = json.loads(sharkd_proc.stdout_str)
+ self.assertEqual(jdata['duration'], 0.0, 'Missing duration.')
+ except:
+ self.fail('Invalid JSON: "{}"'.format(sharkd_proc.stdout_str))
+
+ def test_sharkd_hello_dhcp_pcap(self):
+ '''sharkd hello message, simple capture file'''
+ sharkd_proc = self.startProcess((config.cmd_sharkd, '-'),
+ stdin=subprocess.PIPE
+ )
+
+ sharkd_commands = ''
+ sharkd_commands = '{"req":"load","file":' + json.JSONEncoder().encode(dhcp_pcap) + '}\n'
+ sharkd_commands += '{"req":"status"}\n'
+ sharkd_commands += '{"req":"frames"}\n'
+ if sys.version_info[0] >= 3:
+ sharkd_commands = sharkd_commands.encode('UTF-8')
+
+ sharkd_proc.stdin.write(sharkd_commands)
+ self.waitProcess(sharkd_proc)
+
+ has_dhcp = False
+ for line in sharkd_proc.stdout_str.splitlines():
+ line = line.strip()
+ if not line: continue
+ try:
+ jdata = json.loads(line)
+ except:
+ self.fail('Invalid JSON for "{}"'.format(line))
+
+ try:
+ if 'DHCP' in jdata[0]['c']:
+ has_dhcp = True
+ except:
+ pass
+
+ self.assertTrue(has_dhcp, 'Failed to find DHCP in JSON output')