Test: Fix capinfos output and command paths.
authorGerald Combs <gerald@wireshark.org>
Tue, 1 May 2018 16:09:27 +0000 (09:09 -0700)
committerGerald Combs <gerald@wireshark.org>
Tue, 1 May 2018 18:46:13 +0000 (18:46 +0000)
Convert capinfos output to UTF-8 in getCaptureInfo.

Normalize our command paths, otherwise "./run/RelWithDebInfo/..." might
be interpreted as the command "." with flags "/run", "/RelWithDebInfo",
etc. on Windows.

Change-Id: Ib7336a016db3ee0805739fc44913cb9c6895aaad
Reviewed-on: https://code.wireshark.org/review/27239
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
test/config.py
test/subprocesstest.py
test/suite_text2pcap.py

index b38bf7ceb145c736c4905d54cf9a851498b63946..17f9f66677d38e53eef7d454019bc89130f5a2fb 100644 (file)
@@ -149,7 +149,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
index e7b3fa8a201b962268b6abeea884b1df396318b1..837ecfb0aad34e26af2ea5b9cb59ceb5d6f3a643 100644 (file)
@@ -202,8 +202,12 @@ class SubprocessTestCase(unittest.TestCase):
         if capinfos_args is not None:
             capinfos_cmd += capinfos_args
         capinfos_cmd.append(cap_file)
-        capinfos_stdout = str(subprocess.check_output(capinfos_cmd))
-        self.log_fd_write_bytes(capinfos_stdout)
+        capinfos_data = subprocess.check_output(capinfos_cmd)
+        if sys.version_info[0] >= 3:
+            capinfos_stdout = capinfos_data.decode('UTF-8', 'replace')
+        else:
+            capinfos_stdout = unicode(capinfos_data, 'UTF-8', 'replace')
+        self.log_fd.write(capinfos_stdout)
         return capinfos_stdout
 
     def checkPacketCount(self, num_packets, cap_file=None):
index 3ee84f2b131d8e1b5f33fd46447b3434867a0e36..1a1534515fa6d00957533d3a9de542d0d9d27a97 100644 (file)
@@ -78,17 +78,18 @@ def check_capinfos_info(self, cap_file):
     }
     capinfos_out = self.getCaptureInfo(capinfos_args=('-t', '-E', '-c', '-d', '-M'), cap_file=cap_file)
 
-    for sp_key in str_pats:
-        str_pat = '{}:\s+([\S ]+)'.format(str_pats[sp_key])
-        str_res = re.search(str_pat, capinfos_out)
-        self.assertTrue(str_res is not None, 'Failed to generate {}'.format(sp_key))
-        cap_info[sp_key] = str_res.group(1)
-
-    for ip_key in int_pats:
-        int_pat = '{}:\s+(\d+)'.format(int_pats[ip_key])
-        int_res = re.search(int_pat, capinfos_out)
-        self.assertTrue(int_res is not None, 'Failed to generate {}'.format(ip_key))
-        cap_info[ip_key] = int(int_res.group(1))
+    for ci_line in capinfos_out.splitlines():
+        for sp_key in str_pats:
+            str_pat = '{}:\s+([\S ]+)'.format(str_pats[sp_key])
+            str_res = re.search(str_pat, ci_line)
+            if str_res is not None:
+                cap_info[sp_key] = str_res.group(1)
+
+        for ip_key in int_pats:
+            int_pat = '{}:\s+(\d+)'.format(int_pats[ip_key])
+            int_res = re.search(int_pat, ci_line)
+            if int_res is not None:
+                cap_info[ip_key] = int(int_res.group(1))
 
     return cap_info