def test_cfs_config_init_error(caplog): Global.load_config("./configs/default_config.ini") caplog.clear() with patch.object(Global.config, 'get') as mock_config: mock_config.side_effect = Exception("Mock Error") cfs_config = CfsConfig("cfs") assert cfs_config.get_error_count() > 0
def test_set_logger_options_from_config(): Global.load_config('./configs/default_config.ini') with patch('os.makedirs') as mock_makedir: with patch('time.localtime', MagicMock(return_value=time.gmtime(0))): logger.set_logger_options_from_config(Global.config) assert Global.CTF_log_dir == os.path.abspath('./CTF_Results') assert Global.test_log_dir == os.path.abspath('./CTF_Results/Run_01_01_1970_00_00_00') assert Global.CTF_log_dir_file == os.path.abspath('./CTF_Results/Run_01_01_1970_00_00_00/CTF_Log_File.log') mock_makedir.assert_called_with(Global.test_log_dir)
def initialize(self) -> bool: """Initializes the plugin by creating the CfsTimeManager. This method is intended to be called by the plugin manager before the test script runs. """ # ENHANCE - May want to have a single CTF time manager, that allows adding and removal # of pre/post-command callbacks. # When re-adding Trick CFS, the Trick cfs_time_manager should be the only time manager # used. There is a potential that the cfs_time_manager is used instead. Need to figure out # how to select a time manager. Global.set_time_manager(CfsTimeManager(self.targets)) log.info("Initialized CfsPlugin") return True
def _test_instance_inited(): Global.set_time_manager(Mock()) test = Test() status_manager = StatusManager(port=None) script_reader = JSONScriptReader( 'functional_tests/cfe_6_7_tests/cfe_tests/CfeEsTest.json') script_reader.process_tests() script_list = [script_reader.script] status_manager.set_scripts(script_list) instructions = script_reader.script.tests[0].instructions test.instructions = instructions status_manager.start() test.status_manager = status_manager return test
def test_ctf_global_create_arg_parser(): with patch.object(sys, 'argv', [ 'ctf', '--port=1234', '--pluginInfo=./plugins/info', '--config_file=./configs/ci_config.ini' ]): args = Global.create_arg_parser().parse_args() assert not args.scripts assert args.port == 1234 assert args.pluginInfo == './plugins/info' assert args.config_file == './configs/ci_config.ini' with patch.object(sys, 'argv', [ 'ctf', './functional_tests/plugin_tests/test_ctf_basic_example.json', './functional_tests/plugin_tests/test_ctf_intermediate_example.json', './functional_tests/plugin_tests/test_ctf_advanced_example.json' ]): args = Global.create_arg_parser().parse_args() assert len(args.scripts) == 3 assert not args.port assert not args.pluginInfo assert args.config_file == 'configs/default_config.ini'
def test_ccsds_plugin_validate_cfs_ccsds_data(ccsds_plugin_instance, cfs_plugin_instance): """ Test CCSDS plugin validate_cfs_ccsds_data method: Validates the CCSDS data types by sending an empty instance of each command code found in the MID map to CFS. """ with patch('plugins.cfs.pycfs.cfs_controllers.LocalCfsInterface'): if Global.get_time_manager() is None: print("Global.get_time_manager() is None:") cfs_plugin_instance.initialize() Global.plugins_available = {"CFS Plugin": cfs_plugin_instance} cfs_plugin_instance.register_cfs('cfs') with patch('plugins.cfs.cfs_plugin.CfsPlugin.send_cfs_command', return_value=True), \ patch('lib.ctf_global.Global.time_manager.wait', return_value=True): ccsds_plugin_instance.validate_cfs_ccsds_data('cfs')
def on_packet_received(self, mid: int, payload: any) -> None: """ If this is the first time receiving a packet with the given mid then print the value of the mid. """ if not self.has_received_mid[mid]: log.info("Receiving Packet for Data Type: {} with MID: {}".format( type(payload), hex(mid))) # Update the array so that the message is not printed again self.has_received_mid[mid] = True payload_count = len(self.received_mid_packets_dic[mid]) + 1 # Add the received packet to the dictionary under the correct mid packet = Packet(mid, payload, payload_count, Global.get_time_manager().exec_time) self.received_mid_packets_dic[mid].append(packet) self.tlm_has_been_received = True self.unchecked_packet_mids.append(mid)
def write_tlm_log(self, payload, buf, mid): """ Write payload and mid to telemetry log file. if log file does not exist, create one. """ if self.tlm_log_file is None: tlm_log_file_path = os.path.join( Global.current_script_log_dir, self.config.name + "_tlm_msgs.log") self.tlm_log_file = open(tlm_log_file_path, "w+") self.tlm_log_file.write("Time: MID, Data\n") try: self.tlm_log_file.write("{}: {}\n\t{}\n".format( Global.get_time_manager().exec_time, hex(mid), str(payload).replace("\n", "\n\t"))) if self.config.telemetry_debug: self.tlm_log_file.write( " For mid {} Payload length: {} hex values: 0X{}\n". format(hex(mid), len(buf), buf.hex())) except IOError: log.error( "Failed to write telemetry packet received for {}".format( hex(mid))) traceback.format_exc()
def test_ctf_global_load_config(): status = Global.load_config("configs/default_config.ini") assert status assert Global.config assert os.environ['workspace_dir'] == '~/sample_cfs_workspace'
def init_global(): Global.load_config("./configs/default_config.ini")
def cfs_config(): Global.load_config("./configs/default_config.ini") return CfsConfig("cfs")
def init_global(): Global.load_config("./configs/default_config.ini") # Global.plugin_manager is set by PluginManager constructor PluginManager(['plugins'])
def init_global(): Global.load_config("./configs/default_config.ini") Global.set_time_manager(Mock())
def init_global(): Global.load_config('./configs/default_config.ini') time_mgr = MagicMock() time_mgr.exec_time = 1.0 Global.time_manager = time_mgr Global.current_script_log_dir = '.'
def remote_cfs_config(): Global.load_config("./configs/example_configs/cfe_6_7_config_examples.ini") return RemoteCfsConfig("local_ssh")
def init_global(): from lib.ctf_global import Global from lib.logger import set_logger_options_from_config Global.load_config("./configs/default_config.ini") with patch('os.makedirs'): set_logger_options_from_config(Global.config)
def test_ctf_global_load_config_invalid(): # trigger exit call if config files do not exist with patch('lib.ctf_global.sys.exit', side_effect=Exception('mock exit')): with pytest.raises(Exception): Global.load_config('') assert not Global.config
def test_cfs_config_init_invalid(caplog): Global.load_config("./configs/default_config.ini") caplog.clear() cfs_config = CfsConfig("invalid") assert cfs_config.get_error_count() == 1
def test_ctf_global_time_manager(): assert Global.get_time_manager() is None Global.set_time_manager(Mock()) assert Global.get_time_manager() == Global.time_manager
def init_global(): Global.load_config("./configs/default_config.ini") Global.time_manager = Mock() # Global.plugin_manager is set by PluginManager constructor : Global.plugin_manager = self PluginManager(['plugins'])