Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
def _cfs_controller_instance_inited():
    config = CfsConfig("cfs")
    # give the interface something harmless to do
    config.cfs_build_cmd = 'echo "building"'
    config.cfs_run_cmd = 'tail -f /dev/null'
    controller = CfsController(config)
    controller.initialize()
    return controller
Ejemplo n.º 3
0
def test_cccsds_interface_add_cmd_msg_with_command_enums(
        ccsdsinterface_instance):
    """
    Test CCSDSInterface class add_cmd_msg method
    Adds a command message to the internal types,command_enums argument is not None
    """

    config = CfsConfig('cfs')
    reader = CCDDExportReader(config)
    cmd_code = {'cc_name': '', 'cc_value': 0, 'args': []}
    [cls, _] = reader._create_parameterized_type(cmd_code,
                                                 type_id="cc_data_type",
                                                 arg_id="args")
    command_codes = {cmd_code['cc_name']: {"CODE": 0, "ARG_CLASS": cls}}

    command_enums = {'FAKE_MID': 98765}
    assert 'SCH_TT_SEND_HK_MID' not in ccsdsinterface_instance.enum_map

    assert 'FAKE_MID' not in ccsdsinterface_instance.enum_map

    ccsdsinterface_instance.add_cmd_msg(mid_name='SCH_TT_SEND_HK_MID',
                                        mid=10981,
                                        command_code_map=command_codes,
                                        command_enums=command_enums)

    assert 'SCH_TT_SEND_HK_MID' in ccsdsinterface_instance.enum_map

    assert 'FAKE_MID' in ccsdsinterface_instance.enum_map

    assert ccsdsinterface_instance.enum_map['SCH_TT_SEND_HK_MID'] == 10981

    assert ccsdsinterface_instance.enum_map['FAKE_MID'] == 98765
Ejemplo n.º 4
0
def test_ccdd_export_reader_init(ccdd_export_reader, utils):
    """
    Test CCDDExportReader class constructor
    """
    assert not ccdd_export_reader.type_dict
    assert ccdd_export_reader.current_file_name is None
    assert ccdd_export_reader.ctype_structure is ctypes.LittleEndianStructure

    config = CfsConfig("cfs")
    config.endianess_of_target = 'big'
    reader = CCDDExportReader(config)
    assert reader.ctype_structure is ctypes.BigEndianStructure

    utils.clear_log()
    config.endianess_of_target = 'none'
    reader = CCDDExportReader(config)
    assert utils.has_log_level("ERROR")
Ejemplo n.º 5
0
def test_ccdd_export_reader_process_ccsds_get_ccsds_messages_from_dir(
        ccdd_export_reader):
    """
    Test CCDDExportReader class method: get_ccsds_messages_from_dir
    Walks through a directory and parses CCSDS command and telemetry messages and type macros
    from the JSON, as appropriate. Creates and returns dictionaries mapping names to these constructs.
    """
    config = CfsConfig('cfs')
    directory = config.ccsds_data_dir
    mid_map, macro_map = ccdd_export_reader.get_ccsds_messages_from_dir(
        directory)
    assert len(mid_map) > 0
    assert len(macro_map) > 0
Ejemplo n.º 6
0
def test_ccdd_export_reader_process_ccsds_json_file_exception(
        ccdd_export_reader, utils):
    """
    Test CCDDExportReader class method: process_ccsds_json_file  raise exception
    Reads JSON from a single file and, if it matches the filter, parses the contents
    """
    utils.clear_log()
    config = CfsConfig('cfs')
    directory = config.ccsds_data_dir
    json_file = directory + '/auto_cf_CMD.json'
    ccdd_export_reader.process_ccsds_json_file(json_file)

    with patch(
            'plugins.ccsds_plugin.readers.ccdd_export_reader.CCDDExportReader.process_command'
    ) as mock_command:
        mock_command.side_effect = CtfTestError('Mock process_command')
        ccdd_export_reader.process_ccsds_json_file(json_file)
        assert utils.has_log_level("ERROR")
Ejemplo n.º 7
0
def test_cccsds_interface_add_telem_msg(ccsdsinterface_instance):
    """
    Test CCSDSInterface class add_telem_msg: Adds a telemetry message to the internal types
    """

    config = CfsConfig('cfs')
    reader = CCDDExportReader(config)
    json_dict = {
        'tlm_mid_name': 'CI_OUT_DATA_MID',
        'tlm_description': '',
        'tlm_data_type': 'CI_OutData_t',
        'tlm_parameters': []
    }

    param_class, _ = reader._create_parameterized_type(json_dict,
                                                       type_id="tlm_data_type",
                                                       arg_id="tlm_parameters")
    tlm_enums = {'FAKE_MID': 98765}

    assert 'CI_OUT_DATA_MID' not in ccsdsinterface_instance.enum_map

    assert 'FAKE_MID' not in ccsdsinterface_instance.enum_map

    assert 'CI_OUT_DATA_MID' not in ccsdsinterface_instance.mid_map

    ccsdsinterface_instance.add_telem_msg(mid_name='CI_OUT_DATA_MID',
                                          mid=10757,
                                          name='CI_OutData_t',
                                          parameters=param_class,
                                          parameter_enums=tlm_enums)

    assert 'CI_OUT_DATA_MID' in ccsdsinterface_instance.enum_map

    assert 'FAKE_MID' in ccsdsinterface_instance.enum_map

    assert 'CI_OUT_DATA_MID' in ccsdsinterface_instance.mid_map

    assert ccsdsinterface_instance.enum_map['CI_OUT_DATA_MID'] == 10757

    assert ccsdsinterface_instance.enum_map['FAKE_MID'] == 98765

    assert ccsdsinterface_instance.mid_map['CI_OUT_DATA_MID']['MID'] == 10757
Ejemplo n.º 8
0
def test_ccdd_export_reader_process_ccsds_json_file_invalid_file(
        ccdd_export_reader, utils):
    """
    Test CCDDExportReader class method: process_ccsds_json_file  process invalid file
    Reads JSON from a single file and, if it matches the filter, parses the contents
    """
    utils.clear_log()
    config = CfsConfig('cfs')
    directory = config.ccsds_data_dir
    json_file = directory + '/auto_cf_CMD.json'
    ccdd_export_reader.process_ccsds_json_file(json_file)
    json_file = directory + '/auto_ci_CMD.json'
    ccdd_export_reader.process_ccsds_json_file(json_file)
    invalid_file = directory + '/invalid.json'
    echo_cmd = "echo 'invalid file' >> {}".format(invalid_file)
    rm_cmd = "rm {}".format(invalid_file)
    os.system(echo_cmd)
    ccdd_export_reader.process_ccsds_json_file(invalid_file)
    os.system(rm_cmd)
    assert utils.has_log_level("ERROR")
Ejemplo n.º 9
0
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
Ejemplo n.º 10
0
Archivo: conftest.py Proyecto: nasa/CTF
def cfs_config():
    Global.load_config("./configs/default_config.ini")
    return CfsConfig("cfs")
Ejemplo n.º 11
0
Archivo: conftest.py Proyecto: nasa/CTF
def _ccsdsinterface_instance():
    # need to pass CfsController.config to config argument self.ccsds_reader = CCDDExportReader(self.config)
    config = CfsConfig("cfs")
    return CCSDSInterface(config=config)
Ejemplo n.º 12
0
def _ccdd_export_reader_instance():
    config = CfsConfig("cfs")
    return CCDDExportReader(config)