GenericTest.py 1.1 KB

123456789101112131415161718192021222324252627282930
  1. import random
  2. import unittest
  3. import inspect
  4. import ID2TLib.Controller as Ctrl
  5. import ID2TLib.TestLibrary as Lib
  6. class GenericTest(unittest.TestCase):
  7. def generic_test(self, attack_args, sha_checksum, seed=5, cleanup=False, pcap=Lib.test_pcap, flag_write_file=False,
  8. flag_recalculate_stats=False, flag_print_statistics=False, attack_sub_dir=True, test_sub_dir=True):
  9. # TODO: move seed to attacks
  10. random.seed(seed)
  11. controller = Ctrl.Controller(pcap_file_path=pcap, do_extra_tests=False)
  12. controller.load_pcap_statistics(flag_write_file, flag_recalculate_stats, flag_print_statistics)
  13. controller.process_attacks(attack_args)
  14. caller_function = inspect.stack()[1].function
  15. try:
  16. self.assertEqual(Lib.get_sha256(controller.pcap_dest_path), sha_checksum)
  17. except self.failureException:
  18. Lib.rename_test_result_files(controller, caller_function, attack_sub_dir, test_sub_dir)
  19. raise
  20. if cleanup:
  21. Lib.clean_up(controller)
  22. else:
  23. Lib.rename_test_result_files(controller, caller_function, attack_sub_dir, test_sub_dir)