|
@@ -2,6 +2,7 @@ import inspect
|
|
|
import unittest
|
|
|
|
|
|
import scapy.utils as pcr
|
|
|
+import memory_profiler as memprof
|
|
|
|
|
|
import Core.Controller as Ctrl
|
|
|
import ID2TLib.TestLibrary as Lib
|
|
@@ -54,7 +55,7 @@ class ID2TAttackTest(unittest.TestCase):
|
|
|
flag_write_file=False, flag_recalculate_stats=False, flag_print_statistics=False,
|
|
|
attack_sub_dir=True, test_sub_dir=True):
|
|
|
"""
|
|
|
- Runs the attack with given aruments and monitors time efficiency.
|
|
|
+ Runs the attack with given arguments and monitors time efficiency.
|
|
|
|
|
|
:param attack_args: A list of attacks with their attack parameters (as defined in Controller.process_attacks).
|
|
|
:param time_limit: The given time limit in seconds.
|
|
@@ -152,3 +153,35 @@ class ID2TAttackTest(unittest.TestCase):
|
|
|
Lib.clean_up(controller)
|
|
|
else:
|
|
|
Lib.rename_test_result_files(controller, caller_function, attack_sub_dir, test_sub_dir)
|
|
|
+
|
|
|
+ def memory_test(self, attack_args, seed=None, cleanup=True, pcap=Lib.test_pcap,
|
|
|
+ flag_write_file=False, flag_recalculate_stats=False, flag_print_statistics=False,
|
|
|
+ attack_sub_dir=True, test_sub_dir=True):
|
|
|
+ """
|
|
|
+ Runs the attack with given arguments and monitors memory usage.
|
|
|
+
|
|
|
+ :param attack_args: A list of attacks with their attack parameters (as defined in Controller.process_attacks).
|
|
|
+ :param seed: A random seed to keep random values static (care for count and order of random generation).
|
|
|
+ :param cleanup: Clean up attack output after testing.
|
|
|
+ :param pcap: The input pcap for the attack.
|
|
|
+ :param flag_write_file: Writes the statistics to a file.
|
|
|
+ :param flag_recalculate_stats: Forces the recalculation of statistics.
|
|
|
+ :param flag_print_statistics: Prints the statistics on the terminal.
|
|
|
+ :param attack_sub_dir: create sub-directory for each attack-class if True
|
|
|
+ :param test_sub_dir: create sub-directory for each test-function/case if True
|
|
|
+ """
|
|
|
+
|
|
|
+ controller = Ctrl.Controller(pcap_file_path=pcap, do_extra_tests=False)
|
|
|
+ controller.load_pcap_statistics(flag_write_file, flag_recalculate_stats, flag_print_statistics)
|
|
|
+ controller.process_attacks(attack_args, [[seed]])
|
|
|
+
|
|
|
+ mem_usage = memprof.memory_usage()
|
|
|
+ print(attack_args[0][0] + ' uses: ' + str(mem_usage[0]) + ' MB of memory')
|
|
|
+
|
|
|
+ caller_function = inspect.stack()[1].function
|
|
|
+
|
|
|
+
|
|
|
+ if cleanup:
|
|
|
+ Lib.clean_up(controller)
|
|
|
+ else:
|
|
|
+ Lib.rename_test_result_files(controller, caller_function, attack_sub_dir, test_sub_dir)
|