|
@@ -20,6 +20,17 @@ class PcapComparison(unittest.TestCase):
|
|
|
|
|
|
OUTPUT_FILES_PREFIX_LINE = "Output files created:"
|
|
|
|
|
|
+ def __init__(self, *args, **kwargs):
|
|
|
+ unittest.TestCase.__init__(self, *args, **kwargs)
|
|
|
+
|
|
|
+ # params to call id2t with, as a list[list[str]]
|
|
|
+ # do a round of testing for each list[str] we get
|
|
|
+ # if none generate some params itself
|
|
|
+ self.id2t_params = None
|
|
|
+
|
|
|
+ def set_id2t_params(self, params: "list[list[str]]"):
|
|
|
+ self.id2t_params = params
|
|
|
+
|
|
|
def setUp(self):
|
|
|
self.generated_files = []
|
|
|
self.keep_files = []
|
|
@@ -28,7 +39,14 @@ class PcapComparison(unittest.TestCase):
|
|
|
input_pcap = os.environ.get(self.PCAP_ENVIRONMENT_VALUE, self.DEFAULT_PCAP)
|
|
|
seed = os.environ.get(self.SEED_ENVIRONMENT_VALUE, self.DEFAULT_SEED)
|
|
|
|
|
|
- command_args = [self.ID2T_LOCATION, "-i", input_pcap, "--seed", seed, "-a", "MembersMgmtCommAttack"]
|
|
|
+ if self.id2t_params is None:
|
|
|
+ self.id2t_params = self.random_id2t_params()
|
|
|
+
|
|
|
+ for params in self.id2t_params:
|
|
|
+ self.do_test_round(input_pcap, seed, params)
|
|
|
+
|
|
|
+ def do_test_round(self, input_pcap, seed, additional_params):
|
|
|
+ command_args = [self.ID2T_LOCATION, "-i", input_pcap, "--seed", seed, "-a", "MembersMgmtCommAttack"] + additional_params
|
|
|
command = " ".join(map(shlex.quote, command_args))
|
|
|
self.print_warning("The command that gets executed is:", command)
|
|
|
|
|
@@ -44,7 +62,8 @@ class PcapComparison(unittest.TestCase):
|
|
|
|
|
|
pcap = self.find_pcap(files)
|
|
|
if generated_pcap is not None:
|
|
|
- try: self.compare_pcaps(generated_pcap, pcap)
|
|
|
+ try:
|
|
|
+ self.compare_pcaps(generated_pcap, pcap)
|
|
|
except AssertionError as e:
|
|
|
self.keep_files = [generated_pcap, pcap]
|
|
|
raise e
|
|
@@ -52,7 +71,7 @@ class PcapComparison(unittest.TestCase):
|
|
|
generated_pcap = pcap
|
|
|
|
|
|
self.print_warning()
|
|
|
- time.sleep(1) # let some time pass between calls because files are based on the time
|
|
|
+ time.sleep(1) # let some time pass between calls because files are based on the time
|
|
|
|
|
|
def tearDown(self):
|
|
|
self.print_warning("Cleaning up files generated by the test-calls...")
|
|
@@ -109,8 +128,22 @@ class PcapComparison(unittest.TestCase):
|
|
|
def print_warning(self, *text):
|
|
|
print(*text, file=sys.stderr)
|
|
|
|
|
|
+ def random_id2t_params(self):
|
|
|
+ param = lambda key, val: "-p%s=%s" % (str(key), str(val))
|
|
|
+
|
|
|
+ return [
|
|
|
+ []
|
|
|
+ ]
|
|
|
+
|
|
|
if __name__ == "__main__":
|
|
|
+ import sys
|
|
|
+
|
|
|
+ # parameters for this program are interpreted as id2t-parameters
|
|
|
+ id2t_args = sys.argv[1:]
|
|
|
+ comparison = PcapComparison("test_determinism")
|
|
|
+ if id2t_args: comparison.set_id2t_params([id2t_args])
|
|
|
+
|
|
|
suite = unittest.TestSuite()
|
|
|
- suite.addTest(PcapComparison("test_determinism"))
|
|
|
+ suite.addTest(comparison)
|
|
|
|
|
|
unittest.TextTestRunner().run(suite)
|