Procházet zdrojové kódy

Add option to print verbose

Print non verbose by default as the other ID2T tests. Verbose
printing needs to be enabled in the source files.
dustin.born před 6 roky
rodič
revize
276113a958

+ 8 - 2
code/Test/test_determinism_mmcomm.py

@@ -45,6 +45,8 @@ class PcapComparison(unittest.TestCase):
     DEFAULT_PCAP = "resources/test/Botnet/telnet-raw.pcap"
     DEFAULT_SEED = "42"
 
+    VERBOSE = False
+
     def __init__(self, *args, **kwargs):
         unittest.TestCase.__init__(self, *args, **kwargs)
 
@@ -52,6 +54,7 @@ class PcapComparison(unittest.TestCase):
         # do a round of testing for each list[str] we get
         # if none generate some params itself
         self.id2t_params = None
+        self.printed_newline = False
 
     def set_id2t_params(self, params: "list[list[str]]"):
         self.id2t_params = params
@@ -60,7 +63,6 @@ class PcapComparison(unittest.TestCase):
         self.executions = []
 
     def test_determinism(self):
-        self.print_warning("\n")  # print initial new line
         self.print_warning("Conducting test for determinism of Membership Management Communication Attack:\n")
         input_pcap = os.environ.get(self.PCAP_ENVIRONMENT_VALUE, self.DEFAULT_PCAP)
         seed = os.environ.get(self.SEED_ENVIRONMENT_VALUE, self.DEFAULT_SEED)
@@ -126,7 +128,11 @@ class PcapComparison(unittest.TestCase):
         PcapComparator().compare_files(self.ID2T_PATH + "/" + one, self.ID2T_PATH + "/" + other)
 
     def print_warning(self, *text):
-        print(*text, file=sys.stderr)
+        if self.VERBOSE:
+            if not self.printed_newline:
+                print("\n", file=sys.stderr)
+                self.printed_newline = True
+            print(*text, file=sys.stderr)
 
     def random_id2t_params(self):
         """

+ 7 - 3
code/Test/test_regression_mmcomm.py

@@ -10,11 +10,11 @@ class RegressionTest(unittest.TestCase):
     REGRESSION_DIRECTORY = "../resources/test/Botnet/regression_files"
     REGRESSION_DIRECTORY_ID2T_RELATIVE = "resources/test/Botnet/regression_files"
     ID2T_RELATIVE_TO_LOCAL_PREFIX = "../"
-
+    VERBOSE = False
     META_FILE = "fileinfo.xml"
 
     def test_regression(self):
-        self.print_warning("\n")  # print initial new line
+        self.printed_newline = False
         config_location = self.REGRESSION_DIRECTORY + os.sep + self.META_FILE
         xml_root = xml.etree.ElementTree.parse(config_location).getroot()
         comparator = PcapComparator()
@@ -56,4 +56,8 @@ class RegressionTest(unittest.TestCase):
         self.assertIsNotNone(tag.get(attribute), msg)
 
     def print_warning(self, *text):
-        print(*text, file=sys.stderr)
+        if self.VERBOSE:
+            if not self.printed_newline:
+                print("\n", file=sys.stderr)
+                self.printed_newline = True
+            print(*text, file=sys.stderr)