test: do not silently ignore feature detection failures
[metze/wireshark/wip.git] / test / config.py
index 51531b866515c222adbbca009b7a691bfe6d75c6..240875140c0622f88a501f7e12d68c7c8a5d0de1 100644 (file)
@@ -9,6 +9,7 @@
 #
 '''Configuration'''
 
+import logging
 import os
 import os.path
 import re
@@ -22,6 +23,7 @@ commands = (
     'dumpcap',
     'mergecap',
     'rawshark',
+    'sharkd',
     'text2pcap',
     'tshark',
     'wireshark',
@@ -46,6 +48,7 @@ args_ping = None
 have_lua = False
 have_nghttp2 = False
 have_kerberos = False
+have_libgcrypt16 = False
 have_libgcrypt17 = False
 
 test_env = None
@@ -63,6 +66,8 @@ key_dir = os.path.join(this_dir, 'keys')
 lua_dir = os.path.join(this_dir, 'lua')
 tools_dir = os.path.join(this_dir, '..', 'tools')
 
+all_groups = []
+
 def canCapture():
     # XXX This appears to be evaluated at the wrong time when called
     # from a unittest.skipXXX decorator.
@@ -89,24 +94,27 @@ def getTsharkInfo():
     global have_lua
     global have_nghttp2
     global have_kerberos
+    global have_libgcrypt16
     global have_libgcrypt17
-    have_lua = False
-    have_nghttp2 = False
-    have_kerberos = False
-    have_libgcrypt17 = False
+    if not cmd_tshark:
+        logging.warning("tshark binary is not yet set")
+        return
     try:
-        tshark_v_blob = str(subprocess.check_output((cmd_tshark, '--version'), stderr=subprocess.PIPE))
-        tshark_v = ' '.join(tshark_v_blob.splitlines())
-        if re.search('with +Lua', tshark_v):
-            have_lua = True
-        if re.search('with +nghttp2', tshark_v):
-            have_nghttp2 = True
-        if re.search('(with +MIT +Kerberos|with +Heimdal +Kerberos)', tshark_v):
-            have_kerberos = True
-        gcry_m = re.search('with +Gcrypt +([0-9]+\.[0-9]+)', tshark_v)
-        have_libgcrypt17 = gcry_m and float(gcry_m.group(1)) >= 1.7
-    except:
-        pass
+        tshark_v = subprocess.check_output(
+            (cmd_tshark, '--version'),
+            stderr=subprocess.PIPE,
+            universal_newlines=True,
+            env={'WIRESHARK_CONFIG_DIR': '/dummy/non/existing'}
+        ).replace('\n', ' ')
+    except subprocess.CalledProcessError as e:
+        logging.warning("Failed to detect tshark features: %s", e)
+        tshark_v = ''
+    have_lua = bool(re.search('with +Lua', tshark_v))
+    have_nghttp2 = bool(re.search('with +nghttp2', tshark_v))
+    have_kerberos = bool(re.search('(with +MIT +Kerberos|with +Heimdal +Kerberos)', tshark_v))
+    gcry_m = re.search('with +Gcrypt +([0-9]+\.[0-9]+)', tshark_v)
+    have_libgcrypt16 = gcry_m and float(gcry_m.group(1)) >= 1.6
+    have_libgcrypt17 = gcry_m and float(gcry_m.group(1)) >= 1.7
 
 def getDefaultCaptureInterface():
     '''Choose a default capture interface for our platform. Currently Windows only.'''
@@ -118,8 +126,12 @@ def getDefaultCaptureInterface():
     if not sys.platform.startswith('win32'):
         return
     try:
-        dumpcap_d_blob = str(subprocess.check_output((cmd_dumpcap, '-D'), stderr=subprocess.PIPE))
-        for d_line in dumpcap_d_blob.splitlines():
+        dumpcap_d_data = subprocess.check_output((cmd_dumpcap, '-D'), stderr=subprocess.PIPE)
+        if sys.version_info[0] >= 3:
+            dumpcap_d_stdout = dumpcap_d_data.decode('UTF-8', 'replace')
+        else:
+            dumpcap_d_stdout = unicode(dumpcap_d_data, 'UTF-8', 'replace')
+        for d_line in dumpcap_d_stdout.splitlines():
             iface_m = re.search('(\d+)\..*(Ethernet|Network Connection|VMware|Intel)', d_line)
             if iface_m:
                 capture_interface = iface_m.group(1)
@@ -149,7 +161,7 @@ def setProgramPath(path):
         dotexe = '.exe'
     for cmd in commands:
         cmd_var = 'cmd_' + cmd
-        cmd_path = os.path.join(path, cmd + dotexe)
+        cmd_path = os.path.normpath(os.path.join(path, cmd + dotexe))
         if not os.path.exists(cmd_path) or not os.access(cmd_path, os.X_OK):
             cmd_path = None
             program_path = None
@@ -168,6 +180,8 @@ def setUpTestEnvironment():
     global conf_path
     global custom_profile_path
     global test_env
+
+    # Create our directories
     test_confdir = tempfile.mkdtemp(prefix='wireshark-tests.')
     home_path = os.path.join(test_confdir, 'home')
     if sys.platform.startswith('win32'):
@@ -180,8 +194,25 @@ def setUpTestEnvironment():
     # Test spaces while we're here.
     custom_profile_path = os.path.join(conf_path, 'profiles', custom_profile_name)
     os.makedirs(custom_profile_path)
+
+    # Populate our UAT files
+    uat_files = [
+        '80211_keys',
+        'dtlsdecrypttablefile',
+        'esp_sa',
+        'ssl_keys',
+        'c1222_decryption_table',
+        'ikev1_decryption_table',
+        'ikev2_decryption_table',
+    ]
+    for uat in uat_files:
+        setUpUatFile(uat)
+
+    # Set up our environment
     test_env = os.environ.copy()
-    test_env['WIRESHARK_RUN_FROM_BUILD_DIRECTORY'] = '1'
+    test_env['WIRESHARK_RUN_FROM_BUILD_DIRECTORY'] = 'True'
+    test_env['WIRESHARK_QUIT_AFTER_CAPTURE'] = 'True'
+    test_env['TZ'] = 'UTC'
     test_env[home_env] = home_path
 
 def setUpUatFile(conf_file):
@@ -225,4 +256,3 @@ if sys.platform.startswith('win32') or sys.platform.startswith('darwin'):
 
 # Initialize ourself.
 getPingCommand()
-setProgramPath(os.path.curdir)