3 # By Gerald Combs <gerald@wireshark.org>
5 # Ported from a set of Bash scripts which were copyright 2005 Ulf Lamping
7 # SPDX-License-Identifier: GPL-2.0-or-later
26 capture_interface = None
40 have_libgcrypt17 = False
45 this_dir = os.path.dirname(__file__)
46 baseline_dir = os.path.join(this_dir, 'baseline')
47 capture_dir = os.path.join(this_dir, 'captures')
48 config_dir = os.path.join(this_dir, 'config')
49 key_dir = os.path.join(this_dir, 'keys')
50 lua_dir = os.path.join(this_dir, 'lua')
53 return can_capture and capture_interface is not None
55 def setCanCapture(new_cc):
58 def setCaptureInterface(iface):
59 global capture_interface
60 capture_interface = iface
63 return not sys.platform.startswith('win32')
66 if sys.platform.startswith('win32') or sys.platform.startswith('darwin'):
68 # Qt requires XKEYBOARD and Xrender, which Xvnc doesn't provide.
75 global have_libgcrypt17
79 have_libgcrypt17 = False
81 tshark_v_blob = str(subprocess.check_output((cmd_tshark, '--version'), stderr=subprocess.PIPE))
82 tshark_v = ' '.join(tshark_v_blob.splitlines())
83 if re.search('with +Lua', tshark_v):
85 if re.search('with +nghttp2', tshark_v):
87 if re.search('(with +MIT +Kerberos|with +Heimdal +Kerberos)', tshark_v):
89 gcry_m = re.search('with +Gcrypt +([0-9]+\.[0-9]+)', tshark_v)
90 have_libgcrypt = gcry_m and float(gcry_m.group(1)) >= 1.7
94 def getDefaultCaptureInterface():
95 '''Choose a default capture interface for our platform. Currently Windows only.'''
96 global capture_interface
99 if cmd_dumpcap is None:
101 if not sys.platform.startswith('win32'):
104 dumpcap_d = subprocess.check_output((cmd_dumpcap, '-D'), stderr=subprocess.PIPE)
105 for d_line in dumpcap_d.splitlines():
106 iface_m = re.search('(\d+)\..*(Ethernet|Network Connection|VMware|Intel)', d_line)
108 capture_interface = iface_m.group(1)
113 def getPingCommand():
114 '''Return an argument list required to ping www.wireshark.org for 60 seconds.'''
116 # XXX The shell script tests swept over packet sizes from 1 to 240 every 0.25 seconds.
117 if sys.platform.startswith('win32'):
118 # XXX Check for psping? https://docs.microsoft.com/en-us/sysinternals/downloads/psping
119 args_ping = ('ping', '-n', '60', '-l', '100', 'www.wireshark.org')
120 elif sys.platform.startswith('linux') or sys.platform.startswith('freebsd'):
121 args_ping = ('ping', '-c', '240', '-s', '100', '-i', '0.25', 'www.wireshark.org')
122 elif sys.platform.startswith('darwin'):
123 args_ping = ('ping', '-c', '1', '-g', '1', '-G', '240', '-i', '0.25', 'www.wireshark.org')
124 # XXX Other BSDs, Solaris, etc
126 def setProgramPath(path):
131 if sys.platform.startswith('win32'):
134 cmd_var = 'cmd_' + cmd
135 cmd_path = os.path.join(path, cmd + dotexe)
136 if not os.path.exists(cmd_path) or not os.access(cmd_path, os.X_OK):
139 globals()[cmd_var] = cmd_path
141 getDefaultCaptureInterface()
144 def testEnvironment():
147 def setUpTestEnvironment():
151 test_confdir = tempfile.mkdtemp(prefix='wireshark-tests.')
152 home_path = os.path.join(test_confdir, 'home')
153 if sys.platform.startswith('win32'):
155 conf_path = os.path.join(home_path, 'Wireshark')
158 conf_path = os.path.join(home_path, '.config', 'wireshark')
159 os.makedirs(conf_path)
160 test_env = os.environ.copy()
161 test_env[home_env] = home_path
163 def setUpConfigFile(conf_file):
166 if home_path is None or conf_path is None:
167 setUpTestEnvironment()
168 template = os.path.join(os.path.dirname(__file__), 'config', conf_file) + '.tmpl'
169 with open(template, 'r') as tplt_fd:
170 tplt_contents = tplt_fd.read()
172 key_dir_path = os.path.join(key_dir, '')
173 # uat.c replaces backslashes...
174 key_dir_path = key_dir_path.replace('\\', '\\x5c')
175 cf_contents = tplt_contents.replace('TEST_KEYS_DIR', key_dir_path)
176 out_file = os.path.join(conf_path, conf_file)
177 with open(out_file, 'w') as cf_fd:
178 cf_fd.write(cf_contents)
181 if sys.platform.startswith('win32') or sys.platform.startswith('darwin'):
184 # Initialize ourself.
186 setProgramPath(os.path.curdir)