GenericTest.py 1.1 KB

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