GenericTest.py 1.2 KB

1234567891011121314151617181920212223242526272829
  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. attack_args[0].append("seed=" + str(seed))
  12. controller.process_attacks(attack_args)
  13. caller_function = inspect.stack()[1].function
  14. try:
  15. self.assertEqual(sha_checksum, Lib.get_sha256(controller.pcap_dest_path))
  16. except self.failureException:
  17. Lib.rename_test_result_files(controller, caller_function, attack_sub_dir, test_sub_dir)
  18. raise
  19. if cleanup:
  20. Lib.clean_up(controller)
  21. else:
  22. Lib.rename_test_result_files(controller, caller_function, attack_sub_dir, test_sub_dir)