Browse Source

Improve failure resistance of determinism test

Prior to this commit, the determinism test would fail, if ID2T
could not inject any packets. Now it does not and makes sure
all other runs with the same parameters also don't inject packets.

Additionally, reduce the number of determinism iterations by 1.
dustin.born 6 years ago
parent
commit
be644db152
2 changed files with 19 additions and 8 deletions
  1. 8 1
      code/Test/TestUtil.py
  2. 11 7
      code/Test/test_pcap_comparator.py

+ 8 - 1
code/Test/TestUtil.py

@@ -126,9 +126,13 @@ class ID2TExecution:
 
     def get_files_for_deletion(self):
         self._require_run()
-        return [file for file in self.generated_files if file not in self.keep_files]
+        return [file for file in self.generated_files if file not in self.keep_files and not "No packets were injected." in file]
 
     def _find_pcap(self) -> str:
+        for gen_file in self.generated_files:
+            if "No packets were injected." in gen_file:
+                return "No packets were injected."
+
         return next(file for file in self.generated_files if file.endswith(".pcap"))
 
     def _require_run(self):
@@ -140,6 +144,9 @@ class ID2TExecution:
             id2t_relative = os.path.dirname(self.id2t_path)
 
             for file in self.get_files_for_deletion():
+                if "No packets were injected." in file:
+                    pass
+
                 try:
                     os.unlink(id2t_relative + "/" + file)
                 except: pass

+ 11 - 7
code/Test/test_pcap_comparator.py

@@ -37,7 +37,7 @@ class PcapComparison(unittest.TestCase):
     ID2T_LOCATION = ID2T_PATH + "/" + "id2t"
 
     NUM_ITERATIONS_PER_PARAMS = 3
-    NUM_ITERATIONS = 5
+    NUM_ITERATIONS = 4
 
     PCAP_ENVIRONMENT_VALUE = "ID2T_SRC_PCAP"
     SEED_ENVIRONMENT_VALUE = "ID2T_SEED"
@@ -86,13 +86,17 @@ class PcapComparison(unittest.TestCase):
             self.print_warning(execution.get_output())
 
             pcap = execution.get_pcap_filename()
+
             if generated_pcap is not None:
-                try:
-                    self.compare_pcaps(generated_pcap, pcap)
-                except AssertionError as e:
-                    execution.keep_file(pcap)
-                    self.executions[-2].keep_file(generated_pcap)
-                    raise e
+                if "No packets were injected." in pcap or "No packets were injected." in generated_pcap:
+                    self.assertEqual(pcap, generated_pcap)
+                else:
+                    try:
+                        self.compare_pcaps(generated_pcap, pcap)
+                    except AssertionError as e:
+                        execution.keep_file(pcap)
+                        self.executions[-2].keep_file(generated_pcap)
+                        raise e
             else:
                 generated_pcap = pcap